gtsam
Loading...
Searching...
No Matches
gtsam::BayesTreeMarginalizationHelper< BayesTree > Class Template Reference

Detailed Description

template<typename BayesTree>
class gtsam::BayesTreeMarginalizationHelper< BayesTree >

This class provides helper functions for marginalizing variables from a Bayes Tree.

Static Public Member Functions

static std::unordered_set< Key > gatherAdditionalKeysToReEliminate (const BayesTree &bayesTree, const KeyVector &marginalizableKeys)
 This function identifies variables that need to be re-eliminated before performing marginalization.

Public Types

using Clique = typename BayesTree::Clique
using sharedClique = typename BayesTree::sharedClique

Classes

struct  CachedSearch
 A struct to cache the results of the below two functions. More...

Static Protected Member Functions

static std::unordered_set< const Clique * > gatherAdditionalCliquesToReEliminate (const BayesTree &bayesTree, const KeyVector &marginalizableKeys)
 This function identifies cliques that need to be re-eliminated before performing marginalization.
static std::unordered_set< const Clique * > getCliquesContainingKeys (const BayesTree &bayesTree, const std::unordered_set< Key > &keysOfInterest)
 Gather the cliques containing any of the given keys.
static bool isWholeCliqueMarginalizable (const Clique *clique, const std::unordered_set< Key > &marginalizableKeys, CachedSearch *cache)
 Check if all variables in the clique are marginalizable.
static bool isWholeSubtreeMarginalizable (const Clique *subtree, const std::unordered_set< Key > &marginalizableKeys, CachedSearch *cache)
 Check if all variables in the subtree are marginalizable.
static bool needsReelimination (const Clique *clique, const std::unordered_set< Key > &marginalizableKeys, CachedSearch *cache)
 Check if a clique contains variables that need reelimination due to elimination ordering conflicts.
static void gatherDependentCliques (const Clique *rootClique, const std::unordered_set< Key > &marginalizableKeys, std::unordered_set< const Clique * > *additionalCliques, CachedSearch *cache)
 Gather all dependent nodes that lie on a path from the root clique to a clique containing a non-marginalizable variable at the leaf side.
static void gatherDependentCliquesFromChildren (const std::vector< const Clique * > &dependentChildren, const std::unordered_set< Key > &marginalizableKeys, std::unordered_set< const Clique * > *additionalCliques, CachedSearch *cache)
 A helper function for the above gatherDependentCliques().
static void addCliqueToKeySet (const Clique *clique, std::unordered_set< Key > *additionalKeys)
 Add all frontal variables from a clique to a key set.
static bool hasDependency (const Clique *clique, Key key)
 Check if the clique depends on the given key.
static bool hasDependency (const Clique *clique, const std::unordered_set< Key > &keys)
 Check if the clique depends on any of the given keys.

Member Function Documentation

◆ addCliqueToKeySet()

template<typename BayesTree>
void gtsam::BayesTreeMarginalizationHelper< BayesTree >::addCliqueToKeySet ( const Clique * clique,
std::unordered_set< Key > * additionalKeys )
inlinestaticprotected

Add all frontal variables from a clique to a key set.

Parameters
[in]cliqueClique to add keys from
[out]additionalKeysPointer to the output key set

◆ gatherAdditionalCliquesToReEliminate()

template<typename BayesTree>
std::unordered_set< const Clique * > gtsam::BayesTreeMarginalizationHelper< BayesTree >::gatherAdditionalCliquesToReEliminate ( const BayesTree & bayesTree,
const KeyVector & marginalizableKeys )
inlinestaticprotected

This function identifies cliques that need to be re-eliminated before performing marginalization.

See the docstring of gatherAdditionalKeysToReEliminate().

◆ gatherAdditionalKeysToReEliminate()

template<typename BayesTree>
std::unordered_set< Key > gtsam::BayesTreeMarginalizationHelper< BayesTree >::gatherAdditionalKeysToReEliminate ( const BayesTree & bayesTree,
const KeyVector & marginalizableKeys )
inlinestatic

This function identifies variables that need to be re-eliminated before performing marginalization.

Re-elimination is necessary for a clique containing marginalizable variables if:

  1. Some non-marginalizable variables appear before marginalizable ones in that clique;
  2. Or it has a child node depending on a marginalizable variable AND the subtree rooted at that child contains non-marginalizables.

In addition, for any descendant node depending on a marginalizable variable, if the subtree rooted at that descendant contains non-marginalizable variables (i.e., it lies on a path from one of the aforementioned cliques that require re-elimination to a node containing non-marginalizable variables at the leaf side), then it also needs to be re-eliminated.

Parameters
[in]bayesTreeThe Bayes tree
[in]marginalizableKeysKeys to be marginalized
Returns
Set of additional keys that need to be re-eliminated

◆ gatherDependentCliques()

template<typename BayesTree>
void gtsam::BayesTreeMarginalizationHelper< BayesTree >::gatherDependentCliques ( const Clique * rootClique,
const std::unordered_set< Key > & marginalizableKeys,
std::unordered_set< const Clique * > * additionalCliques,
CachedSearch * cache )
inlinestaticprotected

Gather all dependent nodes that lie on a path from the root clique to a clique containing a non-marginalizable variable at the leaf side.

Parameters
[in]rootCliqueThe root clique
[in]marginalizableKeysSet of keys to be marginalized

◆ getCliquesContainingKeys()

template<typename BayesTree>
std::unordered_set< const Clique * > gtsam::BayesTreeMarginalizationHelper< BayesTree >::getCliquesContainingKeys ( const BayesTree & bayesTree,
const std::unordered_set< Key > & keysOfInterest )
inlinestaticprotected

Gather the cliques containing any of the given keys.

Parameters
[in]bayesTreeThe Bayes tree
[in]keysOfInterestSet of keys of interest
Returns
Set of cliques that contain any of the given keys

◆ hasDependency()

template<typename BayesTree>
bool gtsam::BayesTreeMarginalizationHelper< BayesTree >::hasDependency ( const Clique * clique,
Key key )
inlinestaticprotected

Check if the clique depends on the given key.

Parameters
[in]cliqueClique to check
[in]keyKey to check for dependencies
Returns
true if clique depends on the key

◆ isWholeCliqueMarginalizable()

template<typename BayesTree>
bool gtsam::BayesTreeMarginalizationHelper< BayesTree >::isWholeCliqueMarginalizable ( const Clique * clique,
const std::unordered_set< Key > & marginalizableKeys,
CachedSearch * cache )
inlinestaticprotected

Check if all variables in the clique are marginalizable.

Note we use a cache map to avoid repeated searches.

◆ isWholeSubtreeMarginalizable()

template<typename BayesTree>
bool gtsam::BayesTreeMarginalizationHelper< BayesTree >::isWholeSubtreeMarginalizable ( const Clique * subtree,
const std::unordered_set< Key > & marginalizableKeys,
CachedSearch * cache )
inlinestaticprotected

Check if all variables in the subtree are marginalizable.

Note we use a cache map to avoid repeated searches.

◆ needsReelimination()

template<typename BayesTree>
bool gtsam::BayesTreeMarginalizationHelper< BayesTree >::needsReelimination ( const Clique * clique,
const std::unordered_set< Key > & marginalizableKeys,
CachedSearch * cache )
inlinestaticprotected

Check if a clique contains variables that need reelimination due to elimination ordering conflicts.

Parameters
[in]cliqueThe clique to check
[in]marginalizableKeysSet of keys to be marginalized
Returns
true if any variables in the clique need re-elimination

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