| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  |  * @file    timeGaussianFactor.cpp | 
					
						
							|  |  |  |  * @brief   time GaussianFactor.eliminate | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  * @author  Alireza Fathi | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <time.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*STL/C++*/ | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/tuple/tuple.hpp>
 | 
					
						
							|  |  |  | #include "Matrix.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | #include "GaussianFactor.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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. | 
					
						
							|  |  |  | 		       ); | 
					
						
							|  |  |  |                       | 
					
						
							|  |  |  |   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. | 
					
						
							|  |  |  | 		       ); | 
					
						
							|  |  |  |                       | 
					
						
							|  |  |  |   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. | 
					
						
							|  |  |  | 		       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // 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; | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  |   GaussianFactor combined("x2", Ax2,  "l1", Al1, "x1", Ax1, b2); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |   long timeLog = clock(); | 
					
						
							|  |  |  |   int n = 1000000; | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  |   GaussianConditional::shared_ptr conditional; | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  |   GaussianFactor::shared_ptr factor; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for(int i = 0; i < n; i++) | 
					
						
							|  |  |  |     boost::tie(conditional,factor) = combined.eliminate("x2"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   long timeLog2 = clock(); | 
					
						
							|  |  |  |   double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC; | 
					
						
							|  |  |  |   cout << seconds << " seconds" << endl; | 
					
						
							|  |  |  |   cout << ((double)n/seconds) << " calls/second" << endl; | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | } |