| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  |  * @file    GaussianFactor.h | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  * @brief   Linear Factor....A Gaussian | 
					
						
							|  |  |  |  * @brief   linearFactor | 
					
						
							|  |  |  |  * @author  Christian Potthast | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // \callgraph
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/shared_ptr.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | #include <boost/tuple/tuple.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-11-02 11:50:30 +08:00
										 |  |  | #include <boost/serialization/map.hpp>
 | 
					
						
							| 
									
										
										
										
											2010-02-25 16:16:33 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | #include <list>
 | 
					
						
							| 
									
										
										
										
											2010-01-22 12:41:40 +08:00
										 |  |  | #include <set>
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "Factor.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-02 11:50:30 +08:00
										 |  |  | #include "Matrix.h"
 | 
					
						
							|  |  |  | #include "VectorConfig.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-23 01:36:57 +08:00
										 |  |  | #include "SharedDiagonal.h"
 | 
					
						
							| 
									
										
										
										
											2010-02-22 07:50:28 +08:00
										 |  |  | #include "GaussianConditional.h" // Needed for MATLAB
 | 
					
						
							| 
									
										
										
										
											2010-07-11 15:30:27 +08:00
										 |  |  | #include "GaussianBayesNet.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-22 12:41:40 +08:00
										 |  |  | #include "SymbolMap.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-02 11:50:30 +08:00
										 |  |  | 	class Ordering; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-13 12:07:05 +08:00
										 |  |  | 	/** A map from key to dimension, useful in various contexts */ | 
					
						
							|  |  |  |   typedef SymbolMap<int> Dimensions; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Base Class for a linear factor. | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  |  * GaussianFactor is non-mutable (all methods const!). | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  * The factor value is exp(-0.5*||Ax-b||^2) | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | class GaussianFactor: boost::noncopyable, public Factor<VectorConfig> { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	typedef boost::shared_ptr<GaussianFactor> shared_ptr; | 
					
						
							| 
									
										
										
										
											2010-01-22 12:41:40 +08:00
										 |  |  | 	typedef SymbolMap<Matrix>::iterator iterator; | 
					
						
							|  |  |  | 	typedef SymbolMap<Matrix>::const_iterator const_iterator; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 01:36:57 +08:00
										 |  |  | 	SharedDiagonal model_; // Gaussian noise model with diagonal covariance matrix
 | 
					
						
							| 
									
										
										
										
											2010-01-22 12:41:40 +08:00
										 |  |  | 	SymbolMap<Matrix> As_; // linear matrices
 | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	Vector b_; // right-hand-side
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-23 01:23:24 +08:00
										 |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 11:20:15 +08:00
										 |  |  | 	/* default constructor for I/O */ | 
					
						
							|  |  |  | 	GaussianFactor()  {} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** Construct Null factor */ | 
					
						
							| 
									
										
										
										
											2010-02-26 11:20:15 +08:00
										 |  |  | 	GaussianFactor(const Vector& b_in); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** Construct unary factor */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	GaussianFactor(const Symbol& key1, const Matrix& A1, | 
					
						
							| 
									
										
										
										
											2010-02-26 11:20:15 +08:00
										 |  |  | 			const Vector& b, const SharedDiagonal& model); | 
					
						
							| 
									
										
										
										
											2009-12-11 12:59:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/** Construct binary factor */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	GaussianFactor(const Symbol& key1, const Matrix& A1, | 
					
						
							|  |  |  | 			const Symbol& key2, const Matrix& A2, | 
					
						
							| 
									
										
										
										
											2010-02-26 11:20:15 +08:00
										 |  |  | 			const Vector& b, const SharedDiagonal& model); | 
					
						
							| 
									
										
										
										
											2010-01-20 08:26:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/** Construct ternary factor */ | 
					
						
							| 
									
										
										
										
											2010-02-26 11:20:15 +08:00
										 |  |  | 	GaussianFactor(const Symbol& key1, const Matrix& A1, const Symbol& key2, | 
					
						
							|  |  |  | 			const Matrix& A2, const Symbol& key3, const Matrix& A3, | 
					
						
							|  |  |  | 			const Vector& b, const SharedDiagonal& model); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 22:27:03 +08:00
										 |  |  | 	/** Construct an n-ary factor */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	GaussianFactor(const std::vector<std::pair<Symbol, Matrix> > &terms, | 
					
						
							| 
									
										
										
										
											2010-02-26 11:20:15 +08:00
										 |  |  | 	    const Vector &b, const SharedDiagonal& model); | 
					
						
							| 
									
										
										
										
											2009-10-22 22:27:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 16:16:33 +08:00
										 |  |  | 	GaussianFactor(const std::list<std::pair<Symbol, Matrix> > &terms, | 
					
						
							| 
									
										
										
										
											2010-02-26 11:20:15 +08:00
										 |  |  | 	    const Vector &b, const SharedDiagonal& model); | 
					
						
							| 
									
										
										
										
											2010-02-25 16:16:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/** Construct from Conditional Gaussian */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  | 	GaussianFactor(const boost::shared_ptr<GaussianConditional>& cg); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 11:20:15 +08:00
										 |  |  | 	/** Constructor that combines a set of factors */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | 	GaussianFactor(const std::vector<shared_ptr> & factors); | 
					
						
							| 
									
										
										
										
											2009-10-23 01:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Implementing Testable virtual functions
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void print(const std::string& s = "") const; | 
					
						
							|  |  |  | 	bool equals(const Factor<VectorConfig>& lf, double tol = 1e-9) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	// Implementing Factor virtual functions
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-12 02:03:43 +08:00
										 |  |  | 	Vector unweighted_error(const VectorConfig& c) const; /** (A*x-b) */ | 
					
						
							| 
									
										
										
										
											2009-12-12 01:42:54 +08:00
										 |  |  | 	Vector error_vector(const VectorConfig& c) const; /** (A*x-b)/sigma */ | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	double error(const VectorConfig& c) const; /**  0.5*(A*x-b)'*D*(A*x-b) */ | 
					
						
							|  |  |  | 	std::size_t size() const { return As_.size();} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** STL like, return the iterator pointing to the first node */ | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	const_iterator const begin() const { return As_.begin();} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** STL like, return the iterator pointing to the last node */ | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	const_iterator const end() const { return As_.end();	} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** check if empty */ | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	bool empty() const { return b_.size() == 0;} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** get a copy of b */ | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	const Vector& get_b() const {	return b_;	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 05:34:20 +08:00
										 |  |  | 	/** get a copy of sigmas */ | 
					
						
							| 
									
										
										
										
											2010-01-19 12:39:28 +08:00
										 |  |  | 	const Vector& get_sigmas() const {	return model_->sigmas();	} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-19 13:46:04 +08:00
										 |  |  | 	/** get a copy of model */ | 
					
						
							| 
									
										
										
										
											2010-01-23 01:36:57 +08:00
										 |  |  | 	const SharedDiagonal& get_model() const { return model_;  } | 
					
						
							| 
									
										
										
										
											2010-01-19 13:45:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * get a copy of the A matrix from a specific node | 
					
						
							|  |  |  | 	 * O(log n) | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	const Matrix& get_A(const Symbol& key) const { | 
					
						
							| 
									
										
										
										
											2010-01-22 12:41:40 +08:00
										 |  |  | 		return As_.at(key); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-05 07:39:36 +08:00
										 |  |  | 	/** erase the A associated with the input key */ | 
					
						
							|  |  |  | 	size_t erase_A(const Symbol& key) { return As_.erase(key); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/** operator[] syntax for get */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	inline const Matrix& operator[](const Symbol& name) const { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		return get_A(name); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** Check if factor involves variable with key */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	bool involves(const Symbol& key) const { | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 		const_iterator it = As_.find(key); | 
					
						
							|  |  |  | 		return (it != As_.end()); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * return the number of rows from the b vector | 
					
						
							|  |  |  | 	 * @return a integer with the number of rows from the b vector | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	int numberOfRows() const { return b_.size();} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 11:50:44 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Find all variables | 
					
						
							|  |  |  | 	 * @return The set of all variable keys | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	std::list<Symbol> keys() const; | 
					
						
							| 
									
										
										
										
											2009-09-12 11:50:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-14 07:59:46 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * return the first key | 
					
						
							| 
									
										
										
										
											2010-07-11 05:01:06 +08:00
										 |  |  | 	 * TODO: this function should be removed and the minimum spanning tree code | 
					
						
							|  |  |  | 	 * modified accordingly. | 
					
						
							| 
									
										
										
										
											2010-01-14 07:59:46 +08:00
										 |  |  | 	 * @return The set of all variable keys | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	Symbol key1() const { return As_.begin()->first; } | 
					
						
							| 
									
										
										
										
											2010-01-14 07:59:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * return the first key | 
					
						
							| 
									
										
										
										
											2010-07-11 05:01:06 +08:00
										 |  |  |    * TODO: this function should be removed and the minimum spanning tree code | 
					
						
							|  |  |  |    * modified accordingly. | 
					
						
							| 
									
										
										
										
											2010-01-14 07:59:46 +08:00
										 |  |  | 	 * @return The set of all variable keys | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	Symbol key2() const { | 
					
						
							| 
									
										
										
										
											2010-01-14 07:59:46 +08:00
										 |  |  | 		if (As_.size() < 2) throw std::invalid_argument("GaussianFactor: less than 2 keys!"); | 
					
						
							|  |  |  | 		return (++(As_.begin()))->first; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Find all variables and their dimensions | 
					
						
							|  |  |  | 	 * @return The set of all variable/dimension pairs | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 	Dimensions dimensions() const; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Get the dimension of a particular variable | 
					
						
							|  |  |  | 	 * @param key is the name of the variable | 
					
						
							|  |  |  | 	 * @return the size of the variable | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	size_t getDim(const Symbol& key) const; | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Add to separator set if this factor involves key, but don't add key itself | 
					
						
							|  |  |  | 	 * @param key | 
					
						
							|  |  |  | 	 * @param separator set to add to | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	void tally_separator(const Symbol& key, | 
					
						
							|  |  |  | 			std::set<Symbol>& separator) const; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 11:33:53 +08:00
										 |  |  | 	/** Return A*x */ | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | 	Vector operator*(const VectorConfig& x) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 11:33:53 +08:00
										 |  |  | 	/** Return A'*e */ | 
					
						
							| 
									
										
										
										
											2009-12-27 20:13:31 +08:00
										 |  |  | 	VectorConfig operator^(const Vector& e) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-31 11:33:53 +08:00
										 |  |  | 	/** x += A'*e */ | 
					
						
							|  |  |  | 	void transposeMultiplyAdd(double alpha, const Vector& e, VectorConfig& x) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Return (dense) matrix associated with factor | 
					
						
							|  |  |  | 	 * @param ordering of variables needed for matrix column order | 
					
						
							| 
									
										
										
										
											2009-11-11 22:42:09 +08:00
										 |  |  | 	 * @param set weight to true to bake in the weights | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-11-11 22:42:09 +08:00
										 |  |  | 	std::pair<Matrix, Vector> matrix(const Ordering& ordering, bool weight = true) const; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-05 23:08:58 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Return (dense) matrix associated with factor | 
					
						
							|  |  |  | 	 * The returned system is an augmented matrix: [A b] | 
					
						
							|  |  |  | 	 * @param ordering of variables needed for matrix column order | 
					
						
							| 
									
										
										
										
											2010-01-20 00:52:01 +08:00
										 |  |  | 	 * @param set weight to use whitening to bake in weights | 
					
						
							| 
									
										
										
										
											2009-11-05 23:08:58 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-01-20 00:52:01 +08:00
										 |  |  | 	Matrix matrix_augmented(const Ordering& ordering, bool weight = true) const; | 
					
						
							| 
									
										
										
										
											2009-11-05 23:08:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Return vectors i, j, and s to generate an m-by-n sparse matrix | 
					
						
							|  |  |  | 	 * such that S(i(k),j(k)) = s(k), which can be given to MATLAB's sparse. | 
					
						
							|  |  |  | 	 * As above, the standard deviations are baked into A and b | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | 	 * @param first column index for each variable | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	boost::tuple<std::list<int>, std::list<int>, std::list<double> > | 
					
						
							| 
									
										
										
										
											2009-12-12 14:18:29 +08:00
										 |  |  | 		sparse(const Dimensions& columnIndices) const; | 
					
						
							| 
									
										
										
										
											2009-11-06 13:43:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-23 01:23:24 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 	// MUTABLE functions. FD:on the path to being eradicated
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** insert, copies A */ | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	void insert(const Symbol& key, const Matrix& A) { | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 		As_.insert(std::make_pair(key, A)); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** set RHS, copies b */ | 
					
						
							|  |  |  | 	void set_b(const Vector& b) { | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 		this->b_ = b; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// set A matrices for the linear factor, same as insert ?
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	inline void set_A(const Symbol& key, const Matrix &A) { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		insert(key, A); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							| 
									
										
										
										
											2009-11-05 04:59:16 +08:00
										 |  |  | 	 * Current Implementation: Full QR factorization | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	 * eliminate (in place!) one of the variables connected to this factor | 
					
						
							|  |  |  | 	 * @param key the key of the node to be eliminated | 
					
						
							|  |  |  | 	 * @return a new factor and a conditional gaussian on the eliminated variable | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-11-13 00:41:18 +08:00
										 |  |  | 	std::pair<boost::shared_ptr<GaussianConditional>, shared_ptr> | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | 	eliminate(const Symbol& key) const; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Performs elimination given an augmented matrix | 
					
						
							|  |  |  | 	 * @param | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2010-07-11 15:30:27 +08:00
										 |  |  | 	static std::pair<GaussianBayesNet, shared_ptr> | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 	eliminateMatrix(Matrix& Ab, SharedDiagonal model, | 
					
						
							| 
									
										
										
										
											2010-07-09 17:06:58 +08:00
										 |  |  | 			const Ordering& frontal, const Ordering& separator, | 
					
						
							|  |  |  | 			const Dimensions& dimensions); | 
					
						
							| 
									
										
										
										
											2010-02-01 01:49:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-11 15:30:27 +08:00
										 |  |  | 	static std::pair<GaussianConditional::shared_ptr, shared_ptr> | 
					
						
							|  |  |  | 	eliminateMatrix(Matrix& Ab, SharedDiagonal model, | 
					
						
							|  |  |  | 			const Symbol& frontal, const Ordering& separator, | 
					
						
							|  |  |  | 			const Dimensions& dimensions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Take the factor f, and append to current matrices. Not very general. | 
					
						
							|  |  |  | 	 * @param f linear factor graph | 
					
						
							|  |  |  | 	 * @param m final number of rows of f, needs to be known in advance | 
					
						
							|  |  |  | 	 * @param pos where to insert in the m-sized matrices | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-12-11 04:19:15 +08:00
										 |  |  | 	void append_factor(GaussianFactor::shared_ptr f, size_t m, size_t pos); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | }; // GaussianFactor
 | 
					
						
							| 
									
										
										
										
											2009-10-23 01:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 21:33:44 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * creates a C++ string a la "x3", "m768" | 
					
						
							|  |  |  |  * @param c the base character | 
					
						
							|  |  |  |  * @param index the integer to be added | 
					
						
							|  |  |  |  * @return a C++ string | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | std::string symbol(char c, int index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } // namespace gtsam
 |