GncParams.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 
27 #pragma once
28 
31 
32 namespace gtsam {
33 
34 /* ************************************************************************* */
37  GM /*Geman McClure*/,
38  TLS /*Truncated least squares*/
39 };
40 
41 template<class BaseOptimizerParameters>
42 class GncParams {
43  public:
45  typedef typename BaseOptimizerParameters::OptimizerType OptimizerType;
46 
48  enum Verbosity {
49  SILENT = 0,
52  };
53 
55  GncParams(const BaseOptimizerParameters& baseOptimizerParams)
56  : baseOptimizerParams(baseOptimizerParams) {
57  }
58 
62  }
63 
65  BaseOptimizerParameters baseOptimizerParams;
68  size_t maxIterations = 100;
69  double muStep = 1.4;
70  double relativeCostTol = 1e-5;
71  double weightsTol = 1e-4;
73  std::vector<size_t> knownInliers = std::vector<size_t>();
74 
77  lossType = type;
78  }
79 
81  void setMaxIterations(const size_t maxIter) {
82  std::cout
83  << "setMaxIterations: changing the max nr of iters might lead to less accurate solutions and is not recommended! "
84  << std::endl;
85  maxIterations = maxIter;
86  }
87 
89  void setMuStep(const double step) {
90  muStep = step;
91  }
92 
94  void setRelativeCostTol(double value) {
95  relativeCostTol = value;
96  }
97 
99  void setWeightsTol(double value) {
100  weightsTol = value;
101  }
102 
105  verbosity = value;
106  }
107 
114  void setKnownInliers(const std::vector<size_t>& knownIn) {
115  for (size_t i = 0; i < knownIn.size(); i++)
116  knownInliers.push_back(knownIn[i]);
117  }
118 
120  bool equals(const GncParams& other, double tol = 1e-9) const {
121  return baseOptimizerParams.equals(other.baseOptimizerParams)
122  && lossType == other.lossType && maxIterations == other.maxIterations
123  && std::fabs(muStep - other.muStep) <= tol
124  && verbosity == other.verbosity && knownInliers == other.knownInliers;
125  }
126 
128  void print(const std::string& str) const {
129  std::cout << str << "\n";
130  switch (lossType) {
131  case GM:
132  std::cout << "lossType: Geman McClure" << "\n";
133  break;
134  case TLS:
135  std::cout << "lossType: Truncated Least-squares" << "\n";
136  break;
137  default:
138  throw std::runtime_error("GncParams::print: unknown loss type.");
139  }
140  std::cout << "maxIterations: " << maxIterations << "\n";
141  std::cout << "muStep: " << muStep << "\n";
142  std::cout << "relativeCostTol: " << relativeCostTol << "\n";
143  std::cout << "weightsTol: " << weightsTol << "\n";
144  std::cout << "verbosity: " << verbosity << "\n";
145  for (size_t i = 0; i < knownInliers.size(); i++)
146  std::cout << "knownInliers: " << knownInliers[i] << "\n";
147  baseOptimizerParams.print(str);
148  }
149 };
150 
151 }
def step(data, isam, result, truth, currPoseIndex)
Definition: visual_isam.py:82
BaseOptimizerParameters::OptimizerType OptimizerType
For each parameter, specify the corresponding optimizer: e.g., GaussNewtonParams -> GaussNewtonOptimi...
Definition: GncParams.h:45
void setWeightsTol(double value)
Set the maximum difference between the weights and their rounding in {0,1} to stop iterating...
Definition: GncParams.h:99
Verbosity verbosity
Verbosity level.
Definition: GncParams.h:72
GncLossType lossType
any other specific GNC parameters:
Definition: GncParams.h:67
GncParams()
Default constructor.
Definition: GncParams.h:60
double muStep
Multiplicative factor to reduce/increase the mu in gnc.
Definition: GncParams.h:69
double relativeCostTol
If relative cost change is below this threshold, stop iterating.
Definition: GncParams.h:70
BaseOptimizerParameters baseOptimizerParams
GNC parameters.
Definition: GncParams.h:65
double weightsTol
If the weights are within weightsTol from being binary, stop iterating (only for TLS) ...
Definition: GncParams.h:71
Real fabs(const Real &a)
void setKnownInliers(const std::vector< size_t > &knownIn)
Definition: GncParams.h:114
GncParams(const BaseOptimizerParameters &baseOptimizerParams)
Constructor.
Definition: GncParams.h:55
size_t maxIterations
Maximum number of iterations.
Definition: GncParams.h:68
void setLossType(const GncLossType type)
Set the robust loss function to be used in GNC (chosen among the ones in GncLossType).
Definition: GncParams.h:76
void setMuStep(const double step)
Set the graduated non-convexity step: at each GNC iteration, mu is updated as mu <- mu * muStep...
Definition: GncParams.h:89
Definition: pytypes.h:928
void setVerbosityGNC(const Verbosity value)
Set the verbosity level.
Definition: GncParams.h:104
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void setMaxIterations(const size_t maxIter)
Set the maximum number of iterations in GNC (changing the max nr of iters might lead to less accurate...
Definition: GncParams.h:81
std::vector< size_t > knownInliers
Slots in the factor graph corresponding to measurements that we know are inliers. ...
Definition: GncParams.h:73
GncLossType
Choice of robust loss function for GNC.
Definition: GncParams.h:36
traits
Definition: chartTesting.h:28
void setRelativeCostTol(double value)
Set the maximum relative difference in mu values to stop iterating.
Definition: GncParams.h:94
void print(const std::string &str) const
Print.
Definition: GncParams.h:128
bool equals(const GncParams &other, double tol=1e-9) const
Equals.
Definition: GncParams.h:120
const G double tol
Definition: Group.h:83
Verbosity
Verbosity levels.
Definition: GncParams.h:48
Definition: pytypes.h:897


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:09