Hi Tiago,
Thanks again for your helpful reply. I have now changed my approach to modifying the beta parameter instead, as you suggested in your previous reply. However, I’m still running into unexpected behaviour. I would expect that I can change the beta parameters after the model is instantiated, to modify the progress of infection between iterations of the model; at least that is what I thought the constant_beta flag is for. However, it seems that the model ignores any changes that I make to the beta map after instantiating. What am I doing or understanding wrong? Here’s my minimum working example (adapted to the new approach), where I set beta to 0 for all edges but new infections still happen. # SETUP from graph_tool.generation import price_network from graph_tool.dynamics import SIRSState g = price_network(20, directed=False) # Initialise beta map with transmission probability 1 for all edges beta_map = g.new_edge_property('float', 1) model = SIRSState(g, beta=beta_map, r=0, constant_beta=False) # ensure no spontaneous infections state = model.get_state() # TEST print("before quarantining:\n", state.a) # Set transmission probability to 0 for all edges beta_map.a = 0 # Run model one time step model.iterate_sync() # New nodes in the filtered graph are infected print("filtered state after quarantining:\n", state.a) Essentially, I am looking for some way to isolate vertices and ensure they cannot infect others. On a related note, I am running into issues implementing the following subroutine efficiently: for a list of vertices (as a numpy integer array), determine the indices of all edges in the graph incident to at least one of the vertices in the list. Here the index is w.r.t. edge property maps. Is there an efficient way using a graphtool function that I’m missing? Many thanks for all your help. Best, Edwin > On 10 Apr 2020, at 18:01, [hidden email] wrote: > > > Message: 1 > Date: Fri, 10 Apr 2020 12:04:34 +0200 > From: Tiago de Paula Peixoto <[hidden email]> > To: [hidden email] > Subject: Re: [graphtool] Extending SIR epidemic model with a > quarantined/immunised state > MessageID: <[hidden email]> > ContentType: text/plain; charset="utf8" > > Am 10.04.20 um 09:54 schrieb Edwin Lock: >> Thanks for getting back to me so quickly! >> >> I have a ?quarantined? vertex property map that maintains who is quarantined and have set a vertex filter on the graph to filter out quarantined people. Quarantined people are not supposed to be able to infect others. >> >> Here is a minimum working example where I quarantine all infected people from the graph but new people are infected in the next time step. >> >> # SETUP >> from graph_tool.generation import price_network >> from graph_tool.dynamics import SIRSState >> g = price_network(20) >> model = SIRSState(g, r=0) # make sure there are no spontaneous infections >> state = model.get_state() >> # Keep track of who is quarantined >> quarantined = g.new_vertex_property('bool', False) >> # Filter out quarantined nodes from graph >> g.set_vertex_filter(quarantined, inverted=True) > > I imagined you were maybe doing it like this... Indeed, the SIRSState > keeps track of the original unfiltered graph. > > What you need to do is to set the filter before you create the > SIRSState, and it should work as you are expecting. > >> Another question: I want to stop quarantined people from infecting others, but I do want them to recover with the same probability as nonquarantined people. In this case it makes sense to use an edge filter to remove all edges adjacent to a quarantined person >> instead of filtering the person?s vertex itself, right? > > Yes, this would be the correct approach. It would also be equivalent to > modifying the beta parameter as I described previously. > > Best, > Tiago _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool 
Administrator

Am 10.04.20 um 22:29 schrieb Edwin Lock:
> Hi Tiago, > > Thanks again for your helpful reply. I have now changed my approach to modifying the beta parameter instead, as you suggested in your previous reply. However, I’m still running into unexpected behaviour. > > I would expect that I can change the beta parameters after the model is instantiated, to modify the progress of infection between iterations of the model; at least that is what I thought the constant_beta flag is for. However, it seems that the model ignores any changes that I make to the beta map after instantiating. What am I doing or understanding wrong? > > Here’s my minimum working example (adapted to the new approach), where I set beta to 0 for all edges but new infections still happen. > > # SETUP > from graph_tool.generation import price_network > from graph_tool.dynamics import SIRSState > g = price_network(20, directed=False) > # Initialise beta map with transmission probability 1 for all edges > beta_map = g.new_edge_property('float', 1) > model = SIRSState(g, beta=beta_map, r=0, > constant_beta=False) # ensure no spontaneous infections > state = model.get_state() > > # TEST > print("before quarantining:\n", state.a) > # Set transmission probability to 0 for all edges > beta_map.a = 0 > # Run model one time step > model.iterate_sync() > # New nodes in the filtered graph are infected > print("filtered state after quarantining:\n", state.a) > > Essentially, I am looking for some way to isolate vertices and ensure they cannot infect others. This is in fact a bug with constant_beta=False: for efficiency, the state keeps track of the total transmission probability per node, separately from what beta says. So the change in beta will take effect only the next time a node is infected. So for now you will have to reinitialize the state every time you change beta (or filter the graph), until I fix things for the next release. > On a related note, I am running into issues implementing the following subroutine efficiently: for a list of vertices (as a numpy integer array), determine the indices of all edges in the graph incident to at least one of the vertices in the list. Here the index is w.r.t. edge property maps. Is there an efficient way using a graphtool function that I’m missing? You can get something similar to this by marking the nodes with a boolean property map and then calling edge_endpoint_property() which will mark the incident edges. Best, Tiago  Tiago de Paula Peixoto <[hidden email]> _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool

Tiago de Paula Peixoto <tiago@skewed.de> 
Free forum by Nabble  Edit this page 