Python / Scipy - implementing optimize.curve_fit 's sigma into optimize.leastsq

前端 未结 3 761
日久生厌
日久生厌 2021-01-12 21:03

I am fitting data points using a logistic model. As I sometimes have data with a ydata error, I first used curve_fit and its sigma argument to include my individual standard

3条回答
  •  甜味超标
    2021-01-12 21:26

    The scipy.optimize.curve_fit docs say:

    pcov : 2d array

    The estimated covariance of popt. The diagonals provide the variance of the parameter estimate. To compute one standard deviation errors on the parameters use perr = np.sqrt(np.diag(pcov)). How the sigma parameter affects the estimated covariance depends on absolute_sigma argument, as described above.

    And the section on

    absolute_sigma : bool, optional

    If True, sigma is used in an absolute sense and the estimated parameter covariance pcov reflects these absolute values.

    If False, only the relative magnitudes of the sigma values matter. The returned parameter covariance matrix pcov is based on scaling sigma by a constant factor. This constant is set by demanding that the reduced chisq for the optimal parameters popt when using the scaled sigma equals unity. In other words, sigma is scaled to match the sample variance of the residuals after the fit. Mathematically, pcov(absolute_sigma=False) = pcov(absolute_sigma=True) * chisq(popt)/(M-N)

    So, you could just leave absolute_sigma to the default value (False) and then use

     perr = np.sqrt(np.diag(pcov))
     fitStdErr0 = perr[0]
     fitStdErr1 = perr[1]
     ...
    

    to get the standard deviation error of each fit parameter (as a 1D numpy array). Now you can just pick the useful members (and combine them in a way that is most representative of your data).

提交回复
热议问题