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

Recovery rate in discrete model #64

Closed atilaajones closed 4 years ago

atilaajones commented 4 years ago

Is it possible to set a node recovery rate for discrete modeling? As for example in the discrete_SIR.

joelmiller commented 4 years ago

I think you're asking abut having people be infected for some integer number of time units, where at each time step there is a fixed probability of recovering. Is that correct?

If so, that is not currently built in, but I agree I should add it.

If you do want this, a way to accomplish it would be through the fast_nonMarkov_SIR function. You would need to create a function that defines the time to recovery for a newly infected node (so it would need to return from a geometric distribution). You would also need to create a function that defines the time to transmission for an edge between an infected and susceptible (presumably also a geometric distribution).

If node u recovers at time t+t_0 and would transmit to its neighbor at some time t+t_1, then if t_1<=t_0 the transmission happens.

atilaajones commented 4 years ago

Yeah! I need exactly it. I believe your proposal works. But I don't see how to define the probability of recovery, even with the use of time. Thanks for your attention.

joelmiller commented 4 years ago

Here is the documentation on the fast_nonMarkov_SIR function.

Here are 2 ways to create a function that returns the time to recovery given a probability p of recovering at each time step. The first one is a bit more obvious what is going on. The second is going to be faster. If you want a faster way that doesn't use numpy it is doable with random, but it's a bit more involved:

import random
def rec_time_fxn(p):
    rec_time = 1
    while random.random()<p:
        rec_time += 1

    return rec_time

import numpy
def rec_time_fxn2(p):
    return numpy.random.geometric(p)

You would need a similar function for the time to transmission.

atilaajones commented 4 years ago

Great. Thank you for your attention and sorry for the simple question. I'll try this solution.