Public Types | Protected Attributes | List of all members
gtsam::HybridConditional Class Reference

#include <HybridConditional.h>

Inheritance diagram for gtsam::HybridConditional:
Inheritance graph
[legend]

Public Types

typedef Conditional< BaseFactor, ThisBaseConditional
 Typedef to our conditional base class. More...
 
typedef HybridFactor BaseFactor
 Typedef to our factor base class. More...
 
typedef std::shared_ptr< Thisshared_ptr
 shared_ptr to this class More...
 
typedef HybridConditional This
 Typedef to this class. More...
 
- Public Types inherited from gtsam::HybridFactor
typedef Factor Base
 Our base class. More...
 
enum  Category { Category::None, Category::Discrete, Category::Continuous, Category::Hybrid }
 Enum to help with categorizing hybrid factors. 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 Types inherited from gtsam::Conditional< HybridFactor, HybridConditional >
typedef std::pair< typename HybridFactor ::const_iterator, typename HybridFactor ::const_iterator > ConstFactorRange
 
typedef ConstFactorRangeIterator Frontals
 
typedef ConstFactorRangeIterator Parents
 

Public Member Functions

Standard Constructors
 HybridConditional ()=default
 Default constructor needed for serialization. More...
 
 HybridConditional (const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys, size_t nFrontals)
 Construct a new Hybrid Conditional object. More...
 
 HybridConditional (const KeyVector &continuousFrontals, const DiscreteKeys &discreteFrontals, const KeyVector &continuousParents, const DiscreteKeys &discreteParents)
 Construct a new Hybrid Conditional object. More...
 
 HybridConditional (const std::shared_ptr< GaussianConditional > &continuousConditional)
 Construct a new Hybrid Conditional object. More...
 
 HybridConditional (const std::shared_ptr< DiscreteConditional > &discreteConditional)
 Construct a new Hybrid Conditional object. More...
 
 HybridConditional (const std::shared_ptr< HybridGaussianConditional > &hybridGaussianCond)
 Construct a new Hybrid Conditional object. More...
 
Testable
void print (const std::string &s="Hybrid Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
 GTSAM-style print. More...
 
bool equals (const HybridFactor &other, double tol=1e-9) const override
 GTSAM-style equals. More...
 
Standard Interface
HybridGaussianConditional::shared_ptr asHybrid () const
 Return HybridConditional as a HybridGaussianConditional. More...
 
GaussianConditional::shared_ptr asGaussian () const
 Return HybridConditional as a GaussianConditional. More...
 
DiscreteConditional::shared_ptr asDiscrete () const
 Return conditional as a DiscreteConditional. More...
 
std::shared_ptr< Factorinner () const
 Get the type-erased pointer to the inner type. More...
 
double error (const HybridValues &values) const override
 Return the error of the underlying conditional. More...
 
AlgebraicDecisionTree< KeyerrorTree (const VectorValues &values) const override
 Compute error of the HybridConditional as a tree. More...
 
double logProbability (const HybridValues &values) const override
 Return the log-probability (or density) of the underlying conditional. More...
 
double negLogConstant () const override
 
double evaluate (const HybridValues &values) const override
 Return the probability (or density) of the underlying conditional. More...
 
bool frontalsIn (const VectorValues &measurements) const
 Check if VectorValues measurements contains all frontal keys. 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...
 
void print (const std::string &s="HybridFactor\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override
 print 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 ()
 
- Public Member Functions inherited from gtsam::Conditional< HybridFactor, HybridConditional >
void print (const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
 
bool equals (const This &c, double tol=1e-9) const
 
virtual ~Conditional ()
 
size_t nrFrontals () const
 
size_t nrParents () const
 
Key firstFrontalKey () const
 
Frontals frontals () const
 
Parents parents () const
 
double operator() (const HybridValues &x) const
 Evaluate probability density, sugar. More...
 
virtual double negLogConstant () const
 All conditional types need to implement this as the negative log of the normalization constant to make it such that error>=0. More...
 
size_tnrFrontals ()
 
HybridFactor ::const_iterator beginFrontals () const
 
HybridFactor ::iterator beginFrontals ()
 
HybridFactor ::const_iterator endFrontals () const
 
HybridFactor ::iterator endFrontals ()
 
HybridFactor ::const_iterator beginParents () const
 
HybridFactor ::iterator beginParents ()
 
HybridFactor ::const_iterator endParents () const
 
HybridFactor ::iterator endParents ()
 

Protected Attributes

std::shared_ptr< Factorinner_
 Type-erased pointer to the inner type. More...
 
- 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...
 
- Protected Attributes inherited from gtsam::Conditional< HybridFactor, HybridConditional >
size_t nrFrontals_
 

Additional Inherited Members

- Static Public Member Functions inherited from gtsam::Conditional< HybridFactor, HybridConditional >
static bool CheckInvariants (const HybridConditional &conditional, const VALUES &x)
 
- Protected Member Functions inherited from gtsam::Factor
 Factor ()
 
template<typename CONTAINER >
 Factor (const CONTAINER &keys)
 
template<typename ITERATOR >
 Factor (ITERATOR first, ITERATOR last)
 
- Protected Member Functions inherited from gtsam::Conditional< HybridFactor, HybridConditional >
 Conditional ()
 
 Conditional (size_t nrFrontals)
 
- 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)
 

Detailed Description

Hybrid Conditional Density

As a type-erased variant of:

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

Definition at line 60 of file HybridConditional.h.

Member Typedef Documentation

◆ BaseConditional

Typedef to our conditional base class.

Definition at line 69 of file HybridConditional.h.

◆ BaseFactor

Typedef to our factor base class.

Definition at line 67 of file HybridConditional.h.

◆ shared_ptr

typedef std::shared_ptr<This> gtsam::HybridConditional::shared_ptr

shared_ptr to this class

Definition at line 66 of file HybridConditional.h.

◆ This

Typedef to this class.

Definition at line 65 of file HybridConditional.h.

Constructor & Destructor Documentation

◆ HybridConditional() [1/6]

gtsam::HybridConditional::HybridConditional ( )
default

Default constructor needed for serialization.

◆ HybridConditional() [2/6]

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

Construct a new Hybrid Conditional object.

Parameters
continuousKeysVector of keys for continuous variables.
discreteKeysKeys and cardinalities for discrete variables.
nFrontalsThe number of frontal variables in the conditional.

Definition at line 89 of file HybridConditional.h.

◆ HybridConditional() [3/6]

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

Construct a new Hybrid Conditional object.

Parameters
continuousFrontalsVector of keys for continuous variables.
discreteFrontalsKeys and cardinalities for discrete variables.
continuousParentsVector of keys for parent continuous variables.
discreteParentsKeys and cardinalities for parent discrete variables.

Definition at line 28 of file HybridConditional.cpp.

◆ HybridConditional() [4/6]

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

Construct a new Hybrid Conditional object.

Parameters
continuousConditionalConditional used to create the HybridConditional.

Definition at line 37 of file HybridConditional.cpp.

◆ HybridConditional() [5/6]

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

Construct a new Hybrid Conditional object.

Parameters
discreteConditionalConditional used to create the HybridConditional.

Definition at line 45 of file HybridConditional.cpp.

◆ HybridConditional() [6/6]

gtsam::HybridConditional::HybridConditional ( const std::shared_ptr< HybridGaussianConditional > &  hybridGaussianCond)

Construct a new Hybrid Conditional object.

Parameters
hybridGaussianCondHybrid Gaussian Conditional used to create the HybridConditional.

Definition at line 53 of file HybridConditional.cpp.

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

Definition at line 173 of file HybridConditional.h.

◆ asGaussian()

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

Return HybridConditional as a GaussianConditional.

Returns
nullptr if not a GaussianConditional
GaussianConditional::shared_ptr otherwise

Definition at line 164 of file HybridConditional.h.

◆ asHybrid()

HybridGaussianConditional::shared_ptr gtsam::HybridConditional::asHybrid ( ) const
inline

Return HybridConditional as a HybridGaussianConditional.

Returns
nullptr if not a conditional
HybridGaussianConditional::shared_ptr otherwise

Definition at line 155 of file HybridConditional.h.

◆ equals()

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

GTSAM-style equals.

Reimplemented from gtsam::HybridFactor.

Definition at line 97 of file HybridConditional.cpp.

◆ error()

double gtsam::HybridConditional::error ( const HybridValues values) const
overridevirtual

Return the error of the underlying conditional.

Reimplemented from gtsam::Factor.

Definition at line 115 of file HybridConditional.cpp.

◆ errorTree()

AlgebraicDecisionTree< Key > gtsam::HybridConditional::errorTree ( const VectorValues values) const
overridevirtual

Compute error of the HybridConditional as a tree.

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

Implements gtsam::HybridFactor.

Definition at line 128 of file HybridConditional.cpp.

◆ evaluate()

double gtsam::HybridConditional::evaluate ( const HybridValues values) const
overridevirtual

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

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

Definition at line 168 of file HybridConditional.cpp.

◆ frontalsIn()

bool gtsam::HybridConditional::frontalsIn ( const VectorValues measurements) const
inline

Check if VectorValues measurements contains all frontal keys.

Definition at line 208 of file HybridConditional.h.

◆ inner()

std::shared_ptr<Factor> gtsam::HybridConditional::inner ( ) const
inline

Get the type-erased pointer to the inner type.

Definition at line 178 of file HybridConditional.h.

◆ logProbability()

double gtsam::HybridConditional::logProbability ( const HybridValues values) const
overridevirtual

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

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

Definition at line 142 of file HybridConditional.cpp.

◆ negLogConstant()

double gtsam::HybridConditional::negLogConstant ( ) const
override

Return the negative log of the normalization constant. This shows up in the error as -(error(x) + negLogConstant) Note this is 0.0 for discrete and hybrid conditionals, but depends on the continuous parameters for Gaussian conditionals.

Definition at line 155 of file HybridConditional.cpp.

◆ print()

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

GTSAM-style print.

Reimplemented from gtsam::Factor.

Definition at line 62 of file HybridConditional.cpp.

Member Data Documentation

◆ inner_

std::shared_ptr<Factor> gtsam::HybridConditional::inner_
protected

Type-erased pointer to the inner type.

Definition at line 73 of file HybridConditional.h.


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


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:23:54