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 
39  QR
40  };
41 
42 protected:
43 
48 
49 public:
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 
125 protected:
126 
128  void computeBayesTree();
129 
131  void computeBayesTree(const Ordering& ordering);
132 
133 public:
135  Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization,
136  const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
137 
139  Marginals(const GaussianFactorGraph& graph, const Values& solution, Factorization factorization,
140  const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
141 
143  Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, Factorization factorization,
144  const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
145 
146 };
147 
151 class GTSAM_EXPORT JointMarginal {
152 
153 protected:
157 
158 public:
161 
175  Matrix operator()(Key iVariable, Key jVariable) const {
176  const auto indexI = indices_.at(iVariable);
177  const auto indexJ = indices_.at(jVariable);
178  return blockMatrix_.block(indexI, indexJ);
179  }
180 
182  Matrix at(Key iVariable, Key jVariable) const {
183  return (*this)(iVariable, jVariable);
184  }
185 
187  Matrix fullMatrix() const {
188  return blockMatrix_.selfadjointView();
189  }
190 
192  void print(const std::string& s = "", const KeyFormatter& formatter = DefaultKeyFormatter) const;
193 
194 protected:
195  JointMarginal(const Matrix& fullMatrix, const std::vector<size_t>& dims, const KeyVector& keys) :
196  blockMatrix_(dims, fullMatrix), keys_(keys), indices_(Ordering(keys).invert()) {}
197 
198  friend class Marginals;
199 
200 };
201 
202 } /* namespace gtsam */
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
GaussianFactorGraph graph_
Definition: Marginals.h:44
A non-templated config holding any types of Manifold-group elements.
Factor Graph consisting of non-linear factors.
static enum @843 ordering
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
NonlinearFactorGraph graph
Matrix operator()(Key iVariable, Key jVariable) const
Definition: Marginals.h:175
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
Values values_
Definition: Marginals.h:45
const KeyFormatter & formatter
JointMarginal(const Matrix &fullMatrix, const std::vector< size_t > &dims, const KeyVector &keys)
Definition: Marginals.h:195
Marginals(const GaussianFactorGraph &graph, const Values &solution, Factorization factorization, const Ordering &ordering)
Definition: Marginals.h:139
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)
GaussianBayesTree bayesTree_
Definition: Marginals.h:47
SymmetricBlockMatrix blockMatrix_
Definition: Marginals.h:154
Marginals(const GaussianFactorGraph &graph, const VectorValues &solution, Factorization factorization, const Ordering &ordering)
Definition: Marginals.h:143
FastMap< Key, size_t > indices_
Definition: Marginals.h:156
Definition: pytypes.h:928
Marginals()
Default constructor only for wrappers.
Definition: Marginals.h:52
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
RealScalar s
Matrix at(Key iVariable, Key jVariable) const
Definition: Marginals.h:182
JointMarginal()
Default constructor only for wrappers.
Definition: Marginals.h:160
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
traits
Definition: chartTesting.h:28
Matrix block(DenseIndex I, DenseIndex J) const
Factorization factorization_
Definition: Marginals.h:46
Eigen::SelfAdjointView< constBlock, Eigen::Upper > selfadjointView(DenseIndex I, DenseIndex J) const
Return the square sub-matrix that contains blocks(i:j, i:j).
Matrix fullMatrix() const
Definition: Marginals.h:187
const KeyVector keys
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
Marginals(const NonlinearFactorGraph &graph, const Values &solution, Factorization factorization, const Ordering &ordering)
Definition: Marginals.h:135
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:45