| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file bayesTreeOperations.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @brief Types and utility functions for operating on linear systems | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * @date Jun 22, 2012 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-06 03:06:28 +08:00
										 |  |  | #include <gtsam_unstable/base/dllexport.h>
 | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | #include <gtsam/linear/GaussianFactorGraphOrdered.h>
 | 
					
						
							|  |  |  | #include <gtsam/linear/GaussianBayesTreeOrdered.h>
 | 
					
						
							|  |  |  | #include <gtsam/nonlinear/OrderingOrdered.h>
 | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Managing orderings
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** Converts sets of keys to indices by way of orderings */ | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GTSAM_UNSTABLE_EXPORT std::set<Index> keysToIndices(const KeySet& keys, const OrderingOrdered& ordering); | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Linear Graph Operations
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Given a graph, splits each factor into factors where the dimension is | 
					
						
							|  |  |  |  * that of the first variable. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GTSAM_UNSTABLE_EXPORT GaussianFactorGraphOrdered splitFactors(const GaussianFactorGraphOrdered& fullgraph); | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Splits a factor into factors where the dimension is | 
					
						
							|  |  |  |  * that of the first variable. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GTSAM_UNSTABLE_EXPORT GaussianFactorGraphOrdered splitFactor(const GaussianFactorOrdered::shared_ptr& factor); | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** Removes prior jacobian factors from the graph */ | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GTSAM_UNSTABLE_EXPORT GaussianFactorGraphOrdered removePriors(const GaussianFactorGraphOrdered& fullgraph); | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Bayes Tree / Conditional operations
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Given a Bayes Tree, return conditionals corresponding to cliques that have or | 
					
						
							|  |  |  |  * are connected to a set of wanted variables. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return the set of conditionals extracted from cliques. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GTSAM_UNSTABLE_EXPORT std::set<GaussianConditionalOrdered::shared_ptr> findAffectedCliqueConditionals( | 
					
						
							|  |  |  |     const GaussianBayesTreeOrdered& bayesTree, const std::set<Index>& savedIndices); | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Recursively traverses from a given clique in a Bayes Tree and collects all of the conditionals | 
					
						
							|  |  |  |  * Adds any new cliques from path to root to the result set. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note the use of a set of shared_ptr: this will sort/filter on unique *pointer* locations, | 
					
						
							|  |  |  |  * which ensures unique cliques, but the order of the cliques is meaningless | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GTSAM_UNSTABLE_EXPORT void findCliqueConditionals(const GaussianBayesTreeOrdered::sharedClique& current_clique, | 
					
						
							|  |  |  |     std::set<GaussianConditionalOrdered::shared_ptr>& result); | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Given a clique, returns a sequence of clique parents to the root, not including the | 
					
						
							|  |  |  |  * given clique. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GTSAM_UNSTABLE_EXPORT std::deque<GaussianBayesTreeOrdered::sharedClique> | 
					
						
							|  |  |  | findPathCliques(const GaussianBayesTreeOrdered::sharedClique& initial); | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2013-06-11 22:36:53 +08:00
										 |  |  |  * Liquefies a BayesTree into a GaussianFactorGraph recursively, given a | 
					
						
							|  |  |  |  * root clique | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @param splitConditionals flag enables spliting multi-frontal conditionals into separate factors | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-06-11 22:36:53 +08:00
										 |  |  | template <class BAYESTREE> | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GaussianFactorGraphOrdered liquefy(const typename BAYESTREE::sharedClique& root, bool splitConditionals = false) { | 
					
						
							|  |  |  |   GaussianFactorGraphOrdered result; | 
					
						
							| 
									
										
										
										
											2013-06-11 22:36:53 +08:00
										 |  |  |   if (root && root->conditional()) { | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  |     GaussianConditionalOrdered::shared_ptr conditional = root->conditional(); | 
					
						
							| 
									
										
										
										
											2013-06-11 22:36:53 +08:00
										 |  |  |     if (!splitConditionals) | 
					
						
							|  |  |  |       result.push_back(conditional->toFactor()); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       result.push_back(splitFactor(conditional->toFactor())); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   BOOST_FOREACH(const typename BAYESTREE::sharedClique& child, root->children()) | 
					
						
							|  |  |  |     result.push_back(liquefy<BAYESTREE>(child, splitConditionals)); | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Liquefies a BayesTree into a GaussianFactorGraph recursively, from a full bayes tree. | 
					
						
							| 
									
										
										
										
											2013-06-11 22:36:54 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @param splitConditionals flag enables spliting multi-frontal conditionals into separate factors | 
					
						
							| 
									
										
										
										
											2013-06-11 22:36:53 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | template <class BAYESTREE> | 
					
						
							| 
									
										
										
										
											2013-07-30 07:55:40 +08:00
										 |  |  | GaussianFactorGraphOrdered liquefy(const BAYESTREE& bayesTree, bool splitConditionals = false) { | 
					
						
							| 
									
										
										
										
											2013-06-11 22:36:53 +08:00
										 |  |  |   return liquefy<BAYESTREE>(bayesTree.root(), splitConditionals); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-03-24 04:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // \namespace gtsam
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |