Loading...
Searching...
No Matches
gtsam::HybridConditional Class Reference
Hybrid

## Detailed Description

Hybrid Conditional Density.

As a type-erased variant of:

- DiscreteConditional
- GaussianConditional
- GaussianMixture

The reason why this is important is that Conditional<T> is a CRTP class. CRTP is static polymorphism such that all CRTP classes, while bearing the same name, are different classes not sharing a vtable. This prevents them from being contained in any container, and thus it is impossible to dynamically cast between them. A better option, as illustrated here, is treating them as an implementation detail - such that the hybrid mechanism does not know what is inside the HybridConditional. This prevents us from having diamond inheritances, and neutralized the need to change other components of GTSAM to make hybrid elimination work.

A great reference to the type-erasure pattern is Eduardo Madrid's CppCon talk (https://www.youtube.com/watch?v=s082Qmd_nHs).

Inheritance diagram for gtsam::HybridConditional:

## Public Member Functions

Standard Constructors
| HybridConditional ()=default
| Default constructor needed for serialization.
| HybridConditional (const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys, size_t nFrontals)
| Construct a new Hybrid Conditional object.
| HybridConditional (const KeyVector &continuousFrontals, const DiscreteKeys &discreteFrontals, const KeyVector &continuousParents, const DiscreteKeys &discreteParents)
| Construct a new Hybrid Conditional object.
| HybridConditional (const boost::shared_ptr< GaussianConditional > &continuousConditional)
| Construct a new Hybrid Conditional object.
| HybridConditional (const boost::shared_ptr< DiscreteConditional > &discreteConditional)
| Construct a new Hybrid Conditional object.
| HybridConditional (const boost::shared_ptr< GaussianMixture > &gaussianMixture)
| Construct a new Hybrid Conditional object.
Testable
void | print (const std::string &s="Hybrid Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
| GTSAM-style print.
bool | equals (const HybridFactor &other, double tol=1e-9) const override
| GTSAM-style equals.
Standard Interface
GaussianMixture::shared_ptr | asMixture () const
| Return HybridConditional as a GaussianMixture.
GaussianConditional::shared_ptr | asGaussian () const
| Return HybridConditional as a GaussianConditional.
DiscreteConditional::shared_ptr | asDiscrete () const
| Return conditional as a DiscreteConditional.
boost::shared_ptr< Factor > | inner () const
| Get the type-erased pointer to the inner type.
double | error (const HybridValues &values) const override
| Return the error of the underlying conditional.
double | logProbability (const HybridValues &values) const override
| Return the log-probability (or density) of the underlying conditional.
double | logNormalizationConstant () const override
| Return the log normalization constant.
double | evaluate (const HybridValues &values) const override
| Return the probability (or density) of the underlying conditional.
bool | frontalsIn (const VectorValues &measurements) const
| Check if VectorValues measurements contains all frontal keys.
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.
virtual | ~HybridFactor ()=default
| Virtual destructor.
void | print (const std::string &s="HybridFactor\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override
| print
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 Member Functions inherited from gtsam::Conditional< HybridFactor, HybridConditional >
void | print (const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
| print with optional formatter
bool | equals (const This &c, double tol=1e-9) const
| check equality
size_t | nrFrontals () const
| return the number of frontals
size_t | nrParents () const
| return the number of parents
Key | firstFrontalKey () const
| Convenience function to get the first frontal key.
Frontals | frontals () const
| return a view of the frontal keys
Parents | parents () const
| return a view of the parent keys
double | operator() (const HybridValues &x) const
| Evaluate probability density, sugar.
double | normalizationConstant () const
| Non-virtual, exponentiate logNormalizationConstant.
HybridFactor::const_iterator | beginFrontals () const
| Iterator pointing to first frontal key.
HybridFactor::const_iterator | endFrontals () const
| Iterator pointing past the last frontal key.
HybridFactor::const_iterator | beginParents () const
| Iterator pointing to the first parent key.
HybridFactor::const_iterator | endParents () const
| Iterator pointing past the last parent key.

## Public Types

typedef HybridConditional | This
| Typedef to this class.
typedef boost::shared_ptr< This > | shared_ptr
| shared_ptr to this class
typedef HybridFactor | BaseFactor
| Typedef to our factor base class.
typedef Conditional< BaseFactor, This > | BaseConditional
| Typedef to our conditional base class.
Public Types inherited from gtsam::HybridFactor
typedef HybridFactor | This
| This class.
typedef boost::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.
Public Types inherited from gtsam::Conditional< HybridFactor, HybridConditional >
typedef boost::iterator_range< typename HybridFactor::const_iterator > | Frontals
| View of the frontal keys (call frontals()).
typedef boost::iterator_range< typename HybridFactor::const_iterator > | Parents
| View of the separator keys (call parents()).

## Protected Attributes

boost::shared_ptr< Factor > | inner_
| Type-erased pointer to the inner type.
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.
Protected Attributes inherited from gtsam::Conditional< HybridFactor, HybridConditional >
size_t | nrFrontals_
| The first nrFrontal variables are frontal and the rest are parents.

## Friends

class | boost::serialization::access
| Serialization function.

## Additional Inherited Members

static bool | CheckInvariants (const HybridConditional &conditional, const VALUES &x)
| Check invariants of this conditional, given the values x.
| 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.
Protected Member Functions inherited from gtsam::Conditional< HybridFactor, HybridConditional >
| Conditional ()
| Empty Constructor to make serialization possible.
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.

## Constructor & Destructor Documentation

## HybridConditional() [1/5]

gtsam::HybridConditional::HybridConditional | ( | const KeyVector & | continuousKeys,
|  | const DiscreteKeys & | discreteKeys,
|  | size_t | nFrontals )

inline

Construct a new Hybrid Conditional object.

Parameters

  continuousKeys | Vector of keys for continuous variables.
  discreteKeys | Keys and cardinalities for discrete variables.
  nFrontals | The number of frontal variables in the conditional.

## HybridConditional() [2/5]

gtsam::HybridConditional::HybridConditional | ( | const KeyVector & | continuousFrontals,
|  | const DiscreteKeys & | discreteFrontals,
|  | const KeyVector & | continuousParents,
|  | const DiscreteKeys & | discreteParents )

Construct a new Hybrid Conditional object.

Parameters

  continuousFrontals | Vector of keys for continuous variables.
  discreteFrontals | Keys and cardinalities for discrete variables.
  continuousParents | Vector of keys for parent continuous variables.
  discreteParents | Keys and cardinalities for parent discrete variables.

## HybridConditional() [3/5]

gtsam::HybridConditional::HybridConditional | ( | const boost::shared_ptr< GaussianConditional > & | continuousConditional | ) |

Construct a new Hybrid Conditional object.

Parameters

  continuousConditional | Conditional used to create the HybridConditional.

## HybridConditional() [4/5]

gtsam::HybridConditional::HybridConditional | ( | const boost::shared_ptr< DiscreteConditional > & | discreteConditional | ) |

Construct a new Hybrid Conditional object.

Parameters

  discreteConditional | Conditional used to create the HybridConditional.

## HybridConditional() [5/5]

gtsam::HybridConditional::HybridConditional | ( | const boost::shared_ptr< GaussianMixture > & | gaussianMixture | ) |

Construct a new Hybrid Conditional object.

Parameters

  gaussianMixture | Gaussian Mixture Conditional used to create the HybridConditional.

## Member Function Documentation

## asDiscrete()

DiscreteConditional::shared_ptr gtsam::HybridConditional::asDiscrete | ( |  | ) | const

inline

Return conditional as a DiscreteConditional.

Returns
  nullptr if not a DiscreteConditional
  DiscreteConditional::shared_ptr

## asGaussian()

GaussianConditional::shared_ptr gtsam::HybridConditional::asGaussian | ( |  | ) | const

inline

Return HybridConditional as a GaussianConditional.

Returns
  nullptr if not a GaussianConditional
  GaussianConditional::shared_ptr otherwise

## asMixture()

GaussianMixture::shared_ptr gtsam::HybridConditional::asMixture | ( |  | ) | const

inline

Return HybridConditional as a GaussianMixture.

Returns
  nullptr if not a mixture
  GaussianMixture::shared_ptr otherwise

## equals()

bool gtsam::HybridConditional::equals | ( | const HybridFactor & | other,
|  | double | tol = 1e-9 ) const

override virtual

GTSAM-style equals.

Reimplemented from gtsam::HybridFactor.

## error()

double gtsam::HybridConditional::error | ( | const HybridValues & | values | ) | const

override virtual

Return the error of the underlying conditional.

Reimplemented from gtsam::Factor.

## evaluate()

double gtsam::HybridConditional::evaluate | ( | const HybridValues & | values | ) | const

override virtual

Return the probability (or density) of the underlying conditional.

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

## logNormalizationConstant()

double gtsam::HybridConditional::logNormalizationConstant | ( |  | ) | const

override virtual

Return the log normalization constant.

Note this is 0.0 for discrete and hybrid conditionals, but depends on the continuous parameters for Gaussian conditionals.

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

## logProbability()

double gtsam::HybridConditional::logProbability | ( | const HybridValues & | values | ) | const

override virtual

Return the log-probability (or density) of the underlying conditional.

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

## print()

void gtsam::HybridConditional::print | ( | const std::string & | s = "Hybrid Conditional: ",
|  | const KeyFormatter & | formatter = DefaultKeyFormatter ) const

override virtual

GTSAM-style print.

Reimplemented from gtsam::Factor.

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

- /build/gtsam-Xg031d/gtsam-4.2.0+dfsg/gtsam/hybrid/HybridConditional.h
- /build/gtsam-Xg031d/gtsam-4.2.0+dfsg/gtsam/hybrid/HybridConditional.cpp