gtsam  4.0.0
gtsam
IterativeSolver.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 
22 #include <gtsam/base/Vector.h>
23 
24 #include <boost/tuple/tuple.hpp>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/optional.hpp>
27 
28 #include <iosfwd>
29 #include <string>
30 #include <map>
31 
32 namespace gtsam {
33 
34 // Forward declarations
35 class KeyInfo;
36 class KeyInfoEntry;
37 class GaussianFactorGraph;
38 class Values;
39 class VectorValues;
40 
44 class GTSAM_EXPORT IterativeOptimizationParameters {
45 
46 public:
47 
48  typedef boost::shared_ptr<IterativeOptimizationParameters> shared_ptr;
49  enum Verbosity {
50  SILENT = 0, COMPLEXITY, ERROR
51  } verbosity_;
52 
53 public:
54 
55  IterativeOptimizationParameters(Verbosity v = SILENT) :
56  verbosity_(v) {
57  }
58 
60  }
61 
62  /* utility */
63  inline Verbosity verbosity() const {
64  return verbosity_;
65  }
66  std::string getVerbosity() const;
67  void setVerbosity(const std::string &s);
68 
69  /* matlab interface */
70  void print() const;
71 
72  /* virtual print function */
73  virtual void print(std::ostream &os) const;
74 
75  /* for serialization */
76  friend std::ostream& operator<<(std::ostream &os,
78 
79  static Verbosity verbosityTranslator(const std::string &s);
80  static std::string verbosityTranslator(Verbosity v);
81 };
82 
86 class GTSAM_EXPORT IterativeSolver {
87 public:
88  typedef boost::shared_ptr<IterativeSolver> shared_ptr;
89  IterativeSolver() {
90  }
91  virtual ~IterativeSolver() {
92  }
93 
94  /* interface to the nonlinear optimizer, without metadata, damping and initial estimate */
96  boost::optional<const KeyInfo&> = boost::none,
97  boost::optional<const std::map<Key, Vector>&> lambda = boost::none);
98 
99  /* interface to the nonlinear optimizer, without initial estimate */
100  VectorValues optimize(const GaussianFactorGraph &gfg, const KeyInfo &keyInfo,
101  const std::map<Key, Vector> &lambda);
102 
103  /* interface to the nonlinear optimizer that the subclasses have to implement */
104  virtual VectorValues optimize(const GaussianFactorGraph &gfg,
105  const KeyInfo &keyInfo, const std::map<Key, Vector> &lambda,
106  const VectorValues &initial) = 0;
107 
108 };
109 
114 class GTSAM_EXPORT KeyInfoEntry: public boost::tuple<Key, size_t, Key> {
115 
116 public:
117 
118  typedef boost::tuple<Key, size_t, Key> Base;
119 
120  KeyInfoEntry() {
121  }
122  KeyInfoEntry(size_t idx, size_t d, Key start) :
123  Base(idx, d, start) {
124  }
125  size_t index() const {
126  return this->get<0>();
127  }
128  size_t dim() const {
129  return this->get<1>();
130  }
131  size_t colstart() const {
132  return this->get<2>();
133  }
134 };
135 
139 class GTSAM_EXPORT KeyInfo: public std::map<Key, KeyInfoEntry> {
140 
141 public:
142 
143  typedef std::map<Key, KeyInfoEntry> Base;
144 
145 protected:
146 
147  Ordering ordering_;
148  size_t numCols_;
149 
150  void initialize(const GaussianFactorGraph &fg);
151 
152 public:
153 
156  numCols_(0) {
157  }
158 
160  KeyInfo(const GaussianFactorGraph &fg);
161 
163  KeyInfo(const GaussianFactorGraph &fg, const Ordering &ordering);
164 
166  inline size_t numCols() const {
167  return numCols_;
168  }
169 
171  inline const Ordering & ordering() const {
172  return ordering_;
173  }
174 
176  std::vector<size_t> colSpec() const;
177 
179  VectorValues x0() const;
180 
182  Vector x0vector() const;
183 
184 };
185 
186 } // \ namespace gtsam
Handy data structure for iterative solvers key to (index, dimension, colstart)
Definition: IterativeSolver.h:114
Base class for Iterative Solvers like SubgraphSolver.
Definition: IterativeSolver.h:86
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
typedef and functions to augment Eigen&#39;s VectorXd
Handy data structure for iterative solvers.
Definition: IterativeSolver.h:139
parameters for iterative linear solvers
Definition: IterativeSolver.h:44
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:90
size_t numCols() const
Return the total number of columns (scalar variables = sum of dimensions)
Definition: IterativeSolver.h:166
const Ordering & ordering() const
Return the ordering.
Definition: IterativeSolver.h:171
KeyInfo()
Default Constructor.
Definition: IterativeSolver.h:155
Definition: Ordering.h:33
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition: triangulation.cpp:73
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:65
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Global functions in a separate testing namespace.
Definition: chartTesting.h:28