Loading...
Searching...
No Matches
LevenbergMarquardtParams.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/nonlinear/NonlinearOptimizerParams.h>
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
namespace gtsam {
class LevenbergMarquardtOptimizer;
class GTSAM_EXPORT LevenbergMarquardtParams: public NonlinearOptimizerParams {
public:
enum VerbosityLM {
SILENT = 0, SUMMARY, TERMINATION, LAMBDA, TRYLAMBDA, TRYCONFIG, DAMPED, TRYDELTA
};
static VerbosityLM verbosityLMTranslator(const std::string &s);
static std::string verbosityLMTranslator(VerbosityLM value);
using OptimizerType = LevenbergMarquardtOptimizer;
public:
double lambdaInitial;
double lambdaFactor;
double lambdaUpperBound;
double lambdaLowerBound;
VerbosityLM verbosityLM;
double minModelFidelity;
std::string logFile;
bool diagonalDamping;
bool useFixedLambdaFactor;
double minDiagonal;
double maxDiagonal;
LevenbergMarquardtParams()
: verbosityLM(SILENT),
diagonalDamping(false),
minDiagonal(1e-6),
maxDiagonal(1e32) {
SetLegacyDefaults(this);
}
static void SetLegacyDefaults(LevenbergMarquardtParams* p) {
// Relevant NonlinearOptimizerParams:
p->maxIterations = 100;
p->relativeErrorTol = 1e-5;
p->absoluteErrorTol = 1e-5;
// LM-specific:
p->lambdaInitial = 1e-5;
p->lambdaFactor = 10.0;
p->lambdaUpperBound = 1e5;
p->lambdaLowerBound = 0.0;
p->minModelFidelity = 1e-3;
p->diagonalDamping = false;
p->useFixedLambdaFactor = true;
}
// these do seem to work better for SFM
static void SetCeresDefaults(LevenbergMarquardtParams* p) {
// Relevant NonlinearOptimizerParams:
p->maxIterations = 50;
p->absoluteErrorTol = 0; // No corresponding option in CERES
p->relativeErrorTol = 1e-6; // This is function_tolerance
// LM-specific:
p->lambdaUpperBound = 1e32;
p->lambdaLowerBound = 1e-16;
p->lambdaInitial = 1e-04;
p->lambdaFactor = 2.0;
p->minModelFidelity = 1e-3; // options.min_relative_decrease in CERES
p->diagonalDamping = true;
p->useFixedLambdaFactor = false; // This is important
}
static LevenbergMarquardtParams LegacyDefaults() {
LevenbergMarquardtParams p;
SetLegacyDefaults(&p);
return p;
}
static LevenbergMarquardtParams CeresDefaults() {
LevenbergMarquardtParams p;
SetCeresDefaults(&p);
return p;
}
static LevenbergMarquardtParams EnsureHasOrdering(LevenbergMarquardtParams params,
const NonlinearFactorGraph& graph) {
if (!params.ordering)
params.ordering = Ordering::Create(params.orderingType, graph);
return params;
}
static LevenbergMarquardtParams ReplaceOrdering(LevenbergMarquardtParams params,
const Ordering& ordering) {
params.ordering = ordering;
return params;
}
~LevenbergMarquardtParams() override {}
void print(const std::string& str = "") const override;
bool getDiagonalDamping() const { return diagonalDamping; }
double getlambdaFactor() const { return lambdaFactor; }
double getlambdaInitial() const { return lambdaInitial; }
double getlambdaLowerBound() const { return lambdaLowerBound; }
double getlambdaUpperBound() const { return lambdaUpperBound; }
bool getUseFixedLambdaFactor() { return useFixedLambdaFactor; }
std::string getLogFile() const { return logFile; }
std::string getVerbosityLM() const { return verbosityLMTranslator(verbosityLM);}
void setDiagonalDamping(bool flag) { diagonalDamping = flag; }
void setlambdaFactor(double value) { lambdaFactor = value; }
void setlambdaInitial(double value) { lambdaInitial = value; }
void setlambdaLowerBound(double value) { lambdaLowerBound = value; }
void setlambdaUpperBound(double value) { lambdaUpperBound = value; }
void setUseFixedLambdaFactor(bool flag) { useFixedLambdaFactor = flag;}
void setLogFile(const std::string& s) { logFile = s; }
void setVerbosityLM(const std::string& s) { verbosityLM = verbosityLMTranslator(s);}
// @}
boost::shared_ptr<NonlinearOptimizerParams> clone() const {
return boost::shared_ptr<NonlinearOptimizerParams>(new LevenbergMarquardtParams(*this));
}
};
}
NonlinearFactorGraph.h
Factor Graph consisting of non-linear factors.
NonlinearOptimizerParams.h
Parameters for nonlinear optimization.
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
gtsam::LevenbergMarquardtOptimizer
This class performs Levenberg-Marquardt nonlinear optimization.
Definition LevenbergMarquardtOptimizer.h:35
gtsam::LevenbergMarquardtParams
Parameters for Levenberg-Marquardt optimization.
Definition LevenbergMarquardtParams.h:35
gtsam::LevenbergMarquardtParams::lambdaFactor
double lambdaFactor
The amount by which to multiply or divide lambda when adjusting lambda (default: 10....
Definition LevenbergMarquardtParams.h:50
gtsam::LevenbergMarquardtParams::minDiagonal
double minDiagonal
when using diagonal damping saturates the minimum diagonal entries (default: 1e-6)
Definition LevenbergMarquardtParams.h:58
gtsam::LevenbergMarquardtParams::lambdaUpperBound
double lambdaUpperBound
The maximum lambda to try before assuming the optimization has failed (default: 1e5).
Definition LevenbergMarquardtParams.h:51
gtsam::LevenbergMarquardtParams::lambdaInitial
double lambdaInitial
The initial Levenberg-Marquardt damping term (default: 1e-5).
Definition LevenbergMarquardtParams.h:49
gtsam::LevenbergMarquardtParams::maxDiagonal
double maxDiagonal
when using diagonal damping saturates the maximum diagonal entries (default: 1e32)
Definition LevenbergMarquardtParams.h:59
gtsam::LevenbergMarquardtParams::minModelFidelity
double minModelFidelity
Lower bound for the modelFidelity to accept the result of an LM iteration.
Definition LevenbergMarquardtParams.h:54
gtsam::LevenbergMarquardtParams::lambdaLowerBound
double lambdaLowerBound
The minimum lambda used in LM (default: 0).
Definition LevenbergMarquardtParams.h:52
gtsam::LevenbergMarquardtParams::clone
boost::shared_ptr< NonlinearOptimizerParams > clone() const
Definition LevenbergMarquardtParams.h:152
gtsam::LevenbergMarquardtParams::diagonalDamping
bool diagonalDamping
if true, use diagonal of Hessian
Definition LevenbergMarquardtParams.h:56
gtsam::LevenbergMarquardtParams::useFixedLambdaFactor
bool useFixedLambdaFactor
if true applies constant increase (or decrease) to lambda according to lambdaFactor
Definition LevenbergMarquardtParams.h:57
gtsam::LevenbergMarquardtParams::logFile
std::string logFile
an optional CSV log file, with [iteration, time, error, lambda]
Definition LevenbergMarquardtParams.h:55
gtsam::LevenbergMarquardtParams::VerbosityLM
VerbosityLM
See LevenbergMarquardtParams::verbosityLM.
Definition LevenbergMarquardtParams.h:39
gtsam::LevenbergMarquardtParams::verbosityLM
VerbosityLM verbosityLM
The verbosity level for Levenberg-Marquardt (default: SILENT), see also NonlinearOptimizerParams::ver...
Definition LevenbergMarquardtParams.h:53
gtsam::NonlinearOptimizerParams::absoluteErrorTol
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5).
Definition NonlinearOptimizerParams.h:43
gtsam::NonlinearOptimizerParams::maxIterations
size_t maxIterations
The maximum iterations to stop iterating (default 100).
Definition NonlinearOptimizerParams.h:41
gtsam::NonlinearOptimizerParams::relativeErrorTol
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5).
Definition NonlinearOptimizerParams.h:42