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 struct KeyInfoEntry;
36 class KeyInfo;
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 struct GTSAM_EXPORT KeyInfoEntry {
115  size_t index, dim, start;
116  KeyInfoEntry() {
117  }
118  KeyInfoEntry(size_t idx, size_t d, Key start) :
119  index(idx), dim(d), start(start) {
120  }
121 };
122 
126 class GTSAM_EXPORT KeyInfo: public std::map<Key, KeyInfoEntry> {
127 
128 public:
129 
130  typedef std::map<Key, KeyInfoEntry> Base;
131 
132 protected:
133 
134  Ordering ordering_;
135  size_t numCols_;
136 
137  void initialize(const GaussianFactorGraph &fg);
138 
139 public:
140 
143  numCols_(0) {
144  }
145 
147  KeyInfo(const GaussianFactorGraph &fg);
148 
150  KeyInfo(const GaussianFactorGraph &fg, const Ordering &ordering);
151 
153  inline size_t numCols() const {
154  return numCols_;
155  }
156 
158  inline const Ordering & ordering() const {
159  return ordering_;
160  }
161 
163  std::vector<size_t> colSpec() const;
164 
166  VectorValues x0() const;
167 
169  Vector x0vector() const;
170 
171 };
172 
173 } // \ namespace gtsam
KeyInfo()
Default Constructor.
Definition: IterativeSolver.h:142
Base class for Iterative Solvers like SubgraphSolver.
Definition: IterativeSolver.h:86
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
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Variable ordering for the elimination algorithm.
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:65
const Ordering & ordering() const
Return the ordering.
Definition: IterativeSolver.h:158
Handy data structure for iterative solvers.
Definition: IterativeSolver.h:126
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:73
Handy data structure for iterative solvers key to (index, dimension, start)
Definition: IterativeSolver.h:114
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Definition: Ordering.h:34
typedef and functions to augment Eigen's VectorXd
size_t numCols() const
Return the total number of columns (scalar variables = sum of dimensions)
Definition: IterativeSolver.h:153