springer-math / Mathematics-of-Epidemics-on-Networks

Source code accompanying 'Mathematics of Epidemics on Networks' by Kiss, Miller, and Simon http://www.springer.com/us/book/9783319508047 . Documentation for the software package is at https://epidemicsonnetworks.readthedocs.io/en/latest/
MIT License
150 stars 61 forks source link

Dynamic Networks #60

Closed gaianoseworthy closed 4 years ago

gaianoseworthy commented 4 years ago

Is it possible for EoN to work with dynamic networks? Either through major modifications of the "agent" network or through the DyNetX package?

joelmiller commented 4 years ago

At the moment, it's just using networkx graphs, which are static. There are two ideas of how it could work on a dynamic network:

gaianoseworthy commented 4 years ago

Thank you for your quick replies! My apologies for reopening this issue, but I have a few more questions that I felt would fit best here!

I've been thinking about this further, with your reply (and some discussion with the developer of Epydemic as well) in mind, and I have the following idea:

Let's say we wanted to define the simulation with 2 main "states", one of which is a "weekday" state where people are connected with their homes and workplaces, and one is a "weekend / holiday" state, where people have a number of random connections. We could further this by defining each of the 7 days of the week to be different, but my research is concerned about beaches and other major gatherings.

With this simplification of the dynamic problem, would it be possible to run the Gillespie_simple_contagion (or another similar method) such that on "t = 7n or 7n-1 -> use weekend links"? I could easily define a weekend network, so that it is the same every week, as that makes life a lot easier, so in reality there are only 2 major networks.

joelmiller commented 4 years ago

The Gillespie algorithms will struggle if something in the background changes at a specific time. In principle the nonMarkovian algorithms should be able to handle this - in those you define your own function that determines time of transmission. But I don't remember thinking of allowing the current time to be one of the arguments sent to the function you would need to write. So it may require me to modify code to allow this.

With that in mind, I think the best approach would be something like:

import EoN
#define G_weekday, G_weekend, etc
#set infecteds and recovereds for initial condition
for week in range(52):
    weekday_sim = EoN.Gillespie_SIR(G_weekday, tau, gamma, initial_infecteds=infecteds, initial_recovereds=recovereds, tmin=7*week, tmax = 7*week+5, return_full_data = True)
    #extract information from weekday_sim.t, weekday_sim.I, weekday_sim.S, etc
    infecteds = []
    recovereds = []
    for node in G_weekday: 
        status = weekday_sim.nodestatus(node, 7*week+5)
        if status is 'I':
            infecteds.append(node)
        elif status is 'R':
            recovereds.append(node)

    weekend_sim = EoN.Gillespie_SIR(G_weekend, tau, gamma, initial_infecteds=infecteds, initial_recovereds=recovereds, tmin=7*week+5, tmax = 7*week+7, return_full_data = True)
     #update infecteds, recovereds, and extract any information you want.

Or if you're doing the Gillespie_simple_contagion because your model is SEIR or something else like that, I think this approach would still apply.

Does that help?

gaianoseworthy commented 4 years ago

@joelmiller That does, thank you!

As a followup question, how exactly does the rate work? I originally took it as a probability from 0 to 1 of the transition occurring, but it seems that is not the case. With that in mind, if one wanted to simulate the 0 to 1 probability of a state transition occurring, how would they do so?

joelmiller commented 4 years ago

Given a rate tau, the probability of transmitting in a short time Delta t is tau(Delta t) (similarly for recovery at rate gamma). After a bit of calculation, the probability of not receiving a transmission from a given infected neighbor in a time interval of length T is e^(-tau T).

The probability of transmitting along a single edge before recovering works out to be tau/(tau+gamma). So you could vary this ratio.

Alternately, the discrete_SIS and discrete_SIR algorithms set it up where infection lasts a single time step, and then we have a transmission probability. That's not the right approach.

If you're using the non-Markovian methods, there may be a way you can build this in to your functions.

gaianoseworthy commented 4 years ago

Perfect, thank you very much!