Populating the interactive namespace from numpy and matplotlib
Populating the interactive namespace from numpy and matplotlib
β=0.2
γ=0.1
So=990
Io=10
dynamic_sim=sim=Simulation()
sim.add("N=S+I+R")
sim.add("S'=-β*S*I/N",So)
sim.add("I'=+β*S*I/N-γ*I",Io)
sim.add("R'=+γ*I",0)
sim.params(β=β,γ=γ)
sim.run(200)
stoch_sim=sim=Stochastic_Simulation()
sim.add("-S+I",'β*S*I/N',S=So,I=Io)
sim.add("-I +R",'γ*I',R=0)
sim.add("N=S+I+R")
sim.params(β=β,γ=γ)
sim.run(200,Nsims=100)
for i in range(100):
plot(sim.t,sim.S[i],'bo',alpha=0.05)
plot(sim.t,sim.I[i],'ro',alpha=0.05)
plot(dynamic_sim.t,dynamic_sim.S,'c-')
plot(dynamic_sim.t,dynamic_sim.I,'m-')
print(sim.func_str)
100%|█████████████████████████████████████████████████████████████| 100/100 [00:01<00:00, 73.77it/s]
@numba.jit
def _propensity_function(population, args):
S,I,R = population
β,γ = args
N=S+I+R
val = np.array([
β*S*I/N,
γ*I,
])
return val
Sampling Prior...
Done.
0.33 s
Running MCMC 1/3...
Done.
9.49 s
Running MCMC 2/3...
Done.
12.31 s
Running MCMC 3/3...
Done.
12.71 s
<Figure size 864x576 with 0 Axes>
stoch_sim=Stochastic_Simulation()
stoch_sim.add("-S+I",'β*S*I/N',S=So,I=Io)
stoch_sim.add("-I +R",'γ*I',R=0)
stoch_sim.add("N=S+I+R")
stoch_sim.params(β=1.9732213241997467,γ=1.9732213241997467)
stoch_sim.add_data(t=flut,I=flui)
stoch_sim.run(20,Nsims=100)
100%|██████████████████████████████████████████████████████████| 100/100 [00:00<00:00, 17680.33it/s]
for i in range(100):
plot(stoch_sim.t,stoch_sim.I[i],'ro',alpha=0.05)
plot(flut,flui,'ko',ms=10,lw=3,)