23 #include <boost/tuple/tuple.hpp> 28 template<
class FACTORGRAPH>
29 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
39 return eliminateSequential(
function, computedVariableIndex, orderingType);
46 return eliminateSequential(computedOrdering,
function, variableIndex, orderingType);
49 return eliminateSequential(computedOrdering,
function, variableIndex, orderingType);
55 template<
class FACTORGRAPH>
56 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
64 return eliminateSequential(ordering,
function, computedVariableIndex);
66 gttic(eliminateSequential);
69 boost::shared_ptr<BayesNetType> bayesNet;
70 boost::shared_ptr<FactorGraphType> factorGraph;
71 boost::tie(bayesNet,factorGraph) = etree.eliminate(
function);
73 if(!factorGraph->empty())
81 template<
class FACTORGRAPH>
82 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
93 return eliminateMultifrontal(
function, computedVariableIndex, orderingType);
100 return eliminateMultifrontal(computedOrdering,
function, variableIndex, orderingType);
103 return eliminateMultifrontal(computedOrdering,
function, variableIndex, orderingType);
109 template<
class FACTORGRAPH>
110 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
118 return eliminateMultifrontal(ordering,
function, computedVariableIndex);
120 gttic(eliminateMultifrontal);
124 boost::shared_ptr<BayesTreeType> bayesTree;
125 boost::shared_ptr<FactorGraphType> factorGraph;
126 boost::tie(bayesTree,factorGraph) = junctionTree.eliminate(
function);
128 if(!factorGraph->empty())
136 template<
class FACTORGRAPH>
137 std::pair<boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>, boost::shared_ptr<FACTORGRAPH> >
142 gttic(eliminatePartialSequential);
145 return etree.eliminate(
function);
149 return eliminatePartialSequential(ordering,
function, computedVariableIndex);
154 template<
class FACTORGRAPH>
155 std::pair<boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>, boost::shared_ptr<FACTORGRAPH> >
160 gttic(eliminatePartialSequential);
165 Ordering ordering(fullOrdering.begin(), fullOrdering.begin() + variables.size());
166 return eliminatePartialSequential(
ordering,
function, variableIndex);
170 return eliminatePartialSequential(variables,
function, computedVariableIndex);
175 template<
class FACTORGRAPH>
176 std::pair<boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>, boost::shared_ptr<FACTORGRAPH> >
181 gttic(eliminatePartialMultifrontal);
185 return junctionTree.eliminate(
function);
189 return eliminatePartialMultifrontal(ordering,
function, computedVariableIndex);
194 template<
class FACTORGRAPH>
195 std::pair<boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>, boost::shared_ptr<FACTORGRAPH> >
200 gttic(eliminatePartialMultifrontal);
205 Ordering ordering(fullOrdering.begin(), fullOrdering.begin() + variables.size());
206 return eliminatePartialMultifrontal(
ordering,
function, variableIndex);
210 return eliminatePartialMultifrontal(variables,
function, computedVariableIndex);
215 template<
class FACTORGRAPH>
216 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
218 boost::variant<const Ordering&, const KeyVector&> variables,
224 return marginalMultifrontalBayesNet(variables,
function, index);
228 bool unmarginalizedAreOrdered = (boost::get<const Ordering&>(&variables) != 0);
230 unmarginalizedAreOrdered ?
231 boost::get<const Ordering&>(&variables) : boost::get<const KeyVector&>(&variables);
237 const size_t nVars = variablesOrOrdering->size();
238 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - nVars);
239 Ordering marginalVarsOrdering(totalOrdering.end() - nVars, totalOrdering.end());
242 return marginalMultifrontalBayesNet(marginalVarsOrdering, marginalizationOrdering,
function, *variableIndex);
247 template<
class FACTORGRAPH>
248 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
250 boost::variant<const Ordering&, const KeyVector&> variables,
251 const Ordering& marginalizedVariableOrdering,
257 return marginalMultifrontalBayesNet(variables, marginalizedVariableOrdering,
function, index);
259 gttic(marginalMultifrontalBayesNet);
262 boost::shared_ptr<BayesTreeType> bayesTree;
263 boost::shared_ptr<FactorGraphType> factorGraph;
264 boost::tie(bayesTree,factorGraph) =
265 eliminatePartialMultifrontal(marginalizedVariableOrdering,
function, *variableIndex);
267 if(
const Ordering* varsAsOrdering = boost::get<const Ordering&>(&variables))
271 return factorGraph->eliminateSequential(*varsAsOrdering,
function);
276 return factorGraph->eliminateSequential(
function);
282 template<
class FACTORGRAPH>
283 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
285 boost::variant<const Ordering&, const KeyVector&> variables,
291 return marginalMultifrontalBayesTree(variables,
function, computedVariableIndex);
295 bool unmarginalizedAreOrdered = (boost::get<const Ordering&>(&variables) != 0);
297 unmarginalizedAreOrdered ?
298 boost::get<const Ordering&>(&variables) : boost::get<const KeyVector&>(&variables);
304 const size_t nVars = variablesOrOrdering->size();
305 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - nVars);
306 Ordering marginalVarsOrdering(totalOrdering.end() - nVars, totalOrdering.end());
309 return marginalMultifrontalBayesTree(marginalVarsOrdering, marginalizationOrdering,
function, *variableIndex);
314 template<
class FACTORGRAPH>
315 boost::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
317 boost::variant<const Ordering&, const KeyVector&> variables,
318 const Ordering& marginalizedVariableOrdering,
324 return marginalMultifrontalBayesTree(variables, marginalizedVariableOrdering,
function, computedVariableIndex);
326 gttic(marginalMultifrontalBayesTree);
329 boost::shared_ptr<BayesTreeType> bayesTree;
330 boost::shared_ptr<FactorGraphType> factorGraph;
331 boost::tie(bayesTree,factorGraph) =
332 eliminatePartialMultifrontal(marginalizedVariableOrdering,
function, *variableIndex);
334 if(
const Ordering* varsAsOrdering = boost::get<const Ordering&>(&variables))
338 return factorGraph->eliminateMultifrontal(*varsAsOrdering,
function);
343 return factorGraph->eliminateMultifrontal(
function);
349 template<
class FACTORGRAPH>
350 boost::shared_ptr<FACTORGRAPH>
361 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - variables.size());
364 return eliminatePartialMultifrontal(marginalizationOrdering,
function, *variableIndex).second;
370 return marginal(variables,
function, computedVariableIndex);
std::pair< boost::shared_ptr< BayesTreeType >, boost::shared_ptr< FactorGraphType > > eliminatePartialMultifrontal(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
static GTSAM_EXPORT Ordering Metis(const MetisIndex &met)
Compute an ordering determined by METIS from a VariableIndex.
boost::shared_ptr< FactorGraphType > marginal(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Variable elimination algorithms for factor graphs.
static enum @843 ordering
boost::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
boost::shared_ptr< BayesTreeType > marginalMultifrontalBayesTree(boost::variant< const Ordering &, const KeyVector & > variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Exceptions that may be thrown by inference algorithms.
boost::optional< Ordering::OrderingType > OptionalOrderingType
Typedef for an optional ordering type.
static Ordering Colamd(const FACTOR_GRAPH &graph)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
EliminationTraitsType::JunctionTreeType JunctionTreeType
Junction tree type that can do multifrontal elimination of this graph.
std::pair< boost::shared_ptr< BayesNetType >, boost::shared_ptr< FactorGraphType > > eliminatePartialSequential(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
static Ordering ColamdConstrainedFirst(const FACTOR_GRAPH &graph, const KeyVector &constrainFirst, bool forceOrder=false)
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.
boost::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
static Ordering ColamdConstrainedLast(const FACTOR_GRAPH &graph, const KeyVector &constrainLast, bool forceOrder=false)
boost::optional< const VariableIndex & > OptionalVariableIndex
Typedef for an optional variable index as an argument to elimination functions.
boost::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(boost::variant< const Ordering &, const KeyVector & > variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const