我喜欢将语法保持在最通用的形式,通过iminuit
使用以下参数给出它的参数*
:
import iminuit
import numpy as np
x_data = np.array([0,1,2,3,4,5,6,7,8,9])
y_data = np.array([0,1,2,3,4,5,4,3,2,1])
def fit_function(x, *p):
return p[0]*np.exp(-((x-p[1])**2/(2*p[2]**2)))
def minimize_me(*p):
return sum((fit_function(x, *p) - y)**2 for x, y in zip(x_data, y_data))
p=[4.5, 5, 0.4]
print(minimize_me(*p)) # works! --> gives: 57.1645229329
m = iminuit.Minuit(minimize_me, *p)
m.migrad() # fails!
失败并出现错误:
AttributeError: 'float' object has no attribute 'print_banner'
任何想法我做错了什么?谢谢。
ps这个例子是基于这个SO帖子:https ://stackoverflow.com/a/22540079/5177935