| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    NonlinearFactorGraph-inl.h | 
					
						
							|  |  |  |  * @brief   Factor Graph Consisting of non-linear factors | 
					
						
							|  |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  * @author  Carlos Nieto | 
					
						
							|  |  |  |  * @author  Christian Potthast | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | #include "GaussianFactorGraph.h"
 | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | #include "NonlinearFactorGraph.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	template<class Config> | 
					
						
							|  |  |  | 	double NonlinearFactorGraph<Config>::error(const Config& c) const { | 
					
						
							|  |  |  | 		double total_error = 0.; | 
					
						
							|  |  |  | 		// iterate over all the factors_ to accumulate the log probabilities
 | 
					
						
							|  |  |  | 		typedef typename FactorGraph<NonlinearFactor<Config> >::const_iterator | 
					
						
							|  |  |  | 				const_iterator; | 
					
						
							|  |  |  | 		for (const_iterator factor = this->factors_.begin(); factor | 
					
						
							|  |  |  | 				!= this->factors_.end(); factor++) | 
					
						
							|  |  |  | 			total_error += (*factor)->error(c); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return total_error; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	template<class Config> | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	GaussianFactorGraph NonlinearFactorGraph<Config>::linearize( | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 			const Config& config) const { | 
					
						
							|  |  |  | 		// TODO speed up the function either by returning a pointer or by
 | 
					
						
							|  |  |  | 		// returning the linearisation as a second argument and returning
 | 
					
						
							|  |  |  | 		// the reference
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// create an empty linear FG
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 		GaussianFactorGraph linearFG; | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		typedef typename FactorGraph<NonlinearFactor<Config> >::const_iterator | 
					
						
							|  |  |  | 				const_iterator; | 
					
						
							|  |  |  | 		// linearize all factors
 | 
					
						
							|  |  |  | 		for (const_iterator factor = this->factors_.begin(); factor | 
					
						
							|  |  |  | 				< this->factors_.end(); factor++) { | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 			boost::shared_ptr<GaussianFactor> lf = (*factor)->linearize(config); | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 			linearFG.push_back(lf); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return linearFG; | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |