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 }
timing.h
Timing utilities.
Pose2.h
2D Pose
gtsam::NonlinearOptimizer::optimize
virtual const Values & optimize()
Definition: NonlinearOptimizer.h:98
pose
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
gtsam::GaussNewtonOptimizer
Definition: GaussNewtonOptimizer.h:38
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
optimize
int optimize(const SfmData &db, const NonlinearFactorGraph &graph, const Values &initial, bool separateCalibration=false)
Definition: timeSFMBAL.h:64
initial
Values initial
Definition: OdometryOptimize.cpp:2
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:43
result
Values result
Definition: OdometryOptimize.cpp:8
GaussNewtonOptimizer.h
inputFile
string inputFile
Definition: SolverComparer.cpp:89
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
main
int main(int argc, char *argv[])
Definition: timeLago.cpp:31
gtsam::tictoc_print_
void tictoc_print_()
Definition: timing.h:268
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
key
const gtsam::Symbol key('X', 0)
gtsam::Sampler::sample
Vector sample() const
sample from distribution
Definition: Sampler.cpp:59
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
gtsam::Values
Definition: Values.h:65
std
Definition: BFloat16.h:88
gtsam::noiseModel::Diagonal::shared_ptr
std::shared_ptr< Diagonal > shared_ptr
Definition: NoiseModel.h:321
lago.h
Initialize Pose2 in a factor graph using LAGO (Linear Approximation for Graph Optimization)....
initial
Definition: testScenarioRunner.cpp:148
gtsam::LieGroup::retract
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
Definition: Lie.h:131
gtsam::findExampleDataFile
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)
Definition: dataset.cpp:70
Sampler.h
sampling from a NoiseModel
M_PI
#define M_PI
Definition: mconf.h:117
init
Definition: TutorialInplaceLU.cpp:2
ceres::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Definition: gtsam/3rdparty/ceres/eigen.h:38
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gtsam::lago::initialize
Values initialize(const NonlinearFactorGraph &graph, bool useOdometricPath)
Definition: lago.cpp:375
gtsam::Sampler
Definition: Sampler.h:31
gtsam::Pose2
Definition: Pose2.h:39


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