snpl.fit module¶
Utilities for curve fitting analyses
Note
This module is not really useful anymore.
It is encouraged to use directly the scipy.optimize
package instead.
- class snpl.fit.Function(expr, params, share=[], lock=[], headers=[], **lineprops)[source]¶
Bases:
object
- Bound(ind, bound=(-inf, inf))[source]¶
Specify the boundary for the parameter. @param ind: index of the target parameter @param bound: two-tuple of the lower and upper boundary.
- Decode(params)[source]¶
Makes the “full” parameters containing locked parameters, from the “partial” parameters excluding locked ones.
- DecodeErrors(errors)[source]¶
Makes the “full” parameters containing locked parameters, from the “partial” parameters excluding locked ones.
- Encode()[source]¶
Makes the “partial” parameters & bounds excluding locked parameters, from the currently-set parameters & errors. @return: two-tuple of lists
- Evaluate(x)[source]¶
Get the value of the function at x with current parameters. @return: float number
- EvaluateWithParam(x, params)[source]¶
Get the value of the function at x with given parameters. NOTE: This method doesn’t overwrite the parameters held by this class. @return: float number
- EvaluateWithPartialParam(x, *params)[source]¶
Get the value of the function at x with given parameters. This method doesn’t overwrite the parameters held by this class. Unlike EvaluateWithParam(), this method accepts a “partial” parameter excluding locked values.
- Fit(xs, ys, sigma=None, **kwargs)[source]¶
Fit the model to given data set. @param xs: array of x @param ys: array of y @param sigma: array of std. dev., optional
- GetParameterLength()[source]¶
Get the number of parameters needed (including locked/shared parameters).
- GetParamsHeadersString(fmt='{0:>15s}', sep='\t')[source]¶
Returns a formatted string of parameter headers.
- GetPlotData(start, stop, num=1000, xlog=False, baseline=None)[source]¶
Make the arrays for plotting functions. @param start: starting value for x @param stop: stopping value for x @param num: number of points @param xlog: If True, x will be evenly spaced in log scale. @param baseline: another Function() instance @return: (array of x, array of y)
- Lock(*args)[source]¶
Lock the parameter(s). Locked parameters don’t change during fitting. @param *args: index (or indices) of the parameters to be locked. NOT A LIST OF INDICES.
Specify the parameter(s) to be shared. @param *args: index (or indices) of the parameters to be shared. NOT A LIST OF INDICES.
- class snpl.fit.Model(funcs=[])[source]¶
Bases:
object
A class for fitting model function composed of multiple functions.
- Decode(params)[source]¶
Chop the given parameters into parameter lists for each function. @param params: a list of parameters @return: a list of lists of parameters (ret[i][j]: jth parameter of ith function)
- Encode()[source]¶
Return a list of current parameters (considering locked and shared parameters) @return: a list of parameters and a list of two-tuples of bounds
20160930 added bounds tuples
- EvaluateWithParams(x, *params)[source]¶
Evaluate the model using x and given parameters. Note that the parameters given here do not affect the parameters of this instance. To update the parameters of the instance, call self.UpdateParameters. @param x: @param *params: parameters
- Fit(xs, ys, sigma=None)[source]¶
Fit the model to given data set. @param xs: array of x @param ys: array of y @param sigma: array of std. dev., optional
- GetPlotData(start, stop, num=1000, xlog=False, ind=None, baseline=None)[source]¶
Make the arrays for plotting functions. @param start: starting value for x @param stop: stopping value for x @param num: number of points @param xlog: use x evenly spaced in log space if True. @param ind: index of a function to be plotted. If None, the data for whole model will be evaluated. @param baseline: another Function() object @return: (array of x, array of y)
- snpl.fit.Parabolic(x, p)[source]¶
p[0]: height (>0) p[1]: position p[2]: full width at half maximum (fwhm)
- snpl.fit.PseudoVoigt(x, p)[source]¶
Gaussian-Lorentzian Sum (Amplitude), from PeakFit v4.12 Manual 7-11
- class snpl.fit.Residuals(residuals_function, p0)[source]¶
Bases:
object
A class for general least-square optimization. It calculates the sum of squared residuals and try to minimize it with respect to the parameters, starting from p0.