fit_kww
- mdtools.functions.fit_kww(xdata, ydata, ysd=None, return_valid=False, **kwargs)[source]
Fit a stretched exponential function, also known as Kohlrausch- Williams-Watts (KWW) function, to ydata using
scipy.optimize.curve_fit()
.The KWW function reads:
\[f(t) = \exp{\left[ -\left( \frac{t}{\tau} \right)^\beta \right]}\]- 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 to[tau_init, 1]
and bounds is set to([0, 0], [np.inf, 1])
.tau_init
is the point at which ydata falls below \(1/e\).
- Returns:
popt (
numpy.ndarray
) – Optimal values for the parameters so that the sum of the squared residuals is minimized. The first element of popt is the optimal \(\tau\) value, the second element is the optimal \(\beta\) 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.kww()
Stretched exponential function