Байесовский анализ химической сети - PullRequest
2 голосов
/ 10 июня 2019

Я пытаюсь создать простую сеть реакций и вижу чувствительность скоростей реакций k1 и k2.Так что моя реакция идет A -> B -> C с k1 и k2, соответственно.

import numpy as np
import pymc3 as pm
from matplotlib.pyplot import figure, scatter, legend, plot
from scipy.integrate import solve_ivp
from sys import exit
Nt = 11
time  = 10
tt = np.linspace(0,time,Nt+1)
y0 = [1,0,0]


k1_0, k2_0 = 1, 0.5
def equat(t,c):
    da_dt = -k1_0*c[0]
    db_dt = k1_0*c[0] - k2_0*c[1]
    dc_dt = k2_0*c[1]
    return da_dt, db_dt, dc_dt

c_est = solve_ivp(equat, t_span = [0,time], t_eval = tt, y0 = y0)  

niter = 10
with pm.Model() as reak_model:
    k1 = pm.Normal('k1', mu = 0, sd = 100)
    k2 = pm.Normal('k2', mu=0, sd=100, shape = 1)
    sigma = pm.HalfNormal('sigma', sd=1)
    def equat_2(t,c):
        da_dt = -k1*c[0]
        db_dt = k1*c[0] - k1*c[1]
        dc_dt = k1*c[1]
        return da_dt, db_dt, dc_dt
    c = solve_ivp(equat_2, t_span = [0,time], t_eval = tt, y0 = y0)
    likelihood = pm.Normal('y', mu=c.y, sd=sigma, observed=c_est.y)
    trace = pm.sample(niter, chains = 1)
pm.traceplot(trace, varnames=['k1','k2'])

 ValueError: setting an array element with a sequence.

Я получаю эту ошибку.Так как я новичок в Bayesian, мне интересно, есть ли что-то с дистрибутивами?

Traceback (most recent call last):

  File "<ipython-input-95-26ff8f25faea>", line 1, in <module>
    runfile('/Daft regresion.py', wdir='/Final code')

  File "/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

  File "python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "Daft regression.py", line 53, in <module>
    c = solve_ivp(equat_2, t_span = [0,time], t_eval = tt, y0 = y0)

  File "/python3.7/site-packages/scipy/integrate/_ivp/ivp.py", line 454, in solve_ivp
    solver = method(fun, t0, y0, tf, vectorized=vectorized, **options)

  File "/python3.7/site-packages/scipy/integrate/_ivp/rk.py", line 99, in __init__
    self.f = self.fun(self.t, self.y)

  File "/python3.7/site-packages/scipy/integrate/_ivp/base.py", line 139, in fun
    return self.fun_single(t, y)

  File "/python3.7/site-packages/scipy/integrate/_ivp/base.py", line 21, in fun_wrapped
    return np.asarray(fun(t, y), dtype=dtype)

  File "/python3.7/site-packages/numpy/core/numeric.py", line 501, in asarray
    return array(a, dtype, copy=False, order=order)

ValueError: setting an array element with a sequence.

Редактировать: Очевидно, мне нужно реализовать пакет Theano вместо solve_ivp.Тем не менее, помощь приветствуется.

...