![]() | ![]() | ![]() | Gwyddion Library Reference Manual | ![]() |
---|
gwynlfit — Marquardt-Levenbert nonlinear least square fitter.
gdouble (*GwyNLFitFunc) (gdouble x, gint n_par, gdouble *param, gpointer user_data, gboolean *fres); void (*GwyNLFitDerFunc) (gint i, gdouble *x, gint n_par, gdouble *param, GwyNLFitFunc fmarq, gpointer user_data, gdouble *deriv, gboolean *dres); struct GwyNLFitter; GwyNLFitter* gwy_math_nlfit_new (GwyNLFitFunc ff, GwyNLFitDerFunc df); void gwy_math_nlfit_free (GwyNLFitter *nlfit); gdouble gwy_math_nlfit_fit (GwyNLFitter *nlfit, gint n_dat, gdouble *x, gdouble *y, gdouble *weight, gint n_par, gdouble *param, gpointer user_data); gint gwy_math_nlfit_get_max_iterations (GwyNLFitter *nlfit); void gwy_math_nlfit_set_max_iterations (GwyNLFitter *nlfit, gint maxiter); gdouble gwy_math_nlfit_get_dispersion (GwyNLFitter *nlfit); gdouble gwy_math_nlfit_get_correlations (GwyNLFitter *nlfit, gint par1, gint par2); gdouble gwy_math_nlfit_get_sigma (GwyNLFitter *nlfit, gint par); void gwy_math_nlfit_derive (gint i, gdouble *x, gint n_par, gdouble *param, GwyNLFitFunc ff, gpointer user_data, gdouble *deriv, gboolean *dres);
gdouble (*GwyNLFitFunc) (gdouble x, gint n_par, gdouble *param, gpointer user_data, gboolean *fres);
Fitting function type.
x: | The value to compute the function in. |
n_par: | The number of parameters (size of param). |
param: | Parameters. |
user_data: | User data as passed to gwy_math_nlfit_fit(). |
fres: | Set to TRUE if succeeds, FALSE on failure. |
Returns : | The value at x. |
void (*GwyNLFitDerFunc) (gint i, gdouble *x, gint n_par, gdouble *param, GwyNLFitFunc fmarq, gpointer user_data, gdouble *deriv, gboolean *dres);
Fitting function partial derivation type.
i: | The index of the value in x to compute the derivation in. |
x: | x-data as passed to gwy_math_nlfit_fit(). |
n_par: | The number of parameters (size of param). |
param: | Parameters. |
fmarq: | The fitting function. |
user_data: | User data as passed to gwy_math_nlfit_fit(). |
deriv: | Array where the n_par partial derivations by each parameter are to be stored. |
dres: | Set to TRUE if succeeds, FALSE on failure. |
struct GwyNLFitter { GwyNLFitFunc fmarq; /* fitting function */ GwyNLFitDerFunc dmarq; /* fitting function derivations */ gint maxiter; /* max number of iterations */ gboolean eval; /* success? */ gdouble *covar; /* covariance matrix */ gdouble dispersion; /* dispersion */ gdouble mfi; /* fitting parameters -- fi, snizeni, zvyseni lambda, minimalni lambda */ gdouble mdec; gdouble minc; gdouble mtol; };
GwyNLFitter* gwy_math_nlfit_new (GwyNLFitFunc ff, GwyNLFitDerFunc df);
Creates a new Marquardt-Levenberg nonlinear fitter for function ff.
ff: | The fitted function. |
df: | The derivation of fitted function. You can use gwy_math_nlfit_derive() computing the derivation numerically, when you don't know the derivation explicitely. |
Returns : | The newly created fitter. |
Since 1.1.
void gwy_math_nlfit_free (GwyNLFitter *nlfit);
Completely frees a Marquardt-Levenberg nonlinear fitter.
nlfit: | A Marquardt-Levenberg nonlinear fitter. |
Since 1.1.
gdouble gwy_math_nlfit_fit (GwyNLFitter *nlfit, gint n_dat, gdouble *x, gdouble *y, gdouble *weight, gint n_par, gdouble *param, gpointer user_data);
Performs a nonlinear fit of nlfit function on (x,y) data.
nlfit: | A Marquardt-Levenberg nonlinear fitter. |
n_dat: | The number of data points in x, y, w. |
x: | Array of independent variable values. |
y: | Array of dependent variable values. |
weight: | Array of weights associated to each data point. |
n_par: | The nuber of parameters. |
param: | Array of parameters (of size n_par). Note the parameters must be initialized to reasonably near values. |
user_data: | Any pointer that will be passed to the function and derivation as user_data. |
Returns : | The final residual sum, a negative number in the case of failure. |
Since 1.1.
gint gwy_math_nlfit_get_max_iterations (GwyNLFitter *nlfit);
Returns the maximum number of iterations of nonlinear fitter nlfit.
nlfit: | A Marquardt-Levenberg nonlinear fitter. |
Returns : | The maximum number of iterations. |
Since 1.1.
void gwy_math_nlfit_set_max_iterations (GwyNLFitter *nlfit, gint maxiter);
Sets the maximum number of iterations for nonlinear fitter nlfit.
nlfit: | A Marquardt-Levenberg nonlinear fitter. |
maxiter: | The maximum number of iterations. |
Since 1.1.
gdouble gwy_math_nlfit_get_dispersion (GwyNLFitter *nlfit);
Returns the residual sum divided by the number of degrees of freedom.
This function makes sense only after a successful fit.
nlfit: | A Marquardt-Levenberg nonlinear fitter. |
Returns : | The dispersion. |
Since 1.1.
gdouble gwy_math_nlfit_get_correlations (GwyNLFitter *nlfit, gint par1, gint par2);
Returns the correlation coefficient between par1-th and par2-th parameter.
This function makes sense only after a successful fit.
nlfit: | A Marquardt-Levenberg nonlinear fitter. |
par1: | First parameter index. |
par2: | Second parameter index. |
Returns : | The correlation coefficient. |
Since 1.1.
gdouble gwy_math_nlfit_get_sigma (GwyNLFitter *nlfit, gint par);
Returns the standard deviation of parameter number par.
This function makes sense only after a successful fit.
nlfit: | A Marquardt-Levenberg nonlinear fitter. |
par: | Parameter index. |
Returns : | The SD of par-th parameter. |
Since 1.1.
void gwy_math_nlfit_derive (gint i, gdouble *x, gint n_par, gdouble *param, GwyNLFitFunc ff, gpointer user_data, gdouble *deriv, gboolean *dres);
Numerically computes the partial derivations of ff
i: | Index in data_x where to compute the derivation. |
x: | x-data as passed to gwy_math_nlfit_fit(). |
n_par: | The nuber of parameters. |
param: | Array of parameters (of size n_par). |
ff: | The fitted function. |
user_data: | User data as passed to gwy_math_nlfit_fit(). |
deriv: | Array where the put the result to. |
dres: | Set to TRUE if succeeds, FALSE on failure. |
Since 1.1.
<< gwymath | GwySIUnit >> |