| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    testInference.cpp | 
					
						
							|  |  |  |  * @brief   Unit tests for functionality declared in inference.h | 
					
						
							|  |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-26 04:10:33 +08:00
										 |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | #define GTSAM_MAGIC_KEY
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/slam/smallExample.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-22 06:59:54 +08:00
										 |  |  | #include <gtsam/linear/GaussianSequentialSolver.h>
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | using namespace example; | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // The tests below test the *generic* inference algorithms. Some of these have
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | // specialized versions in the derived classes GaussianFactorGraph etc...
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | TEST(GaussianFactorGraph, createSmoother) | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-10 08:51:57 +08:00
										 |  |  | 	GaussianFactorGraph fg2; | 
					
						
							|  |  |  | 	Ordering ordering; | 
					
						
							|  |  |  | 	boost::tie(fg2,ordering) = createSmoother(3); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 	LONGS_EQUAL(5,fg2.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// eliminate
 | 
					
						
							| 
									
										
										
										
											2010-10-22 06:59:54 +08:00
										 |  |  | 	vector<Index> x3var; x3var.push_back(ordering["x3"]); | 
					
						
							|  |  |  | 	vector<Index> x1var; x1var.push_back(ordering["x1"]); | 
					
						
							| 
									
										
										
										
											2010-10-26 06:45:45 +08:00
										 |  |  | 	GaussianBayesNet p_x3 = *GaussianSequentialSolver(*GaussianSequentialSolver(fg2).jointFactorGraph(x3var)).eliminate(); | 
					
						
							|  |  |  | 	GaussianBayesNet p_x1 = *GaussianSequentialSolver(*GaussianSequentialSolver(fg2).jointFactorGraph(x1var)).eliminate(); | 
					
						
							| 
									
										
										
										
											2010-10-10 08:51:57 +08:00
										 |  |  | 	CHECK(assert_equal(*p_x1.back(),*p_x3.front())); // should be the same because of symmetry
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Inference, marginals ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create and marginalize a small Bayes net on "x"
 | 
					
						
							|  |  |  |   GaussianBayesNet cbn = createSmallGaussianBayesNet(); | 
					
						
							| 
									
										
										
										
											2010-10-22 06:59:54 +08:00
										 |  |  |   vector<Index> xvar; xvar.push_back(0); | 
					
						
							| 
									
										
										
										
											2010-10-26 06:45:45 +08:00
										 |  |  |   GaussianBayesNet actual = *GaussianSequentialSolver(*GaussianSequentialSolver(GaussianFactorGraph(cbn)).jointFactorGraph(xvar)).eliminate(); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // expected is just scalar Gaussian on x
 | 
					
						
							| 
									
										
										
										
											2010-10-10 08:51:57 +08:00
										 |  |  |   GaussianBayesNet expected = scalarGaussian(0, 4, sqrt(2)); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  |   CHECK(assert_equal(expected,actual)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} | 
					
						
							|  |  |  | /* ************************************************************************* */ |