简体   繁体   English

使用 Python 进行双重退火优化

[英]Dual annealing optimization with Python

I am currently trying to fit a set of data using the class Minimize().我目前正在尝试使用 Minimize() 类拟合一组数据。 I would like to implement this method with the dual_annealing algorithm but unfortunately I cannot This is the code:我想用 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)

And this is the Attribute error I receive back:这是我收到的属性错误:

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'

Please, if you can suggest some edit to the code, I'll strongly appreciate it!请,如果您能建议对代码进行一些编辑,我将不胜感激!

The method argument of the minimize method is required to be a str, see the docs . minimize方法的method参数必须是 str,请参阅文档 Use

result = minner.minimize(method = "dual_annealing")

instead.反而。

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

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