23#include <boost/tuple/tuple.hpp>
28 template<
class FACTORGRAPH>
29 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
39 return eliminateSequential(orderingType, function, computedVariableIndex);
44 if (orderingType == Ordering::METIS) {
46 return eliminateSequential(computedOrdering, function, variableIndex);
47 }
else if (orderingType == Ordering::COLAMD) {
49 return eliminateSequential(computedOrdering, function, variableIndex);
50 }
else if (orderingType == Ordering::NATURAL) {
52 return eliminateSequential(computedOrdering, function, variableIndex);
54 Ordering computedOrdering = EliminationTraitsType::DefaultOrderingFunc(
55 asDerived(), variableIndex);
56 return eliminateSequential(computedOrdering, function, variableIndex);
62 template<
class FACTORGRAPH>
63 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
71 return eliminateSequential(ordering, function, computedVariableIndex);
73 gttic(eliminateSequential);
76 boost::shared_ptr<BayesNetType> bayesNet;
77 boost::shared_ptr<FactorGraphType> factorGraph;
78 boost::tie(bayesNet,factorGraph) = etree.eliminate(function);
80 if(!factorGraph->empty())
88 template <
class FACTORGRAPH>
101 return eliminateMultifrontal(orderingType, function,
102 computedVariableIndex);
107 if (orderingType == Ordering::METIS) {
109 return eliminateMultifrontal(computedOrdering, function, variableIndex);
110 }
else if (orderingType == Ordering::COLAMD) {
112 return eliminateMultifrontal(computedOrdering, function, variableIndex);
113 }
else if (orderingType == Ordering::NATURAL) {
115 return eliminateMultifrontal(computedOrdering, function, variableIndex);
117 Ordering computedOrdering = EliminationTraitsType::DefaultOrderingFunc(
118 asDerived(), variableIndex);
119 return eliminateMultifrontal(computedOrdering, function, variableIndex);
125 template<
class FACTORGRAPH>
126 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
134 return eliminateMultifrontal(ordering, function, computedVariableIndex);
136 gttic(eliminateMultifrontal);
140 boost::shared_ptr<BayesTreeType> bayesTree;
141 boost::shared_ptr<FactorGraphType> factorGraph;
142 boost::tie(bayesTree,factorGraph) = junctionTree.eliminate(function);
144 if(!factorGraph->empty())
152 template<
class FACTORGRAPH>
153 std::pair<boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>, boost::shared_ptr<FACTORGRAPH> >
158 gttic(eliminatePartialSequential);
161 return etree.eliminate(function);
165 return eliminatePartialSequential(ordering, function, computedVariableIndex);
170 template<
class FACTORGRAPH>
171 std::pair<boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>, boost::shared_ptr<FACTORGRAPH> >
176 gttic(eliminatePartialSequential);
181 Ordering ordering(fullOrdering.begin(), fullOrdering.begin() + variables.size());
182 return eliminatePartialSequential(ordering, function, variableIndex);
186 return eliminatePartialSequential(variables, function, computedVariableIndex);
191 template<
class FACTORGRAPH>
192 std::pair<boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>, boost::shared_ptr<FACTORGRAPH> >
197 gttic(eliminatePartialMultifrontal);
201 return junctionTree.eliminate(function);
205 return eliminatePartialMultifrontal(ordering, function, computedVariableIndex);
210 template<
class FACTORGRAPH>
211 std::pair<boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>, boost::shared_ptr<FACTORGRAPH> >
216 gttic(eliminatePartialMultifrontal);
221 Ordering ordering(fullOrdering.begin(), fullOrdering.begin() + variables.size());
222 return eliminatePartialMultifrontal(ordering, function, variableIndex);
226 return eliminatePartialMultifrontal(variables, function, computedVariableIndex);
231 template<
class FACTORGRAPH>
232 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
234 boost::variant<const Ordering&, const KeyVector&> variables,
244 bool unmarginalizedAreOrdered = (boost::get<const Ordering&>(&variables) != 0);
246 unmarginalizedAreOrdered ?
247 boost::get<const Ordering&>(&variables) : boost::get<const
KeyVector&>(&variables);
253 const size_t nVars = variablesOrOrdering->size();
254 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - nVars);
255 Ordering marginalVarsOrdering(totalOrdering.end() - nVars, totalOrdering.end());
258 return marginalMultifrontalBayesNet(marginalVarsOrdering, marginalizationOrdering, function, *variableIndex);
263 template<
class FACTORGRAPH>
264 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
266 boost::variant<const Ordering&, const KeyVector&> variables,
267 const Ordering& marginalizedVariableOrdering,
273 return marginalMultifrontalBayesNet(variables, marginalizedVariableOrdering, function, index);
275 gttic(marginalMultifrontalBayesNet);
278 boost::shared_ptr<BayesTreeType> bayesTree;
279 boost::shared_ptr<FactorGraphType> factorGraph;
280 boost::tie(bayesTree,factorGraph) =
281 eliminatePartialMultifrontal(marginalizedVariableOrdering, function, *variableIndex);
283 if(
const Ordering* varsAsOrdering = boost::get<const Ordering&>(&variables))
287 return factorGraph->eliminateSequential(*varsAsOrdering, function);
292 return factorGraph->eliminateSequential(Ordering::COLAMD, function);
298 template<
class FACTORGRAPH>
299 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
301 boost::variant<const Ordering&, const KeyVector&> variables,
307 return marginalMultifrontalBayesTree(variables, function, computedVariableIndex);
311 bool unmarginalizedAreOrdered = (boost::get<const Ordering&>(&variables) != 0);
313 unmarginalizedAreOrdered ?
314 boost::get<const Ordering&>(&variables) : boost::get<const KeyVector&>(&variables);
320 const size_t nVars = variablesOrOrdering->size();
321 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - nVars);
322 Ordering marginalVarsOrdering(totalOrdering.end() - nVars, totalOrdering.end());
325 return marginalMultifrontalBayesTree(marginalVarsOrdering, marginalizationOrdering, function, *variableIndex);
330 template<
class FACTORGRAPH>
331 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
333 boost::variant<const Ordering&, const KeyVector&> variables,
334 const Ordering& marginalizedVariableOrdering,
340 return marginalMultifrontalBayesTree(variables, marginalizedVariableOrdering, function, computedVariableIndex);
342 gttic(marginalMultifrontalBayesTree);
345 boost::shared_ptr<BayesTreeType> bayesTree;
346 boost::shared_ptr<FactorGraphType> factorGraph;
347 boost::tie(bayesTree,factorGraph) =
348 eliminatePartialMultifrontal(marginalizedVariableOrdering, function, *variableIndex);
350 if(
const Ordering* varsAsOrdering = boost::get<const Ordering&>(&variables))
354 return factorGraph->eliminateMultifrontal(*varsAsOrdering, function);
359 return factorGraph->eliminateMultifrontal(Ordering::COLAMD, function);
365 template<
class FACTORGRAPH>
366 boost::shared_ptr<FACTORGRAPH>
377 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - variables.size());
380 return eliminatePartialMultifrontal(marginalizationOrdering, function, *variableIndex).second;
386 return marginal(variables, function, computedVariableIndex);
Exceptions that may be thrown by inference algorithms.
Variable elimination algorithms for factor graphs.
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
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:300
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:367
EliminationTraitsType::EliminationTreeType EliminationTreeType
Elimination tree type that can do sequential elimination of this graph.
Definition: EliminateableFactorGraph.h:76
boost::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(boost::variant< const Ordering &, const KeyVector & > variables, const Ordering &marginalizedVariableOrdering, 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:265
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:91
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:154
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:233
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:193
An inference algorithm was called with inconsistent arguments.
Definition: inferenceExceptions.h:29
Definition: Ordering.h:34
static Ordering Natural(const FACTOR_GRAPH &fg)
Return a natural Ordering. Typically used by iterative solvers.
Definition: Ordering.h:190
static Ordering Colamd(const FACTOR_GRAPH &graph)
Compute a fill-reducing ordering using COLAMD from a factor graph (see details for note on performanc...
Definition: Ordering.h:95
static Ordering ColamdConstrainedLast(const FACTOR_GRAPH &graph, const KeyVector &constrainLast, bool forceOrder=false)
Compute a fill-reducing ordering using constrained COLAMD from a factor graph (see details for note o...
Definition: Ordering.h:114
static Ordering ColamdConstrainedFirst(const FACTOR_GRAPH &graph, const KeyVector &constrainFirst, bool forceOrder=false)
Compute a fill-reducing ordering using constrained COLAMD from a factor graph (see details for note o...
Definition: Ordering.h:141
static GTSAM_EXPORT Ordering Metis(const MetisIndex &met)
Compute an ordering determined by METIS from a VariableIndex.
Definition: Ordering.cpp:212
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition: VariableIndex.h:43