gtsam 4.1.1 gtsam
iterative.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
9
10 * -------------------------------------------------------------------------- */
11
19#pragma once
20
21#include <gtsam/base/Matrix.h>
24
25namespace gtsam {
26
36 template<class S, class V, class E>
37 V conjugateGradients(const S& Ab, V x,
38 const ConjugateGradientParameters &parameters, bool steepest = false);
39
44 class GTSAM_EXPORT System {
45
46 private:
47 const Matrix& A_;
48 const Vector& b_;
49
50 public:
51
52 System(const Matrix& A, const Vector& b) :
53 A_(A), b_(b) {
54 }
55
57 const Matrix& A() const { return A_; }
58
60 const Vector& b() const { return b_; }
61
63 Vector operator^(const Vector& e) const {
64 return A_ ^ e;
65 }
66
70 void print (const std::string& s = "System") const;
71
73 Vector gradient(const Vector& x) const {
74 return A() ^ (A() * x - b());
75 }
76
78 Vector operator*(const Vector& x) const {
79 return A() * x;
80 }
81
83 void multiplyInPlace(const Vector& x, Vector& e) const {
84 e = A() * x;
85 }
86
88 void transposeMultiplyAdd(double alpha, const Vector& e, Vector& x) const {
89 x += alpha * A().transpose() * e;
90 }
91 };
92
96 GTSAM_EXPORT Vector steepestDescent(
97 const System& Ab,
98 const Vector& x,
99 const IterativeOptimizationParameters & parameters);
100
105 const System& Ab,
106 const Vector& x,
108
114 GTSAM_EXPORT Vector steepestDescent(
115 const Matrix& A,
116 const Vector& b,
117 const Vector& x,
119
124 const Matrix& A,
125 const Vector& b,
126 const Vector& x,
128
132 GTSAM_EXPORT VectorValues steepestDescent(
133 const GaussianFactorGraph& fg,
134 const VectorValues& x,
136
141 const GaussianFactorGraph& fg,
142 const VectorValues& x,
144
145
146} // namespace gtsam
147
149
typedef and functions to augment Eigen's MatrixXd
Factor Graph Values.
Implementation of Conjugate Gradient solver for a linear system.
Iterative methods, template implementation.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
Method of conjugate gradients (CG) template "System" class S needs gradient(S,v), e=S*v,...
Definition: iterative-inl.h:125
Method of conjugate gradients (CG), System version.
Definition: iterative.cpp:45
parameters for the conjugate gradient method
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:69
Helper class encapsulating the combined system |Ax-b_|^2 Needed to run Conjugate Gradients on matrice...
Definition: iterative.h:44
Vector operator*(const Vector &x) const
Apply operator A.
Definition: iterative.h:78
const Matrix & A() const
Access A matrix.
Definition: iterative.h:57
void multiplyInPlace(const Vector &x, Vector &e) const
Apply operator A in place.
Definition: iterative.h:83
const Vector & b() const
Access b vector.
Definition: iterative.h:60