timeGaussianFactor.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 
18 #include <time.h>
19 
20 /*STL/C++*/
21 #include <iostream>
22 using namespace std;
23 
24 #include <boost/tuple/tuple.hpp>
25 #include <boost/assign/list_of.hpp>
26 
27 #include <gtsam/base/Matrix.h>
32 
33 using namespace gtsam;
34 using namespace boost::assign;
35 
36 static const Key _x1_=1, _x2_=2, _l1_=3;
37 
38 /*
39  * Alex's Machine
40  * Results for Eliminate:
41  * Initial (1891): 17.91 sec, 55834.7 calls/sec
42  * NoiseQR : 11.69 sec
43  *
44  * Results for matrix_augmented:
45  * Initial (1891) : 0.85 sec, 1.17647e+06 calls/sec
46  * int->size_t Version : 8.45 sec (for n1 reps) with memcpy version of collect()
47  * w/ original collect(): 8.73 sec (for n1 reps)
48  * b memcpy Version : 8.64 sec (for n1 reps) with original version of collect()
49  * w/ memcpy collect() : 8.40 sec (for n1 reps)
50  * Rev 2100 : 8.15 sec
51  */
52 
53 int main()
54 {
55  // create a linear factor
56  Matrix Ax2 = (Matrix(8, 2) <<
57  // x2
58  -5., 0.,
59  +0.,-5.,
60  10., 0.,
61  +0.,10.,
62  -5., 0.,
63  +0.,-5.,
64  10., 0.,
65  +0.,10.
66  ).finished();
67 
68  Matrix Al1 = (Matrix(8, 10) <<
69  // l1
70  5., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
71  0., 5.,1.,2.,3.,4.,5.,6.,7.,8.,
72  0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
73  0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
74  5., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
75  0., 5.,1.,2.,3.,4.,5.,6.,7.,8.,
76  0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
77  0., 0.,1.,2.,3.,4.,5.,6.,7.,8.
78  ).finished();
79 
80  Matrix Ax1 = (Matrix(8, 2) <<
81  // x1
82  0.00, 0.,1.,2.,3.,4.,5.,6.,7.,8.,
83  0.00, 0.,1.,2.,3.,4.,5.,6.,7.,8.,
84  -10., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
85  0.00,-10.,1.,2.,3.,4.,5.,6.,7.,8.,
86  0.00, 0.,1.,2.,3.,4.,5.,6.,7.,8.,
87  0.00, 0.,1.,2.,3.,4.,5.,6.,7.,8.,
88  -10., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
89  0.00,-10.,1.,2.,3.,4.,5.,6.,7.,8.
90  ).finished();
91 
92  // and a RHS
93  Vector b2(8);
94  b2(0) = -1;
95  b2(1) = 1.5;
96  b2(2) = 2;
97  b2(3) = -1;
98  b2(4) = -1;
99  b2(5) = 1.5;
100  b2(6) = 2;
101  b2(7) = -1;
102 
103  // time eliminate
104  JacobianFactor combined(_x2_, Ax2, _l1_, Al1, _x1_, Ax1, b2, noiseModel::Isotropic::Sigma(8,1));
105  long timeLog = clock();
106  int n = 1000000;
109 
110  for(int i = 0; i < n; i++)
111  boost::tie(conditional, factor) =
112  JacobianFactor(combined).eliminate(Ordering(boost::assign::list_of(_x2_)));
113 
114  long timeLog2 = clock();
115  double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
116  cout << "Single Eliminate Timing:" << endl;
117  cout << seconds << " seconds" << endl;
118  cout << ((double)n/seconds) << " calls/second" << endl;
119 
120  // time matrix_augmented
121 // Ordering ordering;
122 // ordering += _x2_, _l1_, _x1_;
123 // size_t n1 = 10000000;
124 // timeLog = clock();
125 //
126 // for(size_t i = 0; i < n1; i++)
127 // Matrix Ab = combined.matrix_augmented(ordering, true);
128 //
129 // timeLog2 = clock();
130 // seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
131 // cout << "matrix_augmented Timing:" << endl;
132 // cout << seconds << " seconds" << endl;
133 // cout << ((double)n/seconds) << " calls/second" << endl;
134 
135  return 0;
136 }
int main()
std::pair< boost::shared_ptr< GaussianConditional >, shared_ptr > eliminate(const Ordering &keys)
int n
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
Definition: Half.h:150
static const Key _l1_
static const Key _x1_
Eigen::VectorXd Vector
Definition: Vector.h:38
Vector2 b2(4,-5)
Conditional Gaussian Base class.
traits
Definition: chartTesting.h:28
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
static const Key _x2_
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:50:33