| 
									
										
										
										
											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-12-18 10:48:21 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | #include "GaussianFactorGraph.h"
 | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | #include "NonlinearFactorGraph.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-18 14:55:24 +08:00
										 |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-18 14:55:24 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	template<class Config> | 
					
						
							|  |  |  | 	Vector NonlinearFactorGraph<Config>::error_vector(const Config& c) const { | 
					
						
							|  |  |  | 		list<Vector> errors; | 
					
						
							|  |  |  | 		BOOST_FOREACH(typename NonlinearFactorGraph<Config>::sharedFactor factor, this->factors_) | 
					
						
							|  |  |  | 			errors.push_back(factor->error_vector(c)); | 
					
						
							|  |  |  | 		return concatVectors(errors); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							| 
									
										
										
										
											2009-12-18 10:48:21 +08:00
										 |  |  | 		BOOST_FOREACH(typename NonlinearFactorGraph<Config>::sharedFactor factor, this->factors_) | 
					
						
							|  |  |  | 			total_error += factor->error(c); | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 		return total_error; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-12-18 14:55:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	template<class Config> | 
					
						
							| 
									
										
										
										
											2009-12-12 05:34:08 +08:00
										 |  |  | 	boost::shared_ptr<GaussianFactorGraph> NonlinearFactorGraph<Config>::linearize_( | 
					
						
							|  |  |  | 			const Config& config) const{ | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// create an empty linear FG
 | 
					
						
							| 
									
										
										
										
											2009-12-12 05:34:08 +08:00
										 |  |  | 		boost::shared_ptr<GaussianFactorGraph>  linearFG(new GaussianFactorGraph); | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// linearize all factors
 | 
					
						
							| 
									
										
										
										
											2009-12-18 10:48:21 +08:00
										 |  |  | 		BOOST_FOREACH(typename NonlinearFactorGraph<Config>::sharedFactor factor, this->factors_) { | 
					
						
							|  |  |  | 			boost::shared_ptr<GaussianFactor> lf = factor->linearize(config); | 
					
						
							| 
									
										
										
										
											2009-12-12 05:34:08 +08:00
										 |  |  | 			linearFG->push_back(lf); | 
					
						
							| 
									
										
										
										
											2009-10-29 12:11:23 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return linearFG; | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-12-12 05:34:08 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	template<class Config> | 
					
						
							|  |  |  | 	GaussianFactorGraph NonlinearFactorGraph<Config>::linearize( | 
					
						
							|  |  |  | 			const Config& config) const { | 
					
						
							|  |  |  | 		return *linearize_(config); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-12-18 10:48:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 |