Define a distorted gaussian function that returns two parameters after installation

I know that such questions have already been asked several times, but still I can not get them: I want to define a function that returns more than one parameter.

I wrote the following code to fit the data to a distorted Gaussian function:

def skew(x, sigmag, mu, alpha, c, a):
    normpdf = (1/(sigmag*np.sqrt(2*math.pi)))*np.exp(-(np.power((x-mu),2)/(2*np.power(sigmag,2))))
    normcdf = (0.5*(1+sp.erf((alpha*((x-mu)/sigmag))/(np.sqrt(2)))))
    return 2*a*normpdf*normcdf + c

popt, pcov = curve_fit(skew, xdata, ydata, p0=(5.5, 57636., 4.5, 0.0001, 0.01))
y_fit= skew(xdata, popt[0], popt[1], popt[2], popt[3], popt[4])

However, my idea is to get the peak of the data distribution, and not the average value returned by the function skew, as one of the best match values. Therefore, I need a modedistribution that can be calculated as a maximum normpdf.

How can I get normpdffrom my specific function and get its maximum mounted information?

+4
source share
1 answer

, , , , , . , , ",", , popt, pcov = curve_fit(...). mode . :

def skew2(x, sigmag, mu, alpha, c, a):
    normpdf = (1 / (sigmag * np.sqrt(2 * math.pi))) * np.exp(-(np.power((x - mu), 2) / (2 * np.power(sigmag, 2))))
    normcdf = (0.5 * (1 + sp.erf((alpha * ((x - mu) / sigmag)) / (np.sqrt(2)))))
    return 2 * a * normpdf * normcdf + c, max(normpdf)

def skew(x, sigmag, mu, alpha, c, a):
    return skew2(x, sigmag, mu, alpha, c, a)[0]

popt, pcov = curve_fit(skew, xdata, ydata, p0=(5.5, 57636., 4.5, 0.0001, 0.01))
y_fit, mode = skew2(xdata, *popt[:5])
+3

Source: https://habr.com/ru/post/1691333/


All Articles