if t >= tau: return beta1 + (beta0 - beta1)**(-q * (t - tau)) else: return beta0 # <codecell> N = 1000000 sim = Simulation() sim.add("S'=-beta(t)*(S*I)/N", N, plot=False) sim.add("E'=-beta(t)*(S*I)/N - (E/invk)", 135, plot=1) sim.add("I'=(E/invk) - (1/invGamma *I)", 136, plot=1) sim.add("R'=(1/invGamma*I)", 0, plot=False) sim.params(N=N, k=1 / 6.3, q=0.1000, invGamma=5.5000, invk=6.3) sim.functions(beta) sim.add_data(t=numOfDays, I=numOfCases, plot=1) sim.run(0, 350) # <codecell> model = MCMCModel( sim, { 'beta0': [0, 1], 'invGamma': [3.5, 10.7], 'beta1': [0, 1], 'q': [0, 100], 'tau': [100, 150], 'invk': [5, 22] }) #model = MCMCModel(sim,{'invGamma':[3.5,10.7],'q':[0,10]})
# or you can define your own... # <codecell> def foo(y): return tanh(y) sim=Simulation() # get a simulation object sim.add("x' = -x + foo(a*x)", # the equations 1, # initial value plot=True) # display a plot sim.params(a=2) sim.functions(foo) sim.run(0,40) # <markdowncell> # ## Alternate Integrators # # By default, pyndamics uses odeint, but you can also specify a few different intergrators. I have implemented euler, rk2, rk4, and rk45. # <codecell> from pyndamics import Simulation sim=Simulation(method='rk45') sim.add("deer' = r*deer*(1-deer/K)-c*deer*wolf", initial_value=350,
from numpy import tanh def foo(y): return tanh(y) sim = Simulation() # get a simulation object sim.add( "x' = -x + foo(a*x)", # the equations 1, # initial value plot=True) # display a plot sim.params(a=2) sim.functions(foo) sim.run(0, 40) # ## Alternate Integrators # # By default, pyndamics uses odeint, but you can also specify a few different intergrators. I have implemented euler, rk2, rk4, and rk45. # In[34]: from pyndamics import Simulation sim = Simulation(method='rk45') sim.add("deer' = r*deer*(1-deer/K)-c*deer*wolf", initial_value=350, plot=True) sim.add("wolf' = -Wd*wolf+D*deer*wolf", initial_value=50, plot=True)