gtsam
Loading...
Searching...
No Matches
gtsam::EliminateableFactorGraph< FACTOR_GRAPH > Class Template Reference

Detailed Description

template<class FACTOR_GRAPH>
class gtsam::EliminateableFactorGraph< FACTOR_GRAPH >

EliminateableFactorGraph is a base class for factor graphs that contains elimination algorithms.

Any factor graph holding eliminateable factors can derive from this class to expose functions for computing marginals, conditional marginals, doing multifrontal and sequential elimination, etc.

Public Member Functions

IndexedJunctionTree buildIndexedJunctionTree (const Ordering &ordering, const std::unordered_set< Key > &fixedKeys={}) const
 Build an IndexedJunctionTree for this factor graph and a fixed ordering.
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.
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.
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.
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.
std::shared_ptr< BayesTreeType > eliminateMultifrontal (const IndexedJunctionTree &indexedJunctionTree, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
 Do multifrontal elimination using a pre-built IndexedJunctionTree.
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 remaining factor graph.
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 net and a remaining factor graph.
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 remaining factor graph.
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 Bayes tree and a remaining factor graph.
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.
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.
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.
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.
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.
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.
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.
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.
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.

Public Types

typedef EliminationTraits< FactorGraphType > EliminationTraitsType
 Typedef to the specific EliminationTraits for this graph.
typedef EliminationTraitsType::ConditionalType ConditionalType
 Conditional type stored in the Bayes net produced by elimination.
typedef EliminationTraitsType::BayesNetType BayesNetType
 Bayes net type produced by sequential elimination.
typedef EliminationTraitsType::EliminationTreeType EliminationTreeType
 Elimination tree type that can do sequential elimination of this graph.
typedef EliminationTraitsType::BayesTreeType BayesTreeType
 Bayes tree type produced by multifrontal elimination.
typedef EliminationTraitsType::JunctionTreeType JunctionTreeType
 Junction tree type that can do multifrontal elimination of this graph.
typedef std::pair< std::shared_ptr< ConditionalType >, std::shared_ptr< _FactorType > > EliminationResult
 The pair of conditional and remaining factor produced by a single dense elimination step on a subgraph.
typedef std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
 The function type that does a single dense elimination step on a subgraph.
typedef std::optional< std::reference_wrapper< const VariableIndex > > OptionalVariableIndex
 Typedef for an optional variable index as an argument to elimination functions It is an optional to a constant reference.
typedef std::optional< Ordering::OrderingType > OptionalOrderingType
 Typedef for an optional ordering type.

Member Function Documentation

◆ buildIndexedJunctionTree()

template<class FACTORGRAPH>
IndexedJunctionTree gtsam::EliminateableFactorGraph< FACTORGRAPH >::buildIndexedJunctionTree ( const Ordering & ordering,
const std::unordered_set< Key > & fixedKeys = {} ) const

Build an IndexedJunctionTree for this factor graph and a fixed ordering.

This structure can be cached and reused for repeated eliminations when the factor graph structure and ordering are unchanged.

Parameters
orderingThe elimination ordering
fixedKeysOptional set of keys to filter out (e.g., from hard constraints)
Returns
An IndexedJunctionTree that can be reused for elimination

◆ eliminateMultifrontal() [1/3]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::eliminateMultifrontal ( const IndexedJunctionTree & indexedJunctionTree,
const Eliminate & function = EliminationTraitsType::DefaultEliminate ) const

Do multifrontal elimination using a pre-built IndexedJunctionTree.

This eliminates the factor graph following the cluster structure encoded in the indexed junction tree and calls the provided dense elimination function on each cluster. The indexed junction tree must have been built from a factor graph with the same factor ordering/indices and the same variable ordering.

Parameters
indexedJunctionTreePre-built indexed junction tree
functionThe elimination function to use for each cluster
Returns
A Bayes tree containing the elimination results

◆ eliminateMultifrontal() [2/3]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::eliminateMultifrontal ( const Ordering & ordering,
const Eliminate & function = EliminationTraitsType::DefaultEliminate,
OptionalVariableIndex variableIndex = {} ) const

Do multifrontal elimination of all variables to produce a Bayes tree.

If an ordering is not provided, the ordering will be computed using either COLAMD or METIS, depending on the parameter orderingType (Ordering::COLAMD or Ordering::METIS)

Example - Full QR elimination in specified order:

std::shared_ptr<GaussianBayesTree> result = graph.eliminateMultifrontal(EliminateQR, myOrdering);
std::pair< GaussianConditional::shared_ptr, JacobianFactor::shared_ptr > EliminateQR(const GaussianFactorGraph &factors, const Ordering &keys)
Multiply all factors and eliminate the given keys from the resulting factor using a QR variant that h...
Definition JacobianFactor.cpp:976

◆ eliminateMultifrontal() [3/3]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::eliminateMultifrontal ( OptionalOrderingType orderingType = {},
const Eliminate & function = EliminationTraitsType::DefaultEliminate,
OptionalVariableIndex variableIndex = {} ) const

Do multifrontal elimination of all variables to produce a Bayes tree.

If an ordering is not provided, the ordering will be computed using either COLAMD or METIS, depending on the parameter orderingType (Ordering::COLAMD or Ordering::METIS)

Example - Full Cholesky elimination in COLAMD order:

std::shared_ptr<GaussianBayesTree> result = graph.eliminateMultifrontal(EliminateCholesky);
std::pair< std::shared_ptr< GaussianConditional >, std::shared_ptr< HessianFactor > > EliminateCholesky(const GaussianFactorGraph &factors, const Ordering &keys)
Densely partially eliminate with Cholesky factorization.
Definition HessianFactor.cpp:621

Example - Reusing an existing VariableIndex to improve performance, and using COLAMD ordering:

VariableIndex varIndex(graph); // Build variable index
Data data = otherFunctionUsingVariableIndex(graph, varIndex); // Other code that uses variable index
std::shared_ptr<GaussianBayesTree> result = graph.eliminateMultifrontal(EliminateQR, {}, varIndex);
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:41

◆ eliminatePartialMultifrontal() [1/2]

template<class FACTORGRAPH>
std::pair< std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType >, std::shared_ptr< FACTORGRAPH > > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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 Bayes tree and a remaining factor graph.

This computes the factorization \( p(X) = p(A|B) p(B) \), where \( A = \) variables, \( X \) is all the variables in the factor graph, and \( B = X\backslash A \).

◆ eliminatePartialMultifrontal() [2/2]

template<class FACTORGRAPH>
std::pair< std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType >, std::shared_ptr< FACTORGRAPH > > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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 remaining factor graph.

This computes the factorization \( p(X) = p(A|B) p(B) \), where \( A = \) variables, \( X \) is all the variables in the factor graph, and \( B = X\backslash A \).

◆ eliminatePartialSequential() [1/2]

template<class FACTORGRAPH>
std::pair< std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesNetType >, std::shared_ptr< FACTORGRAPH > > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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 net and a remaining factor graph.

This computes the factorization \( p(X) = p(A|B) p(B) \), where \( A = \) variables, \( X \) is all the variables in the factor graph, and \( B = X\backslash A \).

◆ eliminatePartialSequential() [2/2]

template<class FACTORGRAPH>
std::pair< std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesNetType >, std::shared_ptr< FACTORGRAPH > > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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 remaining factor graph.

This computes the factorization \( p(X) = p(A|B) p(B) \), where \( A = \) variables, \( X \) is all the variables in the factor graph, and \(B = X\backslash A \).

◆ eliminateSequential() [1/2]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesNetType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::eliminateSequential ( const Ordering & ordering,
const Eliminate & function = EliminationTraitsType::DefaultEliminate,
OptionalVariableIndex variableIndex = {} ) const

Do sequential elimination of all variables to produce a Bayes net.

Example - Full QR elimination in specified order:

std::shared_ptr<GaussianBayesNet> result = graph.eliminateSequential(myOrdering, EliminateQR);

Example - Reusing an existing VariableIndex to improve performance:

VariableIndex varIndex(graph); // Build variable index
Data data = otherFunctionUsingVariableIndex(graph, varIndex); // Other code that uses variable index
std::shared_ptr<GaussianBayesNet> result = graph.eliminateSequential(myOrdering, EliminateQR, varIndex, std::nullopt);

◆ eliminateSequential() [2/2]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesNetType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::eliminateSequential ( OptionalOrderingType orderingType = {},
const Eliminate & function = EliminationTraitsType::DefaultEliminate,
OptionalVariableIndex variableIndex = {} ) const

Do sequential elimination of all variables to produce a Bayes net.

If an ordering is not provided, the ordering provided by COLAMD will be used.

Example - Full Cholesky elimination in COLAMD order:

std::shared_ptr<GaussianBayesNet> result = graph.eliminateSequential(EliminateCholesky);

Example - METIS ordering for elimination

std::shared_ptr<GaussianBayesNet> result = graph.eliminateSequential(OrderingType::METIS);

Example - Reusing an existing VariableIndex to improve performance, and using COLAMD ordering:

VariableIndex varIndex(graph); // Build variable index
Data data = otherFunctionUsingVariableIndex(graph, varIndex); // Other code that uses variable index
std::shared_ptr<GaussianBayesNet> result = graph.eliminateSequential(EliminateQR, varIndex, std::nullopt);

◆ marginalMultifrontalBayesNet() [1/4]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesNetType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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.

Uses COLAMD marginalization ordering by default

Parameters
variablesDetermines the variables whose marginal to compute, will be ordered using COLAMD; use Ordering(variables) to specify the variable ordering.
functionOptional dense elimination function.
variableIndexOptional pre-computed VariableIndex for the factor graph, if not provided one will be computed.

◆ marginalMultifrontalBayesNet() [2/4]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesNetType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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.

Parameters
variablesDetermines the variables whose marginal to compute, will be ordered using COLAMD; use Ordering(variables) to specify the variable ordering.
marginalizedVariableOrderingOrdering for the variables being marginalized out, i.e. all variables not in variables.
functionOptional dense elimination function.
variableIndexOptional pre-computed VariableIndex for the factor graph, if not provided one will be computed.

◆ marginalMultifrontalBayesNet() [3/4]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesNetType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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.

Uses COLAMD marginalization ordering by default

Parameters
variablesDetermines the ordered variables whose marginal to compute, will be ordered in the returned BayesNet as specified.
functionOptional dense elimination function.
variableIndexOptional pre-computed VariableIndex for the factor graph, if not provided one will be computed.

◆ marginalMultifrontalBayesNet() [4/4]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesNetType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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.

Parameters
variablesDetermines the ordered variables whose marginal to compute, will be ordered in the returned BayesNet as specified.
marginalizedVariableOrderingOrdering for the variables being marginalized out, i.e. all variables not in variables.
functionOptional dense elimination function.
variableIndexOptional pre-computed VariableIndex for the factor graph, if not provided one will be computed.

◆ marginalMultifrontalBayesTree() [1/4]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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.

Uses COLAMD marginalization order by default

Parameters
variablesDetermines the variables whose marginal to compute, will be ordered using COLAMD; use Ordering(variables) to specify the variable ordering.
functionOptional dense elimination function..
variableIndexOptional pre-computed VariableIndex for the factor graph, if not provided one will be computed.

◆ marginalMultifrontalBayesTree() [2/4]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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.

Parameters
variablesDetermines the variables whose marginal to compute, will be ordered using COLAMD; use Ordering(variables) to specify the variable ordering.
marginalizedVariableOrderingOrdering for the variables being marginalized out, i.e. all variables not in variables.
functionOptional dense elimination function..
variableIndexOptional pre-computed VariableIndex for the factor graph, if not provided one will be computed.

◆ marginalMultifrontalBayesTree() [3/4]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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.

Uses COLAMD marginalization order by default

Parameters
variablesDetermines the ordered variables whose marginal to compute, will be ordered in the returned BayesNet as specified.
functionOptional dense elimination function..
variableIndexOptional pre-computed VariableIndex for the factor graph, if not provided one will be computed.

◆ marginalMultifrontalBayesTree() [4/4]

template<class FACTORGRAPH>
std::shared_ptr< typename EliminateableFactorGraph< FACTORGRAPH >::BayesTreeType > gtsam::EliminateableFactorGraph< FACTORGRAPH >::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.

Parameters
variablesDetermines the ordered variables whose marginal to compute, will be ordered in the returned BayesNet as specified.
marginalizedVariableOrderingOrdering for the variables being marginalized out, i.e. all variables not in variables.
functionOptional dense elimination function..
variableIndexOptional pre-computed VariableIndex for the factor graph, if not provided one will be computed.

The documentation for this class was generated from the following files: