| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    testInference.cpp | 
					
						
							|  |  |  |  * @brief   Unit tests for functionality declared in inference.h | 
					
						
							|  |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Ordering.h"
 | 
					
						
							|  |  |  | #include "smallExample.h"
 | 
					
						
							|  |  |  | #include "inference-inl.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | TEST(GaussianFactorGraph, createSmoother) | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	GaussianFactorGraph fg2 = createSmoother(3); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 	LONGS_EQUAL(5,fg2.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// eliminate
 | 
					
						
							|  |  |  | 	Ordering ordering; | 
					
						
							|  |  |  | 	GaussianBayesNet bayesNet = fg2.eliminate(ordering); | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  | 	FactorGraph<GaussianFactor> p_x3 = marginalize<GaussianFactor,GaussianConditional>(bayesNet, Ordering("x3")); | 
					
						
							|  |  |  | 	FactorGraph<GaussianFactor> p_x1 = marginalize<GaussianFactor,GaussianConditional>(bayesNet, Ordering("x1")); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 	CHECK(assert_equal(p_x1,p_x3)); // should be the same because of symmetry
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Inference, marginals ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create and marginalize a small Bayes net on "x"
 | 
					
						
							|  |  |  |   GaussianBayesNet cbn = createSmallGaussianBayesNet(); | 
					
						
							|  |  |  |   Ordering keys("x"); | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  |   FactorGraph<GaussianFactor> fg = marginalize<GaussianFactor, GaussianConditional>(cbn,keys); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // turn into Bayes net to test easily
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  |   BayesNet<GaussianConditional> actual = eliminate<GaussianFactor,GaussianConditional>(fg,keys); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:52:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // expected is just scalar Gaussian on x
 | 
					
						
							|  |  |  |   GaussianBayesNet expected = scalarGaussian("x",4,sqrt(2)); | 
					
						
							|  |  |  |   CHECK(assert_equal(expected,actual)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} | 
					
						
							|  |  |  | /* ************************************************************************* */ |