Simulation of the homogeneous model of https://arxiv.org/pdf/1201.1178.pdf (Section 2)
In [3]:
# To load the library
import src.rmf_tool as rmf
# To plot the results
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [32]:
# This code creates an object that represents a "density dependent population process"
ddpp = rmf.DDPP()
K = 10
s=7
mu=1
lam=1
# The vector 'e(i)' is a vector where the $i$th coordinate is equal to $1$ (the other being equal to $0$)
def e(i):
l = np.zeros(K+1)
l[i] = 1
return(l)
# We then add the transitions :
for i in range(1,K+1):
ddpp.add_transition(-e(i)+e(i-1),eval('lambda x: lam*x[{}]'.format(i) ))
ddpp.add_transition(e(i)-e(i-1),eval('lambda x: mu*x[{}]*(s- np.sum([j*x[j] for j in range(K+1)]))'.format(i-1) ))
ddpp.set_initial_state(e(s))
In [33]:
T,X=ddpp.ode(time=10)
plt.plot(T,X)
plt.legend(['{}'.format(i) for i in range(K+1)])
Out[33]:
In [56]:
s=7
pi,V,W=ddpp.meanFieldExpansionSteadyState(order=1)
plt.plot(range(K+1),pi,'+')
plt.plot(pi+V/10)
plt.legend(("Mean Field Approx.","Refined Mean Field Approx."))
Out[56]:
In [57]:
s=6
pi,V,W=ddpp.meanFieldExpansionSteadyState(order=1)
plt.plot(range(K+1),pi,'+')
plt.plot(pi+V/10)
plt.legend(("Mean Field Approx.","Refined Mean Field Approx."))
Out[57]:
In [58]:
max(V)
Out[58]:
In [ ]: