Hi, I’m trying to infer two parameters in an ODE system called p0 and p1 in pymc3. Here A is a known 3 * 3 matrix. y is the observation, which is a vector containing 3 elements. The idea is to infer p0 and p1 given the observation y.
In my case the derivative dy/dt includes both :
- product between matrix and column vextor : A @ y, which returns a column vector
- elementwise product between two column vectors: y * (3 - 2y), which returns a column vector
In scipy, we can define such an ODE system by:
import numpy as np
from scipy.integrate import odeint
A = np.array([[-0.25, 0, 0],
[ 0.25, -0.2, 0],
[ 0, 0.2, -0.1]])
def deriv(y, t, p0, p1):
return p0 * A @ y + p1 * y * (3 - 2 *y)
p0 = 2
p1 = 4
time = np.arange(0,100,0.1)
y0 = np.array([10, 20, 30])
sol = odeint(deriv, y0, time, args=(p0,p1))
However, in pymc, when I tried to use DifferentialEquation:
def odefunc(y, t, p):
return p[0] * pm.math.dot(A , y) + p[1] * y * (3 - 2 * y)
times = np.arange(0,100,0.1)
ode_model = DifferentialEquation(func=odefunc, times=times, n_states=3, n_theta=2, t0=0)`
I got the following error:
AssertionError: theano.tensor.jacobian expects a 1 dimensional variable as `expression`. If not use flatten to make it a vector
I also found the sunode package difficult to implement such kind of idea. (Maybe it’s because I’m not so familiar with sunode).
Thus, I’m wondering if there’s a way of implementing such ODE system with both calculations: (product between matrix and column vextor) and (elementwise product between two vectors) mentioned above in pymc? I need these two calculations because in reality my matrix A and vector y are large.
Also, I’ve noticed that the odeint
function in jax.experimental.ode
is able to do that. Is it possible to use the jax odeint solver in pymc?
Thank you so much for your help!