Hi!
I am trying hard to adapt the fairly simple notebook Introduction of pymc3.ode API seen here.
I wrote the code below but it fails even before using the model.
import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pymc3 as pm
import theano
from io import BytesIO
from pymc3.ode import DifferentialEquation
from scipy.integrate import odeint
from scipy.optimize import curve_fit
plt.style.use('seaborn-darkgrid')
n_conditions = 2
n_genes = 12
n_replicats = 4
times = np.array([0., 0.5, 1., 3.5, 6.5, 9.25, 12.5, 18.5, 22.5, 26.5, 30.5])
n_timeintervals = times.size-1 # = 10
n_timesteps = times.size # = 11
Binary = open('data.txt').read().replace(',', '.').encode()
expr = np.genfromtxt(BytesIO(Binary), missing_values = 'NA', filling_values = np.nan, skip_header = 1)
exprtg = expr[: , 3 : ].reshape(7, n_timesteps, n_genes)
exprtgTF = expr[: , 7 ].reshape(7, n_timesteps)
mu0 = np.nanmean(exprtg[:, 0, :], axis = (0, 1))
def geneexpression(mu, t, parameters):
alpha = np.zeros(n_genes)
beta = np.zeros(n_genes)
gamma = np.zeros(n_genes)
delta = np.zeros(n_genes)
for i in range(n_genes):
print(alpha[i], parameters[4*i])
alpha[i] = parameters[4*i]
beta[i] = parameters[4*i+1]
gamma[i] = parameters[4*i+2]
delta[i] = parameters[4*i+3]
eta = np.concatenate(([1.], parameters[4*n_genes : ]))
current_index = np.searchsorted(times, t, side='right')-1
if current_index >= n_timeintervals:
current_index -= 1
current_eta = eta[current_index]
dmu_dt = alpha + beta * current_eta / (gamma + current_eta) - delta * mu
return dmu_dt # return statement of geneexpression
ode_model = DifferentialEquation(
func=geneexpression,
times=times,
n_states=n_genes,
n_theta=4*n_genes + n_timeintervals-1, # eta is normalized with eta=1. on the first time interval
t0=0
)
Data is pasted here.
It fails with the error
ValueError: setting an array element with a sequence.
on line
alpha[i] = parameters[4*i]
so my understanding is that I cannot access to a given parameter with the bracket notation. How should I do then?