GaussianConditional.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 
18 // \callgraph
19 
20 #pragma once
21 
22 #include <gtsam/global_includes.h>
27 
28 #include <random> // for std::mt19937_64
29 
30 namespace gtsam {
31 
38  class GTSAM_EXPORT GaussianConditional :
39  public JacobianFactor,
40  public Conditional<JacobianFactor, GaussianConditional>
41  {
42  public:
44  typedef std::shared_ptr<This> shared_ptr;
47 
50 
53 
55  GaussianConditional(Key key, const Vector& d, const Matrix& R,
57 
59  GaussianConditional(Key key, const Vector& d, const Matrix& R, Key parent1,
60  const Matrix& S,
62 
64  GaussianConditional(Key key, const Vector& d, const Matrix& R, Key parent1,
65  const Matrix& S, Key parent2, const Matrix& T,
67 
71  template<typename TERMS>
72  GaussianConditional(const TERMS& terms,
73  size_t nrFrontals, const Vector& d,
75 
80  template<typename KEYS>
82  const KEYS& keys, size_t nrFrontals, const VerticalBlockMatrix& augmentedMatrix,
84 
86  static GaussianConditional FromMeanAndStddev(Key key, const Vector& mu,
87  double sigma);
88 
90  static GaussianConditional FromMeanAndStddev(Key key, const Matrix& A,
91  Key parent, const Vector& b,
92  double sigma);
93 
96  static GaussianConditional FromMeanAndStddev(Key key, //
97  const Matrix& A1, Key parent1,
98  const Matrix& A2, Key parent2,
99  const Vector& b, double sigma);
100 
102  template<typename... Args>
103  static shared_ptr sharedMeanAndStddev(Args&&... args) {
104  return std::make_shared<This>(FromMeanAndStddev(std::forward<Args>(args)...));
105  }
106 
114  template<typename ITERATOR>
115  static shared_ptr Combine(ITERATOR firstConditional, ITERATOR lastConditional);
116 
120 
122  void print(
123  const std::string& = "GaussianConditional",
124  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
125 
127  bool equals(const GaussianFactor&cg, double tol = 1e-9) const override;
128 
132 
137  double logNormalizationConstant() const override;
138 
146  double logProbability(const VectorValues& x) const;
147 
153  double evaluate(const VectorValues& x) const;
154 
156  double operator()(const VectorValues& x) const {
157  return evaluate(x);
158  }
159 
173  VectorValues solve(const VectorValues& parents) const;
174 
175  VectorValues solveOtherRHS(const VectorValues& parents, const VectorValues& rhs) const;
176 
178  void solveTransposeInPlace(VectorValues& gy) const;
179 
181  JacobianFactor::shared_ptr likelihood(
182  const VectorValues& frontalValues) const;
183 
185  JacobianFactor::shared_ptr likelihood(const Vector& frontal) const;
186 
193  VectorValues sample(std::mt19937_64* rng) const;
194 
202  VectorValues sample(const VectorValues& parentsValues,
203  std::mt19937_64* rng) const;
204 
206  VectorValues sample() const;
207 
209  VectorValues sample(const VectorValues& parentsValues) const;
210 
214 
216  constABlock R() const { return Ab_.range(0, nrFrontals()); }
217 
219  constABlock S() const { return Ab_.range(nrFrontals(), size()); }
220 
222  constABlock S(const_iterator it) const { return BaseFactor::getA(it); }
223 
225  const constBVector d() const { return BaseFactor::getb(); }
226 
238  inline double determinant() const { return exp(logDeterminant()); }
239 
251  double logDeterminant() const;
252 
256 
261  double logProbability(const HybridValues& x) const override;
262 
267  double evaluate(const HybridValues& x) const override;
268 
269  using Conditional::operator(); // Expose evaluate(const HybridValues&) method..
270  using JacobianFactor::error; // Expose error(const HybridValues&) method..
271 
273 
274  private:
275 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
276 
277  friend class boost::serialization::access;
278  template<class Archive>
279  void serialize(Archive & ar, const unsigned int /*version*/) {
280  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseFactor);
281  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseConditional);
282  }
283 #endif
284  }; // GaussianConditional
285 
287 template<>
288 struct traits<GaussianConditional> : public Testable<GaussianConditional> {};
289 
290 } // \ namespace gtsam
291 
293 
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
const gtsam::Symbol key('X', 0)
static Matrix A1
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Base class for conditional densities.
Conditional< BaseFactor, This > BaseConditional
Typedef to our conditional base class.
double error(const VectorValues &c) const override
std::string serialize(const T &input)
serializes to a string
double mu
double logDeterminant(const typename BAYESTREE::sharedClique &clique)
Definition: pytypes.h:2012
static std::mt19937 rng
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Rot2 R(Rot2::fromAngle(0.1))
JacobianFactor BaseFactor
Typedef to our factor base class.
double determinant() const
Compute the determinant of the R matrix.
Conditional Gaussian Base class.
const constBVector d() const
DiscreteKey S(1, 2)
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
Included from all GTSAM files.
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Factor Graph Values.
Eigen::VectorXd Vector
Definition: Vector.h:38
constABlock::ConstColXpr constBVector
GaussianConditional This
Typedef to this class.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
std::shared_ptr< This > shared_ptr
shared_ptr to this 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
const G & b
Definition: Group.h:86
static shared_ptr sharedMeanAndStddev(Args &&... args)
Create shared pointer by forwarding arguments to fromMeanAndStddev.
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:743
traits
Definition: chartTesting.h:28
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
constABlock S(const_iterator it) const
static const double sigma
const G double tol
Definition: Group.h:86
double operator()(const VectorValues &x) const
Evaluate probability density, sugar.
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:82
const KeyVector keys
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102


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