GaussianMixture.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #pragma once
21 
30 
31 namespace gtsam {
32 
33 class HybridValues;
34 
53 class GTSAM_EXPORT GaussianMixture
54  : public HybridFactor,
55  public Conditional<HybridFactor, GaussianMixture> {
56  public:
58  using shared_ptr = std::shared_ptr<GaussianMixture>;
61 
64 
65  private:
67  double logConstant_;
68 
72  GaussianFactorGraphTree asGaussianFactorGraphTree() const;
73 
81  std::function<GaussianConditional::shared_ptr(
83  prunerFunc(const DecisionTreeFactor &decisionTree);
84 
85  public:
88 
90  GaussianMixture() = default;
91 
103  GaussianMixture(const KeyVector &continuousFrontals,
104  const KeyVector &continuousParents,
105  const DiscreteKeys &discreteParents,
106  const Conditionals &conditionals);
107 
116  GaussianMixture(KeyVector &&continuousFrontals, KeyVector &&continuousParents,
117  DiscreteKeys &&discreteParents,
118  std::vector<GaussianConditional::shared_ptr> &&conditionals);
119 
129  const KeyVector &continuousFrontals, const KeyVector &continuousParents,
130  const DiscreteKeys &discreteParents,
131  const std::vector<GaussianConditional::shared_ptr> &conditionals);
132 
136 
138  bool equals(const HybridFactor &lf, double tol = 1e-9) const override;
139 
141  void print(
142  const std::string &s = "GaussianMixture\n",
143  const KeyFormatter &formatter = DefaultKeyFormatter) const override;
144 
148 
151  const DiscreteValues &discreteValues) const;
152 
154  size_t nrComponents() const;
155 
157  KeyVector continuousParents() const;
158 
161  double logNormalizationConstant() const override { return logConstant_; }
162 
167  std::shared_ptr<GaussianMixtureFactor> likelihood(
168  const VectorValues &given) const;
169 
171  const Conditionals &conditionals() const;
172 
180  AlgebraicDecisionTree<Key> logProbability(
181  const VectorValues &continuousValues) const;
182 
208  double error(const HybridValues &values) const override;
209 
217  AlgebraicDecisionTree<Key> error(const VectorValues &continuousValues) const;
218 
225  double logProbability(const HybridValues &values) const override;
226 
228  double evaluate(const HybridValues &values) const override;
229 
231  double operator()(const HybridValues &values) const {
232  return evaluate(values);
233  }
234 
242  void prune(const DecisionTreeFactor &decisionTree);
243 
253 
254  private:
256  bool allFrontalsGiven(const VectorValues &given) const;
257 
258 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
259 
260  friend class boost::serialization::access;
261  template <class Archive>
262  void serialize(Archive &ar, const unsigned int /*version*/) {
263  ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseFactor);
264  ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseConditional);
265  ar &BOOST_SERIALIZATION_NVP(conditionals_);
266  }
267 #endif
268 };
269 
271 std::set<DiscreteKey> DiscreteKeysAsSet(const DiscreteKeys &discreteKeys);
272 
273 // traits
274 template <>
275 struct traits<GaussianMixture> : public Testable<GaussianMixture> {};
276 
277 } // namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
A set of GaussianFactors, indexed by a set of discrete keys.
Decision Tree for use in DiscreteFactors.
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Base class for conditional densities.
std::string serialize(const T &input)
serializes to a string
leaf::MyValues values
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
double operator()(const HybridValues &values) const
Evaluate probability density, sugar.
const KeyFormatter & formatter
double logConstant_
log of the normalization constant.
A conditional of gaussian mixtures indexed by discrete variables, as part of a Bayes Network...
std::set< DiscreteKey > DiscreteKeysAsSet(const DiscreteKeys &discreteKeys)
Return the DiscreteKey vector as a set.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Conditional Gaussian Base class.
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
traits
Definition: chartTesting.h:28
double logNormalizationConstant() const override
specialized key for discrete variables
Conditionals conditionals_
a decision tree of Gaussian conditionals.
std::shared_ptr< GaussianMixture > shared_ptr
std::function< double(const Assignment< Key > &, double)> prunerFunc(const DecisionTreeFactor &prunedDecisionTree, const HybridConditional &conditional)
Helper function to get the pruner functional.
graph add(PriorFactor< Pose2 >(1, priorMean, priorNoise))
static double error
Definition: testRot3.cpp:37
const std::vector< GaussianConditional::shared_ptr > conditionals
const G double tol
Definition: Group.h:86
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:15