File: timeBatch.cpp

package info (click to toggle)
gtsam 4.2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 46,132 kB
  • sloc: cpp: 127,191; python: 14,333; xml: 8,442; makefile: 252; sh: 156; ansic: 101
file content (76 lines) | stat: -rw-r--r-- 2,169 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* ----------------------------------------------------------------------------

* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)

* See LICENSE for the license information
* -------------------------------------------------------------------------- */

/**
* @file    timeBatch.cpp
* @brief   Overall timing tests for batch solving
* @author  Richard Roberts
*/

#include <gtsam/base/timing.h>
#include <gtsam/slam/dataset.h>
#include <gtsam/nonlinear/LevenbergMarquardtOptimizer.h>
#include <gtsam/nonlinear/Marginals.h>

using namespace std;
using namespace gtsam;

int main(int argc, char *argv[]) {

  try {

    cout << "Loading data..." << endl;

    string datasetFile = findExampleDataFile("w10000");
    std::pair<NonlinearFactorGraph::shared_ptr, Values::shared_ptr> data =
      load2D(datasetFile);

    NonlinearFactorGraph graph = *data.first;
    Values initial = *data.second;

    cout << "Optimizing..." << endl;

    gttic_(Create_optimizer);
    LevenbergMarquardtOptimizer optimizer(graph, initial);
    gttoc_(Create_optimizer);
    tictoc_print_();
    double lastError = optimizer.error();
    do {
      gttic_(Iterate_optimizer);
      optimizer.iterate();
      gttoc_(Iterate_optimizer);
      tictoc_finishedIteration_();
      tictoc_print_();
      cout << "Error: " << optimizer.error() << ", lambda: " << optimizer.lambda() << endl;
      break;
    } while(!checkConvergence(optimizer.params().relativeErrorTol,
      optimizer.params().absoluteErrorTol, optimizer.params().errorTol,
      lastError, optimizer.error(), optimizer.params().verbosity));

    // Compute marginals
    Marginals marginals(graph, optimizer.values());
    int i=0;
    for(Key key: initial.keys()) {
      gttic_(marginalInformation);
      Matrix info = marginals.marginalInformation(key);
      gttoc_(marginalInformation);
      tictoc_finishedIteration_();
      if(i % 1000 == 0)
        tictoc_print_();
      ++i;
    }

  } catch(std::exception& e) {
    cout << e.what() << endl;
    return 1;
  }

  return 0;
}