Getting standard error related to parameter evaluation from scipy.optimize.curve_fit

I use scipy.optimize.curve_fitto fit the curve to some data that I have. The curves, for the most part, seem very good. For some reason pcov = inf when I print it.

I really need to calculate the error associated with the parameters that I fit, and I don’t know how to do it exactly, even if it gives me the covariance matrix.

Suitable model:

def intensity(x,R_out,R_in,K_in,K_out,a,b,c):
    K_in,K_out = abs(0.0),abs(K_out)
    if x<=R_in:
        return 2*R_out*(K_out*np.sqrt(1-x**2/R_out**2)-
                (K_out-0.0)*np.sqrt(R_in**2/R_out**2-x**2/R_out**2)) + c
    elif x>=R_in and x<=R_out:
        return K_out*2*R_out*np.sqrt(1-x**2/R_out**2) + c
    elif x>R_out:
        return c

intensity_vec = np.vectorize(intensity)



def intensity_vec_self(x,R_out,R_in,K_in,K_out,a,b,c):
    y = np.zeros(x.shape)
    for i in range(len(y)):
        y[i]=intensity_vec(x[i],R_out,R_in,K_in,K_out,a,b,c)
    return y

and there are 400 data points, I can include this here if you think this will help.

To summarize, I can’t get curve_fitmine to print pcovand you need help to find out why and if I can get it done.

, , , pcov , .

+4
1

- -, - sqarue. np.sqrt(np.diag(pcov))

inf, :

In [129]:
import numpy as np
def func(x, a, b, c, d):
    return a * np.exp(-b * x) + c

xdata = np.linspace(0, 4, 50)
y = func(xdata, 2.5, 1.3, 0.5, 1)
ydata = y + 0.2 * np.random.normal(size=len(xdata))
popt, pcov = so.curve_fit(func, xdata, ydata)
print np.sqrt(np.diag(pcov))
[ inf  inf  inf  inf]

In [130]:

def func(x, a, b, c):
    return a * np.exp(-b * x) + c

xdata = np.linspace(0, 4, 50)
y = func(xdata, 2.5, 1.3, 0.5)
ydata = y + 0.2 * np.random.normal(size=len(xdata))
popt, pcov = so.curve_fit(func, xdata, ydata)
print np.sqrt(np.diag(pcov))
[ 0.11097646  0.11849107  0.05230711]

d func, +inf, , . d func , .

, , :

def func(x, a, b, c, d):
    #return a * np.exp(-b * x) + c
    return a * np.exp(-b * x) + c + d*1e-10

inf - / .

, , a b. .

+6

All Articles