我一直试图将EMG函数拟合到某些数据中,我事先知道它们的行为方式是这样的。 这是数据 http://www.filedropper.com/data_12
到目前为止我的脚本是这样的:
import numpy as np
from matplotlib import pyplot as plt
import numpy.fft.fftpack as F
import math
from scipy import optimize
from scipy.optimize import curve_fit,leastsq
from scipy.special import erf
t,i=np.loadtxt('data.txt',unpack=True)
def EMG(x,a,b,c,d):
'''. a = Gaussian heigth, b = location parameter (Gaussian center),
c = Gaussian width, d = distortion parameter (a.k.a. modification factor or time constant).
'''
return [a*c*np.sqrt(2*np.pi)]/(2*d) * np.exp[(c**2/(2*d**2))-(x-b)/d] * [(d/np.abs(d))+np.erf[((x-b)/np.sqrt(2)*d)] -(c/np/sqrt(2)*d)]
errfunc = lambda p, x, y: (EMG(x, *p) - y)**2
guess=[1,512,1,0.5]
#optim, success = optimize.leastsq(errfunc3, guess, args=(t,i))
print leastsq(errfunc,guess[:], args=(t, i))
#Note the args argument, which is necessary in order to pass the data to the function.
我得到的错误是:
“第25行,在EMG中 返回[a c np.sqrt(2 * np.pi)] /(2 * d)* np.exp [(c 2 /(2 * d 2) ) - (xb)/ d] * [(d / np.abs(d))+ np.erf [((xb)/np.sqrt(2)* d)] - (c / np / sqrt(2) * d)]
TypeError:'numpy.ufunc'对象没有属性' getitem '“
有人可以帮我解决这个问题吗? 非常感谢你!