$\DeclareMathOperator{\erf}{erf} \DeclareMathOperator{\argmin}{argmin} \newcommand{\R}{\mathbb{R}} \newcommand{\n}{\boldsymbol{n}}$

# Module pyqt_fit.curve_fitting¶

Author: Pierre Barbier de Reuille

This module specifically implement the curve fitting, wrapping the default scipy.optimize.leastsq function. It allows for parameter value fixing, different kind of residual and added constraints function.

The main class of the module is the CurveFitting class.

class pyqt_fit.curve_fitting.CurveFitting(xdata, ydata, **kwords)[source]

Fit a curve using the scipy.optimize.leastsq() function

Parameters: xdata (ndarray) – Explaining values ydata (ndarray) – Target values

Once fitted, the following variables contain the result of the fitting:

Variables: popt (ndarray) – The solution (or the result of the last iteration for an unsuccessful call) pcov (ndarray) – The estimated covariance of popt. The diagonals provide the variance of the parameter estimate. res (ndarray) – Final residuals infodict (dict) – a dictionary of outputs with the keys: nfev the number of function calls fvec the function evaluated at the output fjac A permutation of the R matrix of a QR factorization of the final approximate Jacobian matrix, stored column wise. Together with ipvt, the covariance of the estimate can be approximated. ipvt an integer array of length N which defines a permutation matrix, p, such that fjac*p = q*r, where r is upper triangular with diagonal elements of nonincreasing magnitude. Column j of p is column ipvt(j) of the identity matrix. qtf the vector (transpose(q) * fvec) CI list of tuple of parameters, each being the lower and upper bounds for the confidence interval in the CI argument at the same position. est_jacobian True if the jacobian is estimated, false if the user-provided functions have been used

Note

In this implementation, residuals are supposed to be a generalisation of the notion of difference. In the end, the mathematical expression of this minimisation is:

$\hat{\theta} = \argmin_{\theta\in \mathbb{R}^p} \sum_i r(y_i, f(\theta, x_i))^2$

Where $$\theta$$ is the vector of $$p$$ parameters to optimise, $$r$$ is the residual function and $$f$$ is the function being fitted.

__call__(xdata)[source]

Return the value of the fitted function for each of the points in xdata

#### Previous topic

Module pyqt_fit.plot_fit

#### Next topic

Module pyqt_fit.bootstrap