gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
23 #include <gtsam/nonlinear/Values.h>
24 
25 namespace gtsam {
26 
27 class JointMarginal;
28 
32 class GTSAM_EXPORT Marginals {
33 
34 public:
35 
38  CHOLESKY,
39  QR
40  };
41 
42 protected:
43 
44  GaussianFactorGraph graph_;
45  Values values_;
46  Factorization factorization_;
47  GaussianBayesTree bayesTree_;
48 
49 public:
50 
56  Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization = CHOLESKY);
57 
59  void print(const std::string& str = "Marginals: ", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
60 
62  Matrix marginalCovariance(Key variable) const;
63 
67  Matrix marginalInformation(Key variable) const;
68 
70  JointMarginal jointMarginalCovariance(const std::vector<Key>& variables) const;
71 
73  JointMarginal jointMarginalInformation(const std::vector<Key>& variables) const;
74 };
75 
79 class GTSAM_EXPORT JointMarginal {
80 
81 protected:
82  SymmetricBlockMatrix blockMatrix_;
83  std::vector<size_t> keys_;
84  FastMap<Key, size_t> indices_;
85 
86 public:
93 
107  Block operator()(Key iVariable, Key jVariable) const {
108  return blockMatrix_(indices_.at(iVariable), indices_.at(jVariable)); }
109 
111  Block at(Key iVariable, Key jVariable) const {
112  return (*this)(iVariable, jVariable); }
113 
119  Eigen::SelfAdjointView<const Matrix, Eigen::Upper> fullMatrix() const { return blockMatrix_.matrix(); }
120 
122  void print(const std::string& s = "", const KeyFormatter& formatter = DefaultKeyFormatter) const;
123 
124 protected:
125  JointMarginal(const Matrix& fullMatrix, const std::vector<size_t>& dims, const std::vector<Key>& keys) :
126  blockMatrix_(dims, fullMatrix), keys_(keys), indices_(Ordering(keys).invert()) {}
127 
128  friend class Marginals;
129 
130 };
131 
132 } /* namespace gtsam */
Factorization
The linear factorization mode - either CHOLESKY (faster and suitable for most problems) or QR (slower...
Definition: Marginals.h:37
A non-templated config holding any types of Manifold-group elements.
SymmetricBlockMatrix::constBlock Block
A block view of the joint marginal - this stores a reference to the JointMarginal object...
Definition: Marginals.h:92
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
Factor Graph Constsiting of non-linear factors.
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:75
Eigen::SelfAdjointView< const Matrix, Eigen::Upper > fullMatrix() const
The full, dense covariance/information matrix of the joint marginal.
Definition: Marginals.h:119
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
A non-linear factor graph is a graph of non-Gaussian, i.e.
Definition: NonlinearFactorGraph.h:69
A matrix expression that references a single block of a SymmetricBlockMatrix.
Definition: SymmetricBlockMatrixBlockExpr.h:22
A class to store and access a joint marginal, returned from Marginals::jointMarginalCovariance and Ma...
Definition: Marginals.h:79
size_t Key
Integer nonlinear key type.
Definition: types.h:59
Definition: SymmetricBlockMatrix.h:40
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:65
Definition: Ordering.h:30
A class for computing Gaussian marginals of variables in a NonlinearFactorGraph.
Definition: Marginals.h:32
Block operator()(Key iVariable, Key jVariable) const
Access a block, corresponding to a pair of variables, of the joint marginal.
Definition: Marginals.h:107
A Bayes tree representing a Gaussian density.
Definition: GaussianBayesTree.h:49
Block at(Key iVariable, Key jVariable) const
Synonym for operator()
Definition: Marginals.h:111
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62