gtsam
Loading...
Searching...
No Matches
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
18
19#pragma once
20
21#include <memory>
22#include <functional>
23#include <optional>
24#include <unordered_set>
25
28
29namespace gtsam {
30 // Forward declaration
32
36 template<class GRAPH>
38 {
39 // Template for deriving:
40 // typedef MyFactor FactorType; ///< Type of factors in factor graph (e.g. GaussianFactor)
41 // typedef MyFactorGraphType FactorGraphType; ///< Type of the factor graph (e.g. GaussianFactorGraph)
42 // typedef MyConditional ConditionalType; ///< Type of conditionals from elimination (e.g. GaussianConditional)
43 // typedef MyBayesNet BayesNetType; ///< Type of Bayes net from sequential elimination (e.g. GaussianBayesNet)
44 // typedef MyEliminationTree EliminationTreeType; ///< Type of elimination tree (e.g. GaussianEliminationTree)
45 // typedef MyBayesTree BayesTreeType; ///< Type of Bayes tree (e.g. GaussianBayesTree)
46 // typedef MyJunctionTree JunctionTreeType; ///< Type of Junction tree (e.g. GaussianJunctionTree)
47 // static pair<shared_ptr<ConditionalType>, shared_ptr<FactorType>
48 // DefaultEliminate(
49 // const MyFactorGraph& factors, const Ordering& keys); ///< The default dense elimination function
50 };
51
52
57 template<class FACTOR_GRAPH>
59 {
60 private:
62 typedef FACTOR_GRAPH FactorGraphType;
63 // Base factor type stored in this graph (private because derived classes will get this from
64 // their FactorGraph base class)
65 typedef typename EliminationTraits<FactorGraphType>::FactorType _FactorType;
66
67 public:
70
72 typedef typename EliminationTraitsType::ConditionalType ConditionalType;
73
75 typedef typename EliminationTraitsType::BayesNetType BayesNetType;
76
78 typedef typename EliminationTraitsType::EliminationTreeType EliminationTreeType;
79
81 typedef typename EliminationTraitsType::BayesTreeType BayesTreeType;
82
84 typedef typename EliminationTraitsType::JunctionTreeType JunctionTreeType;
85
88 typedef std::pair<std::shared_ptr<ConditionalType>, std::shared_ptr<_FactorType> > EliminationResult;
89
91 typedef std::function<EliminationResult(const FactorGraphType&, const Ordering&)> Eliminate;
92
95 typedef std::optional<std::reference_wrapper<const VariableIndex>> OptionalVariableIndex;
96
98 typedef std::optional<Ordering::OrderingType> OptionalOrderingType;
99
111 const Ordering& ordering,
112 const std::unordered_set<Key>& fixedKeys = {}) const;
113
134 std::shared_ptr<BayesNetType> eliminateSequential(
135 OptionalOrderingType orderingType = {},
136 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
137 OptionalVariableIndex variableIndex = {}) const;
138
153 std::shared_ptr<BayesNetType> eliminateSequential(
154 const Ordering& ordering,
155 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
156 OptionalVariableIndex variableIndex = {}) const;
157
174 std::shared_ptr<BayesTreeType> eliminateMultifrontal(
175 OptionalOrderingType orderingType = {},
176 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
177 OptionalVariableIndex variableIndex = {}) const;
178
188 std::shared_ptr<BayesTreeType> eliminateMultifrontal(
189 const Ordering& ordering,
190 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
191 OptionalVariableIndex variableIndex = {}) const;
192
206 std::shared_ptr<BayesTreeType> eliminateMultifrontal(
207 const IndexedJunctionTree& indexedJunctionTree,
208 const Eliminate& function = EliminationTraitsType::DefaultEliminate) const;
209
214 std::pair<std::shared_ptr<BayesNetType>, std::shared_ptr<FactorGraphType> >
216 const Ordering& ordering,
217 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
218 OptionalVariableIndex variableIndex = {}) const;
219
224 std::pair<std::shared_ptr<BayesNetType>, std::shared_ptr<FactorGraphType> >
226 const KeyVector& variables,
227 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
228 OptionalVariableIndex variableIndex = {}) const;
229
234 std::pair<std::shared_ptr<BayesTreeType>, std::shared_ptr<FactorGraphType> >
236 const Ordering& ordering,
237 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
238 OptionalVariableIndex variableIndex = {}) const;
239
244 std::pair<std::shared_ptr<BayesTreeType>, std::shared_ptr<FactorGraphType> >
246 const KeyVector& variables,
247 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
248 OptionalVariableIndex variableIndex = {}) const;
249
258 std::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
259 const Ordering& variables,
260 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
261 OptionalVariableIndex variableIndex = {}) const;
262
271 std::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
272 const KeyVector& variables,
273 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
274 OptionalVariableIndex variableIndex = {}) const;
275
285 std::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
286 const Ordering& variables,
287 const Ordering& marginalizedVariableOrdering,
288 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
289 OptionalVariableIndex variableIndex = {}) const;
290
300 std::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
301 const KeyVector& variables,
302 const Ordering& marginalizedVariableOrdering,
303 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
304 OptionalVariableIndex variableIndex = {}) const;
305
313 std::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
314 const Ordering& variables,
315 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
316 OptionalVariableIndex variableIndex = {}) const;
317
325 std::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
326 const KeyVector& variables,
327 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
328 OptionalVariableIndex variableIndex = {}) const;
329
338 std::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
339 const Ordering& variables,
340 const Ordering& marginalizedVariableOrdering,
341 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
342 OptionalVariableIndex variableIndex = {}) const;
343
352 std::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
353 const KeyVector& variables,
354 const Ordering& marginalizedVariableOrdering,
355 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
356 OptionalVariableIndex variableIndex = {}) const;
357
359 std::shared_ptr<FactorGraphType> marginal(
360 const KeyVector& variables,
361 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
362 OptionalVariableIndex variableIndex = {}) const;
363
364 private:
365
366 // Access the derived factor graph class
367 const FactorGraphType& asDerived() const { return static_cast<const FactorGraphType&>(*this); }
368
369 // Access the derived factor graph class
370 FactorGraphType& asDerived() { return static_cast<FactorGraphType&>(*this); }
371 };
372
373}
Variable ordering for the elimination algorithm.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
Traits class for eliminateable factor graphs, specifies the types that result from elimination,...
Definition EliminateableFactorGraph.h:38
EliminateableFactorGraph is a base class for factor graphs that contains elimination algorithms.
Definition EliminateableFactorGraph.h:59
std::pair< std::shared_ptr< ConditionalType >, std::shared_ptr< _FactorType > > EliminationResult
Definition EliminateableFactorGraph.h:88
std::pair< std::shared_ptr< BayesNetType >, std::shared_ptr< FactorGraphType > > eliminatePartialSequential(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do sequential elimination of some variables, in ordering provided, to produce a Bayes net and a remai...
Definition EliminateableFactorGraph-inst.h:300
std::pair< std::shared_ptr< BayesTreeType >, std::shared_ptr< FactorGraphType > > eliminatePartialMultifrontal(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do multifrontal elimination of some variables, in ordering provided, to produce a Bayes tree and a re...
Definition EliminateableFactorGraph-inst.h:339
std::shared_ptr< BayesNetType > eliminateSequential(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do sequential elimination of all variables to produce a Bayes net.
Definition EliminateableFactorGraph-inst.h:70
EliminationTraitsType::JunctionTreeType JunctionTreeType
Definition EliminateableFactorGraph.h:84
std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
Definition EliminateableFactorGraph.h:91
EliminationTraitsType::BayesTreeType BayesTreeType
Definition EliminateableFactorGraph.h:81
std::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(const Ordering &variables, const Ordering &marginalizedVariableOrdering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes net.
Definition EliminateableFactorGraph-inst.h:435
std::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes net.
Definition EliminateableFactorGraph-inst.h:407
std::shared_ptr< BayesTreeType > eliminateMultifrontal(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do multifrontal elimination of all variables to produce a Bayes tree.
Definition EliminateableFactorGraph-inst.h:132
EliminationTraitsType::BayesNetType BayesNetType
Definition EliminateableFactorGraph.h:75
std::shared_ptr< FactorGraphType > marginal(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal factor graph of the requested variables.
Definition EliminateableFactorGraph-inst.h:589
std::pair< std::shared_ptr< BayesNetType >, std::shared_ptr< FactorGraphType > > eliminatePartialSequential(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do sequential elimination of the given variables in an ordering computed by COLAMD to produce a Bayes...
Definition EliminateableFactorGraph-inst.h:318
std::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(const Ordering &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes net.
Definition EliminateableFactorGraph-inst.h:379
IndexedJunctionTree buildIndexedJunctionTree(const Ordering &ordering, const std::unordered_set< Key > &fixedKeys={}) const
Build an IndexedJunctionTree for this factor graph and a fixed ordering.
Definition EliminateableFactorGraph-inst.h:158
std::pair< std::shared_ptr< BayesTreeType >, std::shared_ptr< FactorGraphType > > eliminatePartialMultifrontal(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do multifrontal elimination of the given variables in an ordering computed by COLAMD to produce a Bay...
Definition EliminateableFactorGraph-inst.h:358
std::shared_ptr< BayesTreeType > marginalMultifrontalBayesTree(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes tree.
Definition EliminateableFactorGraph-inst.h:512
std::shared_ptr< BayesTreeType > marginalMultifrontalBayesTree(const Ordering &variables, const Ordering &marginalizedVariableOrdering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes tree.
Definition EliminateableFactorGraph-inst.h:540
std::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(const KeyVector &variables, const Ordering &marginalizedVariableOrdering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes net.
Definition EliminateableFactorGraph-inst.h:460
EliminationTraitsType::ConditionalType ConditionalType
Definition EliminateableFactorGraph.h:72
EliminationTraitsType::EliminationTreeType EliminationTreeType
Definition EliminateableFactorGraph.h:78
std::shared_ptr< BayesTreeType > marginalMultifrontalBayesTree(const Ordering &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes tree.
Definition EliminateableFactorGraph-inst.h:484
std::shared_ptr< BayesTreeType > marginalMultifrontalBayesTree(const KeyVector &variables, const Ordering &marginalizedVariableOrdering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes tree.
Definition EliminateableFactorGraph-inst.h:565
std::shared_ptr< BayesTreeType > eliminateMultifrontal(const IndexedJunctionTree &indexedJunctionTree, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
Do multifrontal elimination using a pre-built IndexedJunctionTree.
Definition EliminateableFactorGraph-inst.h:167
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do sequential elimination of all variables to produce a Bayes net.
Definition EliminateableFactorGraph-inst.h:36
std::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do multifrontal elimination of all variables to produce a Bayes tree.
Definition EliminateableFactorGraph-inst.h:96
std::optional< std::reference_wrapper< const VariableIndex > > OptionalVariableIndex
Definition EliminateableFactorGraph.h:95
EliminationTraits< FactorGraphType > EliminationTraitsType
Definition EliminateableFactorGraph.h:69
std::optional< Ordering::OrderingType > OptionalOrderingType
Definition EliminateableFactorGraph.h:98
Definition Ordering.h:33
A symbolic junction tree whose factors record the original factor indices from a corresponding (non-s...
Definition IndexedJunctionTree.h:58