gtsam 4.1.1
gtsam
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 <boost/shared_ptr.hpp>
22#include <functional>
23#include <boost/variant.hpp>
24#include <boost/optional.hpp>
25
28
29namespace gtsam {
30
34 template<class GRAPH>
36 {
37 // Template for deriving:
38 // typedef MyFactor FactorType; ///< Type of factors in factor graph (e.g. GaussianFactor)
39 // typedef MyFactorGraphType FactorGraphType; ///< Type of the factor graph (e.g. GaussianFactorGraph)
40 // typedef MyConditional ConditionalType; ///< Type of conditionals from elimination (e.g. GaussianConditional)
41 // typedef MyBayesNet BayesNetType; ///< Type of Bayes net from sequential elimination (e.g. GaussianBayesNet)
42 // typedef MyEliminationTree EliminationTreeType; ///< Type of elimination tree (e.g. GaussianEliminationTree)
43 // typedef MyBayesTree BayesTreeType; ///< Type of Bayes tree (e.g. GaussianBayesTree)
44 // typedef MyJunctionTree JunctionTreeType; ///< Type of Junction tree (e.g. GaussianJunctionTree)
45 // static pair<shared_ptr<ConditionalType>, shared_ptr<FactorType>
46 // DefaultEliminate(
47 // const MyFactorGraph& factors, const Ordering& keys); ///< The default dense elimination function
48 };
49
50
55 template<class FACTORGRAPH>
57 {
58 private:
60 typedef FACTORGRAPH FactorGraphType;
61 // Base factor type stored in this graph (private because derived classes will get this from
62 // their FactorGraph base class)
63 typedef typename EliminationTraits<FactorGraphType>::FactorType _FactorType;
64
65 public:
68
70 typedef typename EliminationTraitsType::ConditionalType ConditionalType;
71
73 typedef typename EliminationTraitsType::BayesNetType BayesNetType;
74
76 typedef typename EliminationTraitsType::EliminationTreeType EliminationTreeType;
77
79 typedef typename EliminationTraitsType::BayesTreeType BayesTreeType;
80
82 typedef typename EliminationTraitsType::JunctionTreeType JunctionTreeType;
83
86 typedef std::pair<boost::shared_ptr<ConditionalType>, boost::shared_ptr<_FactorType> > EliminationResult;
87
89 typedef std::function<EliminationResult(const FactorGraphType&, const Ordering&)> Eliminate;
90
92 typedef boost::optional<const VariableIndex&> OptionalVariableIndex;
93
95 typedef boost::optional<Ordering::OrderingType> OptionalOrderingType;
96
117 boost::shared_ptr<BayesNetType> eliminateSequential(
118 OptionalOrderingType orderingType = boost::none,
119 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
120 OptionalVariableIndex variableIndex = boost::none) const;
121
136 boost::shared_ptr<BayesNetType> eliminateSequential(
137 const Ordering& ordering,
138 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
139 OptionalVariableIndex variableIndex = boost::none) const;
140
157 boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
158 OptionalOrderingType orderingType = boost::none,
159 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
160 OptionalVariableIndex variableIndex = boost::none) const;
161
171 boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
172 const Ordering& ordering,
173 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
174 OptionalVariableIndex variableIndex = boost::none) const;
175
180 std::pair<boost::shared_ptr<BayesNetType>, boost::shared_ptr<FactorGraphType> >
182 const Ordering& ordering,
183 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
184 OptionalVariableIndex variableIndex = boost::none) const;
185
190 std::pair<boost::shared_ptr<BayesNetType>, boost::shared_ptr<FactorGraphType> >
192 const KeyVector& variables,
193 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
194 OptionalVariableIndex variableIndex = boost::none) const;
195
200 std::pair<boost::shared_ptr<BayesTreeType>, boost::shared_ptr<FactorGraphType> >
202 const Ordering& ordering,
203 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
204 OptionalVariableIndex variableIndex = boost::none) const;
205
210 std::pair<boost::shared_ptr<BayesTreeType>, boost::shared_ptr<FactorGraphType> >
212 const KeyVector& variables,
213 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
214 OptionalVariableIndex variableIndex = boost::none) const;
215
225 boost::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
226 boost::variant<const Ordering&, const KeyVector&> variables,
227 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
228 OptionalVariableIndex variableIndex = boost::none) const;
229
240 boost::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
241 boost::variant<const Ordering&, const KeyVector&> variables,
242 const Ordering& marginalizedVariableOrdering,
243 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
244 OptionalVariableIndex variableIndex = boost::none) const;
245
255 boost::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
256 boost::variant<const Ordering&, const KeyVector&> variables,
257 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
258 OptionalVariableIndex variableIndex = boost::none) const;
259
270 boost::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
271 boost::variant<const Ordering&, const KeyVector&> variables,
272 const Ordering& marginalizedVariableOrdering,
273 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
274 OptionalVariableIndex variableIndex = boost::none) const;
275
277 boost::shared_ptr<FactorGraphType> marginal(
278 const KeyVector& variables,
279 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
280 OptionalVariableIndex variableIndex = boost::none) const;
281
282 private:
283
284 // Access the derived factor graph class
285 const FactorGraphType& asDerived() const { return static_cast<const FactorGraphType&>(*this); }
286
287 // Access the derived factor graph class
288 FactorGraphType& asDerived() { return static_cast<FactorGraphType&>(*this); }
289
290 public:
291 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V41
293 boost::shared_ptr<BayesNetType> GTSAM_DEPRECATED eliminateSequential(
294 const Ordering& ordering,
295 const Eliminate& function,
296 OptionalVariableIndex variableIndex,
297 OptionalOrderingType orderingType) const {
298 return eliminateSequential(ordering, function, variableIndex);
299 }
300
302 boost::shared_ptr<BayesNetType> GTSAM_DEPRECATED eliminateSequential(
303 const Eliminate& function,
304 OptionalVariableIndex variableIndex = boost::none,
305 OptionalOrderingType orderingType = boost::none) const {
306 return eliminateSequential(orderingType, function, variableIndex);
307 }
308
310 boost::shared_ptr<BayesTreeType> GTSAM_DEPRECATED eliminateMultifrontal(
311 const Ordering& ordering,
312 const Eliminate& function,
313 OptionalVariableIndex variableIndex,
314 OptionalOrderingType orderingType) const {
315 return eliminateMultifrontal(ordering, function, variableIndex);
316 }
317
319 boost::shared_ptr<BayesTreeType> GTSAM_DEPRECATED eliminateMultifrontal(
320 const Eliminate& function,
321 OptionalVariableIndex variableIndex = boost::none,
322 OptionalOrderingType orderingType = boost::none) const {
323 return eliminateMultifrontal(orderingType, function, variableIndex);
324 }
325
327 boost::shared_ptr<BayesNetType> GTSAM_DEPRECATED marginalMultifrontalBayesNet(
328 boost::variant<const Ordering&, const KeyVector&> variables,
329 boost::none_t,
330 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
331 OptionalVariableIndex variableIndex = boost::none) const {
332 return marginalMultifrontalBayesNet(variables, function, variableIndex);
333 }
334
336 boost::shared_ptr<BayesTreeType> GTSAM_DEPRECATED marginalMultifrontalBayesTree(
337 boost::variant<const Ordering&, const KeyVector&> variables,
338 boost::none_t,
339 const Eliminate& function = EliminationTraitsType::DefaultEliminate,
340 OptionalVariableIndex variableIndex = boost::none) const {
341 return marginalMultifrontalBayesTree(variables, function, variableIndex);
342 }
343 #endif
344 };
345
346}
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:86
Traits class for eliminateable factor graphs, specifies the types that result from elimination,...
Definition: EliminateableFactorGraph.h:36
EliminateableFactorGraph is a base class for factor graphs that contains elimination algorithms.
Definition: EliminateableFactorGraph.h:57
std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
Definition: EliminateableFactorGraph.h:89
EliminationTraitsType::JunctionTreeType JunctionTreeType
Junction tree type that can do multifrontal elimination of this graph.
Definition: EliminateableFactorGraph.h:82
boost::shared_ptr< BayesTreeType > marginalMultifrontalBayesTree(boost::variant< const Ordering &, const KeyVector & > variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Compute the marginal of the requested variables and return the result as a Bayes tree.
Definition: EliminateableFactorGraph-inst.h:286
boost::optional< const VariableIndex & > OptionalVariableIndex
Typedef for an optional variable index as an argument to elimination functions.
Definition: EliminateableFactorGraph.h:92
boost::shared_ptr< FactorGraphType > marginal(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Compute the marginal factor graph of the requested variables.
Definition: EliminateableFactorGraph-inst.h:353
EliminationTraitsType::EliminationTreeType EliminationTreeType
Elimination tree type that can do sequential elimination of this graph.
Definition: EliminateableFactorGraph.h:76
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
boost::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Do sequential elimination of all variables to produce a Bayes net.
Definition: EliminateableFactorGraph-inst.h:30
boost::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Do multifrontal elimination of all variables to produce a Bayes tree.
Definition: EliminateableFactorGraph-inst.h:84
EliminationTraits< FactorGraphType > EliminationTraitsType
Typedef to the specific EliminationTraits for this graph.
Definition: EliminateableFactorGraph.h:67
EliminationTraitsType::ConditionalType ConditionalType
Conditional type stored in the Bayes net produced by elimination.
Definition: EliminateableFactorGraph.h:70
boost::optional< Ordering::OrderingType > OptionalOrderingType
Typedef for an optional ordering type.
Definition: EliminateableFactorGraph.h:95
EliminationTraitsType::BayesTreeType BayesTreeType
Bayes tree type produced by multifrontal elimination.
Definition: EliminateableFactorGraph.h:79
std::pair< boost::shared_ptr< BayesNetType >, boost::shared_ptr< FactorGraphType > > eliminatePartialSequential(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Do sequential elimination of some variables, in ordering provided, to produce a Bayes net and a remai...
Definition: EliminateableFactorGraph-inst.h:140
boost::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(boost::variant< const Ordering &, const KeyVector & > variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Compute the marginal of the requested variables and return the result as a Bayes net.
Definition: EliminateableFactorGraph-inst.h:219
EliminationTraitsType::BayesNetType BayesNetType
Bayes net type produced by sequential elimination.
Definition: EliminateableFactorGraph.h:73
std::pair< boost::shared_ptr< BayesTreeType >, boost::shared_ptr< FactorGraphType > > eliminatePartialMultifrontal(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Do multifrontal elimination of some variables, in ordering provided, to produce a Bayes tree and a re...
Definition: EliminateableFactorGraph-inst.h:179
Definition: Ordering.h:34