Hello,
I am trying to use the sunode ODE solver instead of the DifferentialEquations solver, but I get the error “When changing to a smaller dtype, its size must be a divisor of the size of original dtype” in doing so. Any pointers or suggestions?
import sunode
import sunode.wrappers.as_theano
def SIR_sunode(t, y, p):
"""Right hand side of Lotka-Volterra equation.
All inputs are dataclasses of sympy variables, or in the case
of non-scalar variables numpy arrays of sympy variables.
"""
return {
'S': -p.lam * y.S * y.I,
'I': p.lam * y.S * y.I - p.mu * y.I,
}
with pm.Model() as model:
sigma = pm.HalfCauchy('sigma', 2, shape=2)
S_init = yobs[0,0]
I_init = yobs[0,1]
lam = pm.Lognormal('lambda', np.log(4), 1.5)
mu = pm.Lognormal('mu', np.log(1), 1)
#sir_curves = sir_model(y0=[0.99, 0.01], theta=[lam, mu])
sir_curves, _, problem, solver, _, _ = sunode.wrappers.as_theano.solve_ivp(
y0={
# The initial conditions of the ode. Each variable
# needs to specify a theano or numpy variable and a shape.
# This dict can be nested.
'S': (S_init, ()),
'I': (I_init, ()),
},
params={
# Each parameter of the ode. sunode will only compute derivatives
# with respect to theano variables. The shape needs to be specified
# as well. It it infered automatically for numpy variables.
# This dict can be nested.
'lam': (lam, ()),
'mu': (mu, ()),
},
# A functions that computes the right-hand-side of the ode using
# sympy variables.
rhs=SIR_sunode,
# The time points where we want to access the solution
tvals=times,
t0=times[0],
)
S = pm.Lognormal('S', mu=pm.math.log(sir_curves['S']), sigma=sigma, observed=yobs[:,0])
I = pm.Lognormal('I', mu=pm.math.log(sir_curves['I']), sigma=sigma, observed=yobs[:,1])
step = pm.Metropolis()
trace = pm.sample(400, tune=100, cores=2)
data = az.from_pymc3(trace=trace)