EliminateableFactorGraph.h
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 
19 #pragma once
20 
21 #include <memory>
22 #include <cstddef>
23 #include <functional>
24 #include <optional>
25 
28 
29 namespace gtsam {
33  template<class GRAPH>
34  struct EliminationTraits
35  {
36  // Template for deriving:
37  // typedef MyFactor FactorType; ///< Type of factors in factor graph (e.g. GaussianFactor)
38  // typedef MyFactorGraphType FactorGraphType; ///< Type of the factor graph (e.g. GaussianFactorGraph)
39  // typedef MyConditional ConditionalType; ///< Type of conditionals from elimination (e.g. GaussianConditional)
40  // typedef MyBayesNet BayesNetType; ///< Type of Bayes net from sequential elimination (e.g. GaussianBayesNet)
41  // typedef MyEliminationTree EliminationTreeType; ///< Type of elimination tree (e.g. GaussianEliminationTree)
42  // typedef MyBayesTree BayesTreeType; ///< Type of Bayes tree (e.g. GaussianBayesTree)
43  // typedef MyJunctionTree JunctionTreeType; ///< Type of Junction tree (e.g. GaussianJunctionTree)
44  // static pair<shared_ptr<ConditionalType>, shared_ptr<FactorType>
45  // DefaultEliminate(
46  // const MyFactorGraph& factors, const Ordering& keys); ///< The default dense elimination function
47  };
48 
49 
54  template<class FACTORGRAPH>
56  {
57  private:
59  typedef FACTORGRAPH FactorGraphType;
60  // Base factor type stored in this graph (private because derived classes will get this from
61  // their FactorGraph base class)
63 
64  public:
67 
69  typedef typename EliminationTraitsType::ConditionalType ConditionalType;
70 
72  typedef typename EliminationTraitsType::BayesNetType BayesNetType;
73 
75  typedef typename EliminationTraitsType::EliminationTreeType EliminationTreeType;
76 
78  typedef typename EliminationTraitsType::BayesTreeType BayesTreeType;
79 
81  typedef typename EliminationTraitsType::JunctionTreeType JunctionTreeType;
82 
85  typedef std::pair<std::shared_ptr<ConditionalType>, std::shared_ptr<_FactorType> > EliminationResult;
86 
88  typedef std::function<EliminationResult(const FactorGraphType&, const Ordering&)> Eliminate;
89 
92  typedef std::optional<std::reference_wrapper<const VariableIndex>> OptionalVariableIndex;
93 
95  typedef std::optional<Ordering::OrderingType> OptionalOrderingType;
96 
117  std::shared_ptr<BayesNetType> eliminateSequential(
118  OptionalOrderingType orderingType = {},
119  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
120  OptionalVariableIndex variableIndex = {}) const;
121 
136  std::shared_ptr<BayesNetType> eliminateSequential(
137  const Ordering& ordering,
138  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
139  OptionalVariableIndex variableIndex = {}) const;
140 
157  std::shared_ptr<BayesTreeType> eliminateMultifrontal(
158  OptionalOrderingType orderingType = {},
159  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
160  OptionalVariableIndex variableIndex = {}) const;
161 
171  std::shared_ptr<BayesTreeType> eliminateMultifrontal(
172  const Ordering& ordering,
173  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
174  OptionalVariableIndex variableIndex = {}) const;
175 
180  std::pair<std::shared_ptr<BayesNetType>, std::shared_ptr<FactorGraphType> >
181  eliminatePartialSequential(
182  const Ordering& ordering,
183  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
184  OptionalVariableIndex variableIndex = {}) const;
185 
190  std::pair<std::shared_ptr<BayesNetType>, std::shared_ptr<FactorGraphType> >
191  eliminatePartialSequential(
192  const KeyVector& variables,
193  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
194  OptionalVariableIndex variableIndex = {}) const;
195 
200  std::pair<std::shared_ptr<BayesTreeType>, std::shared_ptr<FactorGraphType> >
201  eliminatePartialMultifrontal(
202  const Ordering& ordering,
203  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
204  OptionalVariableIndex variableIndex = {}) const;
205 
210  std::pair<std::shared_ptr<BayesTreeType>, std::shared_ptr<FactorGraphType> >
211  eliminatePartialMultifrontal(
212  const KeyVector& variables,
213  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
214  OptionalVariableIndex variableIndex = {}) const;
215 
224  std::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
225  const Ordering& variables,
226  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
227  OptionalVariableIndex variableIndex = {}) const;
228 
237  std::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
238  const KeyVector& variables,
239  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
240  OptionalVariableIndex variableIndex = {}) const;
241 
251  std::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
252  const Ordering& variables,
253  const Ordering& marginalizedVariableOrdering,
254  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
255  OptionalVariableIndex variableIndex = {}) const;
256 
266  std::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
267  const KeyVector& variables,
268  const Ordering& marginalizedVariableOrdering,
269  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
270  OptionalVariableIndex variableIndex = {}) const;
271 
279  std::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
280  const Ordering& variables,
281  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
282  OptionalVariableIndex variableIndex = {}) const;
283 
291  std::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
292  const KeyVector& variables,
293  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
294  OptionalVariableIndex variableIndex = {}) const;
295 
304  std::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
305  const Ordering& variables,
306  const Ordering& marginalizedVariableOrdering,
307  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
308  OptionalVariableIndex variableIndex = {}) const;
309 
318  std::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
319  const KeyVector& variables,
320  const Ordering& marginalizedVariableOrdering,
321  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
322  OptionalVariableIndex variableIndex = {}) const;
323 
325  std::shared_ptr<FactorGraphType> marginal(
326  const KeyVector& variables,
327  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
328  OptionalVariableIndex variableIndex = {}) const;
329 
330  private:
331 
332  // Access the derived factor graph class
333  const FactorGraphType& asDerived() const { return static_cast<const FactorGraphType&>(*this); }
334 
335  // Access the derived factor graph class
336  FactorGraphType& asDerived() { return static_cast<FactorGraphType&>(*this); }
337  };
338 
339 }
EliminateableFactorGraph< FACTORGRAPH > This
Typedef to this class.
std::optional< std::reference_wrapper< const VariableIndex > > OptionalVariableIndex
EliminationTraitsType::ConditionalType ConditionalType
Conditional type stored in the Bayes net produced by elimination.
static enum @1107 ordering
FACTORGRAPH FactorGraphType
Typedef to factor graph type.
EliminationTraitsType::BayesNetType BayesNetType
Bayes net type produced by sequential elimination.
EliminationTraitsType::JunctionTreeType JunctionTreeType
Junction tree type that can do multifrontal elimination of this graph.
std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
std::pair< std::shared_ptr< ConditionalType >, std::shared_ptr< _FactorType > > EliminationResult
EliminationTraits< FactorGraphType >::FactorType _FactorType
const FactorGraphType & asDerived() const
traits
Definition: chartTesting.h:28
EliminationTraitsType::EliminationTreeType EliminationTreeType
Elimination tree type that can do sequential elimination of this graph.
EliminationTraits< FactorGraphType > EliminationTraitsType
Typedef to the specific EliminationTraits for this graph.
EliminationTraitsType::BayesTreeType BayesTreeType
Bayes tree type produced by multifrontal elimination.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
std::optional< Ordering::OrderingType > OptionalOrderingType
Typedef for an optional ordering type.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:12