gtsam 4.2.0
gtsam
gtsam::MixtureFactor Class Reference

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.

+ Inheritance diagram for gtsam::MixtureFactor:

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< boost::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). More...
 
GaussianFactor::shared_ptr linearize (const Values &continuousValues, const DiscreteValues &discreteValues) const
 Linearize specific nonlinear factors based on the assignment in discreteValues.
 
boost::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
 If the component factors are not already normalized, we want to compute their normalizing constants so that the resulting joint distribution is appropriately computed. More...
 
void print (const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
 Testable. More...
 
bool equals (const HybridFactor &other, double tol=1e-9) const override
 Check equality. More...
 
- Public Member Functions inherited from gtsam::HybridFactor
 HybridFactor ()=default
 Default constructor creates empty factor.
 
 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...
 
virtual ~HybridFactor ()=default
 Virtual destructor.
 
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.
 
- Public Member Functions inherited from gtsam::Factor
virtual ~Factor ()=default
 Default destructor.
 
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
 Iterator at beginning of involved variable keys.
 
const_iterator end () const
 Iterator at end of involved variable keys.
 
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
 
KeyVectorkeys ()
 
iterator begin ()
 Iterator at beginning of involved variable keys.
 
iterator end ()
 Iterator at end of involved variable keys.
 

Public Types

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

Additional Inherited Members

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

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< boost::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

◆ 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

◆ equals()

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

Check equality.

Reimplemented from gtsam::HybridFactor.

◆ error() [1/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.

◆ error() [2/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() [3/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.

◆ 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

Testable.

print to stdout

Reimplemented from gtsam::HybridFactor.


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