LABSS/PyPROTON-OC

Too many agents in the meta graph

Closed this issue · 1 comments

def update_meta_links(self, agents: Set[Person]) -> None:
"""
This method creates a new temporary graph that is used to colculate the
oc_embeddedness of an agent.
:param agents: Set[Person], the agentset
:return: None
"""
for agent in agents:
self.meta_graph.add_node(agent.unique_id)
for in_radius_agent in agent.agents_in_radius(
1): # limit the context to the agents in the radius of interest
self.meta_graph.add_node(in_radius_agent.unique_id)
w = 0
for net in Person.network_names:
if in_radius_agent in agent.neighbors.get(net):
if net == "criminal":
if in_radius_agent in agent.num_co_offenses:
w += agent.num_co_offenses[in_radius_agent]
else:
w += 1
self.meta_graph.add_edge(agent.unique_id, in_radius_agent.unique_id, weight=1 / w)

Line 1539 should be:

for in_radius_agent in [i for i in agent.agents_in_radius(1) if i in agents and i != agent]:
    self.meta_graph.add_node(in_radius_agent.unique_id)

Why is this a problem?

     def update_meta_links(self, agents: Set[Person]) -> None: 
         for agent in agents: 
             self.meta_graph.add_node(agent.unique_id) 
             for in_radius_agent in agent.agents_in_radius( 
                     1):  # limit the context to the agents in the radius of interest 
                 self.meta_graph.add_node(in_radius_agent.unique_id) 
                 w = 0 
                 for net in Person.network_names: 
                     if in_radius_agent in agent.neighbors.get(net): 
                         if net == "criminal": 
                             if in_radius_agent in agent.num_co_offenses: 
                                 w += agent.num_co_offenses[in_radius_agent] 
                         else: 
                             w += 1 
                 self.meta_graph.add_edge(agent.unique_id, in_radius_agent.unique_id, weight=1 / w) 

Referring to the above routine. In order to build the meta_graph, we iteratively pick an agent in agents list (the argument of the update_meta_links fucntion) and we draw a link between this agent and all the agents in radius 1.
The problems here are 2:

  1. Not all the agents in agents list are in radius 1 because this depends on the attribute oc_embeddedness_radius that by default is 2.
  2. Not all the agents in radius 1 are included in agents. This creates wrong meta_links, that are unnecessary to calculate oc_embeddedness and then slow down the entire model.

Solution:
Limits the agents to include in the meta_graph, by excluding agent that are not present in agents argument.

for in_radius_agent in [i for i in agent.agents_in_radius(1) if i in agents and i != agent]:
    self.meta_graph.add_node(in_radius_agent.unique_id)