gtsam  4.0.0 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
8  * See LICENSE for the license information
9
10  * -------------------------------------------------------------------------- */
11
19 #pragma once
20
21 #include <gtsam/base/Matrix.h>
24
25 namespace 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
104  GTSAM_EXPORT Vector conjugateGradientDescent(
105  const System& Ab,
106  const Vector& x,
107  const ConjugateGradientParameters & parameters);
108
114  GTSAM_EXPORT Vector steepestDescent(
115  const Matrix& A,
116  const Vector& b,
117  const Vector& x,
118  const ConjugateGradientParameters & parameters);
119
123  GTSAM_EXPORT Vector conjugateGradientDescent(
124  const Matrix& A,
125  const Vector& b,
126  const Vector& x,
127  const ConjugateGradientParameters & parameters);
128
132  GTSAM_EXPORT VectorValues steepestDescent(
133  const GaussianFactorGraph& fg,
134  const VectorValues& x,
135  const ConjugateGradientParameters & parameters);
136
140  GTSAM_EXPORT VectorValues conjugateGradientDescent(
141  const GaussianFactorGraph& fg,
142  const VectorValues& x,
143  const ConjugateGradientParameters & parameters);
144
145
146 } // namespace gtsam
147
149
Vector gradient(const Vector &x) const
gradient of objective function 0.5*|Ax-b_|^2 at x = A_'*(Ax-b_)
Definition: iterative.h:73
void multiplyInPlace(const Vector &x, Vector &e) const
Apply operator A in place.
Definition: iterative.h:83
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
V conjugateGradients(const S &Ab, V x, const ConjugateGradientParameters &parameters, bool steepest)
Method of conjugate gradients (CG) template "System" class S needs gradient(S,v), e=S*v,...
Definition: iterative-inl.h:125
const Matrix & A() const
Access A matrix.
Definition: iterative.h:57
void transposeMultiplyAdd(double alpha, const Vector &e, Vector &x) const
x += alpha* A'*e
Definition: iterative.h:88
Iterative methods, template implementation.
const Vector & b() const
Access b vector.
Definition: iterative.h:60
Implementation of Conjugate Gradient solver for a linear system.
Helper class encapsulating the combined system |Ax-b_|^2 Needed to run Conjugate Gradients on matrice...
Definition: iterative.h:44
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
typedef and functions to augment Eigen's MatrixXd
Factor Graph Values.
Point2 operator *(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:170
Vector conjugateGradientDescent(const System &Ab, const Vector &x, const ConjugateGradientParameters &parameters)
Method of conjugate gradients (CG), System version.
Definition: iterative.cpp:45
Vector operator^(const Vector &e) const
Apply operator A'*e.
Definition: iterative.h:63