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 
40  class GTSAM_EXPORT GaussianConditional :
41  public JacobianFactor,
42  public Conditional<JacobianFactor, GaussianConditional>
43  {
44  public:
46  typedef std::shared_ptr<This> shared_ptr;
49 
52 
55 
57  GaussianConditional(Key key, const Vector& d, const Matrix& R,
59 
61  GaussianConditional(Key key, const Vector& d, const Matrix& R, Key parent1,
62  const Matrix& S,
64 
66  GaussianConditional(Key key, const Vector& d, const Matrix& R, Key parent1,
67  const Matrix& S, Key parent2, const Matrix& T,
69 
73  template<typename TERMS>
74  GaussianConditional(const TERMS& terms,
75  size_t nrFrontals, const Vector& d,
77 
82  template<typename KEYS>
84  const KEYS& keys, size_t nrFrontals, const VerticalBlockMatrix& augmentedMatrix,
86 
88  static GaussianConditional FromMeanAndStddev(Key key, const Vector& mu,
89  double sigma);
90 
92  static GaussianConditional FromMeanAndStddev(Key key, const Matrix& A,
93  Key parent, const Vector& b,
94  double sigma);
95 
98  static GaussianConditional FromMeanAndStddev(Key key, //
99  const Matrix& A1, Key parent1,
100  const Matrix& A2, Key parent2,
101  const Vector& b, double sigma);
102 
104  template<typename... Args>
105  static shared_ptr sharedMeanAndStddev(Args&&... args) {
106  return std::make_shared<This>(FromMeanAndStddev(std::forward<Args>(args)...));
107  }
108 
116  template<typename ITERATOR>
117  static shared_ptr Combine(ITERATOR firstConditional, ITERATOR lastConditional);
118 
122 
124  void print(
125  const std::string& = "GaussianConditional",
126  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
127 
129  bool equals(const GaussianFactor&cg, double tol = 1e-9) const override;
130 
134 
143  double negLogConstant() const override;
144 
152  double logProbability(const VectorValues& x) const;
153 
159  double evaluate(const VectorValues& x) const;
160 
162  double operator()(const VectorValues& x) const {
163  return evaluate(x);
164  }
165 
179  VectorValues solve(const VectorValues& parents) const;
180 
181  VectorValues solveOtherRHS(const VectorValues& parents, const VectorValues& rhs) const;
182 
184  void solveTransposeInPlace(VectorValues& gy) const;
185 
187  JacobianFactor::shared_ptr likelihood(
188  const VectorValues& frontalValues) const;
189 
191  JacobianFactor::shared_ptr likelihood(const Vector& frontal) const;
192 
199  VectorValues sample(std::mt19937_64* rng) const;
200 
208  VectorValues sample(const VectorValues& parentsValues,
209  std::mt19937_64* rng) const;
210 
212  VectorValues sample() const;
213 
215  VectorValues sample(const VectorValues& parentsValues) const;
216 
220 
222  constABlock R() const { return Ab_.range(0, nrFrontals()); }
223 
225  constABlock S() const { return Ab_.range(nrFrontals(), size()); }
226 
228  constABlock S(const_iterator it) const { return BaseFactor::getA(it); }
229 
231  const constBVector d() const { return BaseFactor::getb(); }
232 
244  inline double determinant() const { return exp(logDeterminant()); }
245 
257  double logDeterminant() const;
258 
262 
267  double logProbability(const HybridValues& x) const override;
268 
273  double evaluate(const HybridValues& x) const override;
274 
275  using Conditional::operator(); // Expose evaluate(const HybridValues&) method..
276  using JacobianFactor::error; // Expose error(const HybridValues&) method..
277 
279 
280  private:
281 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
282 
283  friend class boost::serialization::access;
284  template<class Archive>
285  void serialize(Archive & ar, const unsigned int /*version*/) {
286  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseFactor);
287  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseConditional);
288  }
289 #endif
290  }; // GaussianConditional
291 
293 template<>
294 struct traits<GaussianConditional> : public Testable<GaussianConditional> {};
295 
296 } // \ namespace gtsam
297 
299 
gtsam::HybridValues
Definition: HybridValues.h:37
rng
static std::mt19937 rng
Definition: timeFactorOverhead.cpp:31
gtsam::GaussianConditional::S
constABlock S() const
Definition: GaussianConditional.h:225
Eigen::Block
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
gtsam::GaussianConditional::BaseFactor
JacobianFactor BaseFactor
Typedef to our factor base class.
Definition: GaussianConditional.h:47
global_includes.h
Included from all GTSAM files.
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
d
static const double d[K][N]
Definition: igam.h:11
test_constructor::sigmas
Vector1 sigmas
Definition: testHybridNonlinearFactor.cpp:52
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
mu
double mu
Definition: testBoundingConstraint.cpp:37
x
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
Definition: gnuplot_common_settings.hh:12
gtsam::JacobianFactor
Definition: JacobianFactor.h:91
gtsam::GaussianFactor
Definition: GaussianFactor.h:38
gtsam::GaussianConditional::operator()
double operator()(const VectorValues &x) const
Evaluate probability density, sugar.
Definition: GaussianConditional.h:162
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
exp
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
Definition: ArrayCwiseUnaryOps.h:97
gtsam::Factor::shared_ptr
std::shared_ptr< Factor > shared_ptr
A shared_ptr to this class.
Definition: Factor.h:76
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
GaussianConditional-inl.h
Conditional Gaussian Base class.
sampling::sigma
static const double sigma
Definition: testGaussianBayesNet.cpp:170
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
gtsam::GaussianConditional::BaseConditional
Conditional< BaseFactor, This > BaseConditional
Typedef to our conditional base class.
Definition: GaussianConditional.h:48
gtsam::GaussianConditional::R
constABlock R() const
Definition: GaussianConditional.h:222
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
A
Definition: test_numpy_dtypes.cpp:298
gtsam::VerticalBlockMatrix
Definition: VerticalBlockMatrix.h:42
gtsam::VectorValues
Definition: VectorValues.h:74
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::internal::logDeterminant
double logDeterminant(const typename BAYESTREE::sharedClique &clique)
Definition: GaussianBayesTree-inl.h:42
gtsam::GaussianConditional
Definition: GaussianConditional.h:40
gtsam::SharedDiagonal
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:764
A2
static const double A2[]
Definition: expn.h:7
gtsam::GaussianConditional::This
GaussianConditional This
Typedef to this class.
Definition: GaussianConditional.h:45
gtsam::GaussianConditional::d
const constBVector d() const
Definition: GaussianConditional.h:231
gtsam::GaussianConditional::GaussianConditional
GaussianConditional()
Definition: GaussianConditional.h:54
VectorValues.h
Factor Graph Values.
Eigen::Triplet
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:162
gtsam::Conditional
Definition: Conditional.h:63
gtsam::equals
Definition: Testable.h:112
key
const gtsam::Symbol key('X', 0)
JacobianFactor.h
gtsam::b
const G & b
Definition: Group.h:79
gtsam::Factor::const_iterator
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:83
gtsam::JacobianFactor::constBVector
constABlock::ConstColXpr constBVector
Definition: JacobianFactor.h:102
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
gtsam::GaussianConditional::S
constABlock S(const_iterator it) const
Definition: GaussianConditional.h:228
args
Definition: pytypes.h:2210
Combine
Definition: testExpressionFactor.cpp:476
A1
static const double A1[]
Definition: expn.h:6
gtsam::GaussianConditional::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianConditional.h:46
gtsam::JacobianFactor::error
double error(const VectorValues &c) const override
Definition: JacobianFactor.cpp:486
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::JacobianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: JacobianFactor.h:97
Conditional.h
Base class for conditional densities.
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
R
Rot2 R(Rot2::fromAngle(0.1))
Conditional-inst.h
S
DiscreteKey S(1, 2)
gtsam::GaussianConditional::determinant
double determinant() const
Compute the determinant of the R matrix.
Definition: GaussianConditional.h:244
gtsam::GaussianConditional::sharedMeanAndStddev
static shared_ptr sharedMeanAndStddev(Args &&... args)
Create shared pointer by forwarding arguments to fromMeanAndStddev.
Definition: GaussianConditional.h:105


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:34