Loading...
Searching...
No Matches
ISAM2Params.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
* -------------------------------------------------------------------------- */
// \callgraph
#pragma once
#include <gtsam/linear/GaussianFactorGraph.h>
#include <gtsam/nonlinear/DoglegOptimizerImpl.h>
#include <boost/variant.hpp>
#include <string>
namespace gtsam {
struct GTSAM_EXPORT ISAM2GaussNewtonParams {
double
wildfireThreshold;
ISAM2GaussNewtonParams(
double _wildfireThreshold =
0.001
)
: wildfireThreshold(_wildfireThreshold) {}
void print(const std::string str = "") const {
using std::cout;
cout << str << "type: ISAM2GaussNewtonParams\n";
cout << str << "wildfireThreshold: " << wildfireThreshold << "\n";
cout.flush();
}
double getWildfireThreshold() const { return wildfireThreshold; }
void setWildfireThreshold(double wildfireThreshold) {
this->wildfireThreshold = wildfireThreshold;
}
};
struct GTSAM_EXPORT ISAM2DoglegParams {
double initialDelta;
double
wildfireThreshold;
DoglegOptimizerImpl::TrustRegionAdaptationMode
adaptationMode;
bool
verbose;
ISAM2DoglegParams(
double _initialDelta = 1.0,
double _wildfireThreshold =
1e-5,
DoglegOptimizerImpl::TrustRegionAdaptationMode _adaptationMode =
DoglegOptimizerImpl::
SEARCH_EACH_ITERATION,
bool _verbose = false
)
: initialDelta(_initialDelta),
wildfireThreshold(_wildfireThreshold),
adaptationMode(_adaptationMode),
verbose(_verbose) {}
void print(const std::string str = "") const {
using std::cout;
cout << str << "type: ISAM2DoglegParams\n";
cout << str << "initialDelta: " << initialDelta << "\n";
cout << str << "wildfireThreshold: " << wildfireThreshold << "\n";
cout << str
<< "adaptationMode: " << adaptationModeTranslator(adaptationMode)
<< "\n";
cout.flush();
}
double getInitialDelta() const { return initialDelta; }
double getWildfireThreshold() const { return wildfireThreshold; }
std::string getAdaptationMode() const {
return adaptationModeTranslator(adaptationMode);
}
bool isVerbose() const { return verbose; }
void setInitialDelta(double initialDelta) {
this->initialDelta = initialDelta;
}
void setWildfireThreshold(double wildfireThreshold) {
this->wildfireThreshold = wildfireThreshold;
}
void setAdaptationMode(const std::string& adaptationMode) {
this->adaptationMode = adaptationModeTranslator(adaptationMode);
}
void setVerbose(bool verbose) { this->verbose = verbose; }
std::string adaptationModeTranslator(
const DoglegOptimizerImpl::TrustRegionAdaptationMode& adaptationMode)
const;
DoglegOptimizerImpl::TrustRegionAdaptationMode adaptationModeTranslator(
const std::string& adaptationMode) const;
};
typedef FastMap<char, Vector> ISAM2ThresholdMap;
typedef ISAM2ThresholdMap::value_type ISAM2ThresholdMapValue;
struct GTSAM_EXPORT ISAM2Params {
typedef boost::variant<ISAM2GaussNewtonParams, ISAM2DoglegParams>
OptimizationParams;
typedef boost::variant<double, FastMap<char, Vector> >
RelinearizationThreshold;
OptimizationParams optimizationParams;
RelinearizationThreshold relinearizeThreshold;
int relinearizeSkip;
bool enableRelinearization;
bool evaluateNonlinearError;
enum Factorization { CHOLESKY, QR };
Factorization factorization;
bool cacheLinearizedFactors;
KeyFormatter
keyFormatter;
bool enableDetailedResults;
bool enablePartialRelinearizationCheck;
bool findUnusedFactorSlots;
ISAM2Params(OptimizationParams _optimizationParams = ISAM2GaussNewtonParams(),
RelinearizationThreshold _relinearizeThreshold = 0.1,
int _relinearizeSkip = 10, bool _enableRelinearization = true,
bool _evaluateNonlinearError = false,
Factorization _factorization = ISAM2Params::CHOLESKY,
bool _cacheLinearizedFactors = true,
const KeyFormatter& _keyFormatter =
DefaultKeyFormatter,
bool _enableDetailedResults = false)
: optimizationParams(_optimizationParams),
relinearizeThreshold(_relinearizeThreshold),
relinearizeSkip(_relinearizeSkip),
enableRelinearization(_enableRelinearization),
evaluateNonlinearError(_evaluateNonlinearError),
factorization(_factorization),
cacheLinearizedFactors(_cacheLinearizedFactors),
keyFormatter(_keyFormatter),
enableDetailedResults(_enableDetailedResults),
enablePartialRelinearizationCheck(false),
findUnusedFactorSlots(false) {}
void print(const std::string& str = "") const {
using std::cout;
cout << str << "\n";
static const std::string kStr("optimizationParams: ");
if (optimizationParams.type() == typeid(ISAM2GaussNewtonParams))
boost::get<ISAM2GaussNewtonParams>(optimizationParams).print();
else if (optimizationParams.type() == typeid(ISAM2DoglegParams))
boost::get<ISAM2DoglegParams>(optimizationParams).print(kStr);
else
cout << kStr << "{unknown type}\n";
cout << "relinearizeThreshold: ";
if (relinearizeThreshold.type() == typeid(double)) {
cout << boost::get<double>(relinearizeThreshold) << "\n";
} else {
cout << "{mapped}\n";
for (const ISAM2ThresholdMapValue& value :
boost::get<ISAM2ThresholdMap>(relinearizeThreshold)) {
cout << " '" << value.first
<< "' -> [" << value.second.transpose() << " ]\n";
}
}
cout << "relinearizeSkip: " << relinearizeSkip << "\n";
cout << "enableRelinearization: " << enableRelinearization
<< "\n";
cout << "evaluateNonlinearError: " << evaluateNonlinearError
<< "\n";
cout << "factorization: "
<< factorizationTranslator(factorization) << "\n";
cout << "cacheLinearizedFactors: " << cacheLinearizedFactors
<< "\n";
cout << "enableDetailedResults: " << enableDetailedResults
<< "\n";
cout << "enablePartialRelinearizationCheck: "
<< enablePartialRelinearizationCheck << "\n";
cout << "findUnusedFactorSlots: " << findUnusedFactorSlots
<< "\n";
cout.flush();
}
OptimizationParams getOptimizationParams() const {
return this->optimizationParams;
}
RelinearizationThreshold getRelinearizeThreshold() const {
return relinearizeThreshold;
}
std::string getFactorization() const {
return factorizationTranslator(factorization);
}
KeyFormatter getKeyFormatter() const { return keyFormatter; }
void setOptimizationParams(OptimizationParams optimizationParams) {
this->optimizationParams = optimizationParams;
}
void setRelinearizeThreshold(RelinearizationThreshold relinearizeThreshold) {
this->relinearizeThreshold = relinearizeThreshold;
}
void setFactorization(const std::string& factorization) {
this->factorization = factorizationTranslator(factorization);
}
void setKeyFormatter(KeyFormatter keyFormatter) {
this->keyFormatter = keyFormatter;
}
GaussianFactorGraph::Eliminate getEliminationFunction() const {
return factorization == CHOLESKY
? (GaussianFactorGraph::Eliminate)EliminatePreferCholesky
: (GaussianFactorGraph::Eliminate)EliminateQR;
}
static Factorization factorizationTranslator(const std::string& str);
static std::string factorizationTranslator(const Factorization& value);
};
} // namespace gtsam
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
DoglegOptimizerImpl.h
Nonlinear factor graph optimizer using Powell's Dogleg algorithm (detail implementation).
gtsam::ISAM2ThresholdMap
FastMap< char, Vector > ISAM2ThresholdMap
Parameters for the ISAM2 algorithm.
Definition ISAM2Params.h:133
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::KeyFormatter
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
gtsam::EliminateQR
std::pair< GaussianConditional::shared_ptr, JacobianFactor::shared_ptr > EliminateQR(const GaussianFactorGraph &factors, const Ordering &keys)
Multiply all factors and eliminate the given keys from the resulting factor using a QR variant that h...
Definition JacobianFactor.cpp:789
gtsam::FastMap
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:38
gtsam::DoglegOptimizerImpl
This class contains the implementation of the Dogleg algorithm.
Definition DoglegOptimizerImpl.h:32
gtsam::DoglegOptimizerImpl::TrustRegionAdaptationMode
TrustRegionAdaptationMode
Specifies how the trust region is adapted at each Dogleg iteration.
Definition DoglegOptimizerImpl.h:53
gtsam::ISAM2GaussNewtonParams
Parameters for ISAM2 using Gauss-Newton optimization.
Definition ISAM2Params.h:35
gtsam::ISAM2GaussNewtonParams::wildfireThreshold
double wildfireThreshold
Continue updating the linear delta only when changes are above this threshold (default: 0....
Definition ISAM2Params.h:37
gtsam::ISAM2GaussNewtonParams::ISAM2GaussNewtonParams
ISAM2GaussNewtonParams(double _wildfireThreshold=0.001)
Specify parameters as constructor arguments.
Definition ISAM2Params.h:41
gtsam::ISAM2DoglegParams
Parameters for ISAM2 using Dogleg optimization.
Definition ISAM2Params.h:67
gtsam::ISAM2DoglegParams::adaptationMode
DoglegOptimizerImpl::TrustRegionAdaptationMode adaptationMode
See description in DoglegOptimizerImpl::TrustRegionAdaptationMode.
Definition ISAM2Params.h:73
gtsam::ISAM2DoglegParams::verbose
bool verbose
Whether Dogleg prints iteration and convergence information.
Definition ISAM2Params.h:76
gtsam::ISAM2DoglegParams::ISAM2DoglegParams
ISAM2DoglegParams(double _initialDelta=1.0, double _wildfireThreshold=1e-5, DoglegOptimizerImpl::TrustRegionAdaptationMode _adaptationMode=DoglegOptimizerImpl::SEARCH_EACH_ITERATION, bool _verbose=false)
Specify parameters as constructor arguments.
Definition ISAM2Params.h:79
gtsam::ISAM2DoglegParams::initialDelta
double initialDelta
The initial trust region radius for Dogleg.
Definition ISAM2Params.h:68
gtsam::ISAM2DoglegParams::wildfireThreshold
double wildfireThreshold
Continue updating the linear delta only when changes are above this threshold (default: 1e-5).
Definition ISAM2Params.h:70
gtsam::ISAM2Params::enablePartialRelinearizationCheck
bool enablePartialRelinearizationCheck
Check variables for relinearization in tree-order, stopping the check once a variable does not need t...
Definition ISAM2Params.h:218
gtsam::ISAM2Params::optimizationParams
OptimizationParams optimizationParams
Optimization parameters, this both selects the nonlinear optimization method and specifies its parame...
Definition ISAM2Params.h:150
gtsam::ISAM2Params::print
void print(const std::string &str="") const
print iSAM2 parameters
Definition ISAM2Params.h:252
gtsam::ISAM2Params::enableRelinearization
bool enableRelinearization
Controls whether ISAM2 will ever relinearize any variables (default: true).
Definition ISAM2Params.h:174
gtsam::ISAM2Params::cacheLinearizedFactors
bool cacheLinearizedFactors
Whether to cache linear factors (default: true).
Definition ISAM2Params.h:200
gtsam::ISAM2Params::evaluateNonlinearError
bool evaluateNonlinearError
Whether to evaluate the nonlinear error before and after the update, to return in ISAM2Result from up...
Definition ISAM2Params.h:177
gtsam::ISAM2Params::enableDetailedResults
bool enableDetailedResults
Whether to compute and return ISAM2Result::detailedResults, this can increase running time (default: ...
Definition ISAM2Params.h:206
gtsam::ISAM2Params::OptimizationParams
boost::variant< ISAM2GaussNewtonParams, ISAM2DoglegParams > OptimizationParams
Either ISAM2GaussNewtonParams or ISAM2DoglegParams.
Definition ISAM2Params.h:137
gtsam::ISAM2Params::findUnusedFactorSlots
bool findUnusedFactorSlots
When you will be removing many factors, e.g.
Definition ISAM2Params.h:224
gtsam::ISAM2Params::RelinearizationThreshold
boost::variant< double, FastMap< char, Vector > > RelinearizationThreshold
Either a constant relinearization threshold or a per-variable-type set of thresholds.
Definition ISAM2Params.h:140
gtsam::ISAM2Params::relinearizeSkip
int relinearizeSkip
Only relinearize any variables every relinearizeSkip calls to ISAM2::update (default: 10).
Definition ISAM2Params.h:170
gtsam::ISAM2Params::factorization
Factorization factorization
Specifies whether to use QR or CHOESKY numerical factorization (default: CHOLESKY).
Definition ISAM2Params.h:193
gtsam::ISAM2Params::keyFormatter
KeyFormatter keyFormatter
A KeyFormatter for when keys are printed during debugging (default: DefaultKeyFormatter).
Definition ISAM2Params.h:203
gtsam::ISAM2Params::relinearizeThreshold
RelinearizationThreshold relinearizeThreshold
Only relinearize variables whose linear delta magnitude is greater than this threshold (default: 0....
Definition ISAM2Params.h:168
gtsam::ISAM2Params::ISAM2Params
ISAM2Params(OptimizationParams _optimizationParams=ISAM2GaussNewtonParams(), RelinearizationThreshold _relinearizeThreshold=0.1, int _relinearizeSkip=10, bool _enableRelinearization=true, bool _evaluateNonlinearError=false, Factorization _factorization=ISAM2Params::CHOLESKY, bool _cacheLinearizedFactors=true, const KeyFormatter &_keyFormatter=DefaultKeyFormatter, bool _enableDetailedResults=false)
Specify parameters as constructor arguments See the documentation of member variables above.
Definition ISAM2Params.h:230