Loading...
Searching...
No Matches
Marginals.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/linear/GaussianBayesTree.h>
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
#include <gtsam/nonlinear/Values.h>
namespace gtsam {
class JointMarginal;
class GTSAM_EXPORT Marginals {
public:
enum Factorization {
CHOLESKY,
QR
};
protected:
GaussianFactorGraph graph_;
Values values_;
Factorization factorization_;
GaussianBayesTree bayesTree_;
public:
Marginals(){}
Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization = CHOLESKY);
Marginals(const NonlinearFactorGraph& graph, const Values& solution, const Ordering& ordering,
Factorization factorization = CHOLESKY);
Marginals(const GaussianFactorGraph& graph, const Values& solution, Factorization factorization = CHOLESKY);
Marginals(const GaussianFactorGraph& graph, const Values& solution, const Ordering& ordering,
Factorization factorization = CHOLESKY);
Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, Factorization factorization = CHOLESKY);
Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, const Ordering& ordering,
Factorization factorization = CHOLESKY);
void print(const std::string& str = "Marginals: ", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
GaussianFactor::shared_ptr marginalFactor(Key variable) const;
Matrix marginalInformation(Key variable) const;
Matrix marginalCovariance(Key variable) const;
JointMarginal jointMarginalCovariance(const KeyVector& variables) const;
JointMarginal jointMarginalInformation(const KeyVector& variables) const;
VectorValues optimize() const;
protected:
void computeBayesTree();
void computeBayesTree(const Ordering& ordering);
public:
#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
GTSAM_DEPRECATED Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization,
const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
GTSAM_DEPRECATED Marginals(const GaussianFactorGraph& graph, const Values& solution, Factorization factorization,
const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
GTSAM_DEPRECATED Marginals(const GaussianFactorGraph& graph, const VectorValues& solution, Factorization factorization,
const Ordering& ordering) : Marginals(graph, solution, ordering, factorization) {}
#endif
};
class GTSAM_EXPORT JointMarginal {
protected:
SymmetricBlockMatrix blockMatrix_;
KeyVector keys_;
FastMap<Key, size_t> indices_;
public:
JointMarginal() {}
Matrix operator()(Key iVariable, Key jVariable) const {
const auto indexI = indices_.at(iVariable);
const auto indexJ = indices_.at(jVariable);
return blockMatrix_.block(indexI, indexJ);
}
Matrix at(Key iVariable, Key jVariable) const {
return (*this)(iVariable, jVariable);
}
Matrix fullMatrix() const {
return blockMatrix_.selfadjointView();
}
void print(const std::string& s = "", const KeyFormatter& formatter = DefaultKeyFormatter) const;
protected:
JointMarginal(const Matrix& fullMatrix, const std::vector<size_t>& dims, const KeyVector& keys) :
blockMatrix_(dims, fullMatrix), keys_(keys), indices_(Ordering(keys).invert()) {}
friend class Marginals;
};
} /* namespace gtsam */
GaussianBayesTree.h
Gaussian Bayes Tree, the result of eliminating a GaussianJunctionTree.
NonlinearFactorGraph.h
Factor Graph consisting of non-linear factors.
Values.h
A non-templated config holding any types of Manifold-group elements.
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
gtsam::optimize
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition triangulation.cpp:155
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
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::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
gtsam::FastMap
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:38
gtsam::SymmetricBlockMatrix
This class stores a dense matrix and allows it to be accessed as a collection of blocks.
Definition SymmetricBlockMatrix.h:52
gtsam::Ordering
Definition Ordering.h:34
gtsam::GaussianBayesTree
A Bayes tree representing a Gaussian density.
Definition GaussianBayesTree.h:52
gtsam::GaussianFactor::shared_ptr
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianFactor.h:42
gtsam::GaussianFactorGraph
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition GaussianFactorGraph.h:75
gtsam::VectorValues
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:74
gtsam::Marginals
A class for computing Gaussian marginals of variables in a NonlinearFactorGraph.
Definition Marginals.h:32
gtsam::Marginals::Factorization
Factorization
The linear factorization mode - either CHOLESKY (faster and suitable for most problems) or QR (slower...
Definition Marginals.h:37
gtsam::Marginals::Marginals
Marginals()
Default constructor only for wrappers.
Definition Marginals.h:52
gtsam::JointMarginal
A class to store and access a joint marginal, returned from Marginals::jointMarginalCovariance and Ma...
Definition Marginals.h:153
gtsam::JointMarginal::at
Matrix at(Key iVariable, Key jVariable) const
Synonym for operator().
Definition Marginals.h:184
gtsam::JointMarginal::fullMatrix
Matrix fullMatrix() const
The full, dense covariance/information matrix of the joint marginal.
Definition Marginals.h:189
gtsam::JointMarginal::operator()
Matrix operator()(Key iVariable, Key jVariable) const
Access a block, corresponding to a pair of variables, of the joint marginal.
Definition Marginals.h:177
gtsam::JointMarginal::JointMarginal
JointMarginal()
Default constructor only for wrappers.
Definition Marginals.h:162
gtsam::NonlinearFactorGraph
Definition NonlinearFactorGraph.h:55
gtsam::Values
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
Values
In nonlinear factors, the error function returns the negative log-likelihood as a non-linear function...