| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  |  * @file    GaussianFactorGraph.cpp | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  * @brief   Linear Factor Graph where all factors are Gaussians | 
					
						
							|  |  |  |  * @author  Kai Ni | 
					
						
							|  |  |  |  * @author  Christian Potthast | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | #include <boost/tuple/tuple.hpp>
 | 
					
						
							|  |  |  | #include <boost/numeric/ublas/lu.hpp>
 | 
					
						
							|  |  |  | #include <boost/numeric/ublas/io.hpp>
 | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | #include <boost/assign/std/list.hpp> // for operator += in Ordering
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | #include "GaussianFactorGraph.h"
 | 
					
						
							|  |  |  | #include "GaussianFactorSet.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:56:30 +08:00
										 |  |  | #include "FactorGraph-inl.h"
 | 
					
						
							|  |  |  | #include "inference-inl.h"
 | 
					
						
							| 
									
										
										
										
											2009-12-28 18:48:48 +08:00
										 |  |  | #include "iterative.h"
 | 
					
						
							| 
									
										
										
										
											2010-07-19 04:23:23 +08:00
										 |  |  | #include "GaussianJunctionTree.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | using namespace boost::assign; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | // trick from some reading group
 | 
					
						
							|  |  |  | #define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-30 13:45:22 +08:00
										 |  |  | // Explicitly instantiate so we don't have to include everywhere
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | template class FactorGraph<GaussianFactor>; | 
					
						
							| 
									
										
										
										
											2009-10-30 13:45:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | GaussianFactorGraph::GaussianFactorGraph(const GaussianBayesNet& CBN) : | 
					
						
							|  |  |  | 	FactorGraph<GaussianFactor> (CBN) { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-27 06:48:41 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | double GaussianFactorGraph::error(const VectorConfig& x) const { | 
					
						
							|  |  |  | 	double total_error = 0.; | 
					
						
							|  |  |  | 	BOOST_FOREACH(sharedFactor factor,factors_) | 
					
						
							|  |  |  | 		total_error += factor->error(x); | 
					
						
							|  |  |  | 	return total_error; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | Errors GaussianFactorGraph::errors(const VectorConfig& x) const { | 
					
						
							| 
									
										
										
										
											2010-01-19 18:46:12 +08:00
										 |  |  | 	return *errors_(x); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | boost::shared_ptr<Errors> GaussianFactorGraph::errors_(const VectorConfig& x) const { | 
					
						
							|  |  |  | 	boost::shared_ptr<Errors> e(new Errors); | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& factor,factors_) | 
					
						
							| 
									
										
										
										
											2010-01-19 18:46:12 +08:00
										 |  |  | 		e->push_back(factor->error_vector(x)); | 
					
						
							| 
									
										
										
										
											2009-12-27 06:48:41 +08:00
										 |  |  | 	return e; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | Errors GaussianFactorGraph::operator*(const VectorConfig& x) const { | 
					
						
							|  |  |  | 	Errors e; | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& Ai,factors_) | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | 		e.push_back((*Ai)*x); | 
					
						
							|  |  |  | 	return e; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 01:31:05 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | void GaussianFactorGraph::multiplyInPlace(const VectorConfig& x, Errors& e) const { | 
					
						
							|  |  |  | 	multiplyInPlace(x,e.begin()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | void GaussianFactorGraph::multiplyInPlace(const VectorConfig& x, | 
					
						
							|  |  |  | 		const Errors::iterator& e) const { | 
					
						
							|  |  |  | 	Errors::iterator ei = e; | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& Ai,factors_) { | 
					
						
							| 
									
										
										
										
											2010-01-31 01:31:05 +08:00
										 |  |  | 		*ei = (*Ai)*x; | 
					
						
							|  |  |  | 		ei++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | VectorConfig GaussianFactorGraph::operator^(const Errors& e) const { | 
					
						
							|  |  |  | 	VectorConfig x; | 
					
						
							|  |  |  | 	// For each factor add the gradient contribution
 | 
					
						
							| 
									
										
										
										
											2009-12-31 01:13:36 +08:00
										 |  |  | 	Errors::const_iterator it = e.begin(); | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& Ai,factors_) { | 
					
						
							| 
									
										
										
										
											2010-02-17 11:29:12 +08:00
										 |  |  | 		VectorConfig xi = (*Ai)^(*(it++)); | 
					
						
							|  |  |  | 		x.insertAdd(xi); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | 	return x; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 07:59:29 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // x += alpha*A'*e
 | 
					
						
							|  |  |  | void GaussianFactorGraph::transposeMultiplyAdd(double alpha, const Errors& e, | 
					
						
							|  |  |  | 		VectorConfig& x) const { | 
					
						
							|  |  |  | 	// For each factor add the gradient contribution
 | 
					
						
							| 
									
										
										
										
											2010-01-31 11:33:53 +08:00
										 |  |  | 	Errors::const_iterator ei = e.begin(); | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& Ai,factors_) | 
					
						
							| 
									
										
										
										
											2010-01-31 11:33:53 +08:00
										 |  |  | 		Ai->transposeMultiplyAdd(alpha,*(ei++),x); | 
					
						
							| 
									
										
										
										
											2010-01-31 07:59:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | VectorConfig GaussianFactorGraph::gradient(const VectorConfig& x) const { | 
					
						
							| 
									
										
										
										
											2010-02-17 11:29:12 +08:00
										 |  |  | 	// It is crucial for performance to make a zero-valued clone of x
 | 
					
						
							|  |  |  | 	VectorConfig g = VectorConfig::zero(x); | 
					
						
							|  |  |  | 	transposeMultiplyAdd(1.0, errors(x), g); | 
					
						
							|  |  |  | 	return g; | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | set<Symbol> GaussianFactorGraph::find_separator(const Symbol& key) const | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	set<Symbol> separator; | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& factor,factors_) | 
					
						
							| 
									
										
										
										
											2009-08-31 10:40:26 +08:00
										 |  |  | 		factor->tally_separator(key,separator); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return separator; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:56:30 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  | GaussianConditional::shared_ptr | 
					
						
							| 
									
										
										
										
											2010-07-14 06:03:18 +08:00
										 |  |  | GaussianFactorGraph::eliminateOne(const Symbol& key, bool enableJoinFactor) { | 
					
						
							|  |  |  | 	if (enableJoinFactor) | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 		return gtsam::eliminateOne<GaussianFactor,GaussianConditional>(*this, key); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return eliminateOneMatrixJoin(key); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | template <class Factors> | 
					
						
							|  |  |  | std::pair<Matrix, SharedDiagonal> combineFactorsAndCreateMatrix( | 
					
						
							|  |  |  | 		const Factors& factors, | 
					
						
							|  |  |  | 		const Ordering& order, const Dimensions& dimensions) { | 
					
						
							|  |  |  | 	// find the size of Ab
 | 
					
						
							|  |  |  | 	size_t m = 0, n = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// number of rows
 | 
					
						
							|  |  |  | 	BOOST_FOREACH(GaussianFactor::shared_ptr factor, factors) { | 
					
						
							|  |  |  | 		m += factor->numberOfRows(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// find the number of columns
 | 
					
						
							|  |  |  | 	BOOST_FOREACH(const Symbol& key, order) { | 
					
						
							|  |  |  | 		n += dimensions.at(key); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Allocate the new matrix
 | 
					
						
							|  |  |  | 	Matrix Ab = zeros(m,n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Allocate a sigmas vector to make into a full noisemodel
 | 
					
						
							|  |  |  | 	Vector sigmas = ones(m); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// copy data over
 | 
					
						
							|  |  |  | 	size_t cur_m = 0; | 
					
						
							|  |  |  | 	bool constrained = false; | 
					
						
							|  |  |  | 	bool unit = true; | 
					
						
							|  |  |  | 	BOOST_FOREACH(GaussianFactor::shared_ptr factor, factors) { | 
					
						
							|  |  |  | 		// loop through ordering
 | 
					
						
							|  |  |  | 		size_t cur_n = 0; | 
					
						
							|  |  |  | 		BOOST_FOREACH(const Symbol& key, order) { | 
					
						
							|  |  |  | 			// copy over matrix if it exists
 | 
					
						
							|  |  |  | 			if (factor->involves(key)) { | 
					
						
							|  |  |  | 				insertSub(Ab, factor->get_A(key), cur_m, cur_n); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// move onto next element
 | 
					
						
							|  |  |  | 			cur_n += dimensions.at(key); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// copy over the RHS
 | 
					
						
							|  |  |  | 		insertColumn(Ab, factor->get_b(), cur_m, n-1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// check if the model is unit already
 | 
					
						
							|  |  |  | 		if (!boost::shared_dynamic_cast<noiseModel::Unit>(factor->get_model())) { | 
					
						
							|  |  |  | 			unit = false; | 
					
						
							|  |  |  | 			const Vector& subsigmas = factor->get_model()->sigmas(); | 
					
						
							|  |  |  | 			subInsert(sigmas, subsigmas, cur_m); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// check for constraint
 | 
					
						
							|  |  |  | 			if (boost::shared_dynamic_cast<noiseModel::Constrained>(factor->get_model())) | 
					
						
							|  |  |  | 				constrained = true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// move to next row
 | 
					
						
							|  |  |  | 		cur_m += factor->numberOfRows(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// combine the noisemodels
 | 
					
						
							|  |  |  | 	SharedDiagonal model; | 
					
						
							|  |  |  | 	if (unit) { | 
					
						
							|  |  |  | 		model = noiseModel::Unit::Create(m); | 
					
						
							|  |  |  | 	} else if (constrained) { | 
					
						
							|  |  |  | 		model = noiseModel::Constrained::MixedSigmas(sigmas); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		model = noiseModel::Diagonal::Sigmas(sigmas); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return make_pair(Ab, model); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | GaussianConditional::shared_ptr | 
					
						
							|  |  |  | GaussianFactorGraph::eliminateOneMatrixJoin(const Symbol& key) { | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	// find and remove all factors connected to key
 | 
					
						
							| 
									
										
										
										
											2010-07-14 21:55:32 +08:00
										 |  |  | 	vector<GaussianFactor::shared_ptr> factors = findAndRemoveFactors(key); | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	// Collect all dimensions as well as the set of separator keys
 | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 	set<Symbol> separator; | 
					
						
							|  |  |  | 	Dimensions dimensions; | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& factor, factors) { | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 		Dimensions factor_dim = factor->dimensions(); | 
					
						
							|  |  |  | 		dimensions.insert(factor_dim.begin(), factor_dim.end()); | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 		BOOST_FOREACH(const Symbol& k, factor->keys()) | 
					
						
							|  |  |  | 			if (!k.equals(key)) | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 				separator.insert(k); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// add the keys to the rendering
 | 
					
						
							| 
									
										
										
										
											2010-07-11 15:30:27 +08:00
										 |  |  | 	Ordering render; render += key; | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 	BOOST_FOREACH(const Symbol& k, separator) | 
					
						
							|  |  |  | 			if (k != key) render += k; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// combine the factors to get a noisemodel and a combined matrix
 | 
					
						
							|  |  |  | 	Matrix Ab; SharedDiagonal model; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 	boost::tie(Ab, model) =	combineFactorsAndCreateMatrix(factors,render,dimensions); | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// eliminate that joint factor
 | 
					
						
							|  |  |  | 	GaussianFactor::shared_ptr factor; | 
					
						
							|  |  |  | 	GaussianConditional::shared_ptr conditional; | 
					
						
							| 
									
										
										
										
											2010-07-09 17:06:58 +08:00
										 |  |  | 	render.pop_front(); | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	boost::tie(conditional, factor) = | 
					
						
							| 
									
										
										
										
											2010-07-11 15:30:27 +08:00
										 |  |  | 			GaussianFactor::eliminateMatrix(Ab, model, key, render, dimensions); | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// add new factor on separator back into the graph
 | 
					
						
							|  |  |  | 	if (!factor->empty()) push_back(factor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// return the conditional Gaussian
 | 
					
						
							|  |  |  | 	return conditional; | 
					
						
							| 
									
										
										
										
											2009-11-12 12:56:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-09 15:04:26 +08:00
										 |  |  | GaussianBayesNet | 
					
						
							| 
									
										
										
										
											2010-07-14 06:03:18 +08:00
										 |  |  | GaussianFactorGraph::eliminate(const Ordering& ordering, bool enableJoinFactor) | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-09 15:04:26 +08:00
										 |  |  | 	GaussianBayesNet chordalBayesNet; // empty
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	BOOST_FOREACH(const Symbol& key, ordering) { | 
					
						
							| 
									
										
										
										
											2010-07-14 06:03:18 +08:00
										 |  |  | 		GaussianConditional::shared_ptr cg = eliminateOne(key, enableJoinFactor); | 
					
						
							| 
									
										
										
										
											2009-11-09 15:04:26 +08:00
										 |  |  | 		chordalBayesNet.push_back(cg); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return chordalBayesNet; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | GaussianBayesNet | 
					
						
							|  |  |  | GaussianFactorGraph::eliminateFrontals(const Ordering& frontals) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-11 15:30:27 +08:00
										 |  |  | 	// find the factors that contain at least one of the frontal variables
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 	Dimensions dimensions = this->dimensions(); | 
					
						
							| 
									
										
										
										
											2010-07-11 15:30:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// collect separator
 | 
					
						
							|  |  |  | 	Ordering separator; | 
					
						
							|  |  |  | 	set<Symbol> frontal_set(frontals.begin(), frontals.end()); | 
					
						
							|  |  |  | 	BOOST_FOREACH(const Symbol& key, this->keys()) { | 
					
						
							|  |  |  | 		if (frontal_set.find(key) == frontal_set.end()) | 
					
						
							|  |  |  | 			separator.push_back(key); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Matrix Ab; SharedDiagonal model; | 
					
						
							|  |  |  | 	Ordering ord = frontals; | 
					
						
							|  |  |  | 	ord.insert(ord.end(), separator.begin(), separator.end()); | 
					
						
							|  |  |  | 	boost::tie(Ab, model) = combineFactorsAndCreateMatrix(*this, ord, dimensions); | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// eliminate that joint factor
 | 
					
						
							|  |  |  | 	GaussianFactor::shared_ptr factor; | 
					
						
							|  |  |  | 	GaussianBayesNet bn; | 
					
						
							| 
									
										
										
										
											2010-07-11 15:30:27 +08:00
										 |  |  | 	boost::tie(bn, factor) = | 
					
						
							|  |  |  | 			GaussianFactor::eliminateMatrix(Ab, model, frontals, separator, dimensions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// add new factor on separator back into the graph
 | 
					
						
							|  |  |  | 	*this = GaussianFactorGraph(); | 
					
						
							|  |  |  | 	if (!factor->empty()) push_back(factor); | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return bn; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | VectorConfig GaussianFactorGraph::optimize(const Ordering& ordering, bool old) | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	// eliminate all nodes in the given ordering -> chordal Bayes net
 | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 	GaussianBayesNet chordalBayesNet = eliminate(ordering, old); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// calculate new configuration (using backsubstitution)
 | 
					
						
							| 
									
										
										
										
											2010-07-05 07:50:21 +08:00
										 |  |  | 	VectorConfig delta = ::optimize(chordalBayesNet); | 
					
						
							|  |  |  | 	return delta; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-09 15:31:15 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-07-19 04:23:23 +08:00
										 |  |  | VectorConfig GaussianFactorGraph::optimizeMultiFrontals(const Ordering& ordering) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	GaussianJunctionTree junctionTree(*this, ordering); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// calculate new configuration (using backsubstitution)
 | 
					
						
							|  |  |  | 	VectorConfig delta = junctionTree.optimize(); | 
					
						
							|  |  |  | 	return delta; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-07-09 15:31:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-11 15:14:13 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | boost::shared_ptr<GaussianBayesNet> | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | GaussianFactorGraph::eliminate_(const Ordering& ordering) | 
					
						
							| 
									
										
										
										
											2009-11-12 12:56:30 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	boost::shared_ptr<GaussianBayesNet> chordalBayesNet(new GaussianBayesNet); // empty
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	BOOST_FOREACH(const Symbol& key, ordering) { | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  | 		GaussianConditional::shared_ptr cg = eliminateOne(key); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:56:30 +08:00
										 |  |  | 		chordalBayesNet->push_back(cg); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return chordalBayesNet; | 
					
						
							| 
									
										
										
										
											2009-11-11 15:14:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | boost::shared_ptr<VectorConfig> | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | GaussianFactorGraph::optimize_(const Ordering& ordering) { | 
					
						
							| 
									
										
										
										
											2009-11-11 15:14:13 +08:00
										 |  |  | 	return boost::shared_ptr<VectorConfig>(new VectorConfig(optimize(ordering))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | void GaussianFactorGraph::combine(const GaussianFactorGraph &lfg){ | 
					
						
							| 
									
										
										
										
											2009-08-31 10:40:26 +08:00
										 |  |  | 	for(const_iterator factor=lfg.factors_.begin(); factor!=lfg.factors_.end(); factor++){ | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		push_back(*factor); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | GaussianFactorGraph GaussianFactorGraph::combine2(const GaussianFactorGraph& lfg1, | 
					
						
							|  |  |  | 		const GaussianFactorGraph& lfg2) { | 
					
						
							| 
									
										
										
										
											2009-11-05 12:56:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-25 10:36:30 +08:00
										 |  |  | 	// create new linear factor graph equal to the first one
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	GaussianFactorGraph fg = lfg1; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-31 10:40:26 +08:00
										 |  |  | 	// add the second factors_ in the graph
 | 
					
						
							|  |  |  | 	for (const_iterator factor = lfg2.factors_.begin(); factor | 
					
						
							|  |  |  | 			!= lfg2.factors_.end(); factor++) { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		fg.push_back(*factor); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return fg; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */   | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | Dimensions GaussianFactorGraph::dimensions() const { | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 	Dimensions result; | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& factor,factors_) { | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 		Dimensions vs = factor->dimensions(); | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 		Symbol key; int dim; | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 		FOREACH_PAIR(key,dim,vs) result.insert(make_pair(key,dim)); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */   | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | GaussianFactorGraph GaussianFactorGraph::add_priors(double sigma) const { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// start with this factor graph
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	GaussianFactorGraph result = *this; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// find all variables and their dimensions
 | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 	Dimensions vs = dimensions(); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// for each of the variables, add a prior
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	Symbol key; int dim; | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 	FOREACH_PAIR(key,dim,vs) { | 
					
						
							|  |  |  | 		Matrix A = eye(dim); | 
					
						
							|  |  |  | 		Vector b = zero(dim); | 
					
						
							| 
									
										
										
										
											2010-01-23 01:36:57 +08:00
										 |  |  | 		SharedDiagonal model = noiseModel::Isotropic::Sigma(dim,sigma); | 
					
						
							| 
									
										
										
										
											2010-01-21 02:32:48 +08:00
										 |  |  | 		sharedFactor prior(new GaussianFactor(key,A,b, model)); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		result.push_back(prior); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-29 02:46:01 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | Errors GaussianFactorGraph::rhs() const { | 
					
						
							|  |  |  | 	Errors e; | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& factor,factors_) | 
					
						
							| 
									
										
										
										
											2009-12-29 02:46:01 +08:00
										 |  |  | 		e.push_back(ediv(factor->get_b(),factor->get_sigmas())); | 
					
						
							|  |  |  | 	return e; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | Vector GaussianFactorGraph::rhsVector() const { | 
					
						
							| 
									
										
										
										
											2010-01-23 11:49:05 +08:00
										 |  |  | 	Errors e = rhs(); | 
					
						
							|  |  |  | 	return concatVectors(e); | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */   | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | pair<Matrix,Vector> GaussianFactorGraph::matrix(const Ordering& ordering) const { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get all factors
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	GaussianFactorSet found; | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& factor,factors_) | 
					
						
							| 
									
										
										
										
											2009-10-19 00:49:10 +08:00
										 |  |  | 		found.push_back(factor); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// combine them
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	GaussianFactor lf(found); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Return Matrix and Vector
 | 
					
						
							|  |  |  | 	return lf.matrix(ordering); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 11:49:05 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | VectorConfig GaussianFactorGraph::assembleConfig(const Vector& vs, const Ordering& ordering) const { | 
					
						
							|  |  |  | 	Dimensions dims = dimensions(); | 
					
						
							|  |  |  | 	VectorConfig config; | 
					
						
							|  |  |  | 	Vector::const_iterator itSrc = vs.begin(); | 
					
						
							|  |  |  | 	Vector::iterator itDst; | 
					
						
							|  |  |  | 	BOOST_FOREACH(const Symbol& key, ordering){ | 
					
						
							|  |  |  | 		int dim = dims.find(key)->second; | 
					
						
							|  |  |  | 		Vector v(dim); | 
					
						
							|  |  |  | 		for (itDst=v.begin(); itDst!=v.end(); itDst++, itSrc++) | 
					
						
							|  |  |  | 			*itDst = *itSrc; | 
					
						
							|  |  |  | 		config.insert(key, v); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (itSrc != vs.end()) | 
					
						
							|  |  |  | 		throw runtime_error("assembleConfig: input vector and ordering are not compatible with the graph"); | 
					
						
							|  |  |  | 	return config; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-05-31 10:21:37 +08:00
										 |  |  | pair<Dimensions, size_t> GaussianFactorGraph::columnIndices_(const Ordering& ordering) const { | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get the dimensions for all variables
 | 
					
						
							|  |  |  | 	Dimensions variableSet = dimensions(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Find the starting index and dimensions for all variables given the order
 | 
					
						
							|  |  |  | 	size_t j = 1; | 
					
						
							|  |  |  | 	Dimensions result; | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	BOOST_FOREACH(const Symbol& key, ordering) { | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | 		// associate key with first column index
 | 
					
						
							|  |  |  | 		result.insert(make_pair(key,j)); | 
					
						
							|  |  |  | 		// find dimension for this key
 | 
					
						
							|  |  |  | 		Dimensions::const_iterator it = variableSet.find(key); | 
					
						
							| 
									
										
										
										
											2010-01-23 13:16:29 +08:00
										 |  |  | 		if (it==variableSet.end()) // key not found, now what ?
 | 
					
						
							|  |  |  | 				throw invalid_argument("ColumnIndices: this ordering contains keys not in the graph"); | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | 		// advance column index to next block by adding dim(key)
 | 
					
						
							|  |  |  | 		j += it->second; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-31 10:21:37 +08:00
										 |  |  | 	return make_pair(result, j-1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | Dimensions GaussianFactorGraph::columnIndices(const Ordering& ordering) const { | 
					
						
							|  |  |  | 	return columnIndices_(ordering).first; | 
					
						
							| 
									
										
										
										
											2010-01-23 13:29:04 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-26 16:05:31 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | pair<size_t, size_t> GaussianFactorGraph::sizeOfA() const { | 
					
						
							|  |  |  | 	size_t m = 0, n = 0; | 
					
						
							|  |  |  | 	Dimensions variableSet = dimensions(); | 
					
						
							|  |  |  | 	BOOST_FOREACH(const Dimensions::value_type value, variableSet) | 
					
						
							|  |  |  | 		n += value.second; | 
					
						
							|  |  |  | 	BOOST_FOREACH(const sharedFactor& factor,factors_) | 
					
						
							|  |  |  | 		m += factor->numberOfRows(); | 
					
						
							|  |  |  | 	return make_pair(m, n); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 11:38:55 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | Matrix GaussianFactorGraph::sparse(const Ordering& ordering) const { | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | 	// get the starting column indices for all variables
 | 
					
						
							|  |  |  | 	Dimensions indices = columnIndices(ordering); | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 13:16:29 +08:00
										 |  |  | 	return sparse(indices); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | Matrix GaussianFactorGraph::sparse(const Dimensions& indices) const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// return values
 | 
					
						
							|  |  |  | 	list<int> I,J; | 
					
						
							|  |  |  | 	list<double> S; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 	// Collect the I,J,S lists for all factors
 | 
					
						
							|  |  |  | 	int row_index = 0; | 
					
						
							| 
									
										
										
										
											2010-02-22 01:06:11 +08:00
										 |  |  | 	BOOST_FOREACH(const sharedFactor& factor,factors_) { | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// get sparse lists for the factor
 | 
					
						
							|  |  |  | 		list<int> i1,j1; | 
					
						
							|  |  |  | 		list<double> s1; | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | 		boost::tie(i1,j1,s1) = factor->sparse(indices); | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// add row_start to every row index
 | 
					
						
							|  |  |  | 		transform(i1.begin(), i1.end(), i1.begin(), bind2nd(plus<int>(), row_index)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// splice lists from factor to the end of the global lists
 | 
					
						
							|  |  |  | 		I.splice(I.end(), i1); | 
					
						
							|  |  |  | 		J.splice(J.end(), j1); | 
					
						
							|  |  |  | 		S.splice(S.end(), s1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// advance row start
 | 
					
						
							|  |  |  | 		row_index += factor->numberOfRows(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Convert them to vectors for MATLAB
 | 
					
						
							|  |  |  | 	// TODO: just create a sparse matrix class already
 | 
					
						
							|  |  |  | 	size_t nzmax = S.size(); | 
					
						
							|  |  |  | 	Matrix ijs(3,nzmax); | 
					
						
							|  |  |  | 	copy(I.begin(),I.end(),ijs.begin2()); | 
					
						
							|  |  |  | 	copy(J.begin(),J.end(),ijs.begin2()+nzmax); | 
					
						
							|  |  |  | 	copy(S.begin(),S.end(),ijs.begin2()+2*nzmax); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// return the result
 | 
					
						
							|  |  |  | 	return ijs; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-11 12:59:05 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-12-28 20:37:34 +08:00
										 |  |  | VectorConfig GaussianFactorGraph::steepestDescent(const VectorConfig& x0, | 
					
						
							| 
									
										
										
										
											2009-12-29 00:15:26 +08:00
										 |  |  | 		bool verbose, double epsilon, size_t maxIterations) const { | 
					
						
							|  |  |  | 	return gtsam::steepestDescent(*this, x0, verbose, epsilon, maxIterations); | 
					
						
							| 
									
										
										
										
											2009-12-11 12:59:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-12-28 20:37:34 +08:00
										 |  |  | boost::shared_ptr<VectorConfig> GaussianFactorGraph::steepestDescent_( | 
					
						
							| 
									
										
										
										
											2009-12-29 00:15:26 +08:00
										 |  |  | 		const VectorConfig& x0, bool verbose, double epsilon, size_t maxIterations) const { | 
					
						
							| 
									
										
										
										
											2009-12-28 20:37:34 +08:00
										 |  |  | 	return boost::shared_ptr<VectorConfig>(new VectorConfig( | 
					
						
							| 
									
										
										
										
											2009-12-29 00:15:26 +08:00
										 |  |  | 			gtsam::conjugateGradientDescent(*this, x0, verbose, epsilon, | 
					
						
							|  |  |  | 					maxIterations))); | 
					
						
							| 
									
										
										
										
											2009-12-12 12:44:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-13 11:02:14 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-12-28 18:48:48 +08:00
										 |  |  | VectorConfig GaussianFactorGraph::conjugateGradientDescent( | 
					
						
							| 
									
										
										
										
											2009-12-29 00:15:26 +08:00
										 |  |  | 		const VectorConfig& x0, bool verbose, double epsilon, size_t maxIterations) const { | 
					
						
							|  |  |  | 	return gtsam::conjugateGradientDescent(*this, x0, verbose, epsilon, | 
					
						
							|  |  |  | 			maxIterations); | 
					
						
							| 
									
										
										
										
											2009-12-13 11:02:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-12-28 18:48:48 +08:00
										 |  |  | boost::shared_ptr<VectorConfig> GaussianFactorGraph::conjugateGradientDescent_( | 
					
						
							| 
									
										
										
										
											2009-12-29 00:15:26 +08:00
										 |  |  | 		const VectorConfig& x0, bool verbose, double epsilon, size_t maxIterations) const { | 
					
						
							| 
									
										
										
										
											2009-12-28 18:48:48 +08:00
										 |  |  | 	return boost::shared_ptr<VectorConfig>(new VectorConfig( | 
					
						
							| 
									
										
										
										
											2009-12-29 00:15:26 +08:00
										 |  |  | 			gtsam::conjugateGradientDescent(*this, x0, verbose, epsilon, | 
					
						
							|  |  |  | 					maxIterations))); | 
					
						
							| 
									
										
										
										
											2009-12-13 11:02:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-31 10:21:37 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | template std::pair<Matrix, SharedDiagonal> combineFactorsAndCreateMatrix<vector<GaussianFactor::shared_ptr> >( | 
					
						
							|  |  |  | 		const vector<GaussianFactor::shared_ptr>& factors,	const Ordering& order, const Dimensions& dimensions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template std::pair<Matrix, SharedDiagonal> combineFactorsAndCreateMatrix<GaussianFactorGraph>( | 
					
						
							|  |  |  | 		const GaussianFactorGraph& factors,	const Ordering& order, const Dimensions& dimensions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 |