![](/img/trans.png)
[英]What is the R equivalent if the scipy.optimize.dual_annealing function in Python
[英]Dual annealing optimization with Python
我目前正在嘗試使用 Minimize() 類擬合一組數據。 我想用 dual_annealing 算法實現這個方法,但不幸的是我不能 這是代碼:
def fit_msd2(params, x, data):
A = params['A']
a = params['a']
model = x + A * (np.exp(-a*x)-1)
return model - data
# create a set of Parameters
params = Parameters()
params.add('A', value=527, min=0)
params.add('a', value=0.016, min=0)
from scipy.optimize import dual_annealing
# do fit, here with the default leastsq algorithm
minner = Minimizer(fit_msd2, params, fcn_args=(tL, mean_msd_29))
result = minner.minimize(method = dual_annealing)
# calculate final result
#final = mean_msd_29 + result.residual
# write error report
report_fit(result)
這是我收到的屬性錯誤:
AttributeError Traceback (most recent call last)
<ipython-input-531-a8c40dd82948> in <module>
2 # do fit, here with the default leastsq algorithm
3 minner = Minimizer(fit_msd2, params, fcn_args=(tL, mean_msd_29))
----> 4 result = minner.minimize(method = dual_annealing)
5 # calculate final result
6 final = mean_msd_29 + result.residual
~/opt/anaconda3/lib/python3.8/site-packages/lmfit/minimizer.py in minimize(self, method, params, **kws)
2260 kwargs.update(kws)
2261
-> 2262 user_method = method.lower()
2263 if user_method.startswith('leasts'):
2264 function = self.leastsq
AttributeError: 'function' object has no attribute 'lower'
請,如果您能建議對代碼進行一些編輯,我將不勝感激!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.