gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IterativeSolver.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 #pragma once
13 
14 #include <gtsam/base/Vector.h>
15 #include <gtsam/global_includes.h>
17 #include <boost/tuple/tuple.hpp>
18 #include <boost/optional/optional.hpp>
19 #include <boost/none.hpp>
20 #include <iosfwd>
21 #include <map>
22 #include <string>
23 #include <vector>
24 
25 namespace gtsam {
26 
27  // Forward declarations
28  class KeyInfo;
29  class KeyInfoEntry;
30  class GaussianFactorGraph;
31  class Values;
32  class VectorValues;
33 
34  /************************************************************************************/
38  class GTSAM_EXPORT IterativeOptimizationParameters {
39 
40  public:
41 
42  typedef boost::shared_ptr<IterativeOptimizationParameters> shared_ptr;
43  enum Verbosity { SILENT = 0, COMPLEXITY, ERROR } verbosity_;
44 
45  public:
46 
47  IterativeOptimizationParameters(Verbosity v = SILENT)
48  : verbosity_(v) {}
49 
51 
52  /* utility */
53  inline Verbosity verbosity() const { return verbosity_; }
54  std::string getVerbosity() const;
55  void setVerbosity(const std::string &s) ;
56 
57  /* matlab interface */
58  void print() const ;
59 
60  /* virtual print function */
61  virtual void print(std::ostream &os) const ;
62 
63  /* for serialization */
64  friend std::ostream& operator<<(std::ostream &os, const IterativeOptimizationParameters &p);
65 
66  static Verbosity verbosityTranslator(const std::string &s);
67  static std::string verbosityTranslator(Verbosity v);
68  };
69 
70  /************************************************************************************/
71  class GTSAM_EXPORT IterativeSolver {
72  public:
73  typedef boost::shared_ptr<IterativeSolver> shared_ptr;
74  IterativeSolver() {}
75  virtual ~IterativeSolver() {}
76 
77  /* interface to the nonlinear optimizer, without metadata, damping and initial estimate */
79  const GaussianFactorGraph &gfg,
80  boost::optional<const KeyInfo&> = boost::none,
81  boost::optional<const std::map<Key, Vector>&> lambda = boost::none
82  );
83 
84  /* interface to the nonlinear optimizer, without initial estimate */
86  const GaussianFactorGraph &gfg,
87  const KeyInfo &keyInfo,
88  const std::map<Key, Vector> &lambda
89  );
90 
91  /* interface to the nonlinear optimizer that the subclasses have to implement */
92  virtual VectorValues optimize (
93  const GaussianFactorGraph &gfg,
94  const KeyInfo &keyInfo,
95  const std::map<Key, Vector> &lambda,
96  const VectorValues &initial
97  ) = 0;
98 
99  };
100 
101  /************************************************************************************/
102  /* Handy data structure for iterative solvers
103  * key to (index, dimension, colstart) */
104  class GTSAM_EXPORT KeyInfoEntry : public boost::tuple<size_t, size_t, size_t> {
105  public:
106  typedef boost::tuple<Key,size_t,Key> Base;
107  KeyInfoEntry(){}
108  KeyInfoEntry(size_t idx, size_t d, Key start) : Base(idx, d, start) {}
109  const size_t index() const { return this->get<0>(); }
110  const size_t dim() const { return this->get<1>(); }
111  const size_t colstart() const { return this->get<2>(); }
112  };
113 
114  /************************************************************************************/
115  class GTSAM_EXPORT KeyInfo : public std::map<Key, KeyInfoEntry> {
116  public:
117  typedef std::map<Key, KeyInfoEntry> Base;
118  KeyInfo() : numCols_(0) {}
119  KeyInfo(const GaussianFactorGraph &fg);
120  KeyInfo(const GaussianFactorGraph &fg, const Ordering &ordering);
121 
122  std::vector<size_t> colSpec() const ;
123  VectorValues x0() const;
124  Vector x0vector() const;
125 
126  inline size_t numCols() const { return numCols_; }
127  inline const Ordering & ordering() const { return ordering_; }
128 
129  protected:
130 
131  void initialize(const GaussianFactorGraph &fg);
132 
133  Ordering ordering_;
134  size_t numCols_;
135 
136  };
137 
138 
139 }
parameters for iterative linear solvers
Definition: IterativeSolver.h:38
typedef and functions to augment Eigen's VectorXd
Definition: IterativeSolver.h:104
Included from all GTSAM files.
size_t dim(const Vector &v)
dimensionality == size
Definition: Vector.h:90
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Definition: IterativeSolver.h:115
size_t Key
Integer nonlinear key type.
Definition: types.h:59
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition: triangulation.cpp:72
Definition: IterativeSolver.h:71
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:89
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:65
Definition: Ordering.h:30