HybridGaussianISAM.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
25 #include <gtsam/inference/Key.h>
26 
27 #include <iterator>
28 
29 namespace gtsam {
30 
31 // Instantiate base class
32 // template class ISAM<HybridBayesTree>;
33 
34 /* ************************************************************************* */
36 
37 /* ************************************************************************* */
39  : Base(bayesTree) {}
40 
41 /* ************************************************************************* */
44  const HybridGaussianFactorGraph& newFactors) {
45  // Get all the discrete keys from the factors
46  const KeySet allDiscrete = factors.discreteKeySet();
47 
48  // Create KeyVector with continuous keys followed by discrete keys.
49  KeyVector newKeysDiscreteLast;
50  const KeySet newFactorKeys = newFactors.keys();
51  // Insert continuous keys first.
52  for (auto& k : newFactorKeys) {
53  if (!allDiscrete.exists(k)) {
54  newKeysDiscreteLast.push_back(k);
55  }
56  }
57  // Insert discrete keys at the end
58  std::copy(allDiscrete.begin(), allDiscrete.end(),
59  std::back_inserter(newKeysDiscreteLast));
60 
61  const VariableIndex index(factors);
62 
63  // Get an ordering where the new keys are eliminated last
65  index, KeyVector(newKeysDiscreteLast.begin(), newKeysDiscreteLast.end()),
66  true);
67  return ordering;
68 }
69 
70 /* ************************************************************************* */
72  const HybridGaussianFactorGraph& newFactors,
73  HybridBayesTree::Cliques* orphans, const std::optional<size_t>& maxNrLeaves,
74  const std::optional<Ordering>& ordering,
75  const HybridBayesTree::Eliminate& function) {
76  // Remove the contaminated part of the Bayes tree
77  BayesNetType bn;
78  const KeySet newFactorKeys = newFactors.keys();
79  if (!this->empty()) {
80  KeyVector keyVector(newFactorKeys.begin(), newFactorKeys.end());
81  this->removeTop(keyVector, &bn, orphans);
82  }
83 
84  // Add the removed top and the new factors
86  factors.push_back(bn);
87  factors.push_back(newFactors);
88 
89  // Add the orphaned subtrees
90  for (const sharedClique& orphan : *orphans) {
91  factors.emplace_shared<BayesTreeOrphanWrapper<Node>>(orphan);
92  }
93 
94  const VariableIndex index(factors);
95  Ordering elimination_ordering;
96  if (ordering) {
97  elimination_ordering = *ordering;
98  } else {
99  elimination_ordering = GetOrdering(factors, newFactors);
100  }
101 
102  // eliminate all factors (top, added, orphans) into a new Bayes tree
103  HybridBayesTree::shared_ptr bayesTree = factors.eliminateMultifrontal(
104  elimination_ordering, function, std::cref(index));
105 
106  if (maxNrLeaves) {
107  bayesTree->prune(*maxNrLeaves);
108  }
109 
110  // Re-add into Bayes tree data structures
111  this->roots_.insert(this->roots_.end(), bayesTree->roots().begin(),
112  bayesTree->roots().end());
113  this->nodes_.insert(bayesTree->nodes().begin(), bayesTree->nodes().end());
114 }
115 
116 /* ************************************************************************* */
118  const std::optional<size_t>& maxNrLeaves,
119  const std::optional<Ordering>& ordering,
120  const HybridBayesTree::Eliminate& function) {
121  Cliques orphans;
122  this->updateInternal(newFactors, &orphans, maxNrLeaves, ordering, function);
123 }
124 
125 } // namespace gtsam
gtsam::BayesTree< HybridBayesTreeClique >::empty
bool empty() const
Definition: BayesTree.h:141
gtsam::BayesTreeOrphanWrapper
Definition: BayesTree.h:281
gtsam::Ordering::ColamdConstrainedLast
static Ordering ColamdConstrainedLast(const FACTOR_GRAPH &graph, const KeyVector &constrainLast, bool forceOrder=false)
Definition: inference/Ordering.h:112
treeTraversal-inst.h
gtsam::BayesTree< HybridBayesTreeClique >::Eliminate
FactorGraphType::Eliminate Eliminate
Definition: BayesTree.h:85
gtsam::FastSet::exists
bool exists(const VALUE &e) const
Definition: FastSet.h:98
gtsam::BayesTree< HybridBayesTreeClique >::roots_
Roots roots_
Definition: BayesTree.h:103
simple_graph::factors
const GaussianFactorGraph factors
Definition: testJacobianFactor.cpp:213
gtsam::HybridBayesTree
Definition: HybridBayesTree.h:62
gtsam::HybridGaussianISAM::GetOrdering
static Ordering GetOrdering(HybridGaussianFactorGraph &factors, const HybridGaussianFactorGraph &newFactors)
Helper method to get an ordering given the existing factors and any new factors added.
Definition: HybridGaussianISAM.cpp:42
gtsam::FastSet< Key >
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::BayesTree< HybridBayesTreeClique >::removeTop
void removeTop(const KeyVector &keys, BayesNetType *bn, Cliques *orphans)
Definition: BayesTree-inst.h:516
Key.h
gtsam::BayesTree< HybridBayesTreeClique >::nodes_
Nodes nodes_
Definition: BayesTree.h:100
gtsam::HybridGaussianISAM::updateInternal
void updateInternal(const HybridGaussianFactorGraph &newFactors, HybridBayesTree::Cliques *orphans, const std::optional< size_t > &maxNrLeaves={}, const std::optional< Ordering > &ordering={}, const HybridBayesTree::Eliminate &function=HybridBayesTree::EliminationTraitsType::DefaultEliminate)
Internal method that performs the ISAM update.
Definition: HybridGaussianISAM.cpp:71
gtsam::BayesTree< HybridBayesTreeClique >::BayesNetType
HybridBayesTreeClique ::BayesNetType BayesNetType
Definition: BayesTree.h:79
gtsam::FactorGraph::keys
KeySet keys() const
Definition: FactorGraph-inst.h:85
HybridGaussianISAM.h
gtsam::HybridGaussianFactorGraph
Definition: HybridGaussianFactorGraph.h:106
HybridBayesTree.h
Hybrid Bayes Tree, the result of eliminating a HybridJunctionTree.
gtsam::FastList
Definition: FastList.h:43
gtsam::VariableIndex
Definition: VariableIndex.h:41
ordering
static enum @1096 ordering
HybridGaussianFactorGraph.h
Linearized Hybrid factor graph that uses type erasure.
gtsam
traits
Definition: SFMdata.h:40
gtsam::BayesTree< HybridBayesTreeClique >
gtsam::BayesTree< HybridBayesTreeClique >::sharedClique
std::shared_ptr< Clique > sharedClique
Shared pointer to a clique.
Definition: BayesTree.h:74
gtsam::HybridGaussianISAM::HybridGaussianISAM
HybridGaussianISAM()
Definition: HybridGaussianISAM.cpp:35
ISAM-inst.h
Incremental update functionality (iSAM) for BayesTree.
gtsam::Ordering
Definition: inference/Ordering.h:33
gtsam::HybridGaussianISAM::update
void update(const HybridGaussianFactorGraph &newFactors, const std::optional< size_t > &maxNrLeaves={}, const std::optional< Ordering > &ordering={}, const HybridBayesTree::Eliminate &function=HybridBayesTree::EliminationTraitsType::DefaultEliminate)
Perform update step with new factors.
Definition: HybridGaussianISAM.cpp:117
gtsam::HybridBayesTree::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: HybridBayesTree.h:68


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:26