GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
GaussianMixtureFactor.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 
21 #pragma once
22 
29 
30 namespace gtsam {
31 
32 class HybridValues;
33 class DiscreteValues;
34 class VectorValues;
35 
47 class GTSAM_EXPORT GaussianMixtureFactor : public HybridFactor {
48  public:
49  using Base = HybridFactor;
51  using shared_ptr = std::shared_ptr<This>;
52 
53  using sharedFactor = std::shared_ptr<GaussianFactor>;
54 
57 
58  private:
60  Factors factors_;
61 
68  GaussianFactorGraphTree asGaussianFactorGraphTree() const;
69 
70  public:
73 
75  GaussianMixtureFactor() = default;
76 
86  GaussianMixtureFactor(const KeyVector &continuousKeys,
87  const DiscreteKeys &discreteKeys,
88  const Factors &factors);
89 
98  GaussianMixtureFactor(const KeyVector &continuousKeys,
99  const DiscreteKeys &discreteKeys,
100  const std::vector<sharedFactor> &factors)
101  : GaussianMixtureFactor(continuousKeys, discreteKeys,
102  Factors(discreteKeys, factors)) {}
103 
107 
108  bool equals(const HybridFactor &lf, double tol = 1e-9) const override;
109 
110  void print(
111  const std::string &s = "GaussianMixtureFactor\n",
112  const KeyFormatter &formatter = DefaultKeyFormatter) const override;
113 
117 
119  sharedFactor operator()(const DiscreteValues &assignment) const;
120 
129  GaussianFactorGraphTree add(const GaussianFactorGraphTree &sum) const;
130 
138  AlgebraicDecisionTree<Key> error(const VectorValues &continuousValues) const;
139 
144  double error(const HybridValues &values) const override;
145 
148  GaussianFactorGraphTree &sum, const GaussianMixtureFactor &factor) {
149  sum = factor.add(sum);
150  return sum;
151  }
153 
154  private:
155 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
156 
157  friend class boost::serialization::access;
158  template <class ARCHIVE>
159  void serialize(ARCHIVE &ar, const unsigned int /*version*/) {
160  ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
161  ar &BOOST_SERIALIZATION_NVP(factors_);
162  }
163 #endif
164 };
165 
166 // traits
167 template <>
168 struct traits<GaussianMixtureFactor> : public Testable<GaussianMixtureFactor> {
169 };
170 
171 } // namespace gtsam
Definition: HybridValues.h:38
Decision Tree for use in DiscreteFactors.
Definition: HybridFactor.h:52
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
Definition: Testable.h:152
Implementation of a discrete conditional mixture factor. Implements a joint discrete-continuous facto...
Definition: GaussianMixtureFactor.h:47
Definition: Group.h:43
A factor with a quadratic error function - a Gaussian.
Algebraic Decision Trees.
Definition: VectorValues.h:74
Definition: Testable.h:112
GTSAM_EXPORT void print(const Matrix &A, const std::string &s, std::ostream &stream)
Linear Factor Graph where all factors are Gaussians.
Definition: DiscreteValues.h:34
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
Definition: chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
specialized key for discrete variables
GaussianMixtureFactor(const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys, const std::vector< sharedFactor > &factors)
Construct a new GaussianMixtureFactor object using a vector of GaussianFactor shared pointers...
Definition: GaussianMixtureFactor.h:98
friend GaussianFactorGraphTree & operator+=(GaussianFactorGraphTree &sum, const GaussianMixtureFactor &factor)
Add MixtureFactor to a Sum, syntactic sugar.
Definition: GaussianMixtureFactor.h:147
GaussianFactorGraphTree add(const GaussianFactorGraphTree &sum) const
Combine the Gaussian Factor Graphs in sum and this while maintaining the original tree structure...
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41