| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-18 21:18:26 +08:00
										 |  |  | // Magically casts strings like "x3" to a Symbol('x',3) key, see Key.h
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | #define GTSAM_MAGIC_KEY
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 06:59:54 +08:00
										 |  |  | #include <gtsam/linear/GaussianSequentialSolver.h>
 | 
					
						
							| 
									
										
										
										
											2010-12-22 02:23:56 +08:00
										 |  |  | #include <gtsam/slam/smallExample.h>
 | 
					
						
							|  |  |  | #include <gtsam/slam/planarSLAM.h>
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // 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
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Inference, marginals ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-22 02:23:56 +08:00
										 |  |  |   using namespace example; | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 	// 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); | 
					
						
							| 
									
										
										
										
											2011-06-14 00:55:31 +08:00
										 |  |  |   GaussianBayesNet actual = *GaussianSequentialSolver( | 
					
						
							| 
									
										
										
										
											2011-06-14 04:01:58 +08:00
										 |  |  |   		*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)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-22 02:23:56 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Inference, marginals2) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-11-07 03:08:42 +08:00
										 |  |  | 	planarSLAM::Graph fg; | 
					
						
							| 
									
										
										
										
											2010-12-22 02:23:56 +08:00
										 |  |  |   SharedDiagonal poseModel(sharedSigma(3, 0.1)); | 
					
						
							|  |  |  |   SharedDiagonal pointModel(sharedSigma(3, 0.1)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-07 03:08:42 +08:00
										 |  |  |   fg.addPrior(planarSLAM::PoseKey(0), Pose2(), poseModel); | 
					
						
							|  |  |  |   fg.addOdometry(planarSLAM::PoseKey(0), planarSLAM::PoseKey(1), Pose2(1.0,0.0,0.0), poseModel); | 
					
						
							|  |  |  |   fg.addOdometry(planarSLAM::PoseKey(1), planarSLAM::PoseKey(2), Pose2(1.0,0.0,0.0), poseModel); | 
					
						
							|  |  |  |   fg.addBearingRange(planarSLAM::PoseKey(0), planarSLAM::PointKey(0), Rot2(), 1.0, pointModel); | 
					
						
							|  |  |  |   fg.addBearingRange(planarSLAM::PoseKey(1), planarSLAM::PointKey(0), Rot2(), 1.0, pointModel); | 
					
						
							|  |  |  |   fg.addBearingRange(planarSLAM::PoseKey(2), planarSLAM::PointKey(0), Rot2(), 1.0, pointModel); | 
					
						
							| 
									
										
										
										
											2010-12-22 02:23:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-07 03:08:42 +08:00
										 |  |  |   planarSLAM::Values init; | 
					
						
							|  |  |  |   init.insert(planarSLAM::PoseKey(0), Pose2(0.0,0.0,0.0)); | 
					
						
							|  |  |  |   init.insert(planarSLAM::PoseKey(1), Pose2(1.0,0.0,0.0)); | 
					
						
							|  |  |  |   init.insert(planarSLAM::PoseKey(2), Pose2(2.0,0.0,0.0)); | 
					
						
							|  |  |  |   init.insert(planarSLAM::PointKey(0), Point2(1.0,1.0)); | 
					
						
							| 
									
										
										
										
											2010-12-22 02:23:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Ordering ordering(*fg.orderingCOLAMD(init)); | 
					
						
							| 
									
										
										
										
											2011-04-13 05:18:10 +08:00
										 |  |  |   FactorGraph<GaussianFactor>::shared_ptr gfg(fg.linearize(init, ordering)); | 
					
						
							| 
									
										
										
										
											2011-06-14 04:01:58 +08:00
										 |  |  |   GaussianMultifrontalSolver solver(*gfg); | 
					
						
							| 
									
										
										
										
											2011-11-07 03:08:42 +08:00
										 |  |  |   solver.marginalFactor(ordering[planarSLAM::PointKey(0)]); | 
					
						
							| 
									
										
										
										
											2010-12-22 02:23:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} | 
					
						
							|  |  |  | /* ************************************************************************* */ |