Exponential¶
-
class
plasmapy.analysis.fit_functions.
Exponential
(params: Tuple[float, ...] = None, param_errors: Tuple[float, ...] = None)¶ Bases:
plasmapy.analysis.fit_functions.AbstractFitFunction
A sub-class of
AbstractFitFunction
to represent an exponential with an offset.\[ \begin{align}\begin{aligned}y &= f(x) = a \, e^{\alpha \, x}\\\left( \frac{\delta y}{|y|} \right)^2 &= \left( \frac{\delta a}{a} \right)^2 + (x \, \delta \alpha)^2 + (\alpha \, \delta x)^2\end{aligned}\end{align} \]where \(a\) and \(\alpha\) are the real constants to be fitted and \(x\) is the independent variable. \(\delta a\), \(\delta \alpha\), and \(\delta x\) are the respective uncertainties for \(a\), \(\alpha\), and \(x\).
Attributes Summary
curve_fit_results
The results returned by the curve fitting routine used by curve_fit
.latex_str
LaTeX friendly representation of the fit function. param_errors
The associated errors of the fitted params
.param_names
Names of the fitted parameters. params
The fitted parameters for the fit function. rsq
Coefficient of determination (r-squared) value of the fit. Methods Summary
__call__
(x[, x_err, reterr])Direct call of the fit function \(f(x)\). curve_fit
(xdata, ydata, **kwargs)Use a non-linear least squares method to fit the fit function to ( xdata
,ydata
), usingscipy.optimize.curve_fit
.func
(x, a, alpha)The fit function, a exponential function. func_err
(x[, x_err, rety])Calculate dependent variable uncertainties \(\delta y\) for dependent variables \(y=f(x)\). root_solve
(*args, **kwargs)The root \(f(x_r) = 0\) for the fit function. Attributes Documentation
-
curve_fit_results
¶ The results returned by the curve fitting routine used by
curve_fit
. This is typically fromscipy.stats.linregress
orscipy.optimize.curve_fit
.
-
latex_str
¶ LaTeX friendly representation of the fit function.
-
param_names
¶ Names of the fitted parameters.
-
params
¶ The fitted parameters for the fit function.
-
rsq
¶ Coefficient of determination (r-squared) value of the fit.
\[ \begin{align}\begin{aligned}r^2 &= 1 - \frac{SS_{res}}{SS_{tot}}\\SS_{res} &= \sum\limits_{i} (y_i - f(x_i))^2\\SS_{tot} &= \sum\limits_{i} (y_i - \bar{y})^2\end{aligned}\end{align} \]where \((x_i, y_i)\) are the sample data pairs, \(f(x_i)\) is the fitted dependent variable corresponding to \(x_i\), and \(\bar{y}\) is the average of the \(y_i\) values.
The \(r^2\) value is an indicator of how close the points \((x_i, y_i)\) lie to the model \(f(x)\). \(r^2\) values range between 0 and 1. Values close to 0 indicate that the points are uncorrelated and have little tendency to lie close to the model, whereas, values close to 1 indicate a high correlation to the model.
Methods Documentation
-
__call__
(x, x_err=None, reterr=False)¶ Direct call of the fit function \(f(x)\).
Parameters: - x (array_like) – Dependent variables.
- x_err (array_like, optional) – Errors associated with the independent variables
x
. Must be of size one or equal to the size ofx
. - reterr (bool, optional) – (Default:
False
) IfTrue
, return an array of uncertainties associated with the calculated independent variables
Returns: - y (
numpy.ndarray
) – Corresponding dependent variables \(y=f(x)\) of the independent variablesx
. - y_err (
numpy.ndarray
) – Uncertainties associated with the calculated dependent variables \(\delta y\)
-
curve_fit
(xdata, ydata, **kwargs) → None¶ Use a non-linear least squares method to fit the fit function to (
xdata
,ydata
), usingscipy.optimize.curve_fit
. This will set the attributesparameters
,parameters_err
, andrsq
.The results of
scipy.optimize.curve_fit
can be obtained viacurve_fit_results
.Parameters: - xdata (array_like) – The independent variable where data is measured. Should be 1D of length M.
- ydata (array_like) – The dependent data associated with
xdata
. - **kwargs – Any keywords accepted by
scipy.optimize.curve_fit
.
Raises: ValueError
– if eitherydata
orxdata
containnumpy.nan
’s, or if incompatible options are used.RuntimeError
– if the least-squares minimization fails.OptimizeWarning
– if covariance of the parameters can not be estimated.
-
func
(x, a, alpha)¶ The fit function, a exponential function.
\[f(x) = a \, e^{\alpha \, x}\]where \(a\) and \(\alpha\) are real constants and \(x\) is the independent variable.
Parameters: Returns: y – dependent variables corresponding to
x
Return type: array_like
-
func_err
(x, x_err=None, rety=False)¶ Calculate dependent variable uncertainties \(\delta y\) for dependent variables \(y=f(x)\).
\[\left( \frac{\delta y}{|y|} \right)^2 = \left( \frac{\delta a}{a} \right)^2 + (x \, \delta \alpha)^2 + (\alpha \, \delta x)^2\]Parameters: Returns: - err (
numpy.ndarray
) – The calculated uncertainties \(\delta y\) of the dependent variables (\(y = f(x)\)) of the independent variablesx
. - y (
numpy.ndarray
, optional) – (ifrety == True
) The associated dependent variables \(y = f(x)\).
Notes
A good reference for formulating propagation of uncertainty expressions is:
J. R. Taylor. An Introduction to Error Analysis: The Study of Uncertainties in Physical Measurements. University Science Books, second edition, August 1996 (ISBN: 093570275X)
- err (
-
root_solve
(*args, **kwargs)¶ The root \(f(x_r) = 0\) for the fit function. An exponential has no real roots.
Parameters: - *args – Not needed. This is to ensure signature compatibility with
AbstractFitFunction
. - *kwargs – Not needed. This is to ensure signature compatibility with
AbstractFitFunction
.
Returns: - root (float) – The root value for the given fit
parameters
. - err (float) – The uncertainty in the calculated root for the given fit
parameters
andparameters_err
.
- *args – Not needed. This is to ensure signature compatibility with
-