ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
Macros | Functions | Variables
lmmin.cxx File Reference
#include "lmmin.h"
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
Include dependency graph for lmmin.cxx:

Go to the source code of this file.

Macros

#define LM_MACHEP   DBL_EPSILON /* resolution of arithmetic */
 
#define LM_DWARF   DBL_MIN /* smallest nonzero number */
 
#define LM_SQRT_DWARF   sqrt(DBL_MIN) /* square should not underflow */
 
#define LM_SQRT_GIANT   sqrt(DBL_MAX) /* square should not overflow */
 
#define LM_USERTOL   30 * LM_MACHEP /* users are recommended to require this */
 
#define MIN(a, b)   (((a) <= (b)) ? (a) : (b))
 
#define MAX(a, b)   (((a) >= (b)) ? (a) : (b))
 
#define SQR(x)   (x) * (x)
 

Functions

void lm_printout_std (int n_par, const double *par, int m_dat, const void *data, const double *fvec, int printflags, int iflag, int iter, int nfev)
 
void lmmin (int n_par, double *par, int m_dat, const void *data, void(*evaluate)(const double *par, int m_dat, const void *data, double *fvec, int *info), const lm_control_struct *control, lm_status_struct *status, void(*printout)(int n_par, const double *par, int m_dat, const void *data, const double *fvec, int printflags, int iflag, int iter, int nfev))
 
void lm_lmpar (int n, double *r, int ldr, int *ipvt, double *diag, double *qtb, double delta, double *par, double *x, double *sdiag, double *aux, double *xdi)
 
void lm_qrfac (int m, int n, double *a, int pivot, int *ipvt, double *rdiag, double *acnorm, double *wa)
 
void lm_qrsolv (int n, double *r, int ldr, int *ipvt, double *diag, double *qtb, double *x, double *sdiag, double *wa)
 
void lm_lmdif (int m, int n, double *x, double *fvec, double ftol, double xtol, double gtol, int maxfev, double epsfcn, double *diag, int mode, double factor, int *info, int *nfev, double *fjac, int *ipvt, double *qtf, double *wa1, double *wa2, double *wa3, double *wa4, void(*evaluate)(const double *par, int m_dat, const void *data, double *fvec, int *info), void(*printout)(int n_par, const double *par, int m_dat, const void *data, const double *fvec, int printflags, int iflag, int iter, int nfev), int printflags, const void *data)
 
double lm_enorm (int n, const double *x)
 

Variables

const lm_control_struct lm_control_double = {LM_USERTOL, LM_USERTOL, LM_USERTOL, LM_USERTOL, 100., 100, 1, 0}
 
const lm_control_struct lm_control_float = {1.e-7, 1.e-7, 1.e-7, 1.e-7, 100., 100, 0, 0}
 
const char * lm_infmsg []
 
const char * lm_shortmsg []
 

Macro Definition Documentation

◆ LM_DWARF

#define LM_DWARF   DBL_MIN /* smallest nonzero number */

Definition at line 40 of file lmmin.cxx.

◆ LM_MACHEP

#define LM_MACHEP   DBL_EPSILON /* resolution of arithmetic */

Definition at line 39 of file lmmin.cxx.

◆ LM_SQRT_DWARF

#define LM_SQRT_DWARF   sqrt(DBL_MIN) /* square should not underflow */

Definition at line 41 of file lmmin.cxx.

◆ LM_SQRT_GIANT

#define LM_SQRT_GIANT   sqrt(DBL_MAX) /* square should not overflow */

Definition at line 42 of file lmmin.cxx.

◆ LM_USERTOL

#define LM_USERTOL   30 * LM_MACHEP /* users are recommended to require this */

Definition at line 43 of file lmmin.cxx.

◆ MAX

#define MAX (   a,
 
)    (((a) >= (b)) ? (a) : (b))

Definition at line 205 of file lmmin.cxx.

◆ MIN

#define MIN (   a,
 
)    (((a) <= (b)) ? (a) : (b))

Definition at line 204 of file lmmin.cxx.

◆ SQR

#define SQR (   x)    (x) * (x)

Definition at line 206 of file lmmin.cxx.

Function Documentation

◆ lm_enorm()

double lm_enorm ( int  n,
const double *  x 
)

sum squares.

calculation of norm.

Definition at line 1206 of file lmmin.cxx.

◆ lm_lmdif()

void lm_lmdif ( int  m,
int  n,
double *  x,
double *  fvec,
double  ftol,
double  xtol,
double  gtol,
int  maxfev,
double  epsfcn,
double *  diag,
int  mode,
double  factor,
int *  info,
int *  nfev,
double *  fjac,
int *  ipvt,
double *  qtf,
double *  wa1,
double *  wa2,
double *  wa3,
double *  wa4,
void(*)(const double *par, int m_dat, const void *data, double *fvec, int *info)  evaluate,
void(*)(int n_par, const double *par, int m_dat, const void *data, const double *fvec, int printflags, int iflag, int iter, int nfev)  printout,
int  printflags,
const void *  data 
)

Legacy low-level interface.

Definition at line 207 of file lmmin.cxx.

◆ lm_lmpar()

void lm_lmpar ( int  n,
double *  r,
int  ldr,
int *  ipvt,
double *  diag,
double *  qtb,
double  delta,
double *  par,
double *  x,
double *  sdiag,
double *  aux,
double *  xdi 
)

evaluate the function at the current value of par.

if the function is small enough, accept the current value of par. Also test for the exceptional cases where parl is zero or the number of iterations has reached 10.

compute the Newton correction.

depending on the sign of the function, update parl or paru.

compute an improved estimate for par.

Definition at line 664 of file lmmin.cxx.

◆ lm_printout_std()

void lm_printout_std ( int  n_par,
const double *  par,
int  m_dat,
const void *  data,
const double *  fvec,
int  printflags,
int  iflag,
int  iter,
int  nfev 
)

Definition at line 86 of file lmmin.cxx.

◆ lm_qrfac()

void lm_qrfac ( int  m,
int  n,
double *  a,
int  pivot,
int *  ipvt,
double *  rdiag,
double *  acnorm,
double *  wa 
)

bring the column of largest norm into the pivot position.

compute the Householder transformation to reduce the j-th column of a to a multiple of the j-th unit vector.

apply the transformation to the remaining columns and update the norms.

Definition at line 891 of file lmmin.cxx.

◆ lm_qrsolv()

void lm_qrsolv ( int  n,
double *  r,
int  ldr,
int *  ipvt,
double *  diag,
double *  qtb,
double *  x,
double *  sdiag,
double *  wa 
)

determine a Givens rotation which eliminates the appropriate element in the current row of d.

compute the modified diagonal element of r and the modified element of ((q transpose)*b,0).

accumulate the tranformation in the row of s.

store the diagonal element of s and restore the corresponding diagonal element of r.

Definition at line 1037 of file lmmin.cxx.

◆ lmmin()

void lmmin ( int  n_par,
double *  par,
int  m_dat,
const void *  data,
void(*)(const double *par, int m_dat, const void *data, double *fvec, int *info)  evaluate,
const lm_control_struct control,
lm_status_struct status,
void(*)(int n_par, const double *par, int m_dat, const void *data, const double *fvec, int printflags, int iflag, int iter, int nfev)  printout 
)

Definition at line 135 of file lmmin.cxx.

Variable Documentation

◆ lm_control_double

const lm_control_struct lm_control_double = {LM_USERTOL, LM_USERTOL, LM_USERTOL, LM_USERTOL, 100., 100, 1, 0}

Definition at line 58 of file lmmin.cxx.

◆ lm_control_float

const lm_control_struct lm_control_float = {1.e-7, 1.e-7, 1.e-7, 1.e-7, 100., 100, 0, 0}

Definition at line 59 of file lmmin.cxx.

◆ lm_infmsg

const char* lm_infmsg[]
Initial value:
= {"success (sum of squares below underflow limit)",
"success (the relative error in the sum of squares is at most tol)",
"success (the relative error between x and the solution is at most tol)",
"success (both errors are at most tol)",
"trapped by degeneracy (fvec is orthogonal to the columns of the jacobian)",
"timeout (number of calls to fcn has reached maxcall*(n+1))",
"failure (ftol<tol: cannot reduce sum of squares any further)",
"failure (xtol<tol: cannot improve approximate solution any further)",
"failure (gtol<tol: cannot improve approximate solution any further)",
"exception (not enough memory)",
"fatal coding error (improper input parameters)",
"exception (break requested within function evaluation)"}

Definition at line 65 of file lmmin.cxx.

◆ lm_shortmsg

const char* lm_shortmsg[]
Initial value:
= {"success (0)", "success (f)", "success (p)", "success (f,p)",
"degenerate", "call limit", "failed (f)", "failed (p)",
"failed (o)", "no memory", "invalid input", "user break"}

Definition at line 78 of file lmmin.cxx.