File: timeGaussianFactor.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 (134 lines) | stat: -rw-r--r-- 3,780 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* ----------------------------------------------------------------------------

 * 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    timeGaussianFactor.cpp
 * @brief   time JacobianFactor.eliminate
 * @author  Alireza Fathi
 */

#include <time.h>

/*STL/C++*/
#include <iostream>
using namespace std;

#include <boost/tuple/tuple.hpp>

#include <gtsam/base/Matrix.h>
#include <gtsam/linear/JacobianFactor.h>
#include <gtsam/linear/JacobianFactor.h>
#include <gtsam/linear/GaussianConditional.h>
#include <gtsam/linear/NoiseModel.h>

using namespace gtsam;

static const Key _x1_=1, _x2_=2, _l1_=3;

/*
 * Alex's Machine
 * Results for Eliminate:
 * Initial (1891): 17.91 sec, 55834.7 calls/sec
 * NoiseQR       : 11.69 sec
 *
 * Results for matrix_augmented:
 * Initial (1891)       :  0.85 sec, 1.17647e+06 calls/sec
 * int->size_t Version  :  8.45 sec (for n1 reps) with memcpy version of collect()
 * w/ original collect():  8.73 sec (for n1 reps)
 * b memcpy Version     :  8.64 sec (for n1 reps) with original version of collect()
 * w/ memcpy collect()  :  8.40 sec (for n1 reps)
 * Rev 2100             :  8.15 sec
 */

int main()
{
  // create a linear factor
  Matrix Ax2 = (Matrix(8, 2) <<
           // x2
           -5., 0.,
           +0.,-5.,
           10., 0.,
           +0.,10.,
           -5., 0.,
           +0.,-5.,
           10., 0.,
           +0.,10.
           ).finished();

  Matrix Al1 = (Matrix(8, 10) <<
           // l1
           5., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
           0., 5.,1.,2.,3.,4.,5.,6.,7.,8.,
           0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
           0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
           5., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
           0., 5.,1.,2.,3.,4.,5.,6.,7.,8.,
           0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
           0., 0.,1.,2.,3.,4.,5.,6.,7.,8.
           ).finished();

  Matrix Ax1 = (Matrix(8, 2) <<
           // x1
           0.00,  0.,1.,2.,3.,4.,5.,6.,7.,8.,
           0.00,  0.,1.,2.,3.,4.,5.,6.,7.,8.,
           -10.,  0.,1.,2.,3.,4.,5.,6.,7.,8.,
           0.00,-10.,1.,2.,3.,4.,5.,6.,7.,8.,
           0.00,  0.,1.,2.,3.,4.,5.,6.,7.,8.,
           0.00,  0.,1.,2.,3.,4.,5.,6.,7.,8.,
           -10.,  0.,1.,2.,3.,4.,5.,6.,7.,8.,
           0.00,-10.,1.,2.,3.,4.,5.,6.,7.,8.
           ).finished();

  // and a RHS
  Vector b2(8);
  b2(0) = -1;
  b2(1) = 1.5;
  b2(2) = 2;
  b2(3) = -1;
  b2(4) = -1;
  b2(5) = 1.5;
  b2(6) = 2;
  b2(7) = -1;

  // time eliminate
  JacobianFactor combined(_x2_, Ax2,  _l1_, Al1, _x1_, Ax1, b2, noiseModel::Isotropic::Sigma(8,1));
  long timeLog = clock();
  int n = 1000000;
  GaussianConditional::shared_ptr conditional;
  JacobianFactor::shared_ptr factor;

  for(int i = 0; i < n; i++)
    boost::tie(conditional, factor) =
        JacobianFactor(combined).eliminate(Ordering{_x2_});

  long timeLog2 = clock();
  double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
  cout << "Single Eliminate Timing:" << endl;
  cout << seconds << " seconds" << endl;
  cout << ((double)n/seconds) << " calls/second" << endl;

  // time matrix_augmented
//  Ordering ordering;
//  ordering += _x2_, _l1_, _x1_;
//  size_t n1 = 10000000;
//  timeLog = clock();
//
//  for(size_t i = 0; i < n1; i++)
//    Matrix Ab = combined.matrix_augmented(ordering, true);
//
//  timeLog2 = clock();
//  seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
//  cout << "matrix_augmented Timing:" << endl;
//  cout << seconds << " seconds" << endl;
//  cout << ((double)n/seconds) << " calls/second" << endl;

  return 0;
}