laserIMUCalibration
lmmin.c File Reference

Levenberg-Marquardt minimization. More...

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include "lmmin.h"
Include dependency graph for lmmin.c:

Go to the source code of this file.

Macros

#define MIN(a, b)   (((a)<=(b)) ? (a) : (b))
 [brief description] More...
 
#define MAX(a, b)   (((a)>=(b)) ? (a) : (b))
 [brief description] More...
 
#define SQR(x)    (x)*(x)
 [brief description] More...
 
#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 */
 

Functions

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)
 [brief description] More...
 
void lm_qrfac (int m, int n, double *a, int *ipvt, double *rdiag, double *acnorm, double *wa)
 [brief description] More...
 
void lm_qrsolv (int n, double *r, int ldr, int *ipvt, double *diag, double *qtb, double *x, double *sdiag, double *wa)
 [brief description] More...
 
void lm_print_pars (int nout, const double *par, double fnorm, FILE *fout)
 
void lmmin (int n, double *x, int m, const void *data, void(*evaluate)(const double *par, int m_dat, const void *data, double *fvec, int *userbreak), const lm_control_struct *C, lm_status_struct *S)
 Levenberg-Marquardt minimization. More...
 
double lm_enorm (int n, const double *x)
 Refined calculation of Eucledian norm. More...
 

Variables

const lm_control_struct lm_control_double
 Preset (and recommended) control parameter settings. More...
 
const lm_control_struct lm_control_float
 Preset (and recommended) control parameter settings. More...
 
const char * lm_infmsg []
 Preset message texts. More...
 
const char * lm_shortmsg []
 Preset message texts. More...
 

Detailed Description

Levenberg-Marquardt minimization.

Library lmfit (Levenberg-Marquardt least squares fitting)

Author
MINPACK authors, The University of Chikago (1980-1999)
Joachim Wuttke, Forschungszentrum Juelich GmbH (2004-2013)

License: FreeBSD

See also
Homepage

Definition in file lmmin.c.

Macro Definition Documentation

#define LM_DWARF   DBL_MIN /* smallest nonzero number */

Definition at line 102 of file lmmin.c.

#define LM_MACHEP   DBL_EPSILON /* resolution of arithmetic */

Definition at line 101 of file lmmin.c.

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

Definition at line 103 of file lmmin.c.

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

Definition at line 104 of file lmmin.c.

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

Definition at line 105 of file lmmin.c.

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

[brief description]

[long description]

Returns
[description]

Definition at line 35 of file lmmin.c.

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

[brief description]

[long description]

Returns
[description]

Definition at line 28 of file lmmin.c.

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

[brief description]

[long description]

Returns
[description]

Definition at line 42 of file lmmin.c.

Function Documentation

double lm_enorm ( int  n,
const double *  x 
)

Refined calculation of Eucledian norm.

sum squares.

calculation of norm.

Definition at line 1119 of file lmmin.c.

Here is the caller graph for this function:

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 
)

[brief description]

[long description]

Parameters
n[description]
r[description]
ldr[description]
ipvt[description]
diag[description]
qtb[description]
delta[description]
par[description]
x[description]
sdiag[description]
aux[description]
xdi[description]

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 586 of file lmmin.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void lm_print_pars ( int  nout,
const double *  par,
double  fnorm,
FILE *  fout 
)

Definition at line 170 of file lmmin.c.

Here is the caller graph for this function:

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

[brief description]

[long description]

Parameters
m[description]
n[description]
a[description]
ipvt[description]
rdiag[description]
acnorm[description]
wa[description]

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 813 of file lmmin.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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

[brief description]

[long description]

Parameters
n[description]
r[description]
ldr[description]
ipvt[description]
diag[description]
qtb[description]
x[description]
sdiag[description]
wa[description]

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^T)*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 952 of file lmmin.c.

Here is the caller graph for this function:

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 *userbreak)  evaluate,
const lm_control_struct control,
lm_status_struct status 
)

Levenberg-Marquardt minimization.

This routine contains the core algorithm of our library. It minimizes the sum of the squares of m nonlinear functions in n variables by a modified Levenberg-Marquardt algorithm. The function evaluation is done by the user-provided routine 'evaluate'. The Jacobian is then calculated by a forward-difference approximation.

Parameters
n_paris the number of variables (INPUT, positive integer).
paris the solution vector (INPUT/OUTPUT, array of length n). On input it must be set to an estimated solution. On output it yields the final estimate of the solution.
m_datis the number of functions to be minimized (INPUT, positive integer). It must fulfill m>=n.
datais a pointer that is ignored by lmmin; it is however forwarded to the user-supplied functions evaluate and printout. In a typical application, it contains experimental data to be fitted.
evaluateis a user-supplied function that calculates the m functions.
fvecis an array of length m; on OUTPUT, it must contain the m function values for the parameter vector x.
userbreakis an integer pointer. When *userbreak is set to a nonzero value, lmmin will terminate.
controlcontains INPUT variables that control the fit algorithm, as declared and explained in lmstruct.h
statuscontains OUTPUT variables that inform about the fit result, as declared and explained in lmstruct.h

Definition at line 183 of file lmmin.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const lm_control_struct lm_control_double
Initial value:
= {
NULL, 0, -1, -1
}
#define LM_USERTOL
Definition: lmmin.c:105

Preset (and recommended) control parameter settings.

double-precision

Definition at line 121 of file lmmin.c.

const lm_control_struct lm_control_float
Initial value:
= {
1.e-7, 1.e-7, 1.e-7, 1.e-7, 100., 100, 1,
NULL, 0, -1, -1
}

Preset (and recommended) control parameter settings.

float-precision

Definition at line 125 of file lmmin.c.

const char* lm_infmsg[]
Initial value:
= {
"found zero (sum of squares below underflow limit)",
"converged (the relative error in the sum of squares is at most tol)",
"converged (the relative error of the parameter vector is at most tol)",
"converged (both errors are at most tol)",
"trapped (by degeneracy; increasing epsilon might help)",
"exhausted (number of function calls exceeding preset patience)",
"failed (ftol<tol: cannot reduce sum of squares any further)",
"failed (xtol<tol: cannot improve approximate solution any further)",
"failed (gtol<tol: cannot improve approximate solution any further)",
"crashed (not enough memory)",
"exploded (fatal coding error: improper input parameters)",
"stopped (break requested within function evaluation)"
}

Preset message texts.

Definition at line 135 of file lmmin.c.

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

Preset message texts.

Definition at line 150 of file lmmin.c.