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

Implementation of a discrete conditional mixture factor. More...

#include <MixtureFactor.h>

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

Public Types

using Base = HybridFactor
 
using This = MixtureFactor
 
using shared_ptr = std::shared_ptr< MixtureFactor >
 
using sharedFactor = std::shared_ptr< NonlinearFactor >
 
using Factors = DecisionTree< Key, sharedFactor >
 typedef for DecisionTree which has Keys as node labels and NonlinearFactor as leaf nodes.
 
typedef KeyVector::iterator iterator
 Iterator over keys.
 
typedef KeyVector::const_iterator const_iterator
 Const iterator over keys.
 

Public Member Functions

 MixtureFactor (const KeyVector &keys, const DiscreteKeys &discreteKeys, const Factors &factors, bool normalized=false)
 Construct from Decision tree. More...
 
template<typename FACTOR >
 MixtureFactor (const KeyVector &keys, const DiscreteKeys &discreteKeys, const std::vector< std::shared_ptr< FACTOR >> &factors, bool normalized=false)
 Convenience constructor that generates the underlying factor decision tree for us. More...
 
AlgebraicDecisionTree< Keyerror (const Values &continuousValues) const
 Compute error of the MixtureFactor as a tree. More...
 
double error (const Values &continuousValues, const DiscreteValues &discreteValues) const
 Compute error of factor given both continuous and discrete values. More...
 
double error (const HybridValues &values) const override
 Compute error of factor given hybrid values. More...
 
size_t dim () const
 Get the dimension of the factor (number of rows on linearization). Returns the dimension of the first component factor. More...
 
GaussianFactor::shared_ptr linearize (const Values &continuousValues, const DiscreteValues &discreteValues) const
 
std::shared_ptr< GaussianMixtureFactorlinearize (const Values &continuousValues) const
 Linearize all the continuous factors to get a GaussianMixtureFactor.
 
double nonlinearFactorLogNormalizingConstant (const sharedFactor &factor, const Values &values) const
 
void print (const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
 print to stdout More...
 
bool equals (const HybridFactor &other, double tol=1e-9) const override
 Check equality.
 
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 ()
 

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.
 

Detailed Description

Implementation of a discrete conditional mixture factor.

Implements a joint discrete-continuous factor where the discrete variable serves to "select" a mixture component corresponding to a NonlinearFactor type of measurement.

This class stores all factors as HybridFactors which can then be typecast to one of (NonlinearFactor, GaussianFactor) which can then be checked to perform the correct operation.

Constructor & Destructor Documentation

◆ MixtureFactor() [1/2]

gtsam::MixtureFactor::MixtureFactor ( const KeyVector keys,
const DiscreteKeys discreteKeys,
const Factors factors,
bool  normalized = false 
)
inline

Construct from Decision tree.

Parameters
keysVector of keys for continuous factors.
discreteKeysVector of discrete keys.
factorsDecision tree with of shared factors.
normalizedFlag indicating if the factor error is already normalized.

◆ MixtureFactor() [2/2]

template<typename FACTOR >
gtsam::MixtureFactor::MixtureFactor ( const KeyVector keys,
const DiscreteKeys discreteKeys,
const std::vector< std::shared_ptr< FACTOR >> &  factors,
bool  normalized = false 
)
inline

Convenience constructor that generates the underlying factor decision tree for us.

Here it is important that the vector of factors has the correct number of elements based on the number of discrete keys and the cardinality of the keys, so that the decision tree is constructed appropriately.

Template Parameters
FACTORThe type of the factor shared pointers being passed in. Will be typecast to NonlinearFactor shared pointers.
Parameters
keysVector of keys for continuous factors.
discreteKeysVector of discrete keys.
factorsVector of nonlinear factors.
normalizedFlag indicating if the factor error is already normalized.

Member Function Documentation

◆ 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

◆ dim()

size_t gtsam::MixtureFactor::dim ( ) const
inline

Get the dimension of the factor (number of rows on linearization). Returns the dimension of the first component factor.

Returns
size_t

◆ 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

◆ error() [1/3]

AlgebraicDecisionTree<Key> gtsam::MixtureFactor::error ( const Values continuousValues) const
inline

Compute error of the MixtureFactor as a tree.

Parameters
continuousValuesThe continuous values for which to compute the error.
Returns
AlgebraicDecisionTree<Key> A decision tree with the same keys as the factor, and leaf values as the error.

◆ error() [2/3]

double gtsam::MixtureFactor::error ( const Values continuousValues,
const DiscreteValues discreteValues 
) const
inline

Compute error of factor given both continuous and discrete values.

Parameters
continuousValuesThe continuous Values.
discreteValuesThe discrete Values.
Returns
double The error of this factor.

◆ error() [3/3]

double gtsam::MixtureFactor::error ( const HybridValues values) const
inlineoverridevirtual

Compute error of factor given hybrid values.

Parameters
valuesThe continuous Values and the discrete assignment.
Returns
double The error of this factor.

Reimplemented from gtsam::Factor.

◆ 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.

◆ keys()

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

◆ linearize()

GaussianFactor::shared_ptr gtsam::MixtureFactor::linearize ( const Values continuousValues,
const DiscreteValues discreteValues 
) const
inline

Linearize specific nonlinear factors based on the assignment in discreteValues.

◆ nonlinearFactorLogNormalizingConstant()

double gtsam::MixtureFactor::nonlinearFactorLogNormalizingConstant ( const sharedFactor &  factor,
const Values values 
) const
inline

If the component factors are not already normalized, we want to compute their normalizing constants so that the resulting joint distribution is appropriately computed. Remember, this is the negative normalizing constant for the measurement likelihood (since we are minimizing the negative log-likelihood).

◆ print()

void gtsam::MixtureFactor::print ( const std::string &  s = "",
const KeyFormatter keyFormatter = DefaultKeyFormatter 
) const
inlineoverridevirtual

print to stdout

Testable

Reimplemented from gtsam::HybridFactor.

◆ size()

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

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