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 <boost/function.hpp>
23 #include <boost/variant.hpp>
24 #include <boost/optional.hpp>
25 
28 
29 namespace gtsam {
30 
34  template<class GRAPH>
35  struct EliminationTraits
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)
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 boost::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> >
181  eliminatePartialSequential(
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> >
191  eliminatePartialSequential(
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> >
201  eliminatePartialMultifrontal(
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> >
211  eliminatePartialMultifrontal(
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:
292  boost::shared_ptr<BayesNetType> eliminateSequential(
293  const Ordering& ordering,
294  const Eliminate& function,
295  OptionalVariableIndex variableIndex,
296  OptionalOrderingType orderingType) const {
297  return eliminateSequential(ordering, function, variableIndex);
298  }
299 
301  boost::shared_ptr<BayesNetType> eliminateSequential(
302  const Eliminate& function,
303  OptionalVariableIndex variableIndex = boost::none,
304  OptionalOrderingType orderingType = boost::none) const {
305  return eliminateSequential(orderingType, function, variableIndex);
306  }
307 
309  boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
310  const Ordering& ordering,
311  const Eliminate& function,
312  OptionalVariableIndex variableIndex,
313  OptionalOrderingType orderingType) const {
314  return eliminateMultifrontal(ordering, function, variableIndex);
315  }
316 
318  boost::shared_ptr<BayesTreeType> eliminateMultifrontal(
319  const Eliminate& function,
320  OptionalVariableIndex variableIndex = boost::none,
321  OptionalOrderingType orderingType = boost::none) const {
322  return eliminateMultifrontal(orderingType, function, variableIndex);
323  }
324 
326  boost::shared_ptr<BayesNetType> marginalMultifrontalBayesNet(
327  boost::variant<const Ordering&, const KeyVector&> variables,
328  boost::none_t,
329  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
330  OptionalVariableIndex variableIndex = boost::none) const {
331  return marginalMultifrontalBayesNet(variables, function, variableIndex);
332  }
333 
335  boost::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree(
336  boost::variant<const Ordering&, const KeyVector&> variables,
337  boost::none_t,
338  const Eliminate& function = EliminationTraitsType::DefaultEliminate,
339  OptionalVariableIndex variableIndex = boost::none) const {
340  return marginalMultifrontalBayesTree(variables, function, variableIndex);
341  }
342  };
343 
344 }
boost::shared_ptr< BayesTreeType > eliminateMultifrontal(const Eliminate &function, OptionalVariableIndex variableIndex=boost::none, OptionalOrderingType orderingType=boost::none) const
EliminateableFactorGraph< FACTORGRAPH > This
Typedef to this class.
boost::shared_ptr< BayesTreeType > marginalMultifrontalBayesTree(boost::variant< const Ordering &, const KeyVector & > variables, boost::none_t, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
boost::shared_ptr< BayesTreeType > eliminateMultifrontal(const Ordering &ordering, const Eliminate &function, OptionalVariableIndex variableIndex, OptionalOrderingType orderingType) const
boost::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(boost::variant< const Ordering &, const KeyVector & > variables, boost::none_t, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
static enum @843 ordering
EliminationTraitsType::ConditionalType ConditionalType
Conditional type stored in the Bayes net produced by elimination.
const FactorGraphType & asDerived() const
boost::optional< Ordering::OrderingType > OptionalOrderingType
Typedef for an optional ordering type.
FACTORGRAPH FactorGraphType
Typedef to factor graph type.
EliminationTraitsType::BayesNetType BayesNetType
Bayes net type produced by sequential elimination.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
EliminationTraitsType::JunctionTreeType JunctionTreeType
Junction tree type that can do multifrontal elimination of this graph.
EliminationTraits< FactorGraphType >::FactorType _FactorType
traits
Definition: chartTesting.h:28
EliminationTraitsType::EliminationTreeType EliminationTreeType
Elimination tree type that can do sequential elimination of this graph.
boost::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
EliminationTraits< FactorGraphType > EliminationTraitsType
Typedef to the specific EliminationTraits for this graph.
EliminationTraitsType::BayesTreeType BayesTreeType
Bayes tree type produced by multifrontal elimination.
std::pair< boost::shared_ptr< ConditionalType >, boost::shared_ptr< _FactorType > > EliminationResult
boost::shared_ptr< BayesNetType > eliminateSequential(const Ordering &ordering, const Eliminate &function, OptionalVariableIndex variableIndex, OptionalOrderingType orderingType) const
boost::shared_ptr< BayesNetType > eliminateSequential(const Eliminate &function, OptionalVariableIndex variableIndex=boost::none, OptionalOrderingType orderingType=boost::none) const
boost::optional< const VariableIndex & > OptionalVariableIndex
Typedef for an optional variable index as an argument to elimination functions.


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:01