| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * JunctionTree.h | 
					
						
							| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  |  * Created on: Feb 4, 2010 | 
					
						
							|  |  |  |  * @Author: Kai Ni | 
					
						
							|  |  |  |  * @Author: Frank Dellaert | 
					
						
							|  |  |  |  * @brief: The junction tree | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <set>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <list>
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | #include <boost/shared_ptr.hpp>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <boost/pool/pool_alloc.hpp>
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/inference/BayesTree.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/ClusterTree.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <gtsam/inference/Conditional.h>
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 12:32:58 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * A junction tree (or clique-tree) is a cluster-tree where each node k represents a | 
					
						
							|  |  |  | 	 * clique (maximal fully connected subset) of an associated chordal graph, such as a | 
					
						
							|  |  |  | 	 * chordal Bayes net resulting from elimination. In GTSAM the BayesTree is used to | 
					
						
							|  |  |  | 	 * represent the clique tree associated with a Bayes net, and the JunctionTree is | 
					
						
							|  |  |  | 	 * used to collect the factors associated with each clique during the elimination process. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-07-14 20:41:22 +08:00
										 |  |  | 	template<class FG> | 
					
						
							|  |  |  | 	class JunctionTree: public ClusterTree<FG> { | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 12:32:58 +08:00
										 |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 20:41:22 +08:00
										 |  |  | 		// In a junction tree each cluster is associated with a clique
 | 
					
						
							| 
									
										
										
										
											2010-07-14 12:32:58 +08:00
										 |  |  | 		typedef typename ClusterTree<FG>::Cluster Clique; | 
					
						
							| 
									
										
										
										
											2010-07-09 15:31:15 +08:00
										 |  |  | 		typedef typename Clique::shared_ptr sharedClique; | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		typedef class BayesTree<typename FG::factor_type::Conditional> BayesTree; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 20:41:22 +08:00
										 |  |  | 		// And we will frequently refer to a symbolic Bayes tree
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		typedef gtsam::BayesTree<Conditional> SymbolicBayesTree; | 
					
						
							| 
									
										
										
										
											2010-07-14 20:41:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 	private: | 
					
						
							| 
									
										
										
										
											2010-07-19 04:23:23 +08:00
										 |  |  | 		// distribute the factors along the cluster tree
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		sharedClique distributeFactors(const FG& fg, | 
					
						
							|  |  |  | 				const SymbolicBayesTree::sharedClique& clique); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// distribute the factors along the cluster tree
 | 
					
						
							|  |  |  |     sharedClique distributeFactors(const FG& fg, const std::vector<std::list<size_t,boost::fast_pool_allocator<size_t> > >& targets, | 
					
						
							|  |  |  |         const SymbolicBayesTree::sharedClique& clique); | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		// recursive elimination function
 | 
					
						
							|  |  |  | 		std::pair<typename BayesTree::sharedClique, typename FG::sharedFactor> | 
					
						
							|  |  |  | 		eliminateOneClique(const boost::shared_ptr<const Clique>& clique) const; | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2010-07-09 15:31:15 +08:00
										 |  |  | 		// constructor
 | 
					
						
							| 
									
										
										
										
											2010-07-14 20:41:22 +08:00
										 |  |  | 		JunctionTree() { | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-09 15:31:15 +08:00
										 |  |  | 		// constructor given a factor graph and the elimination ordering
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		JunctionTree(const FG& fg); | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// eliminate the factors in the subgraphs
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		typename BayesTree::sharedClique eliminate() const; | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	}; // JunctionTree
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 |