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

A conditional of gaussian mixtures indexed by discrete variables, as part of a Bayes Network. This is the result of the elimination of a continuous variable in a hybrid scheme, such that the remaining variables are discrete+continuous. More...

#include <GaussianMixture.h>

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

Public Types

using This = GaussianMixture
 
using shared_ptr = std::shared_ptr< GaussianMixture >
 
using BaseFactor = HybridFactor
 
using BaseConditional = Conditional< HybridFactor, GaussianMixture >
 
using Conditionals = DecisionTree< Key, GaussianConditional::shared_ptr >
 typedef for Decision Tree of Gaussian Conditionals
 
typedef Factor Base
 Our base class.
 
typedef KeyVector::iterator iterator
 Iterator over keys.
 
typedef KeyVector::const_iterator const_iterator
 Const iterator over keys.
 
typedef std::pair< typename HybridFactor ::const_iterator, typename HybridFactor ::const_iteratorConstFactorRange
 
typedef ConstFactorRangeIterator Frontals
 
typedef ConstFactorRangeIterator Parents
 

Public Member Functions

Constructors
 GaussianMixture ()=default
 Default constructor, mainly for serialization.
 
 GaussianMixture (const KeyVector &continuousFrontals, const KeyVector &continuousParents, const DiscreteKeys &discreteParents, const Conditionals &conditionals)
 Construct a new GaussianMixture object. More...
 
 GaussianMixture (KeyVector &&continuousFrontals, KeyVector &&continuousParents, DiscreteKeys &&discreteParents, std::vector< GaussianConditional::shared_ptr > &&conditionals)
 Make a Gaussian Mixture from a list of Gaussian conditionals. More...
 
 GaussianMixture (const KeyVector &continuousFrontals, const KeyVector &continuousParents, const DiscreteKeys &discreteParents, const std::vector< GaussianConditional::shared_ptr > &conditionals)
 Make a Gaussian Mixture from a list of Gaussian conditionals. More...
 
Testable
bool equals (const HybridFactor &lf, double tol=1e-9) const override
 Test equality with base HybridFactor.
 
void print (const std::string &s="GaussianMixture\, const KeyFormatter &formatter=DefaultKeyFormatter) const override
 Print utility.
 
Standard API
GaussianConditional::shared_ptr operator() (const DiscreteValues &discreteValues) const
 Return the conditional Gaussian for the given discrete assignment.
 
size_t nrComponents () const
 Returns the total number of continuous components.
 
KeyVector continuousParents () const
 Returns the continuous keys among the parents.
 
double logNormalizationConstant () const override
 
std::shared_ptr< GaussianMixtureFactorlikelihood (const VectorValues &given) const
 
const Conditionalsconditionals () const
 Getter for the underlying Conditionals DecisionTree.
 
AlgebraicDecisionTree< KeylogProbability (const VectorValues &continuousValues) const
 Compute logProbability of the GaussianMixture as a tree. More...
 
double error (const HybridValues &values) const override
 Compute the error of this Gaussian Mixture. More...
 
AlgebraicDecisionTree< Keyerror (const VectorValues &continuousValues) const
 Compute error of the GaussianMixture as a tree. More...
 
double logProbability (const HybridValues &values) const override
 Compute the logProbability of this Gaussian Mixture. More...
 
double evaluate (const HybridValues &values) const override
 Calculate probability density for given values.
 
double operator() (const HybridValues &values) const
 Evaluate probability density, sugar.
 
void prune (const DecisionTreeFactor &decisionTree)
 Prune the decision tree of Gaussian factors as per the discrete decisionTree. More...
 
GaussianFactorGraphTree add (const GaussianFactorGraphTree &sum) const
 Merge the Gaussian Factor Graphs in this and sum while maintaining the decision tree structure. More...
 
Testable
bool equals (const This &other, double tol=1e-9) const
 check equality
 
virtual void printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print only keys
 
Standard Interface
bool isDiscrete () const
 True if this is a factor of discrete variables only.
 
bool isContinuous () const
 True if this is a factor of continuous variables only.
 
bool isHybrid () const
 True is this is a Discrete-Continuous factor.
 
size_t nrContinuous () const
 Return the number of continuous variables in this factor.
 
const DiscreteKeysdiscreteKeys () const
 Return the discrete keys for this factor.
 
const KeyVectorcontinuousKeys () const
 Return only the continuous keys for this factor.
 
Standard Interface
bool empty () const
 Whether the factor is empty (involves zero variables).
 
Key front () const
 First key.
 
Key back () const
 Last key.
 
const_iterator find (Key key) const
 find
 
const KeyVectorkeys () const
 Access the factor's involved variable keys.
 
const_iterator begin () const
 
const_iterator end () const
 
size_t size () const
 
Advanced Interface
KeyVectorkeys ()
 
iterator begin ()
 
iterator end ()
 
Testable
bool equals (const This &c, double tol=1e-9) const
 
Standard Interface
size_t nrFrontals () const
 
size_t nrParents () const
 
Key firstFrontalKey () const
 
Frontals frontals () const
 
Parents parents () const
 
double normalizationConstant () const
 

Static Protected Member Functions

Standard Constructors
template<typename CONTAINER >
static Factor FromKeys (const CONTAINER &keys)
 
template<typename ITERATOR >
static Factor FromIterators (ITERATOR first, ITERATOR last)
 

Protected Attributes

DiscreteKeys discreteKeys_
 
KeyVector continuousKeys_
 Record continuous keys for book-keeping.
 
KeyVector keys_
 The keys involved in this factor.
 
size_t nrFrontals_
 

Advanced Interface

size_t & nrFrontals ()
 
HybridFactor ::const_iterator beginFrontals () const
 
HybridFactor ::iterator beginFrontals ()
 
HybridFactor ::const_iterator endFrontals () const
 
HybridFactor ::iterator endFrontals ()
 
HybridFactor ::const_iterator beginParents () const
 
HybridFactor ::iterator beginParents ()
 
HybridFactor ::const_iterator endParents () const
 
HybridFactor ::iterator endParents ()
 
static bool CheckInvariants (const GaussianMixture &conditional, const VALUES &x)
 

Detailed Description

A conditional of gaussian mixtures indexed by discrete variables, as part of a Bayes Network. This is the result of the elimination of a continuous variable in a hybrid scheme, such that the remaining variables are discrete+continuous.

Represents the conditional density P(X | M, Z) where X is the set of continuous random variables, M is the selection of discrete variables corresponding to a subset of the Gaussian variables and Z is parent of this node .

The probability P(x|y,z,...) is proportional to \( \sum_i k_i \exp - \frac{1}{2} |R_i x - (d_i - S_i y - T_i z - ...)|^2 \) where i indexes the components and k_i is a component-wise normalization constant.

a density over continuous variables given discrete/continuous parents.

Member Typedef Documentation

◆ ConstFactorRange

A mini implementation of an iterator range, to share const views of frontals and parents.

◆ Frontals

typedef ConstFactorRangeIterator gtsam::Conditional< HybridFactor , GaussianMixture >::Frontals
inherited

View of the frontal keys (call frontals())

◆ Parents

typedef ConstFactorRangeIterator gtsam::Conditional< HybridFactor , GaussianMixture >::Parents
inherited

View of the separator keys (call parents())

Constructor & Destructor Documentation

◆ GaussianMixture() [1/3]

gtsam::GaussianMixture::GaussianMixture ( const KeyVector continuousFrontals,
const KeyVector continuousParents,
const DiscreteKeys discreteParents,
const Conditionals conditionals 
)

Construct a new GaussianMixture object.

Parameters
continuousFrontalsthe continuous frontals.
continuousParentsthe continuous parents.
discreteParentsthe discrete parents. Will be placed last.
conditionalsa decision tree of GaussianConditionals. The number of conditionals should be C^(number of discrete parents), where C is the cardinality of the DiscreteKeys in discreteParents, since the discreteParents will be used as the labels in the decision tree.

◆ GaussianMixture() [2/3]

gtsam::GaussianMixture::GaussianMixture ( KeyVector &&  continuousFrontals,
KeyVector &&  continuousParents,
DiscreteKeys &&  discreteParents,
std::vector< GaussianConditional::shared_ptr > &&  conditionals 
)

Make a Gaussian Mixture from a list of Gaussian conditionals.

Parameters
continuousFrontalsThe continuous frontal variables
continuousParentsThe continuous parent variables
discreteParentsDiscrete parents variables
conditionalsList of conditionals

◆ GaussianMixture() [3/3]

gtsam::GaussianMixture::GaussianMixture ( const KeyVector continuousFrontals,
const KeyVector continuousParents,
const DiscreteKeys discreteParents,
const std::vector< GaussianConditional::shared_ptr > &  conditionals 
)

Make a Gaussian Mixture from a list of Gaussian conditionals.

Parameters
continuousFrontalsThe continuous frontal variables
continuousParentsThe continuous parent variables
discreteParentsDiscrete parents variables
conditionalsList of conditionals

Member Function Documentation

◆ add()

GaussianFactorGraphTree gtsam::GaussianMixture::add ( const GaussianFactorGraphTree sum) const

Merge the Gaussian Factor Graphs in this and sum while maintaining the decision tree structure.

Parameters
sumDecision Tree of Gaussian Factor Graphs
Returns
GaussianFactorGraphTree

◆ begin() [1/2]

const_iterator gtsam::Factor::begin ( ) const
inlineinherited

Iterator at beginning of involved variable keys

◆ begin() [2/2]

iterator gtsam::Factor::begin ( )
inlineinherited

Iterator at beginning of involved variable keys

◆ beginFrontals() [1/2]

HybridFactor ::const_iterator gtsam::Conditional< HybridFactor , GaussianMixture >::beginFrontals ( ) const
inlineinherited

Iterator pointing to first frontal key.

◆ beginFrontals() [2/2]

HybridFactor ::iterator gtsam::Conditional< HybridFactor , GaussianMixture >::beginFrontals ( )
inlineinherited

Mutable iterator pointing to first frontal key.

◆ beginParents() [1/2]

HybridFactor ::const_iterator gtsam::Conditional< HybridFactor , GaussianMixture >::beginParents ( ) const
inlineinherited

Iterator pointing to the first parent key.

◆ beginParents() [2/2]

HybridFactor ::iterator gtsam::Conditional< HybridFactor , GaussianMixture >::beginParents ( )
inlineinherited

Mutable iterator pointing to the first parent key.

◆ CheckInvariants()

bool gtsam::Conditional< HybridFactor , GaussianMixture >::CheckInvariants ( const GaussianMixture conditional,
const VALUES &  x 
)
staticinherited

Check invariants of this conditional, given the values x. It tests:

Parameters
conditionalThe conditional to test, as a reference to the derived type.
Template Parameters
VALUESHybridValues, or a more narrow type like DiscreteValues.

◆ end() [1/2]

const_iterator gtsam::Factor::end ( ) const
inlineinherited

Iterator at end of involved variable keys

◆ end() [2/2]

iterator gtsam::Factor::end ( )
inlineinherited

Iterator at end of involved variable keys

◆ endFrontals() [1/2]

HybridFactor ::const_iterator gtsam::Conditional< HybridFactor , GaussianMixture >::endFrontals ( ) const
inlineinherited

Iterator pointing past the last frontal key.

◆ endFrontals() [2/2]

HybridFactor ::iterator gtsam::Conditional< HybridFactor , GaussianMixture >::endFrontals ( )
inlineinherited

Mutable iterator pointing past the last frontal key.

◆ endParents() [1/2]

HybridFactor ::const_iterator gtsam::Conditional< HybridFactor , GaussianMixture >::endParents ( ) const
inlineinherited

Iterator pointing past the last parent key.

◆ endParents() [2/2]

HybridFactor ::iterator gtsam::Conditional< HybridFactor , GaussianMixture >::endParents ( )
inlineinherited

Mutable iterator pointing past the last parent key.

◆ equals()

bool gtsam::Conditional< HybridFactor , GaussianMixture >::equals ( const This c,
double  tol = 1e-9 
) const
inherited

check equality

◆ error() [1/2]

double gtsam::GaussianMixture::error ( const HybridValues values) const
overridevirtual

Compute the error of this Gaussian Mixture.

This requires some care, as different mixture components may have different normalization constants. Let's consider p(x|y,m), where m is discrete. We need the error to satisfy the invariant:

error(x;y,m) = K - log(probability(x;y,m))

For all x,y,m. But note that K, the (log) normalization constant defined in Conditional.h, should not depend on x, y, or m, only on the parameters of the density. Hence, we delegate to the underlying Gaussian conditionals, indexed by m, which do satisfy:

log(probability_m(x;y)) = K_m - error_m(x;y)

We resolve by having K == max(K_m) and

error(x;y,m) = error_m(x;y) + K - K_m

which also makes error(x;y,m) >= 0 for all x,y,m.

Parameters
valuesContinuous values and discrete assignment.
Returns
double

Reimplemented from gtsam::Factor.

◆ error() [2/2]

AlgebraicDecisionTree<Key> gtsam::GaussianMixture::error ( const VectorValues continuousValues) const

Compute error of the GaussianMixture as a tree.

Parameters
continuousValuesThe continuous VectorValues.
Returns
AlgebraicDecisionTree<Key> A decision tree on the discrete keys only, with the leaf values as the error for each assignment.

◆ firstFrontalKey()

Key gtsam::Conditional< HybridFactor , GaussianMixture >::firstFrontalKey ( ) const
inlineinherited

Convenience function to get the first frontal key

◆ FromIterators()

template<typename ITERATOR >
static Factor gtsam::Factor::FromIterators ( ITERATOR  first,
ITERATOR  last 
)
inlinestaticprotectedinherited

Construct factor from iterator keys. This is called internally from derived factor static factor methods, as a workaround for not being able to call the protected constructors above.

◆ FromKeys()

template<typename CONTAINER >
static Factor gtsam::Factor::FromKeys ( const CONTAINER &  keys)
inlinestaticprotectedinherited

Construct factor from container of keys. This is called internally from derived factor static factor methods, as a workaround for not being able to call the protected constructors above.

◆ frontals()

Frontals gtsam::Conditional< HybridFactor , GaussianMixture >::frontals ( ) const
inlineinherited

return a view of the frontal keys

◆ keys()

KeyVector& gtsam::Factor::keys ( )
inlineinherited
Returns
keys involved in this factor

◆ likelihood()

std::shared_ptr<GaussianMixtureFactor> gtsam::GaussianMixture::likelihood ( const VectorValues given) const

Create a likelihood factor for a Gaussian mixture, return a Mixture factor on the parents.

◆ logNormalizationConstant()

double gtsam::GaussianMixture::logNormalizationConstant ( ) const
inlineoverridevirtual

The log normalization constant is max of the the individual log-normalization constants.

Reimplemented from gtsam::Conditional< HybridFactor, GaussianMixture >.

◆ logProbability() [1/2]

AlgebraicDecisionTree<Key> gtsam::GaussianMixture::logProbability ( const VectorValues continuousValues) const

Compute logProbability of the GaussianMixture as a tree.

Parameters
continuousValuesThe continuous VectorValues.
Returns
AlgebraicDecisionTree<Key> A decision tree with the same keys as the conditionals, and leaf values as the logProbability.

◆ logProbability() [2/2]

double gtsam::GaussianMixture::logProbability ( const HybridValues values) const
overridevirtual

Compute the logProbability of this Gaussian Mixture.

Parameters
valuesContinuous values and discrete assignment.
Returns
double

Reimplemented from gtsam::Conditional< HybridFactor, GaussianMixture >.

◆ normalizationConstant()

double gtsam::Conditional< HybridFactor , GaussianMixture >::normalizationConstant ( ) const
inherited

Non-virtual, exponentiate logNormalizationConstant.

◆ nrFrontals() [1/2]

size_t gtsam::Conditional< HybridFactor , GaussianMixture >::nrFrontals ( ) const
inlineinherited

return the number of frontals

◆ nrFrontals() [2/2]

size_t& gtsam::Conditional< HybridFactor , GaussianMixture >::nrFrontals ( )
inlineinherited

Mutable version of nrFrontals

◆ nrParents()

size_t gtsam::Conditional< HybridFactor , GaussianMixture >::nrParents ( ) const
inlineinherited

return the number of parents

◆ parents()

Parents gtsam::Conditional< HybridFactor , GaussianMixture >::parents ( ) const
inlineinherited

return a view of the parent keys

◆ prune()

void gtsam::GaussianMixture::prune ( const DecisionTreeFactor decisionTree)

Prune the decision tree of Gaussian factors as per the discrete decisionTree.

Parameters
decisionTreeA pruned decision tree of discrete keys where the leaves are probabilities.

◆ size()

size_t gtsam::Factor::size ( ) const
inlineinherited
Returns
the number of variables involved in this factor

Member Data Documentation

◆ nrFrontals_

size_t gtsam::Conditional< HybridFactor , GaussianMixture >::nrFrontals_
protectedinherited

The first nrFrontal variables are frontal and the rest are parents.


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