我想用积分函数拟合数据(截断的伽马分布)。 我尝试了以下代码,但发生了错误。如果你能帮助我,我感激不尽。非常感谢你提前。
menu_item_1_layout.setOnTouchListener { view, motionEvent ->
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_HIDDEN
navigation.selectedItemId = lastSelectedItemId // views are refreshed here
true
}
发生以下错误。
%matplotlib inline
import numpy as np
from scipy import integrate
import scipy.optimize
import matplotlib.pyplot as plt
xlist=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14]
ylist=[1.0, 0.7028985507246377, 0.4782608695652174, 0.36231884057971014,
0.2536231884057971, 0.1811594202898551, 0.12318840579710147,
0.08695652173913046, 0.057971014492753645, 0.04347826086956524,
0.02173913043478263, 0.007246376811594223]
xdata=np.array(xlist)
ydata=np.array(ylist)
parameter_initial=np.array([0.0,0.0,0.0])#a,b,c
def func(x,a,b,c):
return integrate.quad(lambda t:t^(a-1)*np.exp(-t),x/c,b/c)/integrate.quad(lambda t:t^(a-1)*np.exp(-t),0.0,b/c)
parameter_optimal,cov=scipy.optimize.curve_fit(func,xdata,ydata,p0=parameter_initial)
print "paramater =", paramater_optimal
y = func(xdata,paramater_optimal[0],paramater_optimal[1],paramater_optimal[2])
plt.plot(xdata, ydata, 'o')
plt.plot(xdata, y, '-')
plt.show()