gtsam 4.1.1
gtsam
Marginals.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
19#pragma once
20
24
25namespace gtsam {
26
27class JointMarginal;
28
32class GTSAM_EXPORT Marginals {
33
34public:
35
38 CHOLESKY,
39 QR
40 };
41
42protected:
43
45 Values values_;
46 Factorization factorization_;
47 GaussianBayesTree bayesTree_;
48
49public:
50
53
59 Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization = CHOLESKY);
60
67 Marginals(const NonlinearFactorGraph& graph, const Values& solution, const Ordering& ordering,
68 Factorization factorization = CHOLESKY);
69
75 Marginals(const GaussianFactorGraph& graph, const Values& solution, Factorization factorization = CHOLESKY);
76
83 Marginals(const GaussianFactorGraph& graph, const Values& solution, const Ordering& ordering,
84 Factorization factorization = CHOLESKY);
85
92 Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, Factorization factorization = CHOLESKY);
93
100 Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, const Ordering& ordering,
101 Factorization factorization = CHOLESKY);
102
104 void print(const std::string& str = "Marginals: ", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
105
107 GaussianFactor::shared_ptr marginalFactor(Key variable) const;
108
111 Matrix marginalInformation(Key variable) const;
112
114 Matrix marginalCovariance(Key variable) const;
115
117 JointMarginal jointMarginalCovariance(const KeyVector& variables) const;
118
120 JointMarginal jointMarginalInformation(const KeyVector& variables) const;
121
123 VectorValues optimize() const;
124
125protected:
126
128 void computeBayesTree();
129
131 void computeBayesTree(const Ordering& ordering);
132
133public:
134#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V41
136 GTSAM_DEPRECATED Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization,
137 const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
138
140 GTSAM_DEPRECATED Marginals(const GaussianFactorGraph& graph, const Values& solution, Factorization factorization,
141 const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
142
144 GTSAM_DEPRECATED Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, Factorization factorization,
145 const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
146#endif
147
148};
149
153class GTSAM_EXPORT JointMarginal {
154
155protected:
156 SymmetricBlockMatrix blockMatrix_;
157 KeyVector keys_;
158 FastMap<Key, size_t> indices_;
159
160public:
163
177 Matrix operator()(Key iVariable, Key jVariable) const {
178 const auto indexI = indices_.at(iVariable);
179 const auto indexJ = indices_.at(jVariable);
180 return blockMatrix_.block(indexI, indexJ);
181 }
182
184 Matrix at(Key iVariable, Key jVariable) const {
185 return (*this)(iVariable, jVariable);
186 }
187
189 Matrix fullMatrix() const {
190 return blockMatrix_.selfadjointView();
191 }
192
194 void print(const std::string& s = "", const KeyFormatter& formatter = DefaultKeyFormatter) const;
195
196protected:
197 JointMarginal(const Matrix& fullMatrix, const std::vector<size_t>& dims, const KeyVector& keys) :
198 blockMatrix_(dims, fullMatrix), keys_(keys), indices_(Ordering(keys).invert()) {}
199
200 friend class Marginals;
201
202};
203
204} /* namespace gtsam */
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
A non-templated config holding any types of Manifold-group elements.
Factor Graph consisting of non-linear factors.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition: triangulation.cpp:73
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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: SymmetricBlockMatrix.h:52
Matrix block(DenseIndex I, DenseIndex J) const
Get a copy of a block (anywhere in the matrix).
Definition: SymmetricBlockMatrix.cpp:54
Eigen::SelfAdjointView< constBlock, Eigen::Upper > selfadjointView(DenseIndex I, DenseIndex J) const
Return the square sub-matrix that contains blocks(i:j, i:j).
Definition: SymmetricBlockMatrix.h:161
Definition: Ordering.h:34
A Bayes tree representing a Gaussian density.
Definition: GaussianBayesTree.h:52
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:69
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:74
A class for computing Gaussian marginals of variables in a NonlinearFactorGraph.
Definition: Marginals.h:32
Factorization
The linear factorization mode - either CHOLESKY (faster and suitable for most problems) or QR (slower...
Definition: Marginals.h:37
Marginals()
Default constructor only for wrappers.
Definition: Marginals.h:52
A class to store and access a joint marginal, returned from Marginals::jointMarginalCovariance and Ma...
Definition: Marginals.h:153
Matrix at(Key iVariable, Key jVariable) const
Synonym for operator()
Definition: Marginals.h:184
Matrix fullMatrix() const
The full, dense covariance/information matrix of the joint marginal.
Definition: Marginals.h:189
Matrix operator()(Key iVariable, Key jVariable) const
Access a block, corresponding to a pair of variables, of the joint marginal.
Definition: Marginals.h:177
JointMarginal()
Default constructor only for wrappers.
Definition: Marginals.h:162
A non-linear factor graph is a graph of non-Gaussian, i.e.
Definition: NonlinearFactorGraph.h:78
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:63