| 
									
										
										
										
											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-12-28 07:15:36 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    ISAM-inl.h | 
					
						
							|  |  |  |  * @brief   Incremental update functionality (iSAM) for BayesTree. | 
					
						
							|  |  |  |  * @author  Michael Kaess | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 06:49:37 +08:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | #include <boost/assign/std/list.hpp> // for operator +=
 | 
					
						
							|  |  |  | using namespace boost::assign; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-23 02:02:55 +08:00
										 |  |  | #include <gtsam/inference/ConditionalBase.h>
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/inference/ISAM.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/BayesTree-inl.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-22 06:59:54 +08:00
										 |  |  | #include <gtsam/inference/GenericSequentialSolver-inl.h>
 | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 11:40:47 +08:00
										 |  |  |   using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Create an empty Bayes Tree */ | 
					
						
							|  |  |  |   template<class CONDITIONAL> | 
					
						
							|  |  |  |   ISAM<CONDITIONAL>::ISAM() : BayesTree<CONDITIONAL>() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Create a Bayes Tree from a Bayes Net */ | 
					
						
							|  |  |  |   template<class CONDITIONAL> | 
					
						
							|  |  |  |   ISAM<CONDITIONAL>::ISAM(const BayesNet<CONDITIONAL>& bayesNet) : | 
					
						
							|  |  |  |     BayesTree<CONDITIONAL>(bayesNet) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  |   template<class CONDITIONAL> | 
					
						
							|  |  |  |   template<class FACTORGRAPH> | 
					
						
							|  |  |  |   void ISAM<CONDITIONAL>::update_internal(const FACTORGRAPH& newFactors, Cliques& orphans) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Remove the contaminated part of the Bayes tree
 | 
					
						
							|  |  |  |     BayesNet<CONDITIONAL> bn; | 
					
						
							|  |  |  |     removeTop(newFactors.keys(), bn, orphans); | 
					
						
							|  |  |  |     FACTORGRAPH factors(bn); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // add the factors themselves
 | 
					
						
							|  |  |  |     factors.push_back(newFactors); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // eliminate into a Bayes net
 | 
					
						
							|  |  |  |     typename BayesNet<CONDITIONAL>::shared_ptr bayesNet = GenericSequentialSolver<typename CONDITIONAL::Factor>(factors).eliminate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // insert conditionals back in, straight into the topless bayesTree
 | 
					
						
							|  |  |  |     typename BayesNet<CONDITIONAL>::const_reverse_iterator rit; | 
					
						
							|  |  |  |     for ( rit=bayesNet->rbegin(); rit != bayesNet->rend(); ++rit ) | 
					
						
							|  |  |  |       this->insert(*rit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // add orphans to the bottom of the new tree
 | 
					
						
							|  |  |  |     BOOST_FOREACH(sharedClique orphan, orphans) { | 
					
						
							|  |  |  |       this->insert(orphan); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   template<class CONDITIONAL> | 
					
						
							|  |  |  |   template<class FACTORGRAPH> | 
					
						
							|  |  |  |   void ISAM<CONDITIONAL>::update(const FACTORGRAPH& newFactors) { | 
					
						
							|  |  |  |     Cliques orphans; | 
					
						
							|  |  |  |     this->update_internal(newFactors, orphans); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /// namespace gtsam
 |