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 <memory>
25 
26 #include <iosfwd>
27 #include <string>
28 #include <map>
29 #include <optional>
30 
31 namespace gtsam {
32 
33 // Forward declarations
34 struct KeyInfoEntry;
35 class KeyInfo;
36 class GaussianFactorGraph;
37 class Values;
38 class VectorValues;
39 
44  public:
45  typedef std::shared_ptr<IterativeOptimizationParameters> shared_ptr;
46  enum Verbosity { SILENT = 0, COMPLEXITY, ERROR };
47 
48  protected:
50 
51  public:
52 
54  verbosity_(v) {
55  }
56 
58  }
59 
60  /* utility */
61  inline Verbosity verbosity() const {
62  return verbosity_;
63  }
64  GTSAM_EXPORT std::string getVerbosity() const;
65  GTSAM_EXPORT void setVerbosity(const std::string &s);
66 
67  /* matlab interface */
68  GTSAM_EXPORT void print() const;
69 
70  /* virtual print function */
71  GTSAM_EXPORT virtual void print(std::ostream &os) const;
72 
73  GTSAM_EXPORT virtual bool equals(const IterativeOptimizationParameters &other,
74  double tol = 1e-9) const;
75 
76  /* for serialization */
77  GTSAM_EXPORT friend std::ostream &operator<<(
78  std::ostream &os, const IterativeOptimizationParameters &p);
79 
80  GTSAM_EXPORT static Verbosity verbosityTranslator(const std::string &s);
81  GTSAM_EXPORT static std::string verbosityTranslator(Verbosity v);
82 };
83 
88 public:
89  typedef std::shared_ptr<IterativeSolver> shared_ptr;
91  }
92  virtual ~IterativeSolver() {
93  }
94 
95  /* interface to the nonlinear optimizer, without metadata, damping and initial estimate */
96  GTSAM_EXPORT VectorValues optimize(const GaussianFactorGraph &gfg,
97  const KeyInfo* = nullptr,
98  const std::map<Key, Vector>* lambda = nullptr);
99 
100  /* interface to the nonlinear optimizer, without initial estimate */
101  GTSAM_EXPORT VectorValues optimize(const GaussianFactorGraph &gfg, const KeyInfo &keyInfo,
102  const std::map<Key, Vector> &lambda);
103 
104  /* interface to the nonlinear optimizer that the subclasses have to implement */
105  virtual VectorValues optimize(const GaussianFactorGraph &gfg,
106  const KeyInfo &keyInfo, const std::map<Key, Vector> &lambda,
107  const VectorValues &initial) = 0;
108 
109 };
110 
115 struct GTSAM_EXPORT KeyInfoEntry {
116  size_t index, dim, start;
118  }
119  KeyInfoEntry(size_t idx, size_t d, Key start) :
120  index(idx), dim(d), start(start) {
121  }
122 };
123 
127 class GTSAM_EXPORT KeyInfo: public std::map<Key, KeyInfoEntry> {
128 
129 public:
130 
131  typedef std::map<Key, KeyInfoEntry> Base;
132 
133 protected:
134 
136  size_t numCols_;
137 
138  void initialize(const GaussianFactorGraph &fg);
139 
140 public:
141 
144  numCols_(0) {
145  }
146 
148  KeyInfo(const GaussianFactorGraph &fg);
149 
151  KeyInfo(const GaussianFactorGraph &fg, const Ordering &ordering);
152 
154  inline size_t numCols() const {
155  return numCols_;
156  }
157 
159  inline const Ordering & ordering() const {
160  return ordering_;
161  }
162 
164  std::vector<size_t> colSpec() const;
165 
167  VectorValues x0() const;
168 
170  Vector x0vector() const;
171 
172 };
173 
174 } // \ namespace gtsam
gtsam::KeyInfo::ordering_
Ordering ordering_
Definition: IterativeSolver.h:135
VectorValues
gtsam::IterativeOptimizationParameters::COMPLEXITY
@ COMPLEXITY
Definition: IterativeSolver.h:46
gtsam::KeyInfo::ordering
const Ordering & ordering() const
Return the ordering.
Definition: IterativeSolver.h:159
gtsam::IterativeOptimizationParameters::shared_ptr
std::shared_ptr< IterativeOptimizationParameters > shared_ptr
Definition: IterativeSolver.h:45
Vector.h
typedef and functions to augment Eigen's VectorXd
gtsam::KeyInfo::Base
std::map< Key, KeyInfoEntry > Base
Definition: IterativeSolver.h:131
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
d
static const double d[K][N]
Definition: igam.h:11
gtsam::IterativeOptimizationParameters::print
GTSAM_EXPORT void print() const
Definition: IterativeSolver.cpp:39
gtsam::IterativeOptimizationParameters::getVerbosity
GTSAM_EXPORT std::string getVerbosity() const
Definition: IterativeSolver.cpp:29
Values
gtsam::IterativeOptimizationParameters::verbosity
Verbosity verbosity() const
Definition: IterativeSolver.h:61
Ordering.h
Variable ordering for the elimination algorithm.
os
ofstream os("timeSchurFactors.csv")
gtsam::IterativeSolver
Definition: IterativeSolver.h:87
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::KeyInfo::numCols
size_t numCols() const
Return the total number of columns (scalar variables = sum of dimensions)
Definition: IterativeSolver.h:154
gtsam::KeyInfo
Definition: IterativeSolver.h:127
gtsam::KeyInfoEntry::KeyInfoEntry
KeyInfoEntry(size_t idx, size_t d, Key start)
Definition: IterativeSolver.h:119
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam::IterativeSolver::shared_ptr
std::shared_ptr< IterativeSolver > shared_ptr
Definition: IterativeSolver.h:89
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::IterativeSolver::~IterativeSolver
virtual ~IterativeSolver()
Definition: IterativeSolver.h:92
gtsam::IterativeOptimizationParameters::setVerbosity
GTSAM_EXPORT void setVerbosity(const std::string &s)
Definition: IterativeSolver.cpp:34
gtsam::IterativeOptimizationParameters::SILENT
@ SILENT
Definition: IterativeSolver.h:46
x0
static Symbol x0('x', 0)
gtsam::IterativeOptimizationParameters::ERROR
@ ERROR
Definition: IterativeSolver.h:46
gtsam::IterativeOptimizationParameters::operator<<
GTSAM_EXPORT friend std::ostream & operator<<(std::ostream &os, const IterativeOptimizationParameters &p)
gtsam::IterativeOptimizationParameters::verbosityTranslator
static GTSAM_EXPORT Verbosity verbosityTranslator(const std::string &s)
Definition: IterativeSolver.cpp:62
gtsam::IterativeOptimizationParameters::Verbosity
Verbosity
Definition: IterativeSolver.h:46
lambda
static double lambda[]
Definition: jv.c:524
gtsam::KeyInfoEntry::KeyInfoEntry
KeyInfoEntry()
Definition: IterativeSolver.h:117
ordering
static enum @1096 ordering
gtsam::IterativeSolver::optimize
GTSAM_EXPORT VectorValues optimize(const GaussianFactorGraph &gfg, const KeyInfo *=nullptr, const std::map< Key, Vector > *lambda=nullptr)
Definition: IterativeSolver.cpp:92
gtsam::IterativeOptimizationParameters::verbosity_
Verbosity verbosity_
Definition: IterativeSolver.h:49
gtsam
traits
Definition: SFMdata.h:40
p
float * p
Definition: Tutorial_Map_using.cpp:9
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::IterativeOptimizationParameters::~IterativeOptimizationParameters
virtual ~IterativeOptimizationParameters()
Definition: IterativeSolver.h:57
gtsam::tol
const G double tol
Definition: Group.h:79
initial
Definition: testScenarioRunner.cpp:148
gtsam::IterativeOptimizationParameters
Definition: IterativeSolver.h:43
gtsam::IterativeSolver::IterativeSolver
IterativeSolver()
Definition: IterativeSolver.h:90
gtsam::KeyInfoEntry::start
size_t start
Definition: IterativeSolver.h:116
gtsam::KeyInfo::numCols_
size_t numCols_
Definition: IterativeSolver.h:136
gtsam::IterativeOptimizationParameters::IterativeOptimizationParameters
IterativeOptimizationParameters(Verbosity v=SILENT)
Definition: IterativeSolver.h:53
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::KeyInfo::KeyInfo
KeyInfo()
Default Constructor.
Definition: IterativeSolver.h:143
gtsam::Ordering
Definition: inference/Ordering.h:33
gtsam::IterativeOptimizationParameters::equals
virtual GTSAM_EXPORT bool equals(const IterativeOptimizationParameters &other, double tol=1e-9) const
Definition: IterativeSolver.cpp:50
gtsam::lago::initialize
Values initialize(const NonlinearFactorGraph &graph, bool useOdometricPath)
Definition: lago.cpp:375
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::KeyInfoEntry
Definition: IterativeSolver.h:115


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:54