lmfit
Pythonとモジュールを使用してマルチパラメータフィットを実行しようとしています。私は、コードの基礎として、ここに示されている例に従っています。コードを理解している限り、目的関数を適切に定義し(残差を与える)、適切な引数を指定すれば、最小二乗近似を実行できるはずです。
これが私の現在の目的関数です。
# Define objective function: each data point has a different
# objective function which is defined by the model method
# the objective function returns the array to be minimized
def objfunc(params,trans,sum_in,sum_out,data):
""" model fit using branching ratios and resonance strength
then subtract data """
model = fit_model(params,trans,sum_in,sum_out)
return model - data
ここで、fit_model(args*)
メソッドは次のように定義されます。
def fit_model(params,trans,sum_in,sum_out):
""" model the transition based upon the input string trans
using parameter convention for the branching """
model = []
# The amplitude: technically the resonance strength term
# here it gives the number of resonant decays
amp = params['amp'].value
# For each transition we want to retrieve the parameter values
# for the branching ratios and evaluate the new value for
# the fit (of that transition). The easiest way to do this is
# to store the braching ratios with the same notation used
# previously, and to explicity call those values using the
# 'params.['']value' method
for i in range(len(trans)):
# Employs the termvalue() method to evalueate the branching
# and efficiency values
model.append( str(amp * termValue(trans[i]) + amp * termValue(sum_in[i]) - amp * termValue(sum_out[i])))
return np.array(model,dtype='float64')
これにより、私が期待するもの、numpy.ndarray
つまりデータの長さがわかります。私が抱えている問題は、カイ二乗適合を最小化しようとすると、
result = minimize(objfunc,params,args=(trans,sum_in,sum_out,data))
エラーメッセージが表示されます:
File "path/chisquare.py", line 94, in <module>
result = minimize(objfunc,params,args=(trans,sum_in,sum_out,data))
File "/usr/local/lib/python2.7/dist-packages/lmfit-0.7-py2.7.egg/lmfit/minimizer.py", line 498, in minimize
fitter.leastsq()
File "/usr/local/lib/python2.7/dist-packages/lmfit-0.7-py2.7.egg/lmfit/minimizer.py", line 369, in leastsq
lsout = scipy_leastsq(self.__residual, self.vars, **lskws)
File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 278, in leastsq
raise TypeError('Improper input: N=%s must not exceed M=%s' % (n,m))
TypeError: Improper input: N=26 must not exceed M=25
私はこれが何を意味するのかをlmfit
ソースコードから理解しようとしましたが、それは私の理解を少し超えています。このエラーを解決する方法を知っている人はいますか?
ありがとう