UPD:谢谢,它有效。
我有一个1D矢量,代表一个直方图。它看起来像几个高斯函数的总和:
我在SO上找到了curve_fit
示例代码,但不知道如何修改它以接收更多高斯元组(mu,sigma)。我听说过#curve; fit'仅优化一个函数(在本例中为一个高斯曲线)。
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
def estimate_sigma(hist):
bin_edges = np.arange(len(hist))
bin_centres = bin_edges + 0.5
# Define model function to be used to fit to the data above:
def gauss(x, *p):
A, mu, sigma = p
return A*numpy.exp(-(x-mu)**2/(2.*sigma**2))
# p0 is the initial guess for the fitting coefficients (A, mu and sigma above)
p0 = [1., 0., 1.]
coeff, var_matrix = curve_fit(gauss, bin_centres, hist, p0=p0)
# Get the fitted curve
hist_fit = gauss(bin_centres, *coeff)
plt.plot(bin_centres, hist, label='Test data')
plt.plot(bin_centres, hist_fit, label='Fitted data')
print 'Fitted mean = ', coeff[1]
coeff2 =coeff[2]
print 'Fitted standard deviation = ', coeff2
plt.show()
请你能否建议一些numpy / scipy函数来实现1D vector
格式([m1, sigma1],[m2, sigma2],..,[mN,sigmaN])
的gmm表示?
答案 0 :(得分:0)
建议tBuLi,我将额外的高斯曲线系数传递给<root-logger>
<level name="2000"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
以及gauss
。
现在拟合曲线看起来如此:
更新的代码:
curve_fit