| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * testLieConfig.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Jan 5, 2010 | 
					
						
							|  |  |  |  *      Author: richard | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | #include <stdexcept>
 | 
					
						
							| 
									
										
										
										
											2010-03-10 08:20:12 +08:00
										 |  |  | #include <limits>
 | 
					
						
							| 
									
										
										
										
											2010-03-04 21:21:48 +08:00
										 |  |  | #include <boost/assign/std/list.hpp> // for operator +=
 | 
					
						
							|  |  |  | using namespace boost::assign; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 03:34:57 +08:00
										 |  |  | #define GTSAM_MAGIC_KEY
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-10 08:20:12 +08:00
										 |  |  | #include "Pose2.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  | #include "LieConfig-inl.h"
 | 
					
						
							|  |  |  | #include "Vector.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | using namespace std; | 
					
						
							| 
									
										
										
										
											2010-03-10 08:20:12 +08:00
										 |  |  | static double inf = std::numeric_limits<double>::infinity(); | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( LieConfig, equals1 ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> expected; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   Vector v = Vector_(3, 5.0, 6.0, 7.0); | 
					
						
							|  |  |  |   expected.insert("a",v); | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> actual; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   actual.insert("a",v); | 
					
						
							|  |  |  |   CHECK(assert_equal(expected,actual)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( LieConfig, equals2 ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> cfg1, cfg2; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   Vector v1 = Vector_(3, 5.0, 6.0, 7.0); | 
					
						
							|  |  |  |   Vector v2 = Vector_(3, 5.0, 6.0, 8.0); | 
					
						
							|  |  |  |   cfg1.insert("x", v1); | 
					
						
							|  |  |  |   cfg2.insert("x", v2); | 
					
						
							|  |  |  |   CHECK(!cfg1.equals(cfg2)); | 
					
						
							|  |  |  |   CHECK(!cfg2.equals(cfg1)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( LieConfig, equals_nan ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> cfg1, cfg2; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   Vector v1 = Vector_(3, 5.0, 6.0, 7.0); | 
					
						
							| 
									
										
										
										
											2010-03-10 08:20:12 +08:00
										 |  |  |   Vector v2 = Vector_(3, inf, inf, inf); | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   cfg1.insert("x", v1); | 
					
						
							|  |  |  |   cfg2.insert("x", v2); | 
					
						
							|  |  |  |   CHECK(!cfg1.equals(cfg2)); | 
					
						
							|  |  |  |   CHECK(!cfg2.equals(cfg1)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 10:50:01 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( LieConfig, insert_config ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   LieConfig<string,Vector> cfg1, cfg2, expected; | 
					
						
							|  |  |  |   Vector v1 = Vector_(3, 5.0, 6.0, 7.0); | 
					
						
							|  |  |  |   Vector v2 = Vector_(3, 8.0, 9.0, 1.0); | 
					
						
							|  |  |  |   Vector v3 = Vector_(3, 2.0, 4.0, 3.0); | 
					
						
							|  |  |  |   Vector v4 = Vector_(3, 8.0, 3.0, 7.0); | 
					
						
							|  |  |  |   cfg1.insert("x1", v1); | 
					
						
							|  |  |  |   cfg1.insert("x2", v2); | 
					
						
							|  |  |  |   cfg2.insert("x2", v3); | 
					
						
							|  |  |  |   cfg2.insert("x3", v4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cfg1.insert(cfg2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expected.insert("x1", v1); | 
					
						
							|  |  |  |   expected.insert("x2", v2); | 
					
						
							|  |  |  |   expected.insert("x2", v3); | 
					
						
							|  |  |  |   expected.insert("x3", v4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CHECK(assert_equal(cfg1, expected)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-04 02:07:27 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-05-04 21:41:46 +08:00
										 |  |  | TEST( LieConfig, update_element ) | 
					
						
							| 
									
										
										
										
											2010-05-04 02:07:27 +08:00
										 |  |  | { | 
					
						
							|  |  |  |   LieConfig<string,Vector> cfg; | 
					
						
							|  |  |  |   Vector v1 = Vector_(3, 5.0, 6.0, 7.0); | 
					
						
							|  |  |  |   Vector v2 = Vector_(3, 8.0, 9.0, 1.0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cfg.insert("x1", v1); | 
					
						
							|  |  |  |   CHECK(cfg.size() == 1); | 
					
						
							|  |  |  |   CHECK(assert_equal(v1, cfg.at("x1"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cfg.update("x1", v2); | 
					
						
							|  |  |  |   CHECK(cfg.size() == 1); | 
					
						
							| 
									
										
										
										
											2010-05-04 21:41:46 +08:00
										 |  |  |   CHECK(assert_equal(v2, cfg.at("x1"))); | 
					
						
							| 
									
										
										
										
											2010-05-04 02:07:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-10 08:20:12 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST(LieConfig, dim_zero) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   LieConfig<string,Vector> config0; | 
					
						
							|  |  |  |   config0.insert("v1", Vector_(2, 2.0, 3.0)); | 
					
						
							|  |  |  |   config0.insert("v2", Vector_(3, 5.0, 6.0, 7.0)); | 
					
						
							|  |  |  |   LONGS_EQUAL(5,config0.dim()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   VectorConfig expected; | 
					
						
							|  |  |  |   expected.insert("v1", zero(2)); | 
					
						
							|  |  |  |   expected.insert("v2", zero(3)); | 
					
						
							|  |  |  |   CHECK(assert_equal(expected, config0.zero())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST(LieConfig, expmap_a) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> config0; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   config0.insert("v1", Vector_(3, 1.0, 2.0, 3.0)); | 
					
						
							|  |  |  |   config0.insert("v2", Vector_(3, 5.0, 6.0, 7.0)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   VectorConfig increment; | 
					
						
							|  |  |  |   increment.insert("v1", Vector_(3, 1.0, 1.1, 1.2)); | 
					
						
							|  |  |  |   increment.insert("v2", Vector_(3, 1.3, 1.4, 1.5)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> expected; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   expected.insert("v1", Vector_(3, 2.0, 3.1, 4.2)); | 
					
						
							|  |  |  |   expected.insert("v2", Vector_(3, 6.3, 7.4, 8.5)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CHECK(assert_equal(expected, expmap(config0, increment))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST(LieConfig, expmap_b) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> config0; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   config0.insert("v1", Vector_(3, 1.0, 2.0, 3.0)); | 
					
						
							|  |  |  |   config0.insert("v2", Vector_(3, 5.0, 6.0, 7.0)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   VectorConfig increment; | 
					
						
							|  |  |  |   increment.insert("v2", Vector_(3, 1.3, 1.4, 1.5)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> expected; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   expected.insert("v1", Vector_(3, 1.0, 2.0, 3.0)); | 
					
						
							|  |  |  |   expected.insert("v2", Vector_(3, 6.3, 7.4, 8.5)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CHECK(assert_equal(expected, expmap(config0, increment))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST(LieConfig, expmap_c) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> config0; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   config0.insert("v1", Vector_(3, 1.0, 2.0, 3.0)); | 
					
						
							|  |  |  |   config0.insert("v2", Vector_(3, 5.0, 6.0, 7.0)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Vector increment = Vector_(6, | 
					
						
							|  |  |  |       1.0, 1.1, 1.2, | 
					
						
							|  |  |  |       1.3, 1.4, 1.5); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> expected; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   expected.insert("v1", Vector_(3, 2.0, 3.1, 4.2)); | 
					
						
							|  |  |  |   expected.insert("v2", Vector_(3, 6.3, 7.4, 8.5)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CHECK(assert_equal(expected, expmap(config0, increment))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-10 08:20:12 +08:00
										 |  |  | /* ************************************************************************* *
 | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  | TEST(LieConfig, expmap_d) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Vector> config0; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   config0.insert("v1", Vector_(3, 1.0, 2.0, 3.0)); | 
					
						
							|  |  |  |   config0.insert("v2", Vector_(3, 5.0, 6.0, 7.0)); | 
					
						
							| 
									
										
										
										
											2010-01-11 01:26:44 +08:00
										 |  |  |   //config0.print("config0");
 | 
					
						
							| 
									
										
										
										
											2010-01-11 06:41:23 +08:00
										 |  |  |   CHECK(equal(config0, config0)); | 
					
						
							|  |  |  |   CHECK(config0.equals(config0)); | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  |   LieConfig<string,Pose2> poseconfig; | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  |   poseconfig.insert("p1", Pose2(1,2,3)); | 
					
						
							|  |  |  |   poseconfig.insert("p2", Pose2(0.3, 0.4, 0.5)); | 
					
						
							| 
									
										
										
										
											2010-01-11 01:26:44 +08:00
										 |  |  |   //poseconfig.print("poseconfig");
 | 
					
						
							| 
									
										
										
										
											2010-01-11 06:41:23 +08:00
										 |  |  |   CHECK(equal(config0, config0)); | 
					
						
							|  |  |  |   CHECK(config0.equals(config0)); | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-10 08:20:12 +08:00
										 |  |  | /* ************************************************************************* *
 | 
					
						
							| 
									
										
										
										
											2010-03-04 21:21:48 +08:00
										 |  |  | TEST(LieConfig, extract_keys) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	typedef TypedSymbol<Pose2, 'x'> PoseKey; | 
					
						
							|  |  |  | 	LieConfig<PoseKey, Pose2> config; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config.insert(PoseKey(1), Pose2()); | 
					
						
							|  |  |  | 	config.insert(PoseKey(2), Pose2()); | 
					
						
							|  |  |  | 	config.insert(PoseKey(4), Pose2()); | 
					
						
							|  |  |  | 	config.insert(PoseKey(5), Pose2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list<PoseKey> expected, actual; | 
					
						
							|  |  |  | 	expected += PoseKey(1), PoseKey(2), PoseKey(4), PoseKey(5); | 
					
						
							|  |  |  | 	actual = config.keys(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CHECK(actual.size() == expected.size()); | 
					
						
							|  |  |  | 	list<PoseKey>::const_iterator itAct = actual.begin(), itExp = expected.begin(); | 
					
						
							|  |  |  | 	for (; itAct != actual.end() && itExp != expected.end(); ++itAct, ++itExp) { | 
					
						
							|  |  |  | 		CHECK(assert_equal(*itExp, *itAct)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-29 10:16:18 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST(LieConfig, exists_) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	LieConfig<string,Vector> config0; | 
					
						
							|  |  |  | 	config0.insert("v1", Vector_(1, 1.)); | 
					
						
							|  |  |  | 	config0.insert("v2", Vector_(1, 2.)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	boost::optional<Vector> v = config0.exists_("v1"); | 
					
						
							|  |  |  | 	CHECK(assert_equal(Vector_(1, 1.),*v)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST(LieConfig, update) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	LieConfig<string,Vector> config0; | 
					
						
							|  |  |  | 	config0.insert("v1", Vector_(1, 1.)); | 
					
						
							|  |  |  | 	config0.insert("v2", Vector_(1, 2.)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	LieConfig<string,Vector> superset; | 
					
						
							|  |  |  | 	superset.insert("v1", Vector_(1, -1.)); | 
					
						
							|  |  |  | 	superset.insert("v2", Vector_(1, -2.)); | 
					
						
							|  |  |  | 	superset.insert("v3", Vector_(1, -3.)); | 
					
						
							|  |  |  | 	config0.update(superset); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	LieConfig<string,Vector> expected; | 
					
						
							|  |  |  | 	expected.insert("v1", Vector_(1, -1.)); | 
					
						
							|  |  |  | 	expected.insert("v2", Vector_(1, -2.)); | 
					
						
							|  |  |  | 	CHECK(assert_equal(expected,config0)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-10 14:35:16 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { TestResult tr; return TestRegistry::runAllTests(tr); } | 
					
						
							|  |  |  | /* ************************************************************************* */ |