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

Discrete State Calculation #65

Open Josh-Priest opened 4 years ago

Josh-Priest commented 4 years ago

Hi,

I am trying to use EoN to run discrete time agent-based simulations on graphs, where nodes represent (say) people, and edges represent pair-wise interactions. I have started with the SIR model, but I eventually want to expand to the SIS model as well.

I need time to be incremented in integer times starting at time t=0, then proceeding to t=1, to t=2, to t=3, and so on. I want node state transitions to be computed only at these integer time values. I also need to specify the duration of an agent in each state as appropriate. For example, in an SIR model, I want to specify for each agent vi the time that vi spends in state I.

I have tried a few models and have been unable to control the time; for the fast_SIR function it appears that the model is computed on a continuous time interval and a data point (composed of the t, S, I, R arrays) is output every time any agent changes state. For the SIR_individual_based function, I can output the data points an integer time intervals but I received non-integer agent counts at each interval (for example, in a 100 node graph with 50 nodes infected at time t0, at time t1 there were 35.092798 susceptible, ~27.1 infected, and 37.84878313 recovered). This makes me believe that the model is also running on a continuous time interval and just showing me the data points at my specified intervals while not showing the rest of the data.

Is there a function in EoN that calculates state changes only at discrete intervals and where I also have the option to specify how long an agent remains in each state?

joelmiller commented 4 years ago

The SIR_individual_based is an ordinary differential equations model that is based on some approximations. I do not think it is what you want.

Your description of fast_SIR is fairly accurate. There are some tools I've provided to sample the population at specific times after the simulation is done, but it sounds like you want the simulation itself to be discrete time.

There is a built in discrete time option, but it assumes infection lasts for 1 time step. That also doesn't sound like what you want.

So a solution is to follow this: https://github.com/springer-math/Mathematics-of-Epidemics-on-Networks/issues/64

You'll have to write your own function to determine how long an individual remains infected. You'll also have to write your own function to determine how long it takes until an individual transmits to its neighbor [and if the time is less than the duration of infection, an infection happens, otherwise it is ignored].

When I was reading the documentation for fast_nonMarkov_SIR as I answered the other question I realized it wasn't as complete as I had thought it was, so if you have issue please come back - if you describe the specific rules you want for how long infection lasts and how long it takes to transmit I can probably help more.