| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    GaussianISAM | 
					
						
							| 
									
										
										
										
											2009-12-29 13:57:05 +08:00
										 |  |  |  * @brief   Linear ISAM only | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  |  * @author  Michael Kaess | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // \callgraph
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/linear/GaussianConditional.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <gtsam/linear/GaussianFactor.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/ISAM.h>
 | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | class GaussianISAM : public ISAM<GaussianConditional> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   std::deque<size_t, boost::fast_pool_allocator<size_t> > dims_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Create an empty Bayes Tree */ | 
					
						
							|  |  |  |   GaussianISAM() : ISAM<GaussianConditional>() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Create a Bayes Tree from a Bayes Net */ | 
					
						
							|  |  |  |   GaussianISAM(const GaussianBayesNet& bayesNet) : ISAM<GaussianConditional>(bayesNet) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Override update_internal to also keep track of variable dimensions. */ | 
					
						
							|  |  |  |   template<class FactorGraph> | 
					
						
							|  |  |  |   void update_internal(const FactorGraph& newFactors, Cliques& orphans) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ISAM<GaussianConditional>::update_internal(newFactors, orphans); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // update dimensions
 | 
					
						
							|  |  |  |     BOOST_FOREACH(const typename FactorGraph::sharedFactor& factor, newFactors) { | 
					
						
							|  |  |  |       for(typename FactorGraph::factor_type::const_iterator key = factor->begin(); key != factor->end(); ++key) { | 
					
						
							|  |  |  |         if(*key >= dims_.size()) | 
					
						
							|  |  |  |           dims_.resize(*key + 1); | 
					
						
							|  |  |  |         if(dims_[*key] == 0) | 
					
						
							|  |  |  |           dims_[*key] = factor->getDim(key); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           assert(dims_[*key] == factor->getDim(key)); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   template<class FactorGraph> | 
					
						
							|  |  |  |   void update(const FactorGraph& newFactors) { | 
					
						
							|  |  |  |     Cliques orphans; | 
					
						
							|  |  |  |     this->update_internal(newFactors, orphans); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void clear() { | 
					
						
							|  |  |  |     ISAM<GaussianConditional>::clear(); | 
					
						
							|  |  |  |     dims_.clear(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   friend VectorValues optimize(const GaussianISAM&); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// recursively optimize this conditional and all subtrees
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	void optimize(const GaussianISAM::sharedClique& clique, VectorValues& result); | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// optimize the BayesTree, starting from the root
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	VectorValues optimize(const GaussianISAM& bayesTree); | 
					
						
							| 
									
										
										
										
											2009-12-28 07:15:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | }/// namespace gtsam
 |