Go to the documentation of this file.
56 :
public JunctionTree<ISAM2BayesTree, GaussianFactorGraph> {
63 :
Base(eliminationTree) {}
74 enum { COLAMD } algorithm;
82 static size_t UpdateGaussNewtonDelta(
const ISAM2::Roots& roots,
83 const KeySet& replacedKeys,
84 double wildfireThreshold,
92 const KeySet& replacedKeys,
113 : params_(
params), updateParams_(updateParams) {}
117 const ISAM2& isam2) {
118 gttic(pushBackFactors);
120 const bool verbose =
ISDEBUG(
"ISAM2 update verbose");
123 std::cout <<
"ISAM2::update\n";
124 isam2.
print(
"ISAM2: ");
127 if (
debug || verbose) {
128 newFactors.
print(
"The new factors are: ");
146 KeySet* keysWithRemovedFactors)
const {
147 gttic(pushBackFactors);
153 *newFactorsIndices = nonlinearFactors->
add_factors(
160 removedFactors.
push_back(nonlinearFactors->
at(index));
161 nonlinearFactors->
remove(index);
170 *keysWithRemovedFactors = removedFactors.
keys();
177 const KeySet& keysWithRemovedFactors,
178 KeySet* unusedKeys)
const {
179 gttic(computeUnusedKeys);
181 for (
Key key : keysWithRemovedFactors) {
183 removedAndEmpty.insert(removedAndEmpty.end(),
key);
186 std::set_difference(removedAndEmpty.begin(), removedAndEmpty.end(),
187 newFactorSymbKeys.begin(), newFactorSymbKeys.end(),
188 std::inserter(*unusedKeys, unusedKeys->end()));
193 const Values& estimate, std::optional<double>*
result)
const {
201 const KeySet& keysWithRemovedFactors,
202 KeySet* markedKeys)
const {
203 gttic(gatherInvolvedKeys);
204 *markedKeys = newFactors.
keys();
206 markedKeys->insert(keysWithRemovedFactors.begin(),
207 keysWithRemovedFactors.end());
212 markedKeys->insert(
key);
220 const auto factorIdx = factorAddedKeys.first;
221 const auto& affectedKeys = nonlinearFactors.
at(factorIdx)->keys();
222 markedKeys->insert(affectedKeys.begin(), affectedKeys.end());
232 for (
Key key : markedKeys) {
233 result->detail->variableStatus[
key].isObserved =
true;
237 for (
Key index : markedKeys) {
239 if (
result->unusedKeys.find(index) ==
result->unusedKeys.end())
241 result->observedKeys.push_back(index);
249 bool relinearize =
false;
250 for (
Key var : *clique->conditional()) {
252 const Vector& threshold = thresholds.find(
Symbol(var).chr())->second;
257 if (threshold.rows() != deltaVar.rows())
258 throw std::invalid_argument(
259 "Relinearization threshold vector dimensionality for '" +
260 std::string(1,
Symbol(var).chr()) +
261 "' passed into iSAM2 parameters does not match actual variable "
265 if ((deltaVar.array().abs() > threshold.array()).any()) {
266 relinKeys->insert(var);
274 CheckRelinearizationRecursiveMap(thresholds,
delta, child, relinKeys);
283 bool relinearize =
false;
284 for (
Key var : *clique->conditional()) {
286 if (maxDelta >= threshold) {
287 relinKeys->insert(var);
295 CheckRelinearizationRecursiveDouble(threshold,
delta, child, relinKeys);
318 if (std::holds_alternative<double>(relinearizeThreshold)) {
319 CheckRelinearizationRecursiveDouble(
320 std::get<double>(relinearizeThreshold),
delta, root, &relinKeys);
322 CheckRelinearizationRecursiveMap(
346 if (
const double* threshold = std::get_if<double>(&relinearizeThreshold)) {
349 if (maxDelta >= *threshold) relinKeys.insert(key_delta.first);
355 thresholds->find(
Symbol(key_delta.first).
chr())->second;
356 if (threshold.rows() != key_delta.second.rows())
357 throw std::invalid_argument(
358 "Relinearization threshold vector dimensionality for '" +
359 std::string(1,
Symbol(key_delta.first).
chr()) +
360 "' passed into iSAM2 parameters does not match actual variable "
362 if ((key_delta.second.array().abs() > threshold.array()).any())
363 relinKeys.insert(key_delta.first);
373 const KeySet& fixedVariables,
374 KeySet* markedKeys)
const {
375 gttic(gatherRelinearizeKeys);
379 ? CheckRelinearizationPartial(roots,
delta,
383 relinKeys = CheckRelinearizationFull(
delta, 0.0);
386 for (
Key key : fixedVariables) {
387 relinKeys.erase(
key);
391 relinKeys.erase(
key);
396 markedKeys->insert(relinKeys.begin(), relinKeys.end());
404 for (
Key key : relinKeys) {
405 detail->variableStatus[
key].isAboveRelinThreshold =
true;
406 detail->variableStatus[
key].isRelinearized =
true;
417 for (
const auto& root : roots)
419 root->findAll(relinKeys, markedKeys);
424 for (
const auto& root : roots)
425 root->findAll(relinKeys, &involvedRelinKeys);
426 for (
Key key : involvedRelinKeys) {
427 if (!
detail->variableStatus[
key].isAboveRelinThreshold) {
428 detail->variableStatus[
key].isRelinearizeInvolved =
true;
429 detail->variableStatus[
key].isRelinearized =
true;
437 const Values& theta,
size_t numNonlinearFactors,
440 gttic(linearizeNewFactors);
441 auto linearized = newFactors.
linearize(theta);
443 linearFactors->
resize(numNonlinearFactors);
444 for (
size_t i = 0;
i < newFactors.
size(); ++
i)
445 (*linearFactors)[newFactorsIndices[
i]] = (*linearized)[
i];
449 assert(linearFactors->
size() == numNonlinearFactors);
455 gttic(augmentVariableIndex);
458 variableIndex->
augment(newFactors, newFactorsIndices);
460 variableIndex->
augment(newFactors);
465 const auto factorIdx = factorAddedKeys.first;
475 std::cout <<
"markedKeys: ";
477 std::cout <<
key <<
" ";
479 std::cout << std::endl;
480 std::cout <<
"observedKeys: ";
482 std::cout <<
key <<
" ";
484 std::cout << std::endl;
490 gttic(GetAffectedFactors);
505 for (
const auto& orphan : orphans) {
507 cachedBoundary.
push_back(orphan->cachedFactor());
510 return cachedBoundary;
FactorIndices add_factors(const CONTAINER &factors, bool useEmptySlots=false)
UpdateImpl(const ISAM2Params ¶ms, const ISAM2UpdateParams &updateParams)
bool enableRelinearization
static KeySet CheckRelinearizationFull(const VectorValues &delta, const ISAM2Params::RelinearizationThreshold &relinearizeThreshold)
void augment(const FG &factors, const FactorIndices *newFactorIndices=nullptr)
bool enableDetailedResults
const GaussianFactorGraph factors
std::optional< FastList< Key > > extraReelimKeys
ISAM2JunctionTree(const GaussianEliminationTree &eliminationTree)
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
static KeySet CheckRelinearizationPartial(const ISAM2::Roots &roots, const VectorValues &delta, const ISAM2Params::RelinearizationThreshold &relinearizeThreshold)
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Base::sharedClique sharedClique
Shared pointer to a clique.
static const SmartProjectionParams params
bool enablePartialRelinearizationCheck
const ISAM2UpdateParams & updateParams_
void remove(ITERATOR firstFactor, ITERATOR lastFactor, const FG &factors)
static void CheckRelinearizationRecursiveMap(const FastMap< char, Vector > &thresholds, const VectorValues &delta, const ISAM2::sharedClique &clique, KeySet *relinKeys)
std::optional< FastList< Key > > noRelinKeys
void error(const NonlinearFactorGraph &nonlinearFactors, const Values &estimate, std::optional< double > *result) const
unsigned char chr() const
const sharedFactor at(size_t i) const
double error(const Values &values) const
void augmentExistingFactor(const FactorIndex factorIndex, const KeySet &newKeys)
virtual void resize(size_t size)
RelinearizationThreshold relinearizeThreshold
void updateKeys(const KeySet &markedKeys, ISAM2Result *result) const
Class that stores detailed iSAM2 result.
static constexpr bool debug
void recordRelinearizeDetail(const KeySet &relinKeys, ISAM2Result::DetailedResults *detail) const
static FactorIndexSet GetAffectedFactors(const KeyList &keys, const VariableIndex &variableIndex)
void computeUnusedKeys(const NonlinearFactorGraph &newFactors, const VariableIndex &variableIndex, const KeySet &keysWithRemovedFactors, KeySet *unusedKeys) const
std::shared_ptr< This > shared_ptr
KeySet gatherRelinearizeKeys(const ISAM2::Roots &roots, const VectorValues &delta, const KeySet &fixedVariables, KeySet *markedKeys) const
FastVector< sharedClique > Roots
bool relinarizationNeeded(size_t update_count) const
const gtsam::Symbol key('X', 0)
void linearizeNewFactors(const NonlinearFactorGraph &newFactors, const Values &theta, size_t numNonlinearFactors, const FactorIndices &newFactorsIndices, GaussianFactorGraph *linearFactors) const
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
void findFluid(const ISAM2::Roots &roots, const KeySet &relinKeys, KeySet *markedKeys, ISAM2Result::DetailedResults *detail) const
static GaussianFactorGraph GetCachedBoundaryFactors(const ISAM2::Cliques &orphans)
std::shared_ptr< This > shared_ptr
std::variant< double, FastMap< char, Vector > > RelinearizationThreshold
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
bool findUnusedFactorSlots
const ISAM2Params & params_
void pushBackFactors(const NonlinearFactorGraph &newFactors, NonlinearFactorGraph *nonlinearFactors, GaussianFactorGraph *linearFactors, VariableIndex *variableIndex, FactorIndices *newFactorsIndices, KeySet *keysWithRemovedFactors) const
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
static void LogRecalculateKeys(const ISAM2Result &result)
void reserve(size_t size)
void gatherInvolvedKeys(const NonlinearFactorGraph &newFactors, const NonlinearFactorGraph &nonlinearFactors, const KeySet &keysWithRemovedFactors, KeySet *markedKeys) const
The junction tree, template bodies.
JunctionTree< ISAM2BayesTree, GaussianFactorGraph > Base
bool empty(Key variable) const
Return true if no factors associated with a variable.
value_type KeyValuePair
Typedef to pair<Key, Vector>
std::uint64_t Key
Integer nonlinear key type.
std::optional< FastMap< FactorIndex, KeySet > > newAffectedKeys
bool cacheLinearizedFactors
Container::iterator get(Container &c, Position position)
FactorIndices removeFactorIndices
static void CheckRelinearizationRecursiveDouble(double threshold, const VectorValues &delta, const ISAM2::sharedClique &clique, KeySet *relinKeys)
static void LogStartingUpdate(const NonlinearFactorGraph &newFactors, const ISAM2 &isam2)
ISAM2::sharedClique bayesTree
void augmentVariableIndex(const NonlinearFactorGraph &newFactors, const FactorIndices &newFactorsIndices, VariableIndex *variableIndex) const
FastVector< FactorIndex > FactorIndices
Define collection types:
std::optional< FastMap< Key, int > > constrainedKeys
void print(const std::string &str="NonlinearFactorGraph: ", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:46