| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 22:39:48 +08:00
										 |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  |  * 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-12-10 03:39:25 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  |  * @file    testGaussianISAM.cpp | 
					
						
							|  |  |  |  * @brief   Unit tests for GaussianISAM | 
					
						
							| 
									
										
										
										
											2009-12-10 03:39:25 +08:00
										 |  |  |  * @author  Michael Kaess | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 21:44:22 +08:00
										 |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-10 04:15:44 +08:00
										 |  |  | #include <tests/smallExample.h>
 | 
					
						
							| 
									
										
										
										
											2013-08-19 23:32:16 +08:00
										 |  |  | #include <gtsam/inference/Symbol.h>
 | 
					
						
							| 
									
										
										
										
											2013-07-30 10:11:34 +08:00
										 |  |  | #include <gtsam/linear/GaussianISAM.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/Ordering.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-03 03:05:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <boost/assign/std/list.hpp> // for operator +=
 | 
					
						
							|  |  |  | using namespace boost::assign; | 
					
						
							| 
									
										
										
										
											2013-08-07 03:56:48 +08:00
										 |  |  | #include <boost/range/adaptor/map.hpp>
 | 
					
						
							|  |  |  | namespace br { using namespace boost::adaptors; using namespace boost::range; } | 
					
						
							| 
									
										
										
										
											2009-12-10 03:39:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | using namespace example; | 
					
						
							| 
									
										
										
										
											2009-12-10 03:39:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-03 03:28:21 +08:00
										 |  |  | using symbol_shorthand::X; | 
					
						
							|  |  |  | using symbol_shorthand::L; | 
					
						
							| 
									
										
										
										
											2012-02-21 08:53:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2013-07-30 10:11:34 +08:00
										 |  |  | TEST( ISAM, iSAM_smoother ) | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-30 10:11:34 +08:00
										 |  |  |   Ordering ordering; | 
					
						
							| 
									
										
										
										
											2012-06-03 03:28:21 +08:00
										 |  |  |   for (int t = 1; t <= 7; t++) ordering += X(t); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Create smoother with 7 nodes
 | 
					
						
							| 
									
										
										
										
											2013-08-07 03:56:48 +08:00
										 |  |  |   GaussianFactorGraph smoother = createSmoother(7); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // run iSAM for every factor
 | 
					
						
							| 
									
										
										
										
											2013-07-30 10:11:34 +08:00
										 |  |  |   GaussianISAM actual; | 
					
						
							| 
									
										
										
										
											2016-05-21 09:29:02 +08:00
										 |  |  |   for(boost::shared_ptr<GaussianFactor> factor: smoother) { | 
					
						
							| 
									
										
										
										
											2013-07-30 10:11:34 +08:00
										 |  |  |     GaussianFactorGraph factorGraph; | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     factorGraph.push_back(factor); | 
					
						
							|  |  |  |     actual.update(factorGraph); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Create expected Bayes Tree by solving smoother with "natural" ordering
 | 
					
						
							| 
									
										
										
										
											2013-08-11 08:40:04 +08:00
										 |  |  |   GaussianBayesTree expected = *smoother.eliminateMultifrontal(ordering); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-05 04:23:45 +08:00
										 |  |  |   // Verify sigmas in the bayes tree
 | 
					
						
							| 
									
										
										
										
											2016-05-21 09:29:02 +08:00
										 |  |  |   for(const GaussianBayesTree::sharedClique& clique: expected.nodes() | br::map_values) { | 
					
						
							| 
									
										
										
										
											2013-07-30 10:11:34 +08:00
										 |  |  |     GaussianConditional::shared_ptr conditional = clique->conditional(); | 
					
						
							| 
									
										
										
										
											2013-08-07 03:56:48 +08:00
										 |  |  |     EXPECT(!conditional->get_model()); | 
					
						
							| 
									
										
										
										
											2012-10-05 04:23:45 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Check whether BayesTree is correct
 | 
					
						
							| 
									
										
										
										
											2013-08-11 08:40:04 +08:00
										 |  |  |   EXPECT(assert_equal(GaussianFactorGraph(expected).augmentedHessian(), GaussianFactorGraph(actual).augmentedHessian())); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // obtain solution
 | 
					
						
							| 
									
										
										
										
											2013-08-07 03:56:48 +08:00
										 |  |  |   VectorValues e; // expected solution
 | 
					
						
							|  |  |  |   for (int t = 1; t <= 7; t++) e.insert(X(t), Vector::Zero(2)); | 
					
						
							|  |  |  |   VectorValues optimized = actual.optimize(); // actual solution
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   EXPECT(assert_equal(e, optimized)); | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-10 03:39:25 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} | 
					
						
							|  |  |  | /* ************************************************************************* */ |