gtsam  4.1.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
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 
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 
141  const GaussianFactorGraph& fg,
142  const VectorValues& x,
143  const ConjugateGradientParameters & parameters);
144 
145 
146 } // namespace gtsam
147 
149 
gtsam::GaussianFactorGraph
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:68
gtsam::System::b
const Vector & b() const
Access b vector.
Definition: iterative.h:60
gtsam::ConjugateGradientParameters
parameters for the conjugate gradient method
Definition: ConjugateGradientSolver.h:29
gtsam::IterativeOptimizationParameters
parameters for iterative linear solvers
Definition: IterativeSolver.h:44
ConjugateGradientSolver.h
Implementation of Conjugate Gradient solver for a linear system.
gtsam::System::gradient
Vector gradient(const Vector &x) const
gradient of objective function 0.5*|Ax-b_|^2 at x = A_'*(Ax-b_)
Definition: iterative.h:73
gtsam::System::A
const Matrix & A() const
Access A matrix.
Definition: iterative.h:57
gtsam::VectorValues
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:74
VectorValues.h
Factor Graph Values.
gtsam
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
gtsam::System::multiplyInPlace
void multiplyInPlace(const Vector &x, Vector &e) const
Apply operator A in place.
Definition: iterative.h:83
gtsam::System::operator*
Vector operator*(const Vector &x) const
Apply operator A.
Definition: iterative.h:78
gtsam::System
Helper class encapsulating the combined system |Ax-b_|^2 Needed to run Conjugate Gradients on matrice...
Definition: iterative.h:44
gtsam::conjugateGradientDescent
Vector conjugateGradientDescent(const System &Ab, const Vector &x, const ConjugateGradientParameters &parameters)
Method of conjugate gradients (CG), System version.
Definition: iterative.cpp:45
Matrix.h
typedef and functions to augment Eigen's MatrixXd
gtsam::System::operator^
Vector operator^(const Vector &e) const
Apply operator A'*e.
Definition: iterative.h:63
gtsam::System::transposeMultiplyAdd
void transposeMultiplyAdd(double alpha, const Vector &e, Vector &x) const
x += alpha* A'*e
Definition: iterative.h:88
gtsam::conjugateGradients
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
iterative-inl.h
Iterative methods, template implementation.