gtsam
Loading...
Searching...
No Matches
GaussianBayesNet.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
19// \callgraph
20
21#pragma once
22
27
28#include <utility>
29namespace gtsam {
30
35 class GTSAM_EXPORT GaussianBayesNet: public BayesNet<GaussianConditional>
36 {
37 public:
38
40 typedef GaussianBayesNet This;
41 typedef GaussianConditional ConditionalType;
42 typedef std::shared_ptr<This> shared_ptr;
43 typedef std::shared_ptr<ConditionalType> sharedConditional;
44
47
50
52 template <typename ITERATOR>
53 GaussianBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
54 : Base(firstConditional, lastConditional) {}
55
57 template <class CONTAINER>
58 explicit GaussianBayesNet(const CONTAINER& conditionals) {
59 push_back(conditionals);
60 }
61
64 template <class DERIVEDCONDITIONAL>
66 : Base(graph) {}
67
72 template <class DERIVEDCONDITIONAL>
74 std::initializer_list<std::shared_ptr<DERIVEDCONDITIONAL> > conditionals)
75 : Base(conditionals) {}
76
78
81
83 bool equals(const This& bn, double tol = 1e-9) const;
84
86 friend bool operator==(const GaussianBayesNet& lhs,
87 const GaussianBayesNet& rhs) {
88 return lhs.isEqual(rhs);
89 }
90
92 void print(
93 const std::string& s = "",
94 const KeyFormatter& formatter = DefaultKeyFormatter) const override {
95 Base::print(s, formatter);
96 }
97
99
102
104 double error(const VectorValues& x) const;
105
107 double logProbability(const VectorValues& x) const;
108
114 double evaluate(const VectorValues& x) const;
115
117 double operator()(const VectorValues& x) const {
118 return evaluate(x);
119 }
120
123 VectorValues optimize() const;
124
126 VectorValues optimize(const VectorValues& given) const;
127
134 VectorValues sample(std::mt19937_64* rng = nullptr) const;
135
143 VectorValues sample(const VectorValues& given, std::mt19937_64* rng = nullptr) const;
144
151 Ordering ordering() const;
152
154
157
163 std::pair<Matrix, Vector> matrix(const Ordering& ordering) const;
164
170 std::pair<Matrix, Vector> matrix() const;
171
197 VectorValues optimizeGradientSearch() const;
198
204 VectorValues gradient(const VectorValues& x0) const;
205
212 VectorValues gradientAtZero() const;
213
221 double determinant() const;
222
229 double logDeterminant() const;
230
237 double negLogConstant() const;
238
243 VectorValues backSubstitute(const VectorValues& gx) const;
244
251 VectorValues backSubstituteTranspose(const VectorValues& gx) const;
252
256
257 using Base::evaluate; // Expose evaluate(const HybridValues&) method..
258 using Base::logProbability; // Expose logProbability(const HybridValues&) method..
259 using Base::error; // Expose error(const HybridValues&) method..
260
262
263 private:
264#if GTSAM_ENABLE_BOOST_SERIALIZATION
266 friend class boost::serialization::access;
267 template<class ARCHIVE>
268 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
269 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
270 }
271#endif
272 };
273
275 template<>
276 struct traits<GaussianBayesNet> : public Testable<GaussianBayesNet> {
277 };
278
279} //\ namespace gtsam
Factor Graph Base Class.
Bayes network.
Conditional Gaussian Base class.
Included from all GTSAM files.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition triangulation.cpp:178
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Template to create a binary predicate.
Definition Testable.h:112
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
void print(const std::string &s="BayesNet", const KeyFormatter &formatter=DefaultKeyFormatter) const override
BayesNet()
Definition BayesNet.h:48
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition FactorGraph.h:58
bool isEqual(const FactorGraph &other) const
Check exact equality of the factor pointers. Useful for derived ==.
Definition FactorGraph.h:95
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition FactorGraph.h:147
Definition Ordering.h:33
GaussianBayesNet is a Bayes net made from linear-Gaussian conditionals.
Definition GaussianBayesNet.h:36
friend bool operator==(const GaussianBayesNet &lhs, const GaussianBayesNet &rhs)
Check exact equality.
Definition GaussianBayesNet.h:86
double operator()(const VectorValues &x) const
Evaluate probability density, sugar.
Definition GaussianBayesNet.h:117
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print graph
Definition GaussianBayesNet.h:92
GaussianBayesNet(const FactorGraph< DERIVEDCONDITIONAL > &graph)
Implicit copy/downcast constructor to override explicit template container constructor.
Definition GaussianBayesNet.h:65
GaussianBayesNet(std::initializer_list< std::shared_ptr< DERIVEDCONDITIONAL > > conditionals)
Constructor that takes an initializer list of shared pointers.
Definition GaussianBayesNet.h:73
GaussianBayesNet(const CONTAINER &conditionals)
Construct from container of factors (shared_ptr or plain objects).
Definition GaussianBayesNet.h:58
GaussianBayesNet()
Construct empty bayes net.
Definition GaussianBayesNet.h:49
double evaluate(const VectorValues &x) const
Calculate probability density for given values x: exp(logProbability) where x is the vector of values...
Definition GaussianBayesNet.cpp:111
GaussianBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
Construct from iterator over conditionals.
Definition GaussianBayesNet.h:53
A GaussianConditional functions as the node in a Bayes network.
Definition GaussianConditional.h:43
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73