triqs.fit.fit.Fit
- class triqs.fit.fit.Fit(x_array, y_array, fitter, p0=None)[source]
Bases:
objectLeast-squares fit of a parametric model to 1D data.
Given a model
f(x, p_0, ..., p_{n-1})and an initial guess,Fitadjusts the parameters by minimising \(\sum_i |f(x_i, \mathbf{p}) - y_i|^2\) usingscipy.optimize.leastsq(). The fit is performed in__init__; the constructed object is callable and stringifies to a LaTeX expression, so it can be passed directly totriqs.plot.mpl_interface.oplot().- Parameters:
- x_arrayarray-like
1D array of abscissae.
- y_arrayarray-like
1D array of ordinates, same length as
x_array.- fittertuple
Triple
(F, name, init_value_default)whereFis a callableF(x, *params) -> yacting elementwise on a numpy array,nameis a printf-style template such thatname % paramsyields a LaTeX expression, andinit_value_defaultis a tuple of default initial values used whenp0isNone. Ready-made fitters:linear,quadratic.- p0tuple, optional
Initial guess. Defaults to the third element of
fitter.
Attributes
function
(callable) The model
Fextracted fromfitter.fname
(str) The printf-style LaTeX template extracted from
fitter.param
(numpy.ndarray) Fitted parameter values returned by
scipy.optimize.leastsq.Methods
__call__(x)Evaluate the fitted model at
x.Examples
Linear fit of noisy data, then plotted on top of the data via
oplot():from triqs.fit import Fit, linear from triqs.plot.mpl_interface import oplot, plt f = Fit(x, y, linear) oplot(f) plt.show()