| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * BayesNetPreconditioner.h | 
					
						
							|  |  |  |  * Created on: Dec 31, 2009 | 
					
						
							|  |  |  |  * @Author: Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef BAYESNETPRECONDITIONER_H_
 | 
					
						
							|  |  |  | #define BAYESNETPRECONDITIONER_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/linear/GaussianFactorGraph.h>
 | 
					
						
							|  |  |  | #include <gtsam/linear/GaussianBayesNet.h>
 | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Upper-triangular preconditioner R for the system |A*x-b|^2 | 
					
						
							|  |  |  | 	 * The new system will be |A*inv(R)*y-b|^2, i.e., R*x=y | 
					
						
							|  |  |  | 	 * This class can solve for x=inv(R)*y by back-substituting R*x=y | 
					
						
							|  |  |  | 	 * and also apply the chain rule gy=inv(R')*gx by solving R'*gy=gx. | 
					
						
							|  |  |  | 	 * This is not used currently, just to debug operators below | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	class BayesNetPreconditioner { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// The original system
 | 
					
						
							|  |  |  | 		const GaussianFactorGraph& Ab_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// The preconditioner
 | 
					
						
							|  |  |  | 		const GaussianBayesNet& Rd_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** Constructor */ | 
					
						
							|  |  |  | 		BayesNetPreconditioner(const GaussianFactorGraph& Ab, | 
					
						
							|  |  |  | 				const GaussianBayesNet& Rd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// R*x = y by solving x=inv(R)*y
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		VectorValues backSubstitute(const VectorValues& y) const; | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// gy=inv(L)*gx by solving L*gy=gx.
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		VectorValues backSubstituteTranspose(const VectorValues& gx) const; | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* x = inv(R)*y */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		inline VectorValues x(const VectorValues& y) const { | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 			return backSubstitute(y); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* error, given y */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		double error(const VectorValues& y) const; | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/** gradient */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		VectorValues gradient(const VectorValues& y) const; | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/** Apply operator A */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		Errors operator*(const VectorValues& y) const; | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 01:31:05 +08:00
										 |  |  | 		/** In-place version that overwrites e */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		void multiplyInPlace(const VectorValues& y, Errors& e) const; | 
					
						
							| 
									
										
										
										
											2010-01-31 01:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 		/** Apply operator A' */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		VectorValues operator^(const Errors& e) const; | 
					
						
							| 
									
										
										
										
											2010-01-31 07:59:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/** BLAS level 2 equivalent y += alpha*inv(R')*A'*e */ | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 		void transposeMultiplyAdd(double alpha, const Errors& e, VectorValues& y) const; | 
					
						
							| 
									
										
										
										
											2009-12-31 20:56:47 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* BAYESNETPRECONDITIONER_H_ */
 |