Class fit_nonlin (o2scl)

O2scl : Class List

template<class func_t = gen_fit_funct<>, class vec_t = boost::numeric::ublas::vector<double>, class mat_t = boost::numeric::ublas::matrix<double>>
class o2scl::fit_nonlin : public o2scl::fit_nonlin_b<boost::numeric::ublas::vector<double>, boost::numeric::ublas::matrix<double>>, public o2scl::fit_base<gen_fit_funct<>, boost::numeric::ublas::vector<double>, boost::numeric::ublas::matrix<double>>

Non-linear least-squares fitting class (GSL)

The GSL-based fitting class using a Levenberg-Marquardt type algorithm. The algorithm stops when

\[ |dx_i| < \mathrm{tol\_abs}+\mathrm{tol\_rel}\times|x_i| \]
where \(dx\) is the last step and \(x\) is the current position. If test_gradient is true, then additionally fit() requires that
\[ \sum_i |g_i| < \mathrm{tol\_abs} \]
where \(g_i\) is the \(i\)-th component of the gradient of the function \(\Phi(x)\) where
\[ \Phi(x) = || F(x) ||^2 \]

Default template arguments

  • func_t - gen_fit_funct<>

  • vec_t - boost::numeric::ublas::vector <double >

  • mat_t - boost::numeric::ublas::matrix <double >

    Todo:

    Allow the user to specify the derivatives

    Todo:

    Fix so that the user can specify automatic scaling of the fitting parameters, where the initial guess are used for scaling so that the fitting parameters are near unity.

    Idea for Future:

    Some of these member functions (like update_diag()) don’t depend on member data and could be possibly be moved to a parent class?

Public Functions

fit_nonlin()
~fit_nonlin()
int print_iter_nonlin(size_t nv, vec_t &x, vec_t &dx, int iter2, double l_epsabs, double l_epsrel)

Print the progress in the current iteration.

void resize(size_t n, size_t p)

Allocate memory with n data points and p parameters.

int set(size_t npar, vec_t &parms, func_t &fitfun)

Set the initial values of the parameters and the fitting function to use for the next call to iterate()

int iterate()

Perform an iteration.

int fit(size_t npar, vec_t &parms, mat_t &covar, double &chi2, func_t &fitfun)

Fit the data specified in (xdat,ydat) to the function fitfun with the parameters in par.

The covariance matrix for the parameters is returned in covar and the value of \( \chi^2 \) is returned in chi2.

const char *type()

Return string denoting type (“fit_nonlin”)

Public Members

bool err_nonconv

If true, call the error handler if fit() does not converge (default true)

vec_t dx_

The last step taken in parameter space.

vec_t f_

Desc.

bool test_gradient

If true, test the gradient also (default false)

bool use_scaled

Use the scaled routine if true (default true)

Protected Functions

void free()

Free allocated memory.

Protected Attributes

func_t *cff

Function to fit.

vec_t x_trial

Trial step.

vec_t f_trial

Trial function value.

size_t iter

Number of iterations.

double xnorm

Desc.

double fnorm

Desc.

double delta

Desc.

double par

Desc.

mat_t r

Desc.

vec_t tau

Desc.

vec_t diag

Desc.

vec_t qtf

Desc.

vec_t df

Desc.

vec_t rptdx

Desc.

vec_t newton

Desc.

vec_t gradient

Desc.

vec_t sdiag

Desc.

vec_t w

Desc.

vec_t work1

Desc.

permutation perm

Desc.

size_t ndata

Number of data points.

size_t nparm

Number of parameters.

vec_t g_

Desc.

mat_t J_

Desc.

vec_t *x_

Desc.