| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2012-03-15 10:10:37 +08:00
										 |  |  |  * @file    testSymbolicBayesNetB.cpp | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  |  * @brief   Unit tests for a symbolic Bayes chain | 
					
						
							|  |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/assign/list_inserter.hpp> // for 'insert()'
 | 
					
						
							|  |  |  | #include <boost/assign/std/list.hpp> // for operator +=
 | 
					
						
							|  |  |  | using namespace boost::assign; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-26 04:10:33 +08:00
										 |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-20 10:11:28 +08:00
										 |  |  | #include <gtsam/base/Testable.h>
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/slam/smallExample.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/SymbolicFactorGraph.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-22 06:59:54 +08:00
										 |  |  | #include <gtsam/inference/SymbolicSequentialSolver.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <gtsam/nonlinear/Ordering.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-03 03:05:38 +08:00
										 |  |  | #include <gtsam/nonlinear/Symbol.h>
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | using namespace example; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-03 03:28:21 +08:00
										 |  |  | using symbol_shorthand::X; | 
					
						
							|  |  |  | using symbol_shorthand::L; | 
					
						
							| 
									
										
										
										
											2012-02-21 08:53:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( SymbolicBayesNet, constructor ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-03 03:28:21 +08:00
										 |  |  |   Ordering o; o += X(2),L(1),X(1); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 	// Create manually
 | 
					
						
							| 
									
										
										
										
											2010-10-20 05:31:13 +08:00
										 |  |  | 	IndexConditional::shared_ptr | 
					
						
							| 
									
										
										
										
											2012-06-03 03:28:21 +08:00
										 |  |  | 		x2(new IndexConditional(o[X(2)],o[L(1)], o[X(1)])), | 
					
						
							|  |  |  | 		l1(new IndexConditional(o[L(1)],o[X(1)])), | 
					
						
							|  |  |  | 		x1(new IndexConditional(o[X(1)])); | 
					
						
							| 
									
										
										
										
											2010-10-20 05:31:13 +08:00
										 |  |  | 	BayesNet<IndexConditional> expected; | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 	expected.push_back(x2); | 
					
						
							|  |  |  | 	expected.push_back(l1); | 
					
						
							|  |  |  | 	expected.push_back(x1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Create from a factor graph
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	GaussianFactorGraph factorGraph = createGaussianFactorGraph(o); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 	SymbolicFactorGraph fg(factorGraph); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// eliminate it
 | 
					
						
							| 
									
										
										
										
											2011-03-25 03:27:12 +08:00
										 |  |  |   SymbolicBayesNet actual = *SymbolicSequentialSolver(fg).eliminate( | 
					
						
							|  |  |  | 			&EliminateSymbolic); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   CHECK(assert_equal(expected, actual)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-12 09:25:55 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( SymbolicBayesNet, FromGaussian) { | 
					
						
							|  |  |  |   SymbolicBayesNet expected; | 
					
						
							|  |  |  |   expected.push_back(IndexConditional::shared_ptr(new IndexConditional(0, 1))); | 
					
						
							|  |  |  |   expected.push_back(IndexConditional::shared_ptr(new IndexConditional(1))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GaussianBayesNet gbn = createSmallGaussianBayesNet(); | 
					
						
							|  |  |  |   SymbolicBayesNet actual(gbn); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   EXPECT(assert_equal(expected, actual)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  | 	TestResult tr; | 
					
						
							|  |  |  | 	return TestRegistry::runAllTests(tr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ |