Hi,
I really liked the method for speeding numerical integration of ODES
presented in the sage documentation. However, it uses the GSL solver
instead of the scipy.integrate.odeint I normally use.
I tried to apply the same methodology but I can't get past this error:
ValueError: object too deep for desired array
Here is my code:
%cython
%timeit
from scipy.integrate import odeint
#cimport scipy.integrate.odeint as odeint
import numpy as np
cimport numpy as np
cdef double beta,eta,epsilon,mu,m,alpha,tau,nflu,tf
cdef np.ndarray inits
beta = 0.5 #Transmission coefficient
eta = .0 #infectivity of asymptomatic infections relative to clinical
ones. FIXED
epsilon = .4 #latency period
mu = 0 #nat/mortality rate
m = 1e-5 #Infeccious imported
alpha = .8 #Probability of developing clinical influenza symptoms
tau = .2 #infectious period. FIXED
nflu = 5e-5
tf=100
# Initial conditions
inits = np.ndarray([.998,0.,.002,0.],dtype=np.double) #initial values
for state variables.
cpdef seir(y,double t):
'''ODE model'''
cdef double S,A,E,I,lamb
S,E,I,A = y
lamb = beta*((I-nflu)+m)
return [-lamb*S +mu, #dS/dt
lamb*S - (epsilon+mu)*E, #dE/dt
alpha*epsilon*E - (tau+mu)*I +nflu, #dI/dt
(1-alpha)*epsilon*E - (tau+mu)*A, #dA/dt
]
y = odeint(seir,inits,np.arange(0,tf,1))
any help is appreciated,
Flávio
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org