| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation,  | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  *  @file   testGaussianFactor.cpp | 
					
						
							|  |  |  |  *  @brief  Unit tests for Linear Factor | 
					
						
							|  |  |  |  *  @author Christian Potthast | 
					
						
							|  |  |  |  *  @author Frank Dellaert | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/tuple/tuple.hpp>
 | 
					
						
							|  |  |  | #include <boost/assign/std/list.hpp> // for operator +=
 | 
					
						
							|  |  |  | #include <boost/assign/std/set.hpp>
 | 
					
						
							|  |  |  | #include <boost/assign/std/map.hpp> // for insert
 | 
					
						
							|  |  |  | using namespace boost::assign; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-26 04:10:33 +08:00
										 |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-18 21:18:26 +08:00
										 |  |  | // Magically casts strings like "x3" to a Symbol('x',3) key, see Key.h
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | #define GTSAM_MAGIC_KEY
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/base/Matrix.h>
 | 
					
						
							|  |  |  | #include <gtsam/linear/GaussianConditional.h>
 | 
					
						
							|  |  |  | #include <gtsam/slam/smallExample.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <gtsam/nonlinear/Ordering.h>
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | using namespace example; | 
					
						
							|  |  |  | using namespace boost; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static SharedDiagonal | 
					
						
							|  |  |  | 	sigma0_1 = sharedSigma(2,0.1), sigma_02 = sharedSigma(2,0.2), | 
					
						
							|  |  |  | 	constraintModel = noiseModel::Constrained::All(2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( GaussianFactor, linearFactor ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   Ordering ordering; ordering += "x1","x2","l1"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Matrix I = eye(2); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 	Vector b = Vector_(2, 2.0, -1.0); | 
					
						
							| 
									
										
										
										
											2011-01-21 06:22:00 +08:00
										 |  |  | 	JacobianFactor expected(ordering["x1"], -10*I,ordering["x2"], 10*I, b, noiseModel::Unit::Create(2)); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// create a small linear factor graph
 | 
					
						
							| 
									
										
										
										
											2011-01-21 06:22:00 +08:00
										 |  |  | 	FactorGraph<JacobianFactor> fg = createGaussianFactorGraph(ordering); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get the factor "f2" from the factor graph
 | 
					
						
							| 
									
										
										
										
											2011-01-21 06:22:00 +08:00
										 |  |  | 	JacobianFactor::shared_ptr lf = fg[1]; | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// check if the two factors are the same
 | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | 	EXPECT(assert_equal(expected,*lf)); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | ///* ************************************************************************* */
 | 
					
						
							|  |  |  | // SL-FIX TEST( GaussianFactor, keys )
 | 
					
						
							|  |  |  | //{
 | 
					
						
							|  |  |  | //	// get the factor "f2" from the small linear factor graph
 | 
					
						
							|  |  |  | //  Ordering ordering; ordering += "x1","x2","l1";
 | 
					
						
							|  |  |  | //  GaussianFactorGraph fg = createGaussianFactorGraph(ordering);
 | 
					
						
							|  |  |  | //	GaussianFactor::shared_ptr lf = fg[1];
 | 
					
						
							|  |  |  | //	list<Symbol> expected;
 | 
					
						
							|  |  |  | //	expected.push_back("x1");
 | 
					
						
							|  |  |  | //	expected.push_back("x2");
 | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | //	EXPECT(lf->keys() == expected);
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///* ************************************************************************* */
 | 
					
						
							|  |  |  | // SL-FIX TEST( GaussianFactor, dimensions )
 | 
					
						
							|  |  |  | //{
 | 
					
						
							|  |  |  | //  // get the factor "f2" from the small linear factor graph
 | 
					
						
							|  |  |  | //  Ordering ordering; ordering += "x1","x2","l1";
 | 
					
						
							|  |  |  | //  GaussianFactorGraph fg = createGaussianFactorGraph(ordering);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  // Check a single factor
 | 
					
						
							|  |  |  | //  Dimensions expected;
 | 
					
						
							|  |  |  | //  insert(expected)("x1", 2)("x2", 2);
 | 
					
						
							|  |  |  | //  Dimensions actual = fg[1]->dimensions();
 | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | //  EXPECT(expected==actual);
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //}
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( GaussianFactor, getDim ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// get a factor
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   Ordering ordering; ordering += "x1","x2","l1"; | 
					
						
							|  |  |  |   GaussianFactorGraph fg = createGaussianFactorGraph(ordering); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 	GaussianFactor::shared_ptr factor = fg[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// get the size of a variable
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	size_t actual = factor->getDim(factor->find(ordering["x1"])); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// verify
 | 
					
						
							|  |  |  | 	size_t expected = 2; | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | 	EXPECT_LONGS_EQUAL(expected, actual); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | ///* ************************************************************************* */
 | 
					
						
							|  |  |  | // SL-FIX TEST( GaussianFactor, combine )
 | 
					
						
							|  |  |  | //{
 | 
					
						
							|  |  |  | //	// create a small linear factor graph
 | 
					
						
							|  |  |  | //  Ordering ordering; ordering += "x1","x2","l1";
 | 
					
						
							|  |  |  | //  GaussianFactorGraph fg = createGaussianFactorGraph(ordering);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// get two factors from it and insert the factors into a vector
 | 
					
						
							|  |  |  | //	vector<GaussianFactor::shared_ptr> lfg;
 | 
					
						
							|  |  |  | //	lfg.push_back(fg[4 - 1]);
 | 
					
						
							|  |  |  | //	lfg.push_back(fg[2 - 1]);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// combine in a factor
 | 
					
						
							|  |  |  | //	GaussianFactor combined(lfg);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// sigmas
 | 
					
						
							|  |  |  | //	double sigma2 = 0.1;
 | 
					
						
							|  |  |  | //	double sigma4 = 0.2;
 | 
					
						
							|  |  |  | //	Vector sigmas = Vector_(4, sigma4, sigma4, sigma2, sigma2);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// the expected combined linear factor
 | 
					
						
							|  |  |  | //	Matrix Ax2 = Matrix_(4, 2, // x2
 | 
					
						
							|  |  |  | //			-5., 0.,
 | 
					
						
							|  |  |  | //			+0., -5.,
 | 
					
						
							|  |  |  | //			10., 0.,
 | 
					
						
							|  |  |  | //			+0., 10.);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	Matrix Al1 = Matrix_(4, 2,	// l1
 | 
					
						
							|  |  |  | //			5., 0.,
 | 
					
						
							|  |  |  | //			0., 5.,
 | 
					
						
							|  |  |  | //			0., 0.,
 | 
					
						
							|  |  |  | //			0., 0.);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	Matrix Ax1 = Matrix_(4, 2,	// x1
 | 
					
						
							|  |  |  | //			0.00, 0., // f4
 | 
					
						
							|  |  |  | //			0.00, 0., // f4
 | 
					
						
							|  |  |  | //			-10., 0., // f2
 | 
					
						
							|  |  |  | //			0.00, -10. // f2
 | 
					
						
							|  |  |  | //	);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// the RHS
 | 
					
						
							|  |  |  | //	Vector b2(4);
 | 
					
						
							|  |  |  | //	b2(0) = -1.0;
 | 
					
						
							|  |  |  | //	b2(1) =  1.5;
 | 
					
						
							|  |  |  | //	b2(2) =  2.0;
 | 
					
						
							|  |  |  | //	b2(3) = -1.0;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// use general constructor for making arbitrary factors
 | 
					
						
							|  |  |  | //	vector<pair<Symbol, Matrix> > meas;
 | 
					
						
							|  |  |  | //	meas.push_back(make_pair("x2", Ax2));
 | 
					
						
							|  |  |  | //	meas.push_back(make_pair("l1", Al1));
 | 
					
						
							|  |  |  | //	meas.push_back(make_pair("x1", Ax1));
 | 
					
						
							|  |  |  | //	GaussianFactor expected(meas, b2, noiseModel::Diagonal::Sigmas(ones(4)));
 | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | //	EXPECT(assert_equal(expected,combined));
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //}
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( GaussianFactor, error ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create a small linear factor graph
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   Ordering ordering; ordering += "x1","x2","l1"; | 
					
						
							|  |  |  |   GaussianFactorGraph fg = createGaussianFactorGraph(ordering); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get the first factor from the factor graph
 | 
					
						
							|  |  |  | 	GaussianFactor::shared_ptr lf = fg[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check the error of the first factor with noisy config
 | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  | 	VectorValues cfg = createZeroDelta(ordering); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// calculate the error from the factor "f1"
 | 
					
						
							|  |  |  | 	// note the error is the same as in testNonlinearFactor
 | 
					
						
							|  |  |  | 	double actual = lf->error(cfg); | 
					
						
							|  |  |  | 	DOUBLES_EQUAL( 1.0, actual, 0.00000001 ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | ///* ************************************************************************* */
 | 
					
						
							|  |  |  | // SL-FIX TEST( GaussianFactor, eliminate )
 | 
					
						
							|  |  |  | //{
 | 
					
						
							|  |  |  | //	// create a small linear factor graph
 | 
					
						
							|  |  |  | //  Ordering ordering; ordering += "x1","x2","l1";
 | 
					
						
							|  |  |  | //  GaussianFactorGraph fg = createGaussianFactorGraph(ordering);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// get two factors from it and insert the factors into a vector
 | 
					
						
							|  |  |  | //	vector<GaussianFactor::shared_ptr> lfg;
 | 
					
						
							|  |  |  | //	lfg.push_back(fg[4 - 1]);
 | 
					
						
							|  |  |  | //	lfg.push_back(fg[2 - 1]);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// combine in a factor
 | 
					
						
							|  |  |  | //	GaussianFactor combined(lfg);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// eliminate the combined factor
 | 
					
						
							|  |  |  | //	GaussianConditional::shared_ptr actualCG;
 | 
					
						
							|  |  |  | //	GaussianFactor::shared_ptr actualLF;
 | 
					
						
							|  |  |  | //	boost::tie(actualCG,actualLF) = combined.eliminate("x2");
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// create expected Conditional Gaussian
 | 
					
						
							|  |  |  | //	Matrix I = eye(2)*sqrt(125.0);
 | 
					
						
							|  |  |  | //	Matrix R11 = I, S12 = -0.2*I, S13 = -0.8*I;
 | 
					
						
							|  |  |  | //	Vector d = I*Vector_(2,0.2,-0.14);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// Check the conditional Gaussian
 | 
					
						
							|  |  |  | //	GaussianConditional
 | 
					
						
							|  |  |  | //	expectedCG("x2", d, R11, "l1", S12, "x1", S13, repeat(2, 1.0));
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// the expected linear factor
 | 
					
						
							|  |  |  | //	I = eye(2)/0.2236;
 | 
					
						
							|  |  |  | //	Matrix Bl1 = I, Bx1 = -I;
 | 
					
						
							|  |  |  | //	Vector b1 = I*Vector_(2,0.0,0.2);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	GaussianFactor expectedLF("l1", Bl1, "x1", Bx1, b1, repeat(2,1.0));
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// check if the result matches
 | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | //	EXPECT(assert_equal(expectedCG,*actualCG,1e-3));
 | 
					
						
							|  |  |  | //	EXPECT(assert_equal(expectedLF,*actualLF,1e-3));
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //}
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( GaussianFactor, matrix ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create a small linear factor graph
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   Ordering ordering; ordering += "x1","x2","l1"; | 
					
						
							| 
									
										
										
										
											2011-01-21 06:22:00 +08:00
										 |  |  |   FactorGraph<JacobianFactor> fg = createGaussianFactorGraph(ordering); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get the factor "f2" from the factor graph
 | 
					
						
							|  |  |  | 	//GaussianFactor::shared_ptr lf = fg[1]; // NOTE: using the older version
 | 
					
						
							|  |  |  | 	Vector b2 = Vector_(2, 0.2, -0.1); | 
					
						
							|  |  |  | 	Matrix I = eye(2); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   // render with a given ordering
 | 
					
						
							|  |  |  |   Ordering ord; | 
					
						
							|  |  |  |   ord += "x1","x2"; | 
					
						
							| 
									
										
										
										
											2011-01-21 06:22:00 +08:00
										 |  |  | 	JacobianFactor::shared_ptr lf(new JacobianFactor(ord["x1"], -I, ord["x2"], I, b2, sigma0_1)); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Test whitened version
 | 
					
						
							|  |  |  | 	Matrix A_act1; Vector b_act1; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	boost::tie(A_act1,b_act1) = lf->matrix(true); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Matrix A1 = Matrix_(2,4, | 
					
						
							|  |  |  | 			-10.0,  0.0, 10.0,  0.0, | 
					
						
							|  |  |  | 			000.0,-10.0,  0.0, 10.0 ); | 
					
						
							|  |  |  | 	Vector b1 = Vector_(2, 2.0, -1.0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EQUALITY(A_act1,A1); | 
					
						
							|  |  |  | 	EQUALITY(b_act1,b1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Test unwhitened version
 | 
					
						
							|  |  |  | 	Matrix A_act2; Vector b_act2; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	boost::tie(A_act2,b_act2) = lf->matrix(false); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Matrix A2 = Matrix_(2,4, | 
					
						
							|  |  |  | 			-1.0,  0.0, 1.0,  0.0, | 
					
						
							|  |  |  | 			000.0,-1.0,  0.0, 1.0 ); | 
					
						
							|  |  |  | 	//Vector b2 = Vector_(2, 2.0, -1.0);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EQUALITY(A_act2,A2); | 
					
						
							|  |  |  | 	EQUALITY(b_act2,b2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Ensure that whitening is consistent
 | 
					
						
							|  |  |  | 	shared_ptr<noiseModel::Gaussian> model = lf->get_model(); | 
					
						
							|  |  |  | 	model->WhitenSystem(A_act2, b_act2); | 
					
						
							|  |  |  | 	EQUALITY(A_act1, A_act2); | 
					
						
							|  |  |  | 	EQUALITY(b_act1, b_act2); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( GaussianFactor, matrix_aug ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create a small linear factor graph
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   Ordering ordering; ordering += "x1","x2","l1"; | 
					
						
							| 
									
										
										
										
											2011-01-21 06:22:00 +08:00
										 |  |  |   FactorGraph<JacobianFactor> fg = createGaussianFactorGraph(ordering); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get the factor "f2" from the factor graph
 | 
					
						
							|  |  |  | 	//GaussianFactor::shared_ptr lf = fg[1];
 | 
					
						
							|  |  |  | 	Vector b2 = Vector_(2, 0.2, -0.1); | 
					
						
							|  |  |  | 	Matrix I = eye(2); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   // render with a given ordering
 | 
					
						
							|  |  |  |   Ordering ord; | 
					
						
							|  |  |  |   ord += "x1","x2"; | 
					
						
							| 
									
										
										
										
											2011-01-21 06:22:00 +08:00
										 |  |  | 	JacobianFactor::shared_ptr lf(new JacobianFactor(ord["x1"], -I, ord["x2"], I, b2, sigma0_1)); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Test unwhitened version
 | 
					
						
							|  |  |  | 	Matrix Ab_act1; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	Ab_act1 = lf->matrix_augmented(false); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Matrix Ab1 = Matrix_(2,5, | 
					
						
							|  |  |  | 			-1.0,  0.0, 1.0,  0.0,  0.2, | 
					
						
							|  |  |  | 			00.0,- 1.0, 0.0,  1.0, -0.1 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EQUALITY(Ab_act1,Ab1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Test whitened version
 | 
					
						
							|  |  |  | 	Matrix Ab_act2; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	Ab_act2 = lf->matrix_augmented(true); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Matrix Ab2 = Matrix_(2,5, | 
					
						
							|  |  |  | 		   -10.0,  0.0, 10.0,  0.0,  2.0, | 
					
						
							|  |  |  | 			00.0, -10.0,  0.0, 10.0, -1.0 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EQUALITY(Ab_act2,Ab2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Ensure that whitening is consistent
 | 
					
						
							|  |  |  | 	shared_ptr<noiseModel::Gaussian> model = lf->get_model(); | 
					
						
							|  |  |  | 	model->WhitenInPlace(Ab_act1); | 
					
						
							|  |  |  | 	EQUALITY(Ab_act1, Ab_act2); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // small aux. function to print out lists of anything
 | 
					
						
							|  |  |  | template<class T> | 
					
						
							|  |  |  | void print(const list<T>& i) { | 
					
						
							|  |  |  | 	copy(i.begin(), i.end(), ostream_iterator<T> (cout, ",")); | 
					
						
							|  |  |  | 	cout << endl; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | ///* ************************************************************************* */
 | 
					
						
							|  |  |  | // SL-FIX TEST( GaussianFactor, sparse )
 | 
					
						
							|  |  |  | //{
 | 
					
						
							|  |  |  | //	// create a small linear factor graph
 | 
					
						
							|  |  |  | //  Ordering ordering; ordering += "x1","x2","l1";
 | 
					
						
							|  |  |  | //  GaussianFactorGraph fg = createGaussianFactorGraph(ordering);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// get the factor "f2" from the factor graph
 | 
					
						
							|  |  |  | //	GaussianFactor::shared_ptr lf = fg[1];
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// render with a given ordering
 | 
					
						
							|  |  |  | //	Ordering ord;
 | 
					
						
							|  |  |  | //	ord += "x1","x2";
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	list<int> i,j;
 | 
					
						
							|  |  |  | //	list<double> s;
 | 
					
						
							|  |  |  | //	boost::tie(i,j,s) = lf->sparse(fg.columnIndices(ord));
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	list<int> i1,j1;
 | 
					
						
							|  |  |  | //	i1 += 1,2,1,2;
 | 
					
						
							|  |  |  | //	j1 += 1,2,3,4;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	list<double> s1;
 | 
					
						
							|  |  |  | //	s1 += -10,-10,10,10;
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | //	EXPECT(i==i1);
 | 
					
						
							|  |  |  | //	EXPECT(j==j1);
 | 
					
						
							|  |  |  | //	EXPECT(s==s1);
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///* ************************************************************************* */
 | 
					
						
							|  |  |  | // SL-FIX TEST( GaussianFactor, sparse2 )
 | 
					
						
							|  |  |  | //{
 | 
					
						
							|  |  |  | //	// create a small linear factor graph
 | 
					
						
							|  |  |  | //  Ordering ordering; ordering += "x1","x2","l1";
 | 
					
						
							|  |  |  | //  GaussianFactorGraph fg = createGaussianFactorGraph(ordering);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// get the factor "f2" from the factor graph
 | 
					
						
							|  |  |  | //	GaussianFactor::shared_ptr lf = fg[1];
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	// render with a given ordering
 | 
					
						
							|  |  |  | //	Ordering ord;
 | 
					
						
							|  |  |  | //	ord += "x2","l1","x1";
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	list<int> i,j;
 | 
					
						
							|  |  |  | //	list<double> s;
 | 
					
						
							|  |  |  | //	boost::tie(i,j,s) = lf->sparse(fg.columnIndices(ord));
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	list<int> i1,j1;
 | 
					
						
							|  |  |  | //	i1 += 1,2,1,2;
 | 
					
						
							|  |  |  | //	j1 += 5,6,1,2;
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //	list<double> s1;
 | 
					
						
							|  |  |  | //	s1 += -10,-10,10,10;
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | //	EXPECT(i==i1);
 | 
					
						
							|  |  |  | //	EXPECT(j==j1);
 | 
					
						
							|  |  |  | //	EXPECT(s==s1);
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //}
 | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( GaussianFactor, size ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// create a linear factor graph
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   Ordering ordering; ordering += "x1","x2","l1"; | 
					
						
							|  |  |  |   GaussianFactorGraph fg = createGaussianFactorGraph(ordering); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get some factors from the graph
 | 
					
						
							|  |  |  | 	boost::shared_ptr<GaussianFactor> factor1 = fg[0]; | 
					
						
							|  |  |  | 	boost::shared_ptr<GaussianFactor> factor2 = fg[1]; | 
					
						
							|  |  |  | 	boost::shared_ptr<GaussianFactor> factor3 = fg[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 21:52:08 +08:00
										 |  |  | 	EXPECT_LONGS_EQUAL(1, factor1->size()); | 
					
						
							|  |  |  | 	EXPECT_LONGS_EQUAL(2, factor2->size()); | 
					
						
							|  |  |  | 	EXPECT_LONGS_EQUAL(2, factor3->size()); | 
					
						
							| 
									
										
										
										
											2010-07-12 15:16:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} | 
					
						
							|  |  |  | /* ************************************************************************* */ |