Skip to content

Add logging and data collection for network rewiring and homophily actions #39

@lamurian

Description

@lamurian

User Story

As a developer, I want to log network rewiring and homophily actions at both the agent and model levels so that I can analyze how frequently agents adapt their social connections and how these dynamics affect collective stress and resilience patterns.

Description

The current model does not track how often agents perform network rewiring (_rewire_to_similar_agent()) or network homophily adaptation (_adapt_network()). These mechanisms play a crucial role in social structure evolution and should be logged systematically for both individual agents and the overall model. The logs should integrate seamlessly into the existing Mesa DataCollector in src/python/model.py, allowing access to both per-agent and aggregate metrics.

Proposed Flow

  • Update src/python/agent.py:

    • In the Person class:
      • Add counters for rewiring and homophily actions:
        self.rewire_count = 0
        self.homophily_count = 0
      • Increment rewire_count inside _rewire_to_similar_agent()
      • Increment homophily_count inside _adapt_network()
    • Optionally reset or aggregate counts per simulation step depending on analysis needs
  • Update src/python/model.py:

    • Extend Mesa DataCollector configuration to include:
      agent_reporters={
          "RewireCount": "rewire_count",
          "HomophilyCount": "homophily_count",
          ...
      },
      model_reporters={
          "TotalRewires": lambda m: sum(a.rewire_count for a in m.schedule.agents),
          "TotalHomophily": lambda m: sum(a.homophily_count for a in m.schedule.agents),
          "MeanRewires": lambda m: np.mean([a.rewire_count for a in m.schedule.agents]),
          "MeanHomophily": lambda m: np.mean([a.homophily_count for a in m.schedule.agents]),
          ...
      }
    • Ensure the data collector collects this information every simulation step
  • Testing:

    • Verify that rewire_count and homophily_count increase when corresponding methods are called
    • Confirm data collector captures these values at both agent and model levels
    • Check consistency of aggregation in model reporters (sum/mean values)

Reference

  • src/python/agent.py_rewire_to_similar_agent() and _adapt_network() methods in Person class
  • src/python/model.py → Mesa DataCollector configuration

Notes:

  • Keep logging lightweight to avoid simulation slowdowns.
  • Consider resetting per-day counters if daily aggregation is desired.
  • Ensure compatibility with existing data collection pipeline and output formats.
  • This enhancement enables quantitative analysis of network evolution in response to affect and stress dynamics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions