繁体   English   中英

在微分方程中寻找参数

[英]Finding parameters in differential equation

我有一组数据点,我想找到这个集合的差分模型的3个参数。 我试图从这里调整代码,但我有以下异常:

File "/home/djipey/Thesis/DGL/fit/25_09/etalon.py", line 13, in f
return Vmax * S / (Km + S (1 + S / Ki))
TypeError: 'numpy.ndarray' object is not callable

该模型是:

-dS / dt = Vmax * S /(Km + S(1 + S / Ki))

这是我使用的代码。 它是完全开箱即用的。

import numpy as np
from scipy.optimize import curve_fit
from scipy.integrate import odeint
from matplotlib.pyplot import *



def f(S, t, Vmax, Km, Ki):

    return Vmax * S / (Km + S * (1 + S / Ki))


def S(t, Vmax, Km, Ki, S0):

    #S = odeint(f, 0.4666023864047246, temps, args=(Vmax, Km, Ki))
    S = odeint(f, 0.47, temps, args=(Vmax, Km, Ki))
    #S = odeint(f, S0, temps, args=(Vmax, Km, Ki))
    return S.ravel()

temps = [0.0, 0.0027777777777777779, 0.0055555555555555558, 0.0083333333333333332, 0.011111111111111112, 0.013888888888888888, 0.016666666666666666, 0.019444444444444445, 0.022222222222222223, 0.025000000000000001, 0.027777777777777776, 0.030555555555555555, 0.033333333333333333, 0.036111111111111108, 0.03888888888888889, 0.041666666666666664, 0.044444444444444446, 0.047222222222222221, 0.050000000000000003, 0.052777777777777778, 0.055555555555555552, 0.058333333333333334, 0.061111111111111109, 0.063888888888888884, 0.066666666666666666, 0.069444444444444448, 0.072222222222222215, 0.074999999999999997, 0.077777777777777779, 0.080555555555555561, 0.083333333333333329, 0.08611111111111111, 0.088888888888888892, 0.09166666666666666, 0.094444444444444442, 0.097222222222222224, 0.10000000000000001, 0.10277777777777777, 0.10555555555555556, 0.10833333333333334, 0.1111111111111111, 0.11388888888888889, 0.11666666666666667, 0.11944444444444445, 0.12222222222222222, 0.125, 0.12777777777777777, 0.13055555555555556, 0.13333333333333333, 0.1361111111111111, 0.1388888888888889, 0.14166666666666666, 0.14444444444444443, 0.14722222222222223, 0.14999999999999999, 0.15277777777777779, 0.15555555555555556, 0.15833333333333333, 0.16111111111111112, 0.16388888888888889, 0.16666666666666666, 0.16944444444444445, 0.17222222222222222, 0.17499999999999999, 0.17777777777777778, 0.18055555555555555, 0.18333333333333332, 0.18611111111111112, 0.18888888888888888, 0.19166666666666668, 0.19444444444444445, 0.19722222222222222, 0.20000000000000001, 0.20277777777777778, 0.20555555555555555, 0.20833333333333334, 0.21111111111111111, 0.21388888888888888, 0.21666666666666667, 0.21944444444444444, 0.22222222222222221, 0.22500000000000001, 0.22777777777777777, 0.23055555555555557, 0.23333333333333334, 0.2361111111111111, 0.2388888888888889, 0.24166666666666667, 0.24444444444444444, 0.24722222222222223, 0.25, 0.25277777777777777, 0.25555555555555554, 0.25833333333333336, 0.26111111111111113, 0.2638888888888889, 0.26666666666666666, 0.26944444444444443, 0.2722222222222222, 0.27500000000000002, 0.27777777777777779, 0.28055555555555556, 0.28333333333333333, 0.28611111111111109, 0.28888888888888886, 0.29166666666666669, 0.29444444444444445, 0.29722222222222222, 0.29999999999999999, 0.30277777777777776, 0.30555555555555558, 0.30833333333333335, 0.31111111111111112, 0.31388888888888888, 0.31666666666666665, 0.31944444444444442, 0.32222222222222224, 0.32500000000000001, 0.32777777777777778, 0.33055555555555555]
conc = [0.4666023864047246, 0.28480173556707244, 0.2750391707846209, 0.26141979028564544, 0.2684343738700735, 0.2639026154031578, 0.25474267807641315, 0.2539231047366518, 0.25503193925515244, 0.25652645534530555, 0.24845124743883332, 0.24912619018922502, 0.25131975412799806, 0.25804507653368686, 0.25442931179944556, 0.2469085211522237, 0.2546944678799566, 0.2526455345305532, 0.2563818247559359, 0.24444980113293963, 0.24956008195733398, 0.2501386043148126, 0.245534530553212, 0.25025912980595394, 0.2400867783536218, 0.2414607689526335, 0.2443774858382548, 0.25592382788959867, 0.2495359768591057, 0.24218392189948174, 0.2471013619380499, 0.2592021212486441, 0.24912619018922502, 0.2466915752681692, 0.2396769916837411, 0.2452452693744727, 0.24225623719416656, 0.23856815716524044, 0.24413643485597203, 0.24818609135832229, 0.24158129444377485, 0.24432927564179824, 0.23591659636013015, 0.24237676268530794, 0.23434976497529228, 0.24172592503314452, 0.23444618536820538, 0.23960467638905628, 0.24630589369651681, 0.2388092081475232, 0.2378208991201639, 0.23186693985777992, 0.23331324575147644, 0.23972520188019766, 0.24162950464023142, 0.23786910931662048, 0.23753163794142462, 0.23478365674340124, 0.23560323008316258, 0.24269012896227551, 0.2352175485115102, 0.23548270459202122, 0.2452452693744727, 0.2366638544052067, 0.2411474026756659, 0.23883331324575147, 0.24444980113293963, 0.24519705917801615, 0.24584789683017957, 0.24459443172230927, 0.24242497288176448, 0.24575147643726647, 0.2484753525370616, 0.25025912980595394, 0.24637820899120164, 0.2376280583343377, 0.24399180426660239, 0.2400867783536218, 0.24447390623116788, 0.2370495359768591, 0.23786910931662048, 0.2399662528624804, 0.2315053633843558, 0.23172230926841028, 0.23473544654694467, 0.2393877305050018, 0.24457032662408099, 0.24150897914909003, 0.22911895865975654, 0.2367602747981198, 0.23222851633120406, 0.23649511871760878, 0.22803422923948416, 0.23324093045679162, 0.23418102928769435, 0.23348198143907437, 0.22543087863083042, 0.23222851633120406, 0.23697722068217428, 0.22699771001566832, 0.23721827166445703, 0.23155357358081236, 0.23172230926841028, 0.22928769434735446, 0.23475955164517295, 0.23625406773532603, 0.22938411474026757, 0.22810654453416898, 0.22299626370977463, 0.23030010847294202, 0.23439797517174882, 0.22697360491744004, 0.2276967578642883, 0.2276967578642883, 0.22928769434735446, 0.22449077979992768, 0.22608171628299387, 0.23097505122333373, 0.2246595154875256, 0.23232493672411714] 


temps = np.array(temps)
conc = np.array(conc)

#popt, pcov = curve_fit(S, temps, conc,[1, 1, 1, 0.47], maxfev=3000)
popt, pcov = curve_fit(S, temps, conc,[1, 2, 1, 0.47], maxfev=3000)
#popt, pcov = curve_fit(S, temps, conc, maxfev=109000)
print(popt)

#plot the data
clf() #matplotlib
plot(temps, conc, "gp")
plot(temps, S(temps, popt[0], popt[1], popt[2], popt[3]))

grid(True)
show()

知道我错了吗?

编辑:当我说丑,这就是我的意思:

一个例子

但我不得不提到最后一件事。 我在科学上并不确定我可以在我的数据上使用这个模型。 我只想试试这个选项。

更改

def f(S, t, Vmax, Km, Ki):
    return Vmax * S / (Km + S (1 + S / Ki)) 

def f(S, t, Vmax, Km, Ki):
    return Vmax * S / (Km + S * (1 + S / Ki))

观察乘法,你所做的是用一些参数调用S,这会导致错误,而你想要将S与这些参数相乘

编辑:回复评论中的问题:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html

popt:数组

Optimal values for the parameters so that the sum of the squared error of f(xdata, *popt) - ydata is minimized

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM