コード例 #1
0
from pylab import *

# In[11]:

from pyndamics import Simulation
from pyndamics.emcee import *

# ## Artificial Example with Mice Population

# In[12]:

data_t = [0, 1, 2, 3]
data_mouse = [2, 5, 7, 19]

sim = Simulation()  # get a simulation object

sim.add(
    "mice'=b*mice - d*mice",  # the equations
    2,  # initial value
    plot=True)  # display a plot, which is the default

sim.add_data(t=data_t, mice=data_mouse, plot=True)
sim.params(b=1.1, d=0.08)  # specify the parameters
sim.run(5)

# In[13]:

model = MCMCModel(sim, b=Uniform(0, 10))

# In[14]:
コード例 #2
0
infected_data = np.array([1,2,5,6,7,8,9,11,13,15])
t_data=np.array([0,1,2,3,4,5,6,7,8,9])


# $$
# \frac{dS}{dt} = - \beta S I /N
# $$
# 
# $$
# \frac{dI}{dt} = + \beta S I /N - \gamma I
# $$

# In[22]:


sim=Simulation()
sim.add("N=S+I+R")
sim.add(" S' = -β*S*I/N",1000)
sim.add(" I' = +β*S*I/N - γ*I",1)
sim.add(" R' = +γ*I",0)
sim.add_data(t=t_data,S=susceptible_data)
sim.add_data(t=t_data,I=infected_data)
sim.params(β=0.3,γ=0.1)
sim.run(0,10)


# In[23]:


figure(figsize=(8,4))
コード例 #3
0
#
# Pyndamics provides a way to describe a dynamical system in terms of the differential equations, or the stock-flow formalism. It is a wrapper around the Scipy odeint function, with further functionality for time plots, phase plots, and vector fields.
#
# Page for this package: [https://code.google.com/p/pyndamics/](https://code.google.com/p/pyndamics/)

# In[1]:

from pyndamics import Simulation

# ## Population of Mice - Exponential Growth
#
# ### Specifying the Differential Equation

# In[2]:

sim = Simulation()  # get a simulation object

sim.add(
    "mice'=b*mice - d*mice",  # the equations
    100,  # initial value
    plot=True)  # display a plot

sim.params(b=1.1, d=0.08)

sim.run(0, 4)

# fig=sim.figures[0]
# fig.savefig('mice.pdf')
# fig.savefig('mice.png')

# ### Specifying the Inflows/Outflows