Move virus_on_a_network to discrete_space#2688
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
Performance benchmarks:
|
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
EwoutH
left a comment
There was a problem hiding this comment.
Looks good, one potential improvement comment and one potential follow-up.
| infected_nodes = CellCollection( | ||
| self.random.sample(list(self.grid.all_cells), self.initial_outbreak_size), | ||
| random=self.random, | ||
| ) |
There was a problem hiding this comment.
Non blocking, but might be interesting if we can make this API-wise a bit cleaner.
There was a problem hiding this comment.
Not sure what you are suggesting. I could rewrite the example to not use a CellCollection, but this kept the code closer to the original code and illustrates how users can create their own CellCollection.
infected_nodes = self.random.sample(list(self.grid.all_cells), self.initial_outbreak_size)
for node in infected_nodes:
for agent in node.agents
a.state = State.INFECTED| for agent in self.cell.neighborhood.agents: | ||
| if (agent.state is State.SUSCEPTIBLE) and ( | ||
| self.random.random() < self.virus_spread_chance | ||
| ): |
There was a problem hiding this comment.
Can we use agents.select() for this?
There was a problem hiding this comment.
No. cell.neighborhood.agents is a list, not an AgentSet. I have tested changing this in discrete_space to agentset and it results in massive performance loss.
This moves virus_on_a_network to discrete_space and cleans up the code.