Loading...
Searching...
No Matches
GaussianMixture.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/DecisionTree-inl.h>
#include <gtsam/discrete/DecisionTree.h>
#include <gtsam/discrete/DecisionTreeFactor.h>
#include <gtsam/discrete/DiscreteKey.h>
#include <gtsam/hybrid/GaussianMixtureFactor.h>
#include <gtsam/hybrid/HybridFactor.h>
#include <gtsam/inference/Conditional.h>
#include <gtsam/linear/GaussianConditional.h>
namespace gtsam {
class HybridValues;
class GTSAM_EXPORT GaussianMixture
: public HybridFactor,
public Conditional<HybridFactor, GaussianMixture> {
public:
using This = GaussianMixture;
using shared_ptr = boost::shared_ptr<GaussianMixture>;
using BaseFactor = HybridFactor;
using BaseConditional = Conditional<HybridFactor, GaussianMixture>;
using Conditionals = DecisionTree<Key, GaussianConditional::shared_ptr>;
private:
Conditionals conditionals_;
double logConstant_;
GaussianFactorGraphTree asGaussianFactorGraphTree() const;
std::function<GaussianConditional::shared_ptr(
const Assignment<Key> &, const GaussianConditional::shared_ptr &)>
prunerFunc(const DecisionTreeFactor &decisionTree);
public:
GaussianMixture() = default;
GaussianMixture(const KeyVector &continuousFrontals,
const KeyVector &continuousParents,
const DiscreteKeys &discreteParents,
const Conditionals &conditionals);
GaussianMixture(KeyVector &&continuousFrontals, KeyVector &&continuousParents,
DiscreteKeys &&discreteParents,
std::vector<GaussianConditional::shared_ptr> &&conditionals);
GaussianMixture(
const KeyVector &continuousFrontals, const KeyVector &continuousParents,
const DiscreteKeys &discreteParents,
const std::vector<GaussianConditional::shared_ptr> &conditionals);
bool equals(const HybridFactor &lf, double tol = 1e-9) const override;
void print(
const std::string &s = "GaussianMixture\n",
const KeyFormatter &formatter = DefaultKeyFormatter) const override;
GaussianConditional::shared_ptr operator()(
const DiscreteValues &discreteValues) const;
size_t nrComponents() const;
KeyVector continuousParents() const;
double logNormalizationConstant() const override { return logConstant_; }
boost::shared_ptr<GaussianMixtureFactor> likelihood(
const VectorValues &given) const;
const Conditionals &conditionals() const;
AlgebraicDecisionTree<Key> logProbability(
const VectorValues &continuousValues) const;
double error(const HybridValues &values) const override;
AlgebraicDecisionTree<Key> error(const VectorValues &continuousValues) const;
double logProbability(const HybridValues &values) const override;
double evaluate(const HybridValues &values) const override;
double operator()(const HybridValues &values) const {
return evaluate(values);
}
void prune(const DecisionTreeFactor &decisionTree);
GaussianFactorGraphTree add(const GaussianFactorGraphTree &sum) const;
private:
bool allFrontalsGiven(const VectorValues &given) const;
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(conditionals_);
}
};
std::set<DiscreteKey> DiscreteKeysAsSet(const DiscreteKeys &discreteKeys);
// traits
template <>
struct traits<GaussianMixture> : public Testable<GaussianMixture> {};
} // namespace gtsam
DecisionTree.h
Decision Tree for use in DiscreteFactors.
DiscreteKey.h
specialized key for discrete variables
DecisionTreeFactor.h
GaussianMixtureFactor.h
A set of GaussianFactors, indexed by a set of discrete keys.
HybridFactor.h
Conditional.h
Base class for conditional densities.
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::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::DiscreteKeysAsSet
std::set< DiscreteKey > DiscreteKeysAsSet(const DiscreteKeys &discreteKeys)
Return the DiscreteKey vector as a set.
Definition GaussianMixture.cpp:221
gtsam::GaussianFactorGraphTree
DecisionTree< Key, GaussianFactorGraph > GaussianFactorGraphTree
Alias for DecisionTree of GaussianFactorGraphs.
Definition HybridFactor.h:34
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::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::AlgebraicDecisionTree
An algebraic decision tree fixes the range of a DecisionTree to double.
Definition AlgebraicDecisionTree.h:38
gtsam::Assignment
An assignment from labels to value index (size_t).
Definition Assignment.h:37
gtsam::DecisionTree
a decision tree is a function from assignments to values.
Definition DecisionTree.h:61
gtsam::DecisionTreeFactor
A discrete probabilistic factor.
Definition DecisionTreeFactor.h:45
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:39
gtsam::DiscreteValues
A map from keys to values.
Definition DiscreteValues.h:34
gtsam::GaussianMixture
A conditional of gaussian mixtures indexed by discrete variables, as part of a Bayes Network.
Definition GaussianMixture.h:55
gtsam::GaussianMixture::logNormalizationConstant
double logNormalizationConstant() const override
The log normalization constant is max of the the individual log-normalization constants.
Definition GaussianMixture.h:161
gtsam::GaussianMixture::operator()
double operator()(const HybridValues &values) const
Evaluate probability density, sugar.
Definition GaussianMixture.h:231
gtsam::GaussianMixture::conditionals
const Conditionals & conditionals() const
Getter for the underlying Conditionals DecisionTree.
Definition GaussianMixture.cpp:52
gtsam::GaussianMixture::GaussianMixture
GaussianMixture()=default
Default constructor, mainly for serialization.
gtsam::GaussianMixture::equals
bool equals(const HybridFactor &lf, double tol=1e-9) const override
Test equality with base HybridFactor.
Definition GaussianMixture.cpp:118
gtsam::GaussianMixture::Conditionals
DecisionTree< Key, GaussianConditional::shared_ptr > Conditionals
typedef for Decision Tree of Gaussian Conditionals
Definition GaussianMixture.h:63
gtsam::GaussianMixture::nrComponents
size_t nrComponents() const
Returns the total number of continuous components.
Definition GaussianMixture.cpp:96
gtsam::GaussianMixture::operator()
GaussianConditional::shared_ptr operator()(const DiscreteValues &discreteValues) const
Return the conditional Gaussian for the given discrete assignment.
Definition GaussianMixture.cpp:105
gtsam::GaussianMixture::evaluate
double evaluate(const HybridValues &values) const override
Calculate probability density for given values.
Definition GaussianMixture.cpp:343
gtsam::GaussianMixture::print
void print(const std::string &s="GaussianMixture\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override
Print utility.
Definition GaussianMixture.cpp:136
gtsam::GaussianMixture::continuousParents
KeyVector continuousParents() const
Returns the continuous keys among the parents.
Definition GaussianMixture.cpp:162
gtsam::HybridFactor::HybridFactor
HybridFactor()=default
Default constructor creates empty factor.
gtsam::HybridValues
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:38
gtsam::Conditional< HybridFactor, GaussianMixture >::Conditional
Conditional()
Definition Conditional.h:85
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