| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-11-01 03:53:20 +08:00
										 |  |  |  * @file    GaussianBayesNet.h | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  * @brief   Chordal Bayes Net, the result of eliminating a factor graph | 
					
						
							| 
									
										
										
										
											2009-11-01 03:53:20 +08:00
										 |  |  |  * @brief   GaussianBayesNet | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // \callgraph
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <list>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <boost/shared_ptr.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam/base/types.h>
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/linear/GaussianConditional.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/BayesNet.h>
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-09 15:04:26 +08:00
										 |  |  | 	/** A Bayes net made from linear-Gaussian densities */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  | 	typedef BayesNet<GaussianConditional> GaussianBayesNet; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-09 06:50:26 +08:00
										 |  |  | 	/** Create a scalar Gaussian */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | 	GaussianBayesNet scalarGaussian(Index key, double mu=0.0, double sigma=1.0); | 
					
						
							| 
									
										
										
										
											2009-11-09 06:50:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** Create a simple Gaussian on a single multivariate variable */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | 	GaussianBayesNet simpleGaussian(Index key, const Vector& mu, double sigma=1.0); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-12 14:09:03 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Add a conditional node with one parent | 
					
						
							|  |  |  | 	 * |Rx+Sy-d| | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | 	void push_front(GaussianBayesNet& bn, Index key, Vector d, Matrix R, | 
					
						
							|  |  |  | 			Index name1, Matrix S, Vector sigmas); | 
					
						
							| 
									
										
										
										
											2009-11-12 14:09:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Add a conditional node with two parents | 
					
						
							|  |  |  | 	 * |Rx+Sy+Tz-d| | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | 	void push_front(GaussianBayesNet& bn, Index key, Vector d, Matrix R, | 
					
						
							|  |  |  | 			Index name1, Matrix S, Index name2, Matrix T, Vector sigmas); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	 * Allocate a VectorValues for the variables in a BayesNet | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	boost::shared_ptr<VectorValues> allocateVectorValues(const GaussianBayesNet& bn); | 
					
						
							| 
									
										
										
										
											2009-11-12 14:09:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 22:14:36 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * optimize, i.e. return x = inv(R)*d | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	VectorValues optimize(const GaussianBayesNet&); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-19 18:46:12 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * shared pointer version | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	boost::shared_ptr<VectorValues> optimize_(const GaussianBayesNet& bn); | 
					
						
							| 
									
										
										
										
											2010-01-19 18:46:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-31 01:13:24 +08:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Backsubstitute | 
					
						
							|  |  |  | 	 * (R*x)./sigmas = y by solving x=inv(R)*(y.*sigmas) | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	VectorValues backSubstitute(const GaussianBayesNet& bn, const VectorValues& y); | 
					
						
							| 
									
										
										
										
											2009-12-31 01:13:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 12:39:41 +08:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Backsubstitute in place, y is replaced with solution | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	void backSubstituteInPlace(const GaussianBayesNet& bn, VectorValues& y); | 
					
						
							| 
									
										
										
										
											2010-01-31 12:39:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-31 01:13:24 +08:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Transpose Backsubstitute | 
					
						
							|  |  |  | 	 * gy=inv(L)*gx by solving L*gy=gx. | 
					
						
							|  |  |  | 	 * gy=inv(R'*inv(Sigma))*gx | 
					
						
							|  |  |  | 	 * gz'*R'=gx', gy = gz.*sigmas | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	VectorValues backSubstituteTranspose(const GaussianBayesNet& bn, const VectorValues& gx); | 
					
						
							| 
									
										
										
										
											2009-12-31 01:13:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Return (dense) upper-triangular matrix representation | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-11-09 15:04:26 +08:00
										 |  |  | 	std::pair<Matrix, Vector> matrix(const GaussianBayesNet&); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 11:56:49 +08:00
										 |  |  |   /**
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |    * Return RHS d as a VectorValues | 
					
						
							| 
									
										
										
										
											2010-03-08 11:56:49 +08:00
										 |  |  |    * Such that backSubstitute(bn,d) = optimize(bn) | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |   VectorValues rhs(const GaussianBayesNet&); | 
					
						
							| 
									
										
										
										
											2010-03-08 11:56:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } /// namespace gtsam
 |