gtsam
Loading...
Searching...
No Matches
gtsam::HybridGaussianFactor Class Reference

Detailed Description

Implementation of a discrete-conditioned hybrid factor.

Implements a joint discrete-continuous factor where the discrete variable serves to "select" a component corresponding to a GaussianFactor.

Represents the underlying hybrid Gaussian components as a Decision Tree, where the set of discrete variables indexes to the continuous gaussian distribution.

In factor graphs the error function typically returns 0.5*|A*x - b|^2, i.e., the negative log-likelihood for a Gaussian noise model. In hybrid factor graphs we allow adding an arbitrary scalar dependent on the discrete assignment. For example, adding a 70/30 mode probability is supported by providing the scalars $-log(.7)$ and $-log(.3)$. Note that adding a common constant will not make any difference in the optimization, so $-log(70)$ and $-log(30)$ work just as well.

Inheritance diagram for gtsam::HybridGaussianFactor:

Public Member Functions

Constructors
 HybridGaussianFactor ()=default
 Default constructor, mainly for serialization.
 HybridGaussianFactor (const DiscreteKey &discreteKey, const std::vector< GaussianFactor::shared_ptr > &factors)
 Construct a new HybridGaussianFactor on a single discrete key, providing the factors for each mode m as a vector of factors ϕ_m(x).
 HybridGaussianFactor (const DiscreteKey &discreteKey, const std::vector< GaussianFactorValuePair > &factorPairs)
 Construct a new HybridGaussianFactor on a single discrete key, including a scalar error value for each mode m.
 HybridGaussianFactor (const DiscreteKeys &discreteKeys, const FactorValuePairs &factorPairs)
 Construct a new HybridGaussianFactor on a several discrete keys M, including a scalar error value for each assignment m.
Testable
bool equals (const HybridFactor &lf, double tol=1e-9) const override
 equals
void print (const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
 print
Standard API
GaussianFactorValuePair operator() (const DiscreteValues &assignment) const
 Get factor at a given discrete assignment.
AlgebraicDecisionTree< Key > errorTree (const VectorValues &continuousValues) const override
 Compute error of the HybridGaussianFactor as a tree.
double error (const HybridValues &hybridValues) const override
 Compute the log-likelihood, including the log-normalizing constant.
const FactorValuePairs & factors () const
 Getter for GaussianFactor decision tree.
virtual HybridGaussianProductFactor asProductFactor () const
 Helper function to return factors and functional to create a DecisionTree of Gaussian Factor Graphs.
std::shared_ptr< Factor > restrict (const DiscreteValues &discreteValues) const override
 Restrict the factor to the given discrete values.
Public Member Functions inherited from gtsam::HybridFactor
 HybridFactor ()=default
 Default constructor creates empty factor.
 HybridFactor (const KeyVector &keys)
 Construct hybrid factor from continuous keys.
 HybridFactor (const DiscreteKeys &discreteKeys)
 Construct hybrid factor from discrete keys.
 HybridFactor (const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys)
 Construct a new Hybrid Factor object.
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 DiscreteKeys & discreteKeys () const
 Return the discrete keys for this factor.
const KeyVector & continuousKeys () 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 KeyVector & keys () 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
bool equals (const This &other, double tol=1e-9) const
 check equality
KeyVector & keys ()
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 = HybridGaussianFactor
using shared_ptr = std::shared_ptr<This>
using sharedFactor = std::shared_ptr<GaussianFactor>
using FactorValuePairs = DecisionTree<Key, GaussianFactorValuePair>
 typedef for Decision Tree of Gaussian factors and arbitrary value.
Public Types inherited from gtsam::HybridFactor
enum class  Category { None , Discrete , Continuous , Hybrid }
 Enum to help with categorizing hybrid factors.
typedef HybridFactor This
 This class.
typedef std::shared_ptr< HybridFactor > shared_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

 Factor ()
 Default constructor for I/O.
template<typename CONTAINER>
 Factor (const CONTAINER &keys)
 Construct factor from container of keys.
template<typename ITERATOR>
 Factor (ITERATOR first, ITERATOR last)
 Construct factor from iterator keys.
template<typename CONTAINER>
static Factor FromKeys (const CONTAINER &keys)
 Construct factor from container of keys.
template<typename ITERATOR>
static Factor FromIterators (ITERATOR first, ITERATOR last)
 Construct factor from iterator keys.
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

◆ HybridGaussianFactor() [1/3]

gtsam::HybridGaussianFactor::HybridGaussianFactor ( const DiscreteKey & discreteKey,
const std::vector< GaussianFactor::shared_ptr > & factors )

Construct a new HybridGaussianFactor on a single discrete key, providing the factors for each mode m as a vector of factors ϕ_m(x).

The value ϕ(x,m) for the factor is simply ϕ_m(x).

Parameters
discreteKeyThe discrete key for the "mode", indexing components.
factorsVector of gaussian factors, one for each mode.

◆ HybridGaussianFactor() [2/3]

gtsam::HybridGaussianFactor::HybridGaussianFactor ( const DiscreteKey & discreteKey,
const std::vector< GaussianFactorValuePair > & factorPairs )

Construct a new HybridGaussianFactor on a single discrete key, including a scalar error value for each mode m.

The factors and scalars are provided as a vector of pairs (ϕ_m(x), E_m). The value ϕ(x,m) for the factor is now ϕ_m(x) + E_m.

Parameters
discreteKeyThe discrete key for the "mode", indexing components.
factorPairsVector of gaussian factor-scalar pairs, one per mode.

◆ HybridGaussianFactor() [3/3]

gtsam::HybridGaussianFactor::HybridGaussianFactor ( const DiscreteKeys & discreteKeys,
const FactorValuePairs & factorPairs )

Construct a new HybridGaussianFactor on a several discrete keys M, including a scalar error value for each assignment m.

The factors and scalars are provided as a DecisionTree<Key> of pairs (ϕ_M(x), E_M). The value ϕ(x,M) for the factor is again ϕ_m(x) + E_m.

Parameters
discreteKeysDiscrete variables and their cardinalities.
factorPairsThe decision tree of Gaussian factor/scalar pairs.

Member Function Documentation

◆ asProductFactor()

HybridGaussianProductFactor gtsam::HybridGaussianFactor::asProductFactor ( ) const
virtual

Helper function to return factors and functional to create a DecisionTree of Gaussian Factor Graphs.

Returns
HybridGaussianProductFactor

◆ equals()

bool gtsam::HybridGaussianFactor::equals ( const HybridFactor & lf,
double tol = 1e-9 ) const
overridevirtual

equals

Reimplemented from gtsam::HybridFactor.

◆ error()

double gtsam::HybridGaussianFactor::error ( const HybridValues & hybridValues) const
overridevirtual

Compute the log-likelihood, including the log-normalizing constant.

Returns
double

Reimplemented from gtsam::Factor.

◆ errorTree()

AlgebraicDecisionTree< Key > gtsam::HybridGaussianFactor::errorTree ( const VectorValues & continuousValues) const
overridevirtual

Compute error of the HybridGaussianFactor as a tree.

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

Implements gtsam::HybridFactor.

◆ print()

void gtsam::HybridGaussianFactor::print ( const std::string & s = "",
const KeyFormatter & formatter = DefaultKeyFormatter ) const
overridevirtual

print

Reimplemented from gtsam::HybridFactor.

◆ restrict()

std::shared_ptr< Factor > gtsam::HybridGaussianFactor::restrict ( const DiscreteValues & discreteValues) const
overridevirtual

Restrict the factor to the given discrete values.

Implements gtsam::HybridFactor.


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