GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
Public Types | Public Member Functions | Protected Attributes | List of all members
gtsam::GaussianBayesTree Class Reference

#include <GaussianBayesTree.h>

Inheritance diagram for gtsam::GaussianBayesTree:
Inheritance graph
[legend]
Collaboration diagram for gtsam::GaussianBayesTree:
Collaboration graph
[legend]

Public Types

typedef GaussianBayesTree This
 
typedef std::shared_ptr< Thisshared_ptr
 
typedef GaussianBayesTreeClique Clique
 The clique type, normally BayesTreeClique.
 
typedef std::shared_ptr< CliquesharedClique
 Shared pointer to a clique.
 
typedef Clique Node
 Synonym for Clique (TODO: remove)
 
typedef sharedClique sharedNode
 Synonym for sharedClique (TODO: remove)
 
typedef GaussianBayesTreeClique ::ConditionalType ConditionalType
 
typedef std::shared_ptr< ConditionalType > sharedConditional
 
typedef GaussianBayesTreeClique ::BayesNetType BayesNetType
 
typedef std::shared_ptr< BayesNetType > sharedBayesNet
 
typedef GaussianBayesTreeClique ::FactorType FactorType
 
typedef std::shared_ptr< FactorType > sharedFactor
 
typedef GaussianBayesTreeClique ::FactorGraphType FactorGraphType
 
typedef std::shared_ptr< FactorGraphType > sharedFactorGraph
 
typedef FactorGraphType::Eliminate Eliminate
 
typedef GaussianBayesTreeClique ::EliminationTraitsType EliminationTraitsType
 
typedef FastList< sharedCliqueCliques
 
typedef ConcurrentMap< Key, sharedCliqueNodes
 
typedef FastVector< sharedCliqueRoots
 

Public Member Functions

 GaussianBayesTree ()
 
bool equals (const This &other, double tol=1e-9) const
 
VectorValues optimize () const
 
VectorValues optimizeGradientSearch () const
 
VectorValues gradient (const VectorValues &x0) const
 
VectorValues gradientAtZero () const
 
double error (const VectorValues &x) const
 
double determinant () const
 
double logDeterminant () const
 
Matrix marginalCovariance (Key key) const
 
Standard Interface
size_t size () const
 
bool empty () const
 
const Nodesnodes () const
 
sharedClique operator[] (Key j) const
 
const Rootsroots () const
 
const sharedCliqueclique (Key j) const
 
BayesTreeCliqueData getCliqueData () const
 
size_t numCachedSeparatorMarginals () const
 
sharedConditional marginalFactor (Key j, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
 
sharedFactorGraph joint (Key j1, Key j2, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
 
sharedBayesNet jointBayesNet (Key j1, Key j2, const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
 
Graph Display
void dot (std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
 Output to graphviz format, stream version.
 
std::string dot (const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
 Output to graphviz format string.
 
void saveGraph (const std::string &filename, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
 output to file with graphviz format.
 

Protected Attributes

Nodes nodes_
 
Roots roots_
 

Testable

void print (const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
 
bool equals (const This &other, double tol=1e-9) const
 

Advanced Interface

Key findParentClique (const CONTAINER &parents) const
 
void clear ()
 
void deleteCachedShortcuts ()
 
void removePath (sharedClique clique, BayesNetType *bn, Cliques *orphans)
 
void removeTop (const KeyVector &keys, BayesNetType *bn, Cliques *orphans)
 
Cliques removeSubtree (const sharedClique &subtree)
 
void insertRoot (const sharedClique &subtree)
 
void addClique (const sharedClique &clique, const sharedClique &parent_clique=sharedClique())
 
void addFactorsToGraph (FactorGraph< FactorType > *graph) const
 
void getCliqueData (sharedClique clique, BayesTreeCliqueData *stats) const
 
void dot (std::ostream &s, sharedClique clique, const KeyFormatter &keyFormatter, int parentnum=0) const
 
void removeClique (sharedClique clique)
 
void fillNodesIndex (const sharedClique &subtree)
 

Detailed Description

A Bayes tree representing a Gaussian density

Member Typedef Documentation

◆ Cliques

A convenience class for a list of shared cliques

◆ Nodes

Map from keys to Clique

◆ Roots

Root cliques

Constructor & Destructor Documentation

◆ GaussianBayesTree()

gtsam::GaussianBayesTree::GaussianBayesTree ( )
inline

Default constructor, creates an empty Bayes tree

Member Function Documentation

◆ addClique()

void gtsam::BayesTree< GaussianBayesTreeClique >::addClique ( const sharedClique clique,
const sharedClique parent_clique = sharedClique() 
)
inherited

add a clique (top down)

◆ addFactorsToGraph()

void gtsam::BayesTree< GaussianBayesTreeClique >::addFactorsToGraph ( FactorGraph< FactorType > *  graph) const
inherited

Add all cliques in this BayesTree to the specified factor graph

◆ clear()

void gtsam::BayesTree< GaussianBayesTreeClique >::clear ( )
inherited

Remove all nodes

◆ clique()

const sharedClique& gtsam::BayesTree< GaussianBayesTreeClique >::clique ( Key  j) const
inlineinherited

alternate syntax for matlab: find the clique that contains the variable with Key j

◆ deleteCachedShortcuts()

void gtsam::BayesTree< GaussianBayesTreeClique >::deleteCachedShortcuts ( )
inherited

Clear all shortcut caches - use before timing on marginal calculation to avoid residual cache data

◆ determinant()

double gtsam::GaussianBayesTree::determinant ( ) const

Computes the determinant of a GassianBayesTree, as if the Bayes tree is reorganized into a matrix. A GassianBayesTree is equivalent to an upper triangular matrix, and for an upper triangular matrix determinant is the product of the diagonal elements. Instead of actually multiplying we add the logarithms of the diagonal elements and take the exponent at the end because this is more numerically stable.

◆ dot()

void gtsam::BayesTree< GaussianBayesTreeClique >::dot ( std::ostream &  s,
sharedClique  clique,
const KeyFormatter keyFormatter,
int  parentnum = 0 
) const
protectedinherited

private helper method for saving the Tree to a text file in GraphViz format

◆ empty()

bool gtsam::BayesTree< GaussianBayesTreeClique >::empty ( ) const
inlineinherited

Check if there are any cliques in the tree

◆ equals() [1/2]

bool gtsam::GaussianBayesTree::equals ( const This other,
double  tol = 1e-9 
) const

Check equality

◆ equals() [2/2]

bool gtsam::BayesTree< GaussianBayesTreeClique >::equals ( const This other,
double  tol = 1e-9 
) const
protectedinherited

check equality

◆ error()

double gtsam::GaussianBayesTree::error ( const VectorValues x) const

0.5 * sum of squared Mahalanobis distances.

◆ fillNodesIndex()

void gtsam::BayesTree< GaussianBayesTreeClique >::fillNodesIndex ( const sharedClique subtree)
protectedinherited

Fill the nodes index for a subtree

◆ findParentClique()

Key gtsam::BayesTree< GaussianBayesTreeClique >::findParentClique ( const CONTAINER &  parents) const
inherited

Find parent clique of a conditional. It will look at all parents and return the one with the lowest index in the ordering.

◆ getCliqueData() [1/2]

BayesTreeCliqueData gtsam::BayesTree< GaussianBayesTreeClique >::getCliqueData ( ) const
inherited

Gather data on all cliques

◆ getCliqueData() [2/2]

void gtsam::BayesTree< GaussianBayesTreeClique >::getCliqueData ( sharedClique  clique,
BayesTreeCliqueData stats 
) const
protectedinherited

Gather data on a single clique

◆ gradient()

VectorValues gtsam::GaussianBayesTree::gradient ( const VectorValues x0) const

Compute the gradient of the energy function, \( \nabla_{x=x_0} \left\Vert \Sigma^{-1} R x - d \right\Vert^2 \), centered around \( x = x_0 \). The gradient is \( R^T(Rx-d) \).

Parameters
x0The center about which to compute the gradient
Returns
The gradient as a VectorValues

◆ gradientAtZero()

VectorValues gtsam::GaussianBayesTree::gradientAtZero ( ) const

Compute the gradient of the energy function, \( \nabla_{x=0} \left\Vert \Sigma^{-1} R x - d \right\Vert^2 \), centered around zero. The gradient about zero is \( -R^T d \). See also gradient(const GaussianBayesNet&, const VectorValues&).

Returns
A VectorValues storing the gradient.

◆ insertRoot()

void gtsam::BayesTree< GaussianBayesTreeClique >::insertRoot ( const sharedClique subtree)
inherited

Insert a new subtree with known parent clique. This function does not check that the specified parent is the correct parent. This function updates all of the internal data structures associated with adding a subtree, such as populating the nodes index.

◆ joint()

BayesTree< GaussianBayesTreeClique >::sharedFactorGraph gtsam::BayesTree< GaussianBayesTreeClique >::joint ( Key  j1,
Key  j2,
const Eliminate &  function = EliminationTraitsType::DefaultEliminate 
) const
inherited

return joint on two variables Limitation: can only calculate joint if cliques are disjoint or one of them is root

◆ jointBayesNet()

BayesTree< GaussianBayesTreeClique >::sharedBayesNet gtsam::BayesTree< GaussianBayesTreeClique >::jointBayesNet ( Key  j1,
Key  j2,
const Eliminate &  function = EliminationTraitsType::DefaultEliminate 
) const
inherited

return joint on two variables as a BayesNet Limitation: can only calculate joint if cliques are disjoint or one of them is root

◆ logDeterminant()

double gtsam::GaussianBayesTree::logDeterminant ( ) const

Computes the determinant of a GassianBayesTree, as if the Bayes tree is reorganized into a matrix. A GassianBayesTree is equivalent to an upper triangular matrix, and for an upper triangular matrix determinant is the product of the diagonal elements. Instead of actually multiplying we add the logarithms of the diagonal elements and take the exponent at the end because this is more numerically stable.

◆ marginalCovariance()

Matrix gtsam::GaussianBayesTree::marginalCovariance ( Key  key) const

Return the marginal on the requested variable as a covariance matrix. See also marginalFactor().

◆ marginalFactor()

BayesTree< GaussianBayesTreeClique >::sharedConditional gtsam::BayesTree< GaussianBayesTreeClique >::marginalFactor ( Key  j,
const Eliminate &  function = EliminationTraitsType::DefaultEliminate 
) const
inherited

Return marginal on any variable. Note that this actually returns a conditional, for which a solution may be directly obtained by calling .solve() on the returned object. Alternatively, it may be directly used as its factor base class. For example, for Gaussian systems, this returns a GaussianConditional, which inherits from JacobianFactor and GaussianFactor.

◆ nodes()

const Nodes& gtsam::BayesTree< GaussianBayesTreeClique >::nodes ( ) const
inlineinherited

Return nodes. Each node is a clique of variables obtained after elimination.

◆ numCachedSeparatorMarginals()

size_t gtsam::BayesTree< GaussianBayesTreeClique >::numCachedSeparatorMarginals ( ) const
inherited

Collect number of cliques with cached separator marginals

◆ operator[]()

sharedClique gtsam::BayesTree< GaussianBayesTreeClique >::operator[] ( Key  j) const
inlineinherited

Access node by variable

◆ optimize()

VectorValues gtsam::GaussianBayesTree::optimize ( ) const

Recursively optimize the BayesTree to produce a vector solution.

◆ optimizeGradientSearch()

VectorValues gtsam::GaussianBayesTree::optimizeGradientSearch ( ) const

Optimize along the gradient direction, with a closed-form computation to perform the line search. The gradient is computed about \( \delta x=0 \).

This function returns \( \delta x \) that minimizes a reparametrized problem. The error function of a GaussianBayesNet is

\[ f(\delta x) = \frac{1}{2} |R \delta x - d|^2 = \frac{1}{2}d^T d - d^T R \delta x + \frac{1}{2} \delta x^T R^T R \delta x \]

with gradient and Hessian

\[ g(\delta x) = R^T(R\delta x - d), \qquad G(\delta x) = R^T R. \]

This function performs the line search in the direction of the gradient evaluated at \( g = g(\delta x = 0) \) with step size \( \alpha \) that minimizes \( f(\delta x = \alpha g) \):

\[ f(\alpha) = \frac{1}{2} d^T d + g^T \delta x + \frac{1}{2} \alpha^2 g^T G g \]

Optimizing by setting the derivative to zero yields \( \hat \alpha = (-g^T g) / (g^T G g) \). For efficiency, this function evaluates the denominator without computing the Hessian \( G \), returning

\[ \delta x = \hat\alpha g = \frac{-g^T g}{(R g)^T(R g)} \]

◆ print()

void gtsam::BayesTree< GaussianBayesTreeClique >::print ( const std::string &  s = "",
const KeyFormatter keyFormatter = DefaultKeyFormatter 
) const
inherited

print

◆ removeClique()

void gtsam::BayesTree< GaussianBayesTreeClique >::removeClique ( sharedClique  clique)
protectedinherited

remove a clique: warning, can result in a forest

◆ removePath()

void gtsam::BayesTree< GaussianBayesTreeClique >::removePath ( sharedClique  clique,
BayesNetType *  bn,
Cliques orphans 
)
inherited

Remove path from clique to root and return that path as factors plus a list of orphaned subtree roots. Used in removeTop below.

◆ removeSubtree()

BayesTree< GaussianBayesTreeClique >::Cliques gtsam::BayesTree< GaussianBayesTreeClique >::removeSubtree ( const sharedClique subtree)
inherited

Remove the requested subtree.

◆ removeTop()

void gtsam::BayesTree< GaussianBayesTreeClique >::removeTop ( const KeyVector keys,
BayesNetType *  bn,
Cliques orphans 
)
inherited

Given a list of indices, turn "contaminated" part of the tree back into a factor graph. Factors and orphans are added to the in/out arguments.

◆ roots()

const Roots& gtsam::BayesTree< GaussianBayesTreeClique >::roots ( ) const
inlineinherited

return root cliques

◆ size()

size_t gtsam::BayesTree< GaussianBayesTreeClique >::size ( ) const
inherited

number of cliques

Member Data Documentation

◆ nodes_

Nodes gtsam::BayesTree< GaussianBayesTreeClique >::nodes_
protectedinherited

Map from indices to Clique

◆ roots_

Roots gtsam::BayesTree< GaussianBayesTreeClique >::roots_
protectedinherited

Root cliques


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