timeGaussianFactorGraph.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 #include <boost/assign/std/list.hpp> // for operator += in Ordering
21 #include <tests/smallExample.h>
22 
23 using namespace std;
24 using namespace gtsam;
25 using namespace example;
26 using namespace boost::assign;
27 
28 /* ************************************************************************* */
29 // Create a Kalman smoother for t=1:T and optimize
30 double timeKalmanSmoother(int T) {
31  GaussianFactorGraph smoother = createSmoother(T);
32  clock_t start = clock();
33  // Keys will come out sorted since keys() returns a set
34  smoother.optimize(Ordering(smoother.keys()));
35  clock_t end = clock ();
36  double dif = (double)(end - start) / CLOCKS_PER_SEC;
37  return dif;
38 }
39 
40 /* ************************************************************************* */
41 // Create a planar factor graph and optimize
42 double timePlanarSmoother(int N, bool old = true) {
43  GaussianFactorGraph fg = planarGraph(N).first;
44  clock_t start = clock();
45  fg.optimize();
46  clock_t end = clock ();
47  double dif = (double)(end - start) / CLOCKS_PER_SEC;
48  return dif;
49 }
50 
51 /* ************************************************************************* */
52 // Create a planar factor graph and eliminate
53 double timePlanarSmootherEliminate(int N, bool old = true) {
54  GaussianFactorGraph fg = planarGraph(N).first;
55  clock_t start = clock();
57  clock_t end = clock ();
58  double dif = (double)(end - start) / CLOCKS_PER_SEC;
59  return dif;
60 }
61 
65 //double timePlanarSmootherJoinAug(int N, size_t reps) {
66 // GaussianFactorGraph fgBase;
67 // VectorValues config;
68 // boost::tie(fgBase,config) = planarGraph(N);
69 // Ordering ordering = fgBase.getOrdering();
70 // Symbol key = ordering.front();
71 //
72 // clock_t start = clock();
73 //
74 // for (size_t i = 0; i<reps; ++i) {
75 // // setup
76 // GaussianFactorGraph fg(fgBase);
77 //
78 // // combine some factors
79 // GaussianFactor::shared_ptr joint_factor = removeAndCombineFactors(fg,key);
80 //
81 // // create an internal ordering to render Ab
82 // Ordering render;
83 // render += key;
84 // for(const Symbol& k: joint_factor->keys())
85 // if (k != key) render += k;
86 //
87 // Matrix Ab = joint_factor->matrix_augmented(render,false);
88 // }
89 //
90 // clock_t end = clock ();
91 // double dif = (double)(end - start) / CLOCKS_PER_SEC;
92 // return dif;
93 //}
94 
98 //double timePlanarSmootherCombined(int N, size_t reps) {
99 // GaussianFactorGraph fgBase;
100 // VectorValues config;
101 // boost::tie(fgBase,config) = planarGraph(N);
102 // Ordering ordering = fgBase.getOrdering();
103 // Symbol key = ordering.front();
104 //
105 // clock_t start = clock();
106 //
107 // for (size_t i = 0; i<reps; ++i) {
108 // GaussianFactorGraph fg(fgBase);
109 // fg.eliminateOneMatrixJoin(key);
110 // }
111 //
112 // clock_t end = clock ();
113 // double dif = (double)(end - start) / CLOCKS_PER_SEC;
114 // return dif;
115 //}
116 
117 
118 /* ************************************************************************* */
119 TEST(timeGaussianFactorGraph, linearTime)
120 {
121  // Original T = 1000;
122 
123  // Alex's Results
124  // T = 100000
125  // 1907 (init) : T - 1.65, 2T = 3.28
126  // int->size_t : T - 1.63, 2T = 3.27
127  // 2100 : T - 1.52, 2T = 2.96
128 
129  int T = 100000;
130  double time1 = timeKalmanSmoother( T); cout << "timeKalmanSmoother( T): " << time1;
131  double time2 = timeKalmanSmoother(2*T); cout << " (2*T): " << time2 << endl;
132  DOUBLES_EQUAL(2*time1,time2,0.2);
133 }
134 
135 
136 // Timing with N = 30
137 // 1741: 8.12, 8.12, 8.12, 8.14, 8.16
138 // 1742: 5.97, 5.97, 5.97, 5.99, 6.02
139 // 1746: 5.96, 5.96, 5.97, 6.00, 6.04
140 // 1748: 5.91, 5.92, 5.93, 5.95, 5.96
141 // 1839: 0.206956 0.206939 0.206213 0.206092 0.206780 // colamd !!!!
142 
143 // Alex's Machine
144 // Initial:
145 // 1907 (N = 30) : 0.14
146 // (N = 100) : 16.36
147 // Improved (int->size_t)
148 // (N = 100) : 15.39
149 // Using GSL/BLAS for updateAb : 12.87
150 // Using NoiseQR : 16.33
151 // Using correct system : 10.00
152 
153 // Switch to 100*100 grid = 10K poses
154 // 1879: 15.6498 15.3851 15.5279
155 
156 int grid_size = 100;
157 
158 /* ************************************************************************* */
159 TEST(timeGaussianFactorGraph, planar_old)
160 {
161  cout << "Timing planar - original version" << endl;
163  cout << "timeGaussianFactorGraph : " << time << endl;
164  //DOUBLES_EQUAL(5.97,time,0.1);
165 }
166 
167 /* ************************************************************************* */
168 TEST(timeGaussianFactorGraph, planar_new)
169 {
170  cout << "Timing planar - new version" << endl;
171  double time = timePlanarSmoother(grid_size, false);
172  cout << "timeGaussianFactorGraph : " << time << endl;
173  //DOUBLES_EQUAL(5.97,time,0.1);
174 }
175 
176 /* ************************************************************************* */
177 TEST(timeGaussianFactorGraph, planar_eliminate_old)
178 {
179  cout << "Timing planar Eliminate - original version" << endl;
181  cout << "timeGaussianFactorGraph : " << time << endl;
182  //DOUBLES_EQUAL(5.97,time,0.1);
183 }
184 
185 /* ************************************************************************* */
186 TEST(timeGaussianFactorGraph, planar_eliminate_new)
187 {
188  cout << "Timing planar Eliminate - new version" << endl;
189  double time = timePlanarSmootherEliminate(grid_size, false);
190  cout << "timeGaussianFactorGraph : " << time << endl;
191  //DOUBLES_EQUAL(5.97,time,0.1);
192 }
193 
194 //size_t reps = 1000;
196 //TEST(timeGaussianFactorGraph, planar_join_old)
197 //{
198 // cout << "Timing planar join - old" << endl;
199 // double time = timePlanarSmootherJoinAug(size, reps);
200 // cout << "timePlanarSmootherJoinAug " << size << " : " << time << endl;
201 // //DOUBLES_EQUAL(5.97,time,0.1);
202 //}
203 //
205 //TEST(timeGaussianFactorGraph, planar_join_new)
206 //{
207 // cout << "Timing planar join - new" << endl;
208 // double time = timePlanarSmootherCombined(size, reps);
209 // cout << "timePlanarSmootherCombined " << size << " : " << time << endl;
210 // //DOUBLES_EQUAL(5.97,time,0.1);
211 //}
212 
213 
214 /* ************************************************************************* */
215 int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
216 /* ************************************************************************* */
VectorValues optimize(const Eliminate &function=EliminationTraitsType::DefaultEliminate) const
GaussianFactorGraph createSmoother(int T)
Definition: smallExample.h:464
static int runAllTests(TestResult &result)
boost::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
#define DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:142
Definition: Half.h:150
#define N
Definition: gksort.c:12
#define time
TEST(timeGaussianFactorGraph, linearTime)
double timePlanarSmoother(int N, bool old=true)
traits
Definition: chartTesting.h:28
std::pair< GaussianFactorGraph, VectorValues > planarGraph(size_t N)
Definition: smallExample.h:631
Create small example with two poses and one landmark.
double timeKalmanSmoother(int T)
double timePlanarSmootherEliminate(int N, bool old=true)


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