Public Types | Public Member Functions | Private 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]

Public Types

using Base = HybridFactor
 
using Factors = DecisionTree< Key, sharedFactor >
 typedef for DecisionTree which has Keys as node labels and NonlinearFactor as leaf nodes. More...
 
using shared_ptr = std::shared_ptr< MixtureFactor >
 
using sharedFactor = std::shared_ptr< NonlinearFactor >
 
using This = MixtureFactor
 
- Public Types inherited from gtsam::HybridFactor
typedef Factor Base
 Our base class. More...
 
typedef std::shared_ptr< HybridFactorshared_ptr
 shared_ptr to this class More...
 
typedef HybridFactor This
 This class. More...
 
- Public Types inherited from gtsam::Factor
typedef KeyVector::const_iterator const_iterator
 Const iterator over keys. More...
 
typedef KeyVector::iterator iterator
 Iterator over keys. More...
 

Public Member Functions

size_t dim () const
 Get the dimension of the factor (number of rows on linearization). Returns the dimension of the first component factor. 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...
 
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. More...
 
 MixtureFactor ()=default
 
 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...
 
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. More...
 
- Public Member Functions inherited from gtsam::HybridFactor
 HybridFactor ()=default
 
 HybridFactor (const KeyVector &keys)
 Construct hybrid factor from continuous keys. More...
 
 HybridFactor (const DiscreteKeys &discreteKeys)
 Construct hybrid factor from discrete keys. More...
 
 HybridFactor (const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys)
 Construct a new Hybrid Factor object. More...
 
bool isDiscrete () const
 True if this is a factor of discrete variables only. More...
 
bool isContinuous () const
 True if this is a factor of continuous variables only. More...
 
bool isHybrid () const
 True is this is a Discrete-Continuous factor. More...
 
size_t nrContinuous () const
 Return the number of continuous variables in this factor. More...
 
const DiscreteKeysdiscreteKeys () const
 Return the discrete keys for this factor. More...
 
const KeyVectorcontinuousKeys () const
 Return only the continuous keys for this factor. More...
 
- Public Member Functions inherited from gtsam::Factor
virtual ~Factor ()=default
 Default destructor. More...
 
bool empty () const
 Whether the factor is empty (involves zero variables). More...
 
Key front () const
 First key. More...
 
Key back () const
 Last key. More...
 
const_iterator find (Key key) const
 find More...
 
const KeyVectorkeys () const
 Access the factor's involved variable keys. More...
 
const_iterator begin () const
 
const_iterator end () const
 
size_t size () const
 
virtual void printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print only keys More...
 
bool equals (const This &other, double tol=1e-9) const
 check equality More...
 
KeyVectorkeys ()
 
iterator begin ()
 
iterator end ()
 

Private Attributes

Factors factors_
 Decision tree of Gaussian factors indexed by discrete keys. More...
 
bool normalized_
 

Additional Inherited Members

- Protected Member Functions inherited from gtsam::Factor
 Factor ()
 
template<typename CONTAINER >
 Factor (const CONTAINER &keys)
 
template<typename ITERATOR >
 Factor (ITERATOR first, ITERATOR last)
 
- Static Protected Member Functions inherited from gtsam::Factor
template<typename CONTAINER >
static Factor FromKeys (const CONTAINER &keys)
 
template<typename ITERATOR >
static Factor FromIterators (ITERATOR first, ITERATOR last)
 
- Protected Attributes inherited from gtsam::HybridFactor
KeyVector continuousKeys_
 Record continuous keys for book-keeping. More...
 
DiscreteKeys discreteKeys_
 
- Protected Attributes inherited from gtsam::Factor
KeyVector keys_
 The keys involved in this factor. More...
 

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.

Definition at line 47 of file MixtureFactor.h.

Member Typedef Documentation

◆ Base

Definition at line 49 of file MixtureFactor.h.

◆ Factors

typedef for DecisionTree which has Keys as node labels and NonlinearFactor as leaf nodes.

Definition at line 58 of file MixtureFactor.h.

◆ shared_ptr

Definition at line 51 of file MixtureFactor.h.

◆ sharedFactor

Definition at line 52 of file MixtureFactor.h.

◆ This

Definition at line 50 of file MixtureFactor.h.

Constructor & Destructor Documentation

◆ MixtureFactor() [1/3]

gtsam::MixtureFactor::MixtureFactor ( )
default

◆ MixtureFactor() [2/3]

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.

Definition at line 77 of file MixtureFactor.h.

◆ MixtureFactor() [3/3]

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.

Definition at line 98 of file MixtureFactor.h.

Member Function Documentation

◆ 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

Definition at line 176 of file MixtureFactor.h.

◆ equals()

bool gtsam::MixtureFactor::equals ( const HybridFactor other,
double  tol = 1e-9 
) const
inlineoverridevirtual

Check equality.

Reimplemented from gtsam::HybridFactor.

Definition at line 203 of file MixtureFactor.h.

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

Definition at line 134 of file MixtureFactor.h.

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

Definition at line 150 of file MixtureFactor.h.

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

Definition at line 167 of file MixtureFactor.h.

◆ linearize() [1/2]

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

Linearize specific nonlinear factors based on the assignment in discreteValues.

Definition at line 229 of file MixtureFactor.h.

◆ linearize() [2/2]

std::shared_ptr<GaussianMixtureFactor> gtsam::MixtureFactor::linearize ( const Values continuousValues) const
inline

Linearize all the continuous factors to get a GaussianMixtureFactor.

Definition at line 237 of file MixtureFactor.h.

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

Definition at line 258 of file MixtureFactor.h.

◆ print()

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

print to stdout

Testable

Reimplemented from gtsam::HybridFactor.

Definition at line 186 of file MixtureFactor.h.

Member Data Documentation

◆ factors_

Factors gtsam::MixtureFactor::factors_
private

Decision tree of Gaussian factors indexed by discrete keys.

Definition at line 62 of file MixtureFactor.h.

◆ normalized_

bool gtsam::MixtureFactor::normalized_
private

Definition at line 63 of file MixtureFactor.h.


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


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:46:23