私は、データ分析に python を使用したり、非線形方程式のフィッティングに lmfit を使用したりすることに少し慣れていません。時間の経過に伴う 1D チャネル内の汚染物質プルームの動きを記述する複雑な半分析関数をモデル化しようとしています。lmfit v0.9.3 を使用しています。私は lmfit チュートリアルのいくつかの例をうまく処理しましたが、自分のモデルを機能させることができないようです。以下のスクリプトは、tsm_mod.fit()
呼び出しまで機能しますが、エラーを返します。
ファイル "C:\Anaconda\lib\site-packages\lmfit\model.py"、501 行目、params.values() の p に適合)
TypeError: 'numpy.ndarray' オブジェクトは呼び出し可能ではありません
コードは以下のとおりです。
import numpy as np
import scipy as sp
import pandas as pd
from lmfit import Model
desmedt = pd.read_table('Directory\desmedt_test.txt',sep='\t')
x = desmedt['Times']
y = desmedt['Conc']
def tsm_intfunc(t,x,tau,u,k,alpha,beta,mass,ac):
return((mass/(2*ac*(t*np.pi*k)**(1/2)))*np.exp(-((x-u*t)**2)/(4*k*t))*np.exp(-alpha*tau-alpha*(t-tau)/beta)
*np.sqrt(beta*tau/(t-tau))*sp.special.iv(2*np.sqrt((alpha**2)*tau*(t-tau)/beta),1))
def tsm_desmedt(t,x,u,k,alpha,beta,mass,ac,nsteps):
dtau = t/nsteps
cxt = (mass/(2*ac*np.sqrt(t*np.pi*k)))*np.exp(-((x-u*t)**2)/(4*k*t))*np.exp(-alpha*t)
cxv = tsm_intfunc(t,x,0.00000001,u,k,alpha,beta,mass,ac)/2
i = 1
while (i<nsteps):
cxv = cxv+tsm_intfunc(t,x,dtau*i,u,k,alpha,beta,mass,ac)/2
i = i+1
return cxt+(alpha/beta)*cxv*dtau
tsm_mod = Model(tsm_desmedt)
tsm_mod.set_param_hint('ac',value=18.2,vary=False)
tsm_mod.set_param_hint('alpha',value=1e-4)
tsm_mod.set_param_hint('beta',value=1e-1)
tsm_mod.set_param_hint('k',value=3)
tsm_mod.set_param_hint('mass',value=157100,vary=False)
tsm_mod.set_param_hint('nsteps',value=100,vary=False)
tsm_mod.set_param_hint('u',value=0.4)
tsm_mod.set_param_hint('x',value=4604,vary=False)
tsm_pars = tsm_mod.make_params()
tsm_fit = tsm_mod.fit(y,x,tsm_pars)
これは lmfit のバグでしょうか? それとも、lmfit を使用して問題を設定した方法にエラーがあると思いますか?
編集: フィッティングで使用されるデータは以下のとおりです。
タイムズ
7787.628 8330.04 8640 8756.244 8988.696 9143.676 9337.392 9492.372 9724.86 9918.576 10034.784 10228.536 10383.516 10577.232 10770.948 11003.4 11119.644 11313.36 11468.34 11700.792 11855.772 12010.752 12204.468 12359.448 12630.672 12824.388 13173.084 13483.044 13793.004 14412.924 14955.336 15575.256 16195.14 17357.472
濃度
0.00944669 0.0850202 0.236167 0.576248 1.00135 2.01215 2.84345 3.51417 4.53441 5.21457 5.59244 5.74359 5.88529 6.0081 5.75304 5.61134 5.20513 4.95007 4.41161 3.74089 3.46694 3.07962 2.80567 2.41835 2.1444 1.74764 1.47368 1.20918 0.935223 0.661269 0.406208 0.132254 0.11336 0.151147