timeBatch.cpp
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 
17 #include <gtsam/base/timing.h>
18 #include <gtsam/slam/dataset.h>
21 
22 using namespace std;
23 using namespace gtsam;
24 
25 int main(int argc, char *argv[]) {
26 
27  try {
28 
29  cout << "Loading data..." << endl;
30 
31  string datasetFile = findExampleDataFile("w10000");
32  std::pair<NonlinearFactorGraph::shared_ptr, Values::shared_ptr> data =
33  load2D(datasetFile);
34 
36  Values initial = *data.second;
37 
38  cout << "Optimizing..." << endl;
39 
40  gttic_(Create_optimizer);
42  gttoc_(Create_optimizer);
43  tictoc_print_();
44  double lastError = optimizer.error();
45  do {
46  gttic_(Iterate_optimizer);
47  optimizer.iterate();
48  gttoc_(Iterate_optimizer);
50  tictoc_print_();
51  cout << "Error: " << optimizer.error() << ", lambda: " << optimizer.lambda() << endl;
52  break;
53  } while(!checkConvergence(optimizer.params().relativeErrorTol,
54  optimizer.params().absoluteErrorTol, optimizer.params().errorTol,
55  lastError, optimizer.error(), optimizer.params().verbosity));
56 
57  // Compute marginals
58  Marginals marginals(graph, optimizer.values());
59  int i=0;
60  for(Key key: initial.keys()) {
61  gttic_(marginalInformation);
63  gttoc_(marginalInformation);
65  if(i % 1000 == 0)
66  tictoc_print_();
67  ++i;
68  }
69 
70  } catch(std::exception& e) {
71  cout << e.what() << endl;
72  return 1;
73  }
74 
75  return 0;
76 }
timing.h
Timing utilities.
gtsam::NonlinearOptimizerParams::absoluteErrorTol
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
Definition: NonlinearOptimizerParams.h:44
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::LevenbergMarquardtOptimizer::iterate
GaussianFactorGraph::shared_ptr iterate() override
Definition: LevenbergMarquardtOptimizer.cpp:273
gtsam::NonlinearOptimizer::values
const Values & values() const
return values in current optimizer state
Definition: NonlinearOptimizer.cpp:57
LevenbergMarquardtOptimizer.h
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
gtsam::Marginals::marginalInformation
Matrix marginalInformation(Key variable) const
Definition: Marginals.cpp:125
gtsam::LevenbergMarquardtOptimizer::params
const LevenbergMarquardtParams & params() const
Definition: LevenbergMarquardtOptimizer.h:106
gtsam::Marginals
Definition: Marginals.h:32
gtsam::LevenbergMarquardtOptimizer::lambda
double lambda() const
Access the current damping value.
Definition: LevenbergMarquardtOptimizer.cpp:71
gtsam::NonlinearOptimizerParams::verbosity
Verbosity verbosity
The printing verbosity during optimization (default SILENT)
Definition: NonlinearOptimizerParams.h:46
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::NonlinearOptimizer::error
double error() const
return error in current optimizer state
Definition: NonlinearOptimizer.cpp:49
gtsam::checkConvergence
bool checkConvergence(double relativeErrorTreshold, double absoluteErrorTreshold, double errorThreshold, double currentError, double newError, NonlinearOptimizerParams::Verbosity verbosity)
Definition: NonlinearOptimizer.cpp:182
data
int data[]
Definition: Map_placement_new.cpp:1
dataset.h
utility functions for loading datasets
gttoc_
#define gttoc_(label)
Definition: timing.h:250
gttic_
#define gttic_(label)
Definition: timing.h:245
gtsam::tictoc_finishedIteration_
void tictoc_finishedIteration_()
Definition: timing.h:264
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::tictoc_print_
void tictoc_print_()
Definition: timing.h:268
info
else if n * info
Definition: 3rdparty/Eigen/lapack/cholesky.cpp:18
gtsam::LevenbergMarquardtOptimizer
Definition: LevenbergMarquardtOptimizer.h:35
key
const gtsam::Symbol key('X', 0)
gtsam::load2D
GraphAndValues load2D(const std::string &filename, SharedNoiseModel model, size_t maxIndex, bool addNoise, bool smart, NoiseFormat noiseFormat, KernelFunctionType kernelFunctionType)
Definition: dataset.cpp:505
gtsam
traits
Definition: SFMdata.h:40
Marginals.h
A class for computing marginals in a NonlinearFactorGraph.
gtsam::Values
Definition: Values.h:65
std
Definition: BFloat16.h:88
gtsam::NonlinearOptimizerParams::relativeErrorTol
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5)
Definition: NonlinearOptimizerParams.h:43
gtsam::NonlinearOptimizerParams::errorTol
double errorTol
The maximum total error to stop iterating (default 0.0)
Definition: NonlinearOptimizerParams.h:45
initial
Definition: testScenarioRunner.cpp:148
gtsam::findExampleDataFile
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)
Definition: dataset.cpp:70
main
int main(int argc, char *argv[])
Definition: timeBatch.cpp:25
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
marginals
Marginals marginals(graph, result)
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:08:57