| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    Factor.h | 
					
						
							|  |  |  |  * @brief   A simple factor class to use in a factor graph | 
					
						
							|  |  |  |  * @brief   factor | 
					
						
							|  |  |  |  * @author  Kai Ni | 
					
						
							| 
									
										
										
										
											2009-10-23 01:23:24 +08:00
										 |  |  |  * @author  Frank Dellaert | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // \callgraph
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 12:13:03 +08:00
										 |  |  | #include <list>
 | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | #include <boost/utility.hpp> // for noncopyable
 | 
					
						
							| 
									
										
										
										
											2009-10-23 01:23:24 +08:00
										 |  |  | #include "Testable.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | #include "Key.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-22 12:41:40 +08:00
										 |  |  | #include "SymbolMap.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 	/** A map from key to dimension, useful in various contexts */ | 
					
						
							| 
									
										
										
										
											2010-01-22 12:41:40 +08:00
										 |  |  |   typedef SymbolMap<int> Dimensions; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	 | 
					
						
							|  |  |  |   /** 
 | 
					
						
							|  |  |  |    * A simple factor class to use in a factor graph. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * We make it noncopyable so we enforce the fact that factors are | 
					
						
							|  |  |  |    * kept in pointer containers. To be safe, you should make them | 
					
						
							|  |  |  |    * immutable, i.e., practicing functional programming. However, this | 
					
						
							|  |  |  |    * conflicts with efficiency as well, esp. in the case of incomplete | 
					
						
							|  |  |  |    * QR factorization. A solution is still being sought. | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  |    *  | 
					
						
							| 
									
										
										
										
											2009-10-15 04:39:59 +08:00
										 |  |  |    * A Factor is templated on a Config, for example VectorConfig is a configuration of | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  |    * labeled vectors. This way, we can have factors that might be defined on discrete | 
					
						
							|  |  |  |    * variables, continuous ones, or a combination of both. It is up to the config to  | 
					
						
							|  |  |  |    * provide the appropriate values at the appropriate time. | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |    */  | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  |   template <class Config> | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  |   class Factor : public Testable< Factor<Config> > | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual ~Factor() {}; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * negative log probability  | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  |     virtual double error(const Config& c) const = 0; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 12:13:03 +08:00
										 |  |  |     /**
 | 
					
						
							|  |  |  |      * return keys in preferred order | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  |     virtual std::list<Symbol> keys() const = 0; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		 | 
					
						
							|  |  |  |     /** 
 | 
					
						
							|  |  |  |      * @return the number of nodes the factor connects | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     virtual std::size_t size() const = 0; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |