timeLago.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  * -------------------------------------------------------------------------- */
11 
19 #include <gtsam/slam/dataset.h>
20 #include <gtsam/slam/lago.h>
21 #include <gtsam/geometry/Pose2.h>
23 #include <gtsam/linear/Sampler.h>
24 #include <gtsam/base/timing.h>
25 
26 #include <iostream>
27 
28 using namespace std;
29 using namespace gtsam;
30 
31 int main(int argc, char *argv[]) {
32 
33  size_t trials = 1;
34 
35  // read graph
36  string inputFile = findExampleDataFile("w10000");
37  auto model = noiseModel::Diagonal::Sigmas((Vector(3) << 0.05, 0.05, 5.0 * M_PI / 180.0).finished());
38  const auto [g, solution] = load2D(inputFile, model);
39 
40  // add noise to create initial estimate
42  auto noise = noiseModel::Diagonal::Sigmas((Vector(3) << 0.5, 0.5, 15.0 * M_PI / 180.0).finished());
43  Sampler sampler(noise);
44  for(const auto& [key,pose]: solution->extract<Pose2>())
45  initial.insert(key, pose.retract(sampler.sample()));
46 
47  // Add prior on the pose having index (key) = 0
48  noiseModel::Diagonal::shared_ptr priorModel = //
49  noiseModel::Diagonal::Sigmas(Vector3(1e-6, 1e-6, 1e-8));
50  g->addPrior(0, Pose2(), priorModel);
51 
52  // LAGO
53  for (size_t i = 0; i < trials; i++) {
54  {
55  gttic_(lago);
56 
57  gttic_(init);
58  Values lagoInitial = lago::initialize(*g);
59  gttoc_(init);
60 
61  gttic_(refine);
62  GaussNewtonOptimizer optimizer(*g, lagoInitial);
63  Values result = optimizer.optimize();
64  gttoc_(refine);
65  }
66 
67  {
69  GaussNewtonOptimizer optimizer(*g, initial);
70  Values result = optimizer.optimize();
71  }
72 
74  }
75 
76  tictoc_print_();
77 
78  return 0;
79 }
const gtsam::Symbol key('X', 0)
Vector sample() const
sample from distribution
Definition: Sampler.cpp:59
virtual const Values & optimize()
#define gttic_(label)
Definition: timing.h:245
Eigen::Vector3d Vector3
Definition: Vector.h:43
noiseModel::Diagonal::shared_ptr model
#define M_PI
Definition: main.h:106
Values initial
Definition: BFloat16.h:88
void g(const string &key, int i)
Definition: testBTree.cpp:41
Initialize Pose2 in a factor graph using LAGO (Linear Approximation for Graph Optimization). see papers:
string inputFile
Values result
GraphAndValues load2D(const std::string &filename, SharedNoiseModel model, size_t maxIndex, bool addNoise, bool smart, NoiseFormat noiseFormat, KernelFunctionType kernelFunctionType)
Definition: dataset.cpp:505
void tictoc_print_()
Definition: timing.h:268
Array< double, 1, 3 > e(1./3., 0.5, 2.)
sampling from a NoiseModel
traits
Definition: chartTesting.h:28
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)
Definition: dataset.cpp:70
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
Definition: Lie.h:131
int optimize(const SfmData &db, const NonlinearFactorGraph &graph, const Values &initial, bool separateCalibration=false)
Definition: timeSFMBAL.h:64
void insert(Key j, const Value &val)
Definition: Values.cpp:155
void tictoc_finishedIteration_()
Definition: timing.h:264
2D Pose
#define gttoc_(label)
Definition: timing.h:250
std::shared_ptr< Diagonal > shared_ptr
Definition: NoiseModel.h:307
int main(int argc, char *argv[])
Definition: timeLago.cpp:31
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Values initialize(const NonlinearFactorGraph &graph, bool useOdometricPath)
Definition: lago.cpp:375
utility functions for loading datasets
Timing utilities.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:40:01