| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  |  * @file    timeGaussianFactorGraph.cpp | 
					
						
							| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  |  * @brief   Time elimination with simple Kalman Smoothing example | 
					
						
							|  |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | #define GTSAM_MAGIC_KEY
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  | #include <time.h>
 | 
					
						
							|  |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | #include "smallExample.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-11 13:13:25 +08:00
										 |  |  | #include "Ordering.h"
 | 
					
						
							| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // Create a Kalman smoother for t=1:T and optimize
 | 
					
						
							|  |  |  | double timeKalmanSmoother(int T) { | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	GaussianFactorGraph smoother = createSmoother(T); | 
					
						
							| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  | 	Ordering ordering; | 
					
						
							| 
									
										
										
										
											2009-11-01 00:54:38 +08:00
										 |  |  | 	for (int t = 1; t <= T; t++) ordering.push_back(symbol('x',t)); | 
					
						
							| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  | 	clock_t start = clock(); | 
					
						
							|  |  |  | 	smoother.optimize(ordering); | 
					
						
							|  |  |  | 	clock_t end = clock (); | 
					
						
							|  |  |  | 	double dif = (double)(end - start) / CLOCKS_PER_SEC; | 
					
						
							|  |  |  | 	return dif; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-16 12:46:35 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // Create a planar factor graph and optimize
 | 
					
						
							|  |  |  | double timePlanarSmoother(int N) { | 
					
						
							|  |  |  | 	GaussianFactorGraph fg; | 
					
						
							|  |  |  | 	VectorConfig config; | 
					
						
							|  |  |  | 	boost::tie(fg,config) = planarGraph(N); | 
					
						
							|  |  |  | 	Ordering ordering = fg.getOrdering(); | 
					
						
							|  |  |  | 	clock_t start = clock(); | 
					
						
							|  |  |  | 	fg.optimize(ordering); | 
					
						
							|  |  |  | 	clock_t end = clock (); | 
					
						
							|  |  |  | 	double dif = (double)(end - start) / CLOCKS_PER_SEC; | 
					
						
							|  |  |  | 	return dif; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | TEST(timeGaussianFactorGraph, linearTime) | 
					
						
							| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-11 13:13:25 +08:00
										 |  |  | 	int T = 1000; | 
					
						
							| 
									
										
										
										
											2010-01-16 12:46:35 +08:00
										 |  |  | 	double time1 = timeKalmanSmoother(  T);  cout << time1 << endl; | 
					
						
							|  |  |  | 	double time2 = timeKalmanSmoother(2*T);  cout << time2 << endl; | 
					
						
							|  |  |  | 	DOUBLES_EQUAL(2*time1,time2,0.1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST(timeGaussianFactorGraph, planar) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-16 14:25:11 +08:00
										 |  |  | 	// 1741: 8.12, 8.12, 8.12, 8.14, 8.16
 | 
					
						
							|  |  |  | 	// 1742: 5.97, 5.97, 5.97, 5.99, 6.02
 | 
					
						
							|  |  |  | 	// 1746: 5.96, 5.96, 5.97, 6.00, 6.04
 | 
					
						
							| 
									
										
										
										
											2010-01-16 15:22:34 +08:00
										 |  |  | 	// 1748: 5.91, 5.92, 5.93, 5.95, 5.96
 | 
					
						
							| 
									
										
										
										
											2010-01-16 12:46:35 +08:00
										 |  |  | 	int N = 30; | 
					
						
							|  |  |  | 	double time = timePlanarSmoother(N); cout << time << endl; | 
					
						
							| 
									
										
										
										
											2010-01-16 12:57:58 +08:00
										 |  |  | 	DOUBLES_EQUAL(5.97,time,0.1); | 
					
						
							| 
									
										
										
										
											2009-10-27 21:34:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  | 	TestResult tr; | 
					
						
							|  |  |  | 	TestRegistry::runAllTests(tr); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ |