fit_exp_decay_log
- mdtools.functions.fit_exp_decay_log(xdata, ydata, ysd=None, return_valid=False, **kwargs)[source]
Fit an exponential decay function to ydata using
scipy.optimize.curve_fit()
.Instead of fitting the data directly with an exponential decay function \(e^{-kt}\), the logarithm of the y-data is fitted by
\[f(t) = -k \cdot t\]- Parameters:
xdata (
array_like
) – The independent variable where the data is measured.ydata (
array_like
) – The dependent data. Must have the same shape as xdata. Only data points with 0 < ydata <= 1 will be considered. NaN’s and infinite values will not be considered, either.ysd (
array_like
, optional) – The standard deviation of ydata. Must have the same shape as ydata.return_valid (
bool
, optional) – IfTrue
, return a boolean array of the same shape as ydata that indicates which elements of ydata meet the requirements given above.kwargs (
dict
, optional) – Additional keyword arguments (besides xdata, ydata and sigma) to parse toscipy.optimize.curve_fit()
. See there for possible options. By default, absolute_sigma is set toTrue
, p0 is set to1 / (len(ydata) * np.mean(ydata))
and bounds is set to(0, np.inf)
.
- Returns:
popt (
numpy.ndarray
) – Optimal values for the parameters so that the sum of the squared residuals is minimized. The first and only element of popt is the optimal \(k\) value.perr (
numpy.ndarray
) – Standard deviation of the optimal parameters.valid (
numpy.ndarray
) – Boolean array of the same shape as ydata indicating, which elements of ydata were used for the fit. Only returned if return_valid isTrue
.
See also
mdtools.functions.exp_decay()
Exponential decay function
mdtools.functions.exp_decay_log()
Logarithm of an exponential decay function