26 #include <boost/variant.hpp> 41 double _wildfireThreshold = 0.001
42 ) : wildfireThreshold(_wildfireThreshold) {}
44 void print(
const std::string str =
"")
const {
45 std::cout << str <<
"type: ISAM2GaussNewtonParams\n";
46 std::cout << str <<
"wildfireThreshold: " << wildfireThreshold <<
"\n";
50 double getWildfireThreshold()
const {
return wildfireThreshold; }
51 void setWildfireThreshold(
double wildfireThreshold) { this->wildfireThreshold = wildfireThreshold; }
68 double _initialDelta = 1.0,
69 double _wildfireThreshold = 1e-5,
72 ) : initialDelta(_initialDelta), wildfireThreshold(_wildfireThreshold),
73 adaptationMode(_adaptationMode), verbose(_verbose) {}
75 void print(
const std::string str =
"")
const {
76 std::cout << str <<
"type: ISAM2DoglegParams\n";
77 std::cout << str <<
"initialDelta: " << initialDelta <<
"\n";
78 std::cout << str <<
"wildfireThreshold: " << wildfireThreshold <<
"\n";
79 std::cout << str <<
"adaptationMode: " << adaptationModeTranslator(adaptationMode) <<
"\n";
83 double getInitialDelta()
const {
return initialDelta; }
84 double getWildfireThreshold()
const {
return wildfireThreshold; }
85 std::string getAdaptationMode()
const {
return adaptationModeTranslator(adaptationMode); };
86 bool isVerbose()
const {
return verbose; };
88 void setInitialDelta(
double initialDelta) { this->initialDelta = initialDelta; }
89 void setWildfireThreshold(
double wildfireThreshold) { this->wildfireThreshold = wildfireThreshold; }
90 void setAdaptationMode(
const std::string& adaptationMode) { this->adaptationMode = adaptationModeTranslator(adaptationMode); }
91 void setVerbose(
bool verbose) { this->verbose = verbose; };
102 typedef ISAM2ThresholdMap::value_type ISAM2ThresholdMapValue;
138 enum Factorization { CHOLESKY, QR };
175 RelinearizationThreshold _relinearizeThreshold = 0.1,
176 int _relinearizeSkip = 10,
177 bool _enableRelinearization =
true,
178 bool _evaluateNonlinearError =
false,
179 Factorization _factorization = ISAM2Params::CHOLESKY,
180 bool _cacheLinearizedFactors =
true,
182 ) : optimizationParams(_optimizationParams), relinearizeThreshold(_relinearizeThreshold),
183 relinearizeSkip(_relinearizeSkip), enableRelinearization(_enableRelinearization),
184 evaluateNonlinearError(_evaluateNonlinearError), factorization(_factorization),
185 cacheLinearizedFactors(_cacheLinearizedFactors), keyFormatter(_keyFormatter),
186 enableDetailedResults(false), enablePartialRelinearizationCheck(false),
187 findUnusedFactorSlots(false) {}
190 void print(
const std::string& str =
"")
const {
191 std::cout << str <<
"\n";
193 boost::get<ISAM2GaussNewtonParams>(optimizationParams).
print(
"optimizationParams: ");
195 boost::get<ISAM2DoglegParams>(optimizationParams).
print(
"optimizationParams: ");
197 std::cout <<
"optimizationParams: " <<
"{unknown type}" <<
"\n";
198 if(relinearizeThreshold.type() ==
typeid(double))
199 std::cout <<
"relinearizeThreshold: " << boost::get<double>(relinearizeThreshold) <<
"\n";
202 std::cout <<
"relinearizeThreshold: " <<
"{mapped}" <<
"\n";
203 for(
const ISAM2ThresholdMapValue& value: boost::get<ISAM2ThresholdMap>(relinearizeThreshold)) {
204 std::cout <<
" '" << value.first <<
"' -> [" << value.second.transpose() <<
" ]\n";
207 std::cout <<
"relinearizeSkip: " << relinearizeSkip <<
"\n";
208 std::cout <<
"enableRelinearization: " << enableRelinearization <<
"\n";
209 std::cout <<
"evaluateNonlinearError: " << evaluateNonlinearError <<
"\n";
210 std::cout <<
"factorization: " << factorizationTranslator(factorization) <<
"\n";
211 std::cout <<
"cacheLinearizedFactors: " << cacheLinearizedFactors <<
"\n";
212 std::cout <<
"enableDetailedResults: " << enableDetailedResults <<
"\n";
213 std::cout <<
"enablePartialRelinearizationCheck: " << enablePartialRelinearizationCheck <<
"\n";
214 std::cout <<
"findUnusedFactorSlots: " << findUnusedFactorSlots <<
"\n";
221 OptimizationParams getOptimizationParams()
const {
return this->optimizationParams; }
222 RelinearizationThreshold getRelinearizeThreshold()
const {
return relinearizeThreshold; }
223 int getRelinearizeSkip()
const {
return relinearizeSkip; }
224 bool isEnableRelinearization()
const {
return enableRelinearization; }
225 bool isEvaluateNonlinearError()
const {
return evaluateNonlinearError; }
226 std::string getFactorization()
const {
return factorizationTranslator(factorization); }
227 bool isCacheLinearizedFactors()
const {
return cacheLinearizedFactors; }
228 KeyFormatter getKeyFormatter()
const {
return keyFormatter; }
229 bool isEnableDetailedResults()
const {
return enableDetailedResults; }
230 bool isEnablePartialRelinearizationCheck()
const {
return enablePartialRelinearizationCheck; }
232 void setOptimizationParams(OptimizationParams optimizationParams) { this->optimizationParams = optimizationParams; }
233 void setRelinearizeThreshold(RelinearizationThreshold relinearizeThreshold) { this->relinearizeThreshold = relinearizeThreshold; }
234 void setRelinearizeSkip(
int relinearizeSkip) { this->relinearizeSkip = relinearizeSkip; }
235 void setEnableRelinearization(
bool enableRelinearization) { this->enableRelinearization = enableRelinearization; }
236 void setEvaluateNonlinearError(
bool evaluateNonlinearError) { this->evaluateNonlinearError = evaluateNonlinearError; }
237 void setFactorization(
const std::string& factorization) { this->factorization = factorizationTranslator(factorization); }
238 void setCacheLinearizedFactors(
bool cacheLinearizedFactors) { this->cacheLinearizedFactors = cacheLinearizedFactors; }
239 void setKeyFormatter(
KeyFormatter keyFormatter) { this->keyFormatter = keyFormatter; }
240 void setEnableDetailedResults(
bool enableDetailedResults) { this->enableDetailedResults = enableDetailedResults; }
241 void setEnablePartialRelinearizationCheck(
bool enablePartialRelinearizationCheck) { this->enablePartialRelinearizationCheck = enablePartialRelinearizationCheck; }
244 return factorization == CHOLESKY
254 static Factorization factorizationTranslator(
const std::string& str);
255 static std::string factorizationTranslator(
const Factorization& value);
341 VariableStatus(): isReeliminated(false), isAboveRelinThreshold(false), isRelinearizeInvolved(false),
342 isRelinearized(false), isObserved(false), isNew(false), inRootClique(false) {}
355 void print(
const std::string str =
"")
const {
356 std::cout << str <<
" Reelimintated: " << variablesReeliminated <<
" Relinearized: " << variablesRelinearized <<
" Cliques: " << cliques << std::endl;
361 size_t getVariablesReeliminated()
const {
return variablesReeliminated; };
362 size_t getCliques()
const {
return cliques; };
374 typedef boost::shared_ptr<This> shared_ptr;
375 typedef boost::weak_ptr<This> weak_ptr;
379 Base::FactorType::shared_ptr cachedFactor_;
380 Vector gradientContribution_;
388 Base(other), cachedFactor_(other.cachedFactor_), gradientContribution_(other.gradientContribution_) {}
393 Base::operator=(other);
394 cachedFactor_ = other.cachedFactor_;
395 gradientContribution_ = other.gradientContribution_;
408 bool equals(
const This& other,
double tol=1e-9)
const;
411 void print(
const std::string& s =
"",
const KeyFormatter& formatter = DefaultKeyFormatter)
const;
416 friend class boost::serialization::access;
417 template<
class ARCHIVE>
418 void serialize(ARCHIVE & ar,
const unsigned int ) {
419 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
420 ar & BOOST_SERIALIZATION_NVP(cachedFactor_);
421 ar & BOOST_SERIALIZATION_NVP(gradientContribution_);
502 virtual bool equals(
const ISAM2& other,
double tol = 1e-9)
const;
534 const FactorIndices& removeFactorIndices = FactorIndices(),
536 const boost::optional<
FastList<Key> >& noRelinKeys = boost::none,
537 const boost::optional<
FastList<Key> >& extraReelimKeys = boost::none,
538 bool force_relinearize =
false);
555 boost::optional<FactorIndices&> marginalFactorsIndices = boost::none,
556 boost::optional<FactorIndices&> deletedFactorsIndices = boost::none);
565 return theta_.
exists(key);
572 Values calculateEstimate()
const;
580 template<
class VALUE>
581 VALUE calculateEstimate(
Key key)
const;
590 const Value& calculateEstimate(
Key key)
const;
593 Matrix marginalCovariance(
Key key)
const;
603 Values calculateBestEstimate()
const;
620 size_t lastAffectedVariableCount;
621 size_t lastAffectedFactorCount;
622 size_t lastAffectedCliqueCount;
623 size_t lastAffectedMarkedCount;
624 mutable size_t lastBacksubVariableCount;
627 const ISAM2Params& params()
const {
return params_; }
630 void printStats()
const { getCliqueData().getStats().print(); }
648 virtual boost::shared_ptr<KeySet > recalculate(
const KeySet& markedKeys,
const KeySet& relinKeys,
650 void updateDelta(
bool forceFullSolve =
false)
const;
668 template<
class CLIQUE>
672 template<
class CLIQUE>
673 size_t optimizeWildfireNonRecursive(
const boost::shared_ptr<CLIQUE>& root,
677 template<
class CLIQUE>
ISAM2Params params_
The current parameters.
Definition: ISAM2.h:473
bool isAboveRelinThreshold
Whether the variable was just relinearized due to being above the relinearization threshold...
Definition: ISAM2.h:335
bool isNew
Whether the variable itself was just added.
Definition: ISAM2.h:339
double initialDelta
The initial trust region radius for Dogleg.
Definition: ISAM2.h:61
bool valueExists(Key key) const
Check whether variable with given key exists in linearization point.
Definition: ISAM2.h:564
void printStats() const
prints out clique statistics
Definition: ISAM2.h:630
virtual ~ISAM2()
default virtual destructor
Definition: ISAM2.h:499
bool enableDetailedResults
Whether to compute and return ISAM2Result::detailedResults, this can increase running time (default: ...
Definition: ISAM2.h:158
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
Base::sharedClique sharedClique
Shared pointer to a clique.
Definition: ISAM2.h:489
int calculate_nnz(const boost::shared_ptr< CLIQUE > &clique)
calculate the number of non-zero entries for the tree starting at clique (use root for complete matri...
Definition: ISAM2-inl.h:303
int relinearizeSkip
Only relinearize any variables every relinearizeSkip calls to ISAM2::update (default: 10) ...
Definition: ISAM2.h:132
FastMap< Key, VariableStatus > variableStatus
The status of each variable during this update, see VariableStatus.
Definition: ISAM2.h:347
bool isObserved
Whether the variable was relinearized, either by being above the relinearization threshold or by invo...
Definition: ISAM2.h:338
ISAM2Clique(const ISAM2Clique &other)
Copy constructor, does not copy solution pointers as these are invalid in different trees...
Definition: ISAM2.h:387
Definition: ISAM2-impl.h:25
std::pair< boost::shared_ptr< ConditionalType >, boost::shared_ptr< _FactorType > > EliminationResult
The pair of conditional and remaining factor produced by a single dense elimination step on a subgrap...
Definition: EliminateableFactorGraph.h:86
ISAM2GaussNewtonParams(double _wildfireThreshold=0.001)
Specify parameters as constructor arguments.
Definition: ISAM2.h:40
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
bool findUnusedFactorSlots
When you will be removing many factors, e.g.
Definition: ISAM2.h:170
Values theta_
The current linearization point.
Definition: ISAM2.h:440
A conditional Gaussian functions as the node in a Bayes network It has a set of parents y...
Definition: GaussianConditional.h:36
boost::variant< double, FastMap< char, Vector > > RelinearizationThreshold
Either a constant relinearization threshold or a per-variable-type set of thresholds.
Definition: ISAM2.h:105
size_t cliques
The number of cliques in the Bayes' Tree.
Definition: ISAM2.h:316
void print(const std::string &str="") const
print iSAM2 parameters
Definition: ISAM2.h:190
Definition: FastList.h:38
bool verbose
Whether Dogleg prints iteration and convergence information.
Definition: ISAM2.h:64
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: ISAM2.h:67
bool enableRelinearization
Controls whether ISAM2 will ever relinearize any variables (default: true)
Definition: ISAM2.h:134
const Vector & gradientContribution() const
Access the gradient contribution.
Definition: ISAM2.h:406
bool evaluateNonlinearError
Whether to evaluate the nonlinear error before and after the update, to return in ISAM2Result from up...
Definition: ISAM2.h:136
boost::shared_ptr< Clique > sharedClique
Shared pointer to a clique.
Definition: BayesTree.h:72
boost::optional< DetailedResults > detail
Detailed results, if enabled by ISAM2Params::enableDetailedResults.
Definition: ISAM2.h:352
Definition: BayesTree.h:64
size_t factorsRecalculated
The number of factors that were included in reelimination of the Bayes' tree.
Definition: ISAM2.h:313
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
Base::FactorType::shared_ptr & cachedFactor()
Access the cached factor.
Definition: ISAM2.h:403
boost::optional< double > errorAfter
The nonlinear error of all of the factors computed after the current update, meaning that variables a...
Definition: ISAM2.h:292
FactorIndices newFactorsIndices
The indices of the newly-added factors, in 1-to-1 correspondence with the factors passed as newFactor...
Definition: ISAM2.h:322
ISAM2Clique()
Default constructor.
Definition: ISAM2.h:384
bool isRelinearizeInvolved
Whether the variable was below the relinearization threshold but was relinearized by being involved i...
Definition: ISAM2.h:336
VectorValues delta_
The linear delta from the last linear solution, an update to the estimate in theta.
Definition: ISAM2.h:451
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
bool exists(Key j) const
Check if a value exists with key j.
Definition: Values.cpp:97
Factorization factorization
Specifies whether to use QR or CHOESKY numerical factorization (default: CHOLESKY).
Definition: ISAM2.h:147
DoglegOptimizerImpl::TrustRegionAdaptationMode adaptationMode
See description in DoglegOptimizerImpl::TrustRegionAdaptationMode.
Definition: ISAM2.h:63
The VariableIndex class computes and stores the block column structure of a factor graph...
Definition: VariableIndex.h:42
GaussianFactorGraph linearFactors_
The current linear factors, which are only updated as needed.
Definition: ISAM2.h:470
size_t variablesRelinearized
The number of variables that were relinearized because their linear deltas exceeded the reslinearizat...
Definition: ISAM2.h:302
Template to create a binary predicate.
Definition: Testable.h:110
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
const VariableIndex & getVariableIndex() const
Access the nonlinear variable index.
Definition: ISAM2.h:615
RelinearizationThreshold relinearizeThreshold
Only relinearize variables whose linear delta magnitude is greater than this threshold (default: 0...
Definition: ISAM2.h:130
KeySet deltaReplacedMask_
A cumulative mask for the variables that were replaced and have not yet been updated in the linear so...
Definition: ISAM2.h:464
boost::optional< double > doglegDelta_
The current Dogleg Delta (trust region radius)
Definition: ISAM2.h:476
double wildfireThreshold
Continue updating the linear delta only when changes are above this threshold (default: 1e-5) ...
Definition: ISAM2.h:62
Nonlinear factor graph optimizer using Powell's Dogleg algorithm (detail implementation) ...
A struct holding detailed results, which must be enabled with ISAM2Params::enableDetailedResults.
Definition: ISAM2.h:327
const KeySet & getFixedVariables() const
Access the nonlinear variable index.
Definition: ISAM2.h:618
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianConditional.h:42
double wildfireThreshold
Continue updating the linear delta only when changes are above this threshold (default: 0...
Definition: ISAM2.h:37
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactorGraph.h:74
KeySet fixedVariables_
Set of variables that are involved with linear factors from marginalized variables and thus cannot ha...
Definition: ISAM2.h:480
bool enablePartialRelinearizationCheck
Check variables for relinearization in tree-order, stopping the check once a variable does not need t...
Definition: ISAM2.h:165
boost::variant< ISAM2GaussNewtonParams, ISAM2DoglegParams > OptimizationParams
Either ISAM2GaussNewtonParams or ISAM2DoglegParams.
Definition: ISAM2.h:104
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:90
TrustRegionAdaptationMode
Specifies how the trust region is adapted at each Dogleg iteration.
Definition: DoglegOptimizerImpl.h:53
size_t optimizeWildfire(const boost::shared_ptr< CLIQUE > &root, double threshold, const KeySet &keys, VectorValues &delta)
Optimize the BayesTree, starting from the root.
Definition: ISAM2-inl.h:254
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
const Values & getLinearizationPoint() const
Access the current linearization point.
Definition: ISAM2.h:559
const NonlinearFactorGraph & getFactorsUnsafe() const
Access the set of nonlinear factors.
Definition: ISAM2.h:612
Base::Clique Clique
A clique.
Definition: ISAM2.h:488
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:712
KeyFormatter keyFormatter
A KeyFormatter for when keys are printed during debugging (default: DefaultKeyFormatter) ...
Definition: ISAM2.h:156
boost::optional< double > errorBefore
The nonlinear error of all of the factors, including new factors and variables added during the curre...
Definition: ISAM2.h:281
VariableIndex variableIndex_
VariableIndex lets us look up factors by involved variable and keeps track of dimensions.
Definition: ISAM2.h:443
OptimizationParams optimizationParams
Optimization parameters, this both selects the nonlinear optimization method and specifies its parame...
Definition: ISAM2.h:113
A non-linear factor graph is a graph of non-Gaussian, i.e.
Definition: NonlinearFactorGraph.h:77
bool inRootClique
Whether the variable is in the root clique.
Definition: ISAM2.h:340
size_t variablesReeliminated
The number of variables that were reeliminated as parts of the Bayes' Tree were recalculated, due to new factors.
Definition: ISAM2.h:310
BayesTree< ISAM2Clique > Base
The BayesTree base class.
Definition: ISAM2.h:487
size_t getVariablesRelinearized() const
Getters and Setters.
Definition: ISAM2.h:360
NonlinearFactorGraph nonlinearFactors_
All original nonlinear factors are stored here to use during relinearization.
Definition: ISAM2.h:467
Factor Graph Constsiting of non-linear factors.
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)
Specify parameters as constructor arguments.
Definition: ISAM2.h:173
Specialized Clique structure for ISAM2, incorporating caching and gradient contribution TODO: more do...
Definition: ISAM2.h:369
boost::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
Definition: EliminateableFactorGraph.h:89
ISAM2 This
This class.
Definition: ISAM2.h:486
ISAM2Clique & operator=(const ISAM2Clique &other)
Assignment operator, does not copy solution pointers as these are invalid in different trees...
Definition: ISAM2.h:391
The status of a single variable, this struct is stored in DetailedResults::variableStatus.
Definition: ISAM2.h:330
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:65
This is the interface class for any value that may be used as a variable assignment in a factor graph...
Definition: Value.h:83
int update_count_
Counter incremented every update(), used to determine periodic relinearization.
Definition: ISAM2.h:482
Base::Cliques Cliques
List of Clique typedef from base class.
Definition: ISAM2.h:490
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
This is the base class for BayesTree cliques.
Definition: BayesTreeCliqueBase.h:44
bool cacheLinearizedFactors
Whether to cache linear factors (default: true).
Definition: ISAM2.h:154
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
bool isReeliminated
Whether the variable was just reeliminated, due to being relinearized, observed, new, or on the path up to the root clique from another reeliminated variable.
Definition: ISAM2.h:334