def __init__(self, env_harshness, env_harshness_death_mult=0.001, migration_death_mult=0.05, name='migration', t=TimeAlways(), i=IterAlways()): super().__init__( name, t, i, group_qry=GroupQry( cond=[lambda g: g.has_attr({'is-migrating': True})])) self.env_harshness = env_harshness # [0=benign .. 1=harsh] self.env_harshness_death_mult = env_harshness_death_mult self.migration_death_mult = migration_death_mult
def __init__(self, severity, scale, severity_death_mult=0.0001, scale_migration_mult=0.01, name='conflict', t=TimeAlways(), i=IterAlways()): super().__init__( name, t, i, group_qry=GroupQry( cond=[lambda g: g.has_attr({'is-migrating': False})])) self.severity = severity # [0=benign .. 1=lethal] self.scale = scale # [0=contained .. 1=wide-spread] self.severity_death_mult = severity_death_mult self.scale_migration_mult = scale_migration_mult
def make_sir(beta, gamma, t=TimeAlways(), i=IterAlways(), dt=0.1): def f_sir_model(t, state): ''' [1] Kermack WO & McKendrick AG (1927) A Contribution to the Mathematical Theory of Epidemics. Proceedings of the Royal Society A. 115(772), 700--721. http://www.public.asu.edu/~hnesse/classes/sir.html ''' s, i, r = state n = s + i + r return [-beta * s * i / n, beta * s * i / n - gamma * i, gamma * i] return ODESystemMass(f_sir_model, [ DotMap(attr={'flu': 's'}), DotMap(attr={'flu': 'i'}), DotMap(attr={'flu': 'r'}) ], t=t, i=i, dt=dt)
# sir_b1 = make_sir(0.50, 0.02, i=IterInt(1000,0), dt=0.1) # 05 Two overlapping and time-unbounded SIR models (B1 starts with a fixed delay): # sir_a1 = make_sir(0.10, 0.05, i=IterAlways(), dt=0.1) # def make_sir_b1_fixed_delay(iter0): # return make_sir(0.50, 0.02, i=IterInt(iter0,0), dt=0.1) # 06 Two overlapping and time-unbounded SIR models (B1 starts with a random delay): # sir_a1 = make_sir(0.10, 0.05, i=IterAlways(), dt=0.1) # def make_sir_b1_random_delay(iter0=900, iter0_dist=gamma(a=5.0, loc=0.0, scale=35.0)): # iter0_rnd = iter0_dist.rvs() # # print(f'rand-iter: {iter0_rnd}') # return make_sir(0.50, 0.02, i=IterInt(iter0 + iter0_rnd,0), dt=0.1) # 07 Two overlapping and time-unbounded SIR models (B1 starts with a random delay and a random 'gamma' parameter): sir_a1 = make_sir(0.10, 0.05, i=IterAlways(), dt=0.1) def make_sir_b1_random_delay_gamma(iter0=900, iter0_dist=gamma(a=5.0, loc=5.0, scale=25.0), gamma=uniform(loc=0.01, scale=0.14)): iter0_rnd = iter0_dist.rvs() gamma_rnd = gamma.rvs() return make_sir(0.50, gamma_rnd, i=IterInt(iter0 + iter0_rnd, 0), dt=0.1) # ---------------------------------------------------------------------------------------------------------------------- # The recurrent flu process: