gtsam  4.0.0
gtsam
PCGSolver.h
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 
12 /*
13  * @file PCGSolver.h
14  * @brief Preconditioned Conjugate Gradient Solver for linear systems
15  * @date Jan 31, 2012
16  * @author Yong-Dian Jian
17  * @author Sungtae An
18  */
19 
20 #pragma once
21 
23 #include <string>
24 
25 namespace gtsam {
26 
27 class GaussianFactorGraph;
28 class KeyInfo;
29 class Preconditioner;
30 class VectorValues;
31 struct PreconditionerParameters;
32 
36 struct GTSAM_EXPORT PCGSolverParameters: public ConjugateGradientParameters {
37 public:
39  typedef boost::shared_ptr<PCGSolverParameters> shared_ptr;
40 
42  }
43 
44  virtual void print(std::ostream &os) const;
45 
46  /* interface to preconditioner parameters */
47  inline const PreconditionerParameters& preconditioner() const {
48  return *preconditioner_;
49  }
50 
51  boost::shared_ptr<PreconditionerParameters> preconditioner_;
52 };
53 
57 class GTSAM_EXPORT PCGSolver: public IterativeSolver {
58 public:
59  typedef IterativeSolver Base;
60  typedef boost::shared_ptr<PCGSolver> shared_ptr;
61 
62 protected:
63 
64  PCGSolverParameters parameters_;
65  boost::shared_ptr<Preconditioner> preconditioner_;
66 
67 public:
68  /* Interface to initialize a solver without a problem */
70  virtual ~PCGSolver() {
71  }
72 
73  using IterativeSolver::optimize;
74 
75  virtual VectorValues optimize(const GaussianFactorGraph &gfg,
76  const KeyInfo &keyInfo, const std::map<Key, Vector> &lambda,
77  const VectorValues &initial);
78 
79 };
80 
84 class GTSAM_EXPORT GaussianFactorGraphSystem {
85 public:
86 
88  const Preconditioner &preconditioner, const KeyInfo &info,
89  const std::map<Key, Vector> &lambda);
90 
91  const GaussianFactorGraph &gfg_;
92  const Preconditioner &preconditioner_;
93  const KeyInfo &keyInfo_;
94  const std::map<Key, Vector> &lambda_;
95 
96  void residual(const Vector &x, Vector &r) const;
97  void multiply(const Vector &x, Vector& y) const;
98  void leftPrecondition(const Vector &x, Vector &y) const;
99  void rightPrecondition(const Vector &x, Vector &y) const;
100  inline void scal(const double alpha, Vector &x) const {
101  x *= alpha;
102  }
103  inline double dot(const Vector &x, const Vector &y) const {
104  return x.dot(y);
105  }
106  inline void axpy(const double alpha, const Vector &x, Vector &y) const {
107  y += alpha * x;
108  }
109 
110  void getb(Vector &b) const;
111 };
112 
115 
117 VectorValues buildVectorValues(const Vector &v, const Ordering &ordering,
118  const std::map<Key, size_t> & dimensions);
119 
121 VectorValues buildVectorValues(const Vector &v, const KeyInfo &keyInfo);
122 
124 
125 }
126 
VectorValues buildVectorValues(const Vector &v, const Ordering &ordering, const map< Key, size_t > &dimensions)
Create VectorValues from a Vector.
Definition: PCGSolver.cpp:129
Definition: Preconditioner.h:24
parameters for the conjugate gradient method
Definition: ConjugateGradientSolver.h:29
double dot(const V1 &a, const V2 &b)
Dot product.
Definition: Vector.h:162
Base class for Iterative Solvers like SubgraphSolver.
Definition: IterativeSolver.h:86
Parameters for PCG.
Definition: PCGSolver.h:36
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition: triangulation.cpp:73
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
System class needed for calling preconditionedConjugateGradient.
Definition: PCGSolver.h:84
void scal(double alpha, Vector &x)
BLAS Level 1 scal: x <- alpha*x.
Definition: Vector.h:178
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:65
Definition: Preconditioner.h:64
Handy data structure for iterative solvers.
Definition: IterativeSolver.h:126
parameters for iterative linear solvers
Definition: IterativeSolver.h:44
void axpy(double alpha, const V1 &x, V2 &y)
BLAS Level 1 axpy: y <- alpha*x + y.
Definition: Vector.h:185
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:73
Implementation of Conjugate Gradient solver for a linear system.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
A virtual base class for the preconditioned conjugate gradient solver.
Definition: PCGSolver.h:57
Definition: Ordering.h:34