gtsam
Loading...
Searching...
No Matches
GaussianFactor.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
24#include <gtsam/base/Matrix.h>
25#include <gtsam/base/Testable.h>
26
27namespace gtsam {
28
29 // Forward declarations
30 class VectorValues;
31 class Scatter;
33
38 class GTSAM_EXPORT GaussianFactor : public Factor
39 {
40 public:
42 typedef std::shared_ptr<This> shared_ptr;
43 typedef Factor Base;
44
47
50
53 template<typename CONTAINER>
54 GaussianFactor(const CONTAINER& keys) : Base(keys) {}
55
59
61 void print(
62 const std::string& s = "",
63 const KeyFormatter& formatter = DefaultKeyFormatter) const override = 0;
64
66 virtual bool equals(const GaussianFactor& lf, double tol = 1e-9) const = 0;
67
71
79 virtual double error(const VectorValues& c) const;
80
85 virtual double deltaError(const VectorValues& c, double* oldError = nullptr,
86 double* newError = nullptr) const;
87
92 double error(const HybridValues& c) const override;
93
95 virtual DenseIndex getDim(const_iterator variable) const = 0;
96
104 virtual Matrix augmentedJacobian() const = 0;
105
113 virtual std::pair<Matrix,Vector> jacobian() const = 0;
114
123 virtual Matrix augmentedInformation() const = 0;
124
128 virtual Matrix information() const = 0;
129
132
134 virtual void hessianDiagonalAdd(VectorValues& d) const = 0;
135
137 virtual void hessianDiagonal(double* d) const = 0;
138
140 virtual std::map<Key,Matrix> hessianBlockDiagonal() const = 0;
141
144
151
157 virtual void updateHessian(const KeyVector& keys,
158 SymmetricBlockMatrix* info) const = 0;
159
168 virtual void updateHessian(const KeyVector& keys,
170 DenseIndex beginCol, DenseIndex endCol) const = 0;
171
175
177 virtual void multiplyHessianAdd(double alpha, const VectorValues& x, VectorValues& y) const = 0;
178
180 virtual VectorValues gradientAtZero() const = 0;
181
183 virtual void gradientAtZero(double* d) const = 0;
184
186 virtual Vector gradient(Key key, const VectorValues& x) const = 0;
187
191
193 virtual bool isJacobian() const { return false; }
194
195 // Determine position of a given key
196 template <typename CONTAINER>
197 static DenseIndex Slot(const CONTAINER& keys, Key key) {
198 return std::find(keys.begin(), keys.end(), key) - keys.begin();
199 }
200
202
203 private:
204#if GTSAM_ENABLE_BOOST_SERIALIZATION
206 friend class boost::serialization::access;
207 template<class ARCHIVE>
208 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
209 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
210 }
211#endif
212 }; // GaussianFactor
213
215template<>
216struct traits<GaussianFactor> : public Testable<GaussianFactor> {
217};
218
219} // \ namespace gtsam
typedef and functions to augment Eigen's MatrixXd
Concept check for values that can be used in unit tests.
The base class for all factors.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition types.h:49
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
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
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
This class stores a dense matrix and allows it to be accessed as a collection of blocks.
Definition SymmetricBlockMatrix.h:80
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143
Factor()
Default constructor for I/O.
Definition Factor.h:94
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition Factor.h:83
An abstract virtual base class for JacobianFactor and HessianFactor.
Definition GaussianFactor.h:39
virtual DenseIndex getDim(const_iterator variable) const =0
Return the dimension of the variable pointed to by the given key iterator.
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianFactor.h:42
virtual std::map< Key, Matrix > hessianBlockDiagonal() const =0
Return the block diagonal of the Hessian for this factor.
virtual std::pair< Matrix, Vector > jacobian() const =0
Return the dense Jacobian and right-hand-side , with the noise models baked into A and b.
virtual Vector gradient(Key key, const VectorValues &x) const =0
Gradient wrt a key at any values.
virtual void updateHessian(const KeyVector &keys, SymmetricBlockMatrix *info, DenseIndex beginCol, DenseIndex endCol) const =0
Update an information matrix by adding the information corresponding to this factor (used internally ...
virtual bool isJacobian() const
Fast check for JacobianFactor-based types.
Definition GaussianFactor.h:193
virtual GaussianFactor::shared_ptr clone() const =0
Clone a factor (make a deep copy).
virtual Matrix information() const =0
Return the non-augmented information matrix represented by this GaussianFactor.
Factor Base
Our base class.
Definition GaussianFactor.h:43
virtual VectorValues gradientAtZero() const =0
A'*b for Jacobian, eta for Hessian.
GaussianFactor(const CONTAINER &keys)
Construct from container of keys.
Definition GaussianFactor.h:54
virtual void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const =0
y += alpha * A'*A*x
virtual bool equals(const GaussianFactor &lf, double tol=1e-9) const =0
assert equality up to a tolerance
virtual Matrix augmentedInformation() const =0
Return the augmented information matrix represented by this GaussianFactor.
virtual Matrix augmentedJacobian() const =0
Return a dense Jacobian matrix, augmented with b with the noise models baked into A and b.
GaussianFactor()
Default constructor creates empty factor.
Definition GaussianFactor.h:49
VectorValues hessianDiagonal() const
Return the diagonal of the Hessian for this factor.
Definition GaussianFactor.cpp:49
virtual GaussianFactor::shared_ptr negate() const =0
Construct the corresponding anti-factor to negate information stored stored in this factor.
virtual void hessianDiagonal(double *d) const =0
Raw memory access version of hessianDiagonal.
GaussianFactor This
This class.
Definition GaussianFactor.h:41
virtual void updateHessian(const KeyVector &keys, SymmetricBlockMatrix *info) const =0
Update an information matrix by adding the information corresponding to this factor (used internally ...
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override=0
print with optional string
virtual void hessianDiagonalAdd(VectorValues &d) const =0
Add the current diagonal to a VectorValues instance.
virtual void gradientAtZero(double *d) const =0
Raw memory access version of gradientAtZero.
Scatter is an intermediate data structure used when building a HessianFactor incrementally,...
Definition Scatter.h:49
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73
the error.
The Factor::error simply extracts the.