Extending SIR epidemic model with a quarantined/immunised state

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Extending SIR epidemic model with a quarantined/immunised state

Edwin Lock
Dear All,

I recently started looking into graph-tool because I was looking for a fast graph library to implement an SIR epidemic model. To my delight, I discovered that graph-tool has extremely fast epidemic models implemented already.

My issue is that I wish to study the effects of immunising/quarantining individuals on the overall spread of the disease and am looking for a way to extend graph-tool’s model to achieve this. In particular, I wish to be able to quarantine people for a fixed amount of time (or indefinitely in the case of immunisation).

Initially, I thought I would be able maintain who is quarantined (and for how long) with a vertex property map and filter the quarantined individuals out from the network using a vertex filter. However, I noticed that the iterate_sync() function, which iterates the model by one time step, seems to ignore vertex filters. In particular, if I filter out all infected individuals, it will still infect new people.

My second idea was to directly edit the vertex property maps that store the state of each individual in the graph (susceptible, infected and recovered), and introduce an additional ‘immunised’ state (with value 4, say). However, I have noticed that changing the values of instance.s and instance.s_copy does not seem to have any effect on iterate_sync(). In particular, if I mark everyone as susceptible and thus nobody as infected, it still infects new people in the next time step when I call iterate_sync(). So I am assuming that the state is also stored elsewhere?

Any pointers that might help me extend graph-tool’s SIR model to incorporate quarantining/immunising would be greatly appreciated. I have tried implementing my own model from scratch, but it is significantly slower.

Best regards,
Edwin
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: Extending SIR epidemic model with a quarantined/immunised state

Tiago Peixoto
Administrator
Am 09.04.20 um 22:24 schrieb Edwin Lock:
> Initially, I thought I would be able maintain who is quarantined (and for how long) with a vertex property map and filter the quarantined individuals out from the network using a vertex filter. However, I noticed that the iterate_sync() function, which iterates the model by one time step, seems to ignore vertex filters. In particular, if I filter out all infected individuals, it will still infect new people.

Using the epidemic models on filtered graphs should work. Maybe you
should try explaining in more detail how you are doing it so we can see
what the problem may be.

> My second idea was to directly edit the vertex property maps that store the state of each individual in the graph (susceptible, infected and recovered), and introduce an additional ‘immunised’ state (with value 4, say). However, I have noticed that changing the values of instance.s and instance.s_copy does not seem to have any effect on iterate_sync(). In particular, if I mark everyone as susceptible and thus nobody as infected, it still infects new people in the next time step when I call iterate_sync(). So I am assuming that the state is also stored elsewhere?

Indeed this approach will not work so well, as the logic of the dynamics
only differentiates between three states, not four.

> Any pointers that might help me extend graph-tool’s SIR model to incorporate quarantining/immunising would be greatly appreciated. I have tried implementing my own model from scratch, but it is significantly slower.

As mentioned above, filtered graphs should work. In addition, the SIR
model allows for different transmission probabilities on each edge, by
passing an edge property map as the 'beta' parameter, which you can set
to zero for the edges incident on quarantined nodes. If these change
over time, don't forget to pass the 'constant_beta=False' option as well.

Best,
Tiago

--
Tiago de Paula Peixoto <[hidden email]>


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool

signature.asc (849 bytes) Download Attachment
--
Tiago de Paula Peixoto <tiago@skewed.de>
Reply | Threaded
Open this post in threaded view
|

Re: Extending SIR epidemic model with a quarantined/immunised state

Edwin Lock
In reply to this post by 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)

# TEST:
print("before quarantining:\n", state.a)
# Quarantine all infected individuals
quarantined.a = (state.a == 1)
# Run model one time step
model.iterate_sync()
# New nodes in the filtered graph are infected (with some probability):
print("filtered state after quarantining:\n", state.fa)

For completeness, here is the complete code of my extended model: https://gist.github.com/edwinlock/ccece9b82d13383ef50df8b6e5aedf60

Another question: I want to stop quarantined people from infecting others, but I do want them to recover with the same probability as non-quarantined 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?

Best,
Edwin


> On 9 Apr 2020, at 22:23, [hidden email] wrote:
>
> Date: Thu, 9 Apr 2020 23:23:07 +0200
> From: Tiago de Paula Peixoto <[hidden email] <mailto:[hidden email]>>
> To: [hidden email] <mailto:[hidden email]>
> Subject: Re: [graph-tool] Extending SIR epidemic model with a
> quarantined/immunised state
> Message-ID: <[hidden email] <mailto:[hidden email]>>
> Content-Type: text/plain; charset="utf-8"
>
> Am 09.04.20 um 22:24 schrieb Edwin Lock:
>> Initially, I thought I would be able maintain who is quarantined (and for how long) with a vertex property map and filter the quarantined individuals out from the network using a vertex filter. However, I noticed that the iterate_sync() function, which iterates the model by one time step, seems to ignore vertex filters. In particular, if I filter out all infected individuals, it will still infect new people.
>
> Using the epidemic models on filtered graphs should work. Maybe you
> should try explaining in more detail how you are doing it so we can see
> what the problem may be.
>
>> My second idea was to directly edit the vertex property maps that store the state of each individual in the graph (susceptible, infected and recovered), and introduce an additional ?immunised? state (with value 4, say). However, I have noticed that changing the values of instance.s and instance.s_copy does not seem to have any effect on iterate_sync(). In particular, if I mark everyone as susceptible and thus nobody as infected, it still infects new people in the next time step when I call iterate_sync(). So I am assuming that the state is also stored elsewhere?
>
> Indeed this approach will not work so well, as the logic of the dynamics
> only differentiates between three states, not four.
>
>> Any pointers that might help me extend graph-tool?s SIR model to incorporate quarantining/immunising would be greatly appreciated. I have tried implementing my own model from scratch, but it is significantly slower.
>
> As mentioned above, filtered graphs should work. In addition, the SIR
> model allows for different transmission probabilities on each edge, by
> passing an edge property map as the 'beta' parameter, which you can set
> to zero for the edges incident on quarantined nodes. If these change
> over time, don't forget to pass the 'constant_beta=False' option as well.
>
> Best,
> Tiago

_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: Extending SIR epidemic model with a quarantined/immunised state

Tiago Peixoto
Administrator
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 non-quarantined 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

--
Tiago de Paula Peixoto <[hidden email]>


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool

signature.asc (849 bytes) Download Attachment
--
Tiago de Paula Peixoto <tiago@skewed.de>