Loading...
Searching...
No Matches
HybridConditional.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/discrete/DiscreteConditional.h>
#include <gtsam/hybrid/GaussianMixture.h>
#include <gtsam/hybrid/HybridFactor.h>
#include <gtsam/hybrid/HybridGaussianFactorGraph.h>
#include <gtsam/inference/Conditional.h>
#include <gtsam/inference/Key.h>
#include <gtsam/linear/GaussianConditional.h>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <vector>
namespace gtsam {
class GTSAM_EXPORT HybridConditional
: public HybridFactor,
public Conditional<HybridFactor, HybridConditional> {
public:
// typedefs needed to play nice with gtsam
typedef HybridConditional This;
typedef boost::shared_ptr<This> shared_ptr;
typedef HybridFactor BaseFactor;
typedef Conditional<BaseFactor, This>
BaseConditional;
protected:
boost::shared_ptr<Factor> inner_;
public:
HybridConditional() = default;
HybridConditional(const KeyVector& continuousKeys,
const DiscreteKeys& discreteKeys, size_t nFrontals)
: BaseFactor(continuousKeys, discreteKeys), BaseConditional(nFrontals) {}
HybridConditional(const KeyVector& continuousFrontals,
const DiscreteKeys& discreteFrontals,
const KeyVector& continuousParents,
const DiscreteKeys& discreteParents);
HybridConditional(
const boost::shared_ptr<GaussianConditional>& continuousConditional);
HybridConditional(
const boost::shared_ptr<DiscreteConditional>& discreteConditional);
HybridConditional(const boost::shared_ptr<GaussianMixture>& gaussianMixture);
void print(
const std::string& s = "Hybrid Conditional: ",
const KeyFormatter& formatter = DefaultKeyFormatter) const override;
bool equals(const HybridFactor& other, double tol = 1e-9) const override;
GaussianMixture::shared_ptr asMixture() const {
return boost::dynamic_pointer_cast<GaussianMixture>(inner_);
}
GaussianConditional::shared_ptr asGaussian() const {
return boost::dynamic_pointer_cast<GaussianConditional>(inner_);
}
DiscreteConditional::shared_ptr asDiscrete() const {
return boost::dynamic_pointer_cast<DiscreteConditional>(inner_);
}
boost::shared_ptr<Factor> inner() const { return inner_; }
double error(const HybridValues& values) const override;
double logProbability(const HybridValues& values) const override;
double logNormalizationConstant() const override;
double evaluate(const HybridValues& values) const override;
bool frontalsIn(const VectorValues& measurements) const {
for (Key key : frontals()) {
if (!measurements.exists(key)) {
return false;
}
}
return true;
}
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int /*version*/) {
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseFactor);
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseConditional);
ar& BOOST_SERIALIZATION_NVP(inner_);
// register the various casts based on the type of inner_
// https://www.boost.org/doc/libs/1_80_0/libs/serialization/doc/serialization.html#runtimecasting
if (isDiscrete()) {
boost::serialization::void_cast_register<DiscreteConditional, Factor>(
static_cast<DiscreteConditional*>(NULL), static_cast<Factor*>(NULL));
} else if (isContinuous()) {
boost::serialization::void_cast_register<GaussianConditional, Factor>(
static_cast<GaussianConditional*>(NULL), static_cast<Factor*>(NULL));
} else {
boost::serialization::void_cast_register<GaussianMixture, Factor>(
static_cast<GaussianMixture*>(NULL), static_cast<Factor*>(NULL));
}
}
}; // HybridConditional
// traits
template <>
struct traits<HybridConditional> : public Testable<HybridConditional> {};
} // namespace gtsam
DiscreteConditional.h
HybridGaussianFactorGraph.h
Linearized Hybrid factor graph that uses type erasure.
GaussianMixture.h
A hybrid conditional in the Conditional Linear Gaussian scheme.
HybridFactor.h
Conditional.h
Base class for conditional densities.
Key.h
GaussianConditional.h
Conditional Gaussian Base class.
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
gtsam::KeyFormatter
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
gtsam::equals
Template to create a binary predicate.
Definition Testable.h:111
gtsam::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::DiscreteConditional
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition DiscreteConditional.h:40
gtsam::DiscreteConditional::shared_ptr
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition DiscreteConditional.h:44
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:39
gtsam::HybridConditional
Hybrid Conditional Density.
Definition HybridConditional.h:62
gtsam::HybridConditional::BaseConditional
Conditional< BaseFactor, This > BaseConditional
Typedef to our conditional base class.
Definition HybridConditional.h:69
gtsam::HybridConditional::BaseFactor
HybridFactor BaseFactor
Typedef to our factor base class.
Definition HybridConditional.h:67
gtsam::HybridConditional::inner_
boost::shared_ptr< Factor > inner_
Type-erased pointer to the inner type.
Definition HybridConditional.h:73
gtsam::HybridConditional::asDiscrete
DiscreteConditional::shared_ptr asDiscrete() const
Return conditional as a DiscreteConditional.
Definition HybridConditional.h:172
gtsam::HybridConditional::asMixture
GaussianMixture::shared_ptr asMixture() const
Return HybridConditional as a GaussianMixture.
Definition HybridConditional.h:154
gtsam::HybridConditional::inner
boost::shared_ptr< Factor > inner() const
Get the type-erased pointer to the inner type.
Definition HybridConditional.h:177
gtsam::HybridConditional::frontalsIn
bool frontalsIn(const VectorValues &measurements) const
Check if VectorValues measurements contains all frontal keys.
Definition HybridConditional.h:196
gtsam::HybridConditional::HybridConditional
HybridConditional(const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys, size_t nFrontals)
Construct a new Hybrid Conditional object.
Definition HybridConditional.h:89
gtsam::HybridConditional::shared_ptr
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition HybridConditional.h:66
gtsam::HybridConditional::asGaussian
GaussianConditional::shared_ptr asGaussian() const
Return HybridConditional as a GaussianConditional.
Definition HybridConditional.h:163
gtsam::HybridConditional::This
HybridConditional This
Typedef to this class.
Definition HybridConditional.h:65
gtsam::HybridConditional::HybridConditional
HybridConditional()=default
Default constructor needed for serialization.
gtsam::HybridFactor
Base class for truly hybrid probabilistic factors.
Definition HybridFactor.h:52
gtsam::HybridFactor::isDiscrete
bool isDiscrete() const
True if this is a factor of discrete variables only.
Definition HybridFactor.h:120
gtsam::HybridFactor::HybridFactor
HybridFactor()=default
Default constructor creates empty factor.
gtsam::HybridFactor::continuousKeys
const KeyVector & continuousKeys() const
Return only the continuous keys for this factor.
Definition HybridFactor.h:135
gtsam::HybridFactor::discreteKeys
const DiscreteKeys & discreteKeys() const
Return the discrete keys for this factor.
Definition HybridFactor.h:132
gtsam::HybridValues
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:38
gtsam::Conditional< HybridFactor, HybridConditional >::Conditional
Conditional()
Definition Conditional.h:85
gtsam::Conditional< HybridFactor, HybridConditional >::frontals
Frontals frontals() const
Definition Conditional.h:124
gtsam::Factor
Definition Factor.h:68
gtsam::GaussianConditional
A GaussianConditional functions as the node in a Bayes network.
Definition GaussianConditional.h:43
gtsam::GaussianConditional::shared_ptr
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianConditional.h:46
gtsam::VectorValues
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:74
gtsam::VectorValues::exists
bool exists(Key j) const
Check whether a variable with key j exists.
Definition VectorValues.h:133