如何更好地拟合双高斯?我关心小的 y 数据。我需要非常准确的结果。
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from sklearn import mixture
from pylab import *
import matplotlib.mlab
from scipy.optimize import leastsq
data2 = pd.read_csv('Downloads/dose_r2.dat',names=
['Promien','Dawka','odchylenie'],sep=' ')
x = data2["Promien"]
y = data2["Dawka"]
%matplotlib inline
def double_gaussian( x, params ):
(c1, mu1, sigma1, c2, mu2, sigma2) = params
res = c1 * np.exp( - (x - mu1)**2.0 / (2.0 * sigma1**2.0) ) \
+ c2 * np.exp( - (x - mu2)**2.0 / (2.0 * sigma2**2.0) )
return res
def double_gaussian_fit( params ):
fit = double_gaussian( x, params )
return (fit - y)
# Least squares fit. Starting values found by inspection.
fit = leastsq( double_gaussian_fit, [1.5,0,0.7,0.00005,10.5,3.0] )
plt.scatter( x, y,s=0.7)
plt.xlabel("zasieg [cm]")
plt.ylabel("dawka [Gy]")
plt.grid(True)
#plt.yscale('log')
#plt.ylim(((0,0.0004)))
plot( x, double_gaussian( x, fit[0] ) )
高斯从远处看起来很棒,但是当我放大...