Image Component Library (ICL)
|
Utility class implementing the multidimensional Levenberg Marquardt Algorithm for non-linear Optimization. More...
#include <LevenbergMarquardtFitter.h>
Classes | |
struct | Data |
utility structure that is used in the static create_data utlity method More... | |
struct | Result |
Utility structure, that represents a fitting result. More... | |
Public Types | |
typedef DynColVector< Scalar > | Vector |
vector type More... | |
typedef DynColVector< Scalar > | Params |
parameter vector type More... | |
typedef DynMatrix< Scalar > | Matrix |
matrix type (used for input data) More... | |
typedef icl::utils::Function< Vector, const Params &, const Vector & > | Function |
to-be-optimized function type y = f(params, x) More... | |
typedef icl::utils::Function< Matrix, const Params &, const Matrix & > | FunctionMat |
typedef icl::utils::Function< void, const Params &, const Vector &, Vector & > | Jacobian |
jacobian of F More... | |
typedef icl::utils::Function< void, const Params &, const Matrix &, Matrix & > | JacobianMat |
typedef icl::utils::Function< void, const Result & > | DebugCallback |
Optionally given debug callback, that is called in every iterations. More... | |
Public Member Functions | |
LevenbergMarquardtFitter () | |
creates a dummy (null instance) More... | |
LevenbergMarquardtFitter (Function f, int outputDim, const std::vector< Jacobian > &js=std::vector< Jacobian >(), Scalar tau=1.e-3, int maxIterations=200, Scalar minError=1.e-6, Scalar lambdaMultiplier=10, Scalar eps1=1.49012e-08, Scalar eps2=1.49012e-08, const std::string &linSolver="svd") | |
create an instance with given parameters More... | |
LevenbergMarquardtFitter (FunctionMat f, int outputDim, const std::vector< JacobianMat > &js=std::vector< JacobianMat >(), Scalar tau=1.e-3, int maxIterations=200, Scalar minError=1.e-6, Scalar lambdaMultiplier=10, Scalar eps1=1.49012e-08, Scalar eps2=1.49012e-08, const std::string &linSolver="svd") | |
void | setUseMultiThreading (bool enable) |
enables openmp based multithreading More... | |
void | init (Function f, int outputDim, const std::vector< Jacobian > &js=std::vector< Jacobian >(), Scalar tau=1.e-8, int maxIterations=1000, Scalar minError=1.e-6, Scalar lambdaMultiplier=10, Scalar eps1=1.49012e-08, Scalar eps2=1.49012e-08, const std::string &linSolver="svd") |
(re)-initialization method More... | |
void | init (FunctionMat f, int outputDim, const std::vector< JacobianMat > &js=std::vector< JacobianMat >(), Scalar tau=1.e-8, int maxIterations=1000, Scalar minError=1.e-6, Scalar lambdaMultiplier=10, Scalar eps1=1.49012e-08, Scalar eps2=1.49012e-08, const std::string &linSolver="svd") |
Result | fit (const Matrix &xs, const Matrix &ys, Params initParams) |
actual parameter fitting with given data and start parameters More... | |
void | setDebugCallback (DebugCallback dbg=default_debug_callback) |
sets a debug callback method, which is called automatically in every interation More... | |
Static Public Member Functions | |
static Jacobian | create_numerical_jacobian (int o, Function f, float delta=1.E-5) |
creates a single numerical Jacobian for a given function f and output dim More... | |
static JacobianMat | create_numerical_jacobian (int o, FunctionMat f, float delta=1.E-5) |
static std::vector< Jacobian > | create_numerical_jacobians (int n, Function f, float delta=1.e-5) |
creates a set of numerical jacobians for output dimension n More... | |
static std::vector< JacobianMat > | create_numerical_jacobians (int n, FunctionMat f, float delta=1.e-5) |
static Data | create_data (const Params &p, Function f, int xDim, int yDim, int num=1000, Scalar minX=-5, Scalar maxX=5) |
creates test data using a given function More... | |
static void | default_debug_callback (const Result &r) |
default debug callback that simply streams r to std::cout More... | |
Protected Member Functions | |
Scalar | error (const Matrix &ys, const Matrix &y_est) const |
returns the complete error More... | |
Protected Attributes | |
Function | f |
Function f. More... | |
FunctionMat | fMat |
Function f. More... | |
bool | useMultiThreading |
flag whether multithreading is enabled More... | |
bool | useMat |
flag whether matrices in the error function More... | |
Scalar | tau |
used for initial damping parameter lambda More... | |
int | maxIterations |
maximum number of iterations More... | |
Scalar | minError |
minimum error threshold More... | |
Scalar | lambdaMultiplier |
mulitplier that is used to increase/decreas lambda More... | |
Scalar | eps1 |
minimum F'(parameters) threshold More... | |
Scalar | eps2 |
minimum change in parameters threshold More... | |
std::string | linSolver |
linear solver that is used More... | |
Vector | dst |
b in Mx=b of linear system solved internally More... | |
Matrix | J |
Jacobian Matrix (rows are Ji) More... | |
Matrix | H |
Hessian Matrix (J^T J) More... | |
std::vector< Jacobian > | js |
output buffers More... | |
std::vector< JacobianMat > | jsMat |
DebugCallback | dbg |
debug callback More... | |
Params | params_new |
new parameters (after update step) More... | |
Matrix | y_est |
current estimated outputs More... | |
Vector | dy |
buffer for current delta More... | |
Private Member Functions | |
Result | fitVec (const Matrix &xs, const Matrix &ys, Params initParams) |
internal fit function using vectors More... | |
Result | fitMat (const Matrix &xs, const Matrix &ys, Params initParams) |
internal fit function using matrices More... | |
Utility class implementing the multidimensional Levenberg Marquardt Algorithm for non-linear Optimization.
The well known Levenberg Marquardt algorithms (LMA) is used for non-linear parameter optimization. Given a function , an intial set of parameters and a set of training data , where depends on model parameters , LMA will find a local minumum of function parameters that minimizes
The complete algorithm can be found at at wikipedia (see http://en.wikipedia.org/wiki/Levenberg-Marquardt_algorithm)
typedef icl::utils::Function<void,const Result&> icl::math::LevenbergMarquardtFitter< Scalar >::DebugCallback |
Optionally given debug callback, that is called in every iterations.
typedef icl::utils::Function<Vector,const Params&,const Vector&> icl::math::LevenbergMarquardtFitter< Scalar >::Function |
to-be-optimized function type y = f(params, x)
typedef icl::utils::Function<Matrix,const Params&,const Matrix&> icl::math::LevenbergMarquardtFitter< Scalar >::FunctionMat |
typedef icl::utils::Function<void,const Params&, const Vector&, Vector&> icl::math::LevenbergMarquardtFitter< Scalar >::Jacobian |
jacobian of F
typedef icl::utils::Function<void,const Params&, const Matrix&, Matrix&> icl::math::LevenbergMarquardtFitter< Scalar >::JacobianMat |
typedef DynMatrix<Scalar> icl::math::LevenbergMarquardtFitter< Scalar >::Matrix |
matrix type (used for input data)
typedef DynColVector<Scalar> icl::math::LevenbergMarquardtFitter< Scalar >::Params |
parameter vector type
typedef DynColVector<Scalar> icl::math::LevenbergMarquardtFitter< Scalar >::Vector |
vector type
icl::math::LevenbergMarquardtFitter< Scalar >::LevenbergMarquardtFitter | ( | ) |
creates a dummy (null instance)
icl::math::LevenbergMarquardtFitter< Scalar >::LevenbergMarquardtFitter | ( | Function | f, |
int | outputDim, | ||
const std::vector< Jacobian > & | js = std::vector< Jacobian >() , |
||
Scalar | tau = 1.e-3 , |
||
int | maxIterations = 200 , |
||
Scalar | minError = 1.e-6 , |
||
Scalar | lambdaMultiplier = 10 , |
||
Scalar | eps1 = 1.49012e-08 , |
||
Scalar | eps2 = 1.49012e-08 , |
||
const std::string & | linSolver = "svd" |
||
) |
create an instance with given parameters
f | function to be optimized |
j | optionally given Jacobian of f. If j is null (e.g. an empty Jacobian() is passed), a numerical jacobian is created automatically. This will use a numerical delta of 1e-5, which is the default parameter for the static LevenbergMarquardtFitter::create_numerical_jacobian method. If a numerical Jacobian with another delta shall be used, create_numerical_jacobian can be called manually to obtain another automatically created numerical jacobian. |
tau | used for the initial damping parameter (small values (eg 1e-6) are a good choice if the first parameters are believed to be a good approximation. Otherwise 1e-3 or 1 should be used) |
maxIterations | maximum number of iterations (usually, LevenbergMarquardtFitter will converge fast, or not at all. Therefore, the default argument of 200 iterations somehow assumes, that the minError criterion is met much earlier. |
minError | if the current error gets less than this threshold, the optimization is finished |
lambdaMultiplier | mulitiplyer used for increasing/decreasing the damping parameter lambda |
eps1 | if the F'(parameters) is less than this threshold, the algorithm is finished |
eps2 | if the change in parameters is less than this threshold, the algorithm is finished |
linSolver | linear solver that is used to estimate a local step internally possible values are documented in icl::DynMatrix::solve (we recommend the most-stable method svd) |
icl::math::LevenbergMarquardtFitter< Scalar >::LevenbergMarquardtFitter | ( | FunctionMat | f, |
int | outputDim, | ||
const std::vector< JacobianMat > & | js = std::vector< JacobianMat >() , |
||
Scalar | tau = 1.e-3 , |
||
int | maxIterations = 200 , |
||
Scalar | minError = 1.e-6 , |
||
Scalar | lambdaMultiplier = 10 , |
||
Scalar | eps1 = 1.49012e-08 , |
||
Scalar | eps2 = 1.49012e-08 , |
||
const std::string & | linSolver = "svd" |
||
) |
|
static |
creates test data using a given function
p | real function parameters |
f | function |
xDim | input dimension of function f |
num | number of samples |
minX | the function input values are randomly drawn from a uniform distribution in range [minX,maxX] |
maxX | see minX |
|
static |
creates a single numerical Jacobian for a given function f and output dim
The Jacobian will evaluate f twice for each parameter in . Here is the internal implementation snippet:
|
static |
|
static |
creates a set of numerical jacobians for output dimension n
|
static |
|
static |
default debug callback that simply streams r to std::cout
|
protected |
returns the complete error
Result icl::math::LevenbergMarquardtFitter< Scalar >::fit | ( | const Matrix & | xs, |
const Matrix & | ys, | ||
Params | initParams | ||
) |
actual parameter fitting with given data and start parameters
This method actually fits the internal function model to the given data. The fitting procedure starts at the given set of initial parameters.
xs | input data matrix, where each data point is one row. Please note, that you can shallowly wrap a Matrix instance around existing other data types. |
ys | output data (Scalar) ys[i] belongs to the ith row of xs |
initParams | initial parameters for starting optimizaiton |
|
private |
internal fit function using matrices
|
private |
internal fit function using vectors
void icl::math::LevenbergMarquardtFitter< Scalar >::init | ( | Function | f, |
int | outputDim, | ||
const std::vector< Jacobian > & | js = std::vector< Jacobian >() , |
||
Scalar | tau = 1.e-8 , |
||
int | maxIterations = 1000 , |
||
Scalar | minError = 1.e-6 , |
||
Scalar | lambdaMultiplier = 10 , |
||
Scalar | eps1 = 1.49012e-08 , |
||
Scalar | eps2 = 1.49012e-08 , |
||
const std::string & | linSolver = "svd" |
||
) |
(re)-initialization method
void icl::math::LevenbergMarquardtFitter< Scalar >::init | ( | FunctionMat | f, |
int | outputDim, | ||
const std::vector< JacobianMat > & | js = std::vector< JacobianMat >() , |
||
Scalar | tau = 1.e-8 , |
||
int | maxIterations = 1000 , |
||
Scalar | minError = 1.e-6 , |
||
Scalar | lambdaMultiplier = 10 , |
||
Scalar | eps1 = 1.49012e-08 , |
||
Scalar | eps2 = 1.49012e-08 , |
||
const std::string & | linSolver = "svd" |
||
) |
void icl::math::LevenbergMarquardtFitter< Scalar >::setDebugCallback | ( | DebugCallback | dbg = default_debug_callback | ) |
sets a debug callback method, which is called automatically in every interation
void icl::math::LevenbergMarquardtFitter< Scalar >::setUseMultiThreading | ( | bool | enable | ) |
enables openmp based multithreading
multithreading using 2 instead of 1 core provides a processing time reduction of about 35%. Please note, that openmp must be enabled using the compiler optionn "-fopenmp" as well
|
protected |
debug callback
|
protected |
b in Mx=b of linear system solved internally
|
protected |
buffer for current delta
|
protected |
minimum F'(parameters) threshold
|
protected |
minimum change in parameters threshold
|
protected |
Function f.
|
protected |
Function f.
|
protected |
Hessian Matrix (J^T J)
|
protected |
Jacobian Matrix (rows are Ji)
|
protected |
output buffers
|
protected |
|
protected |
mulitplier that is used to increase/decreas lambda
|
protected |
linear solver that is used
|
protected |
maximum number of iterations
|
protected |
minimum error threshold
|
protected |
new parameters (after update step)
|
protected |
used for initial damping parameter lambda
|
protected |
flag whether matrices in the error function
|
protected |
flag whether multithreading is enabled
|
protected |
current estimated outputs