2010-01-10 14:35:16 +08:00
|
|
|
/*
|
|
|
|
* testLieConfig.cpp
|
|
|
|
*
|
|
|
|
* Created on: Jan 5, 2010
|
|
|
|
* Author: richard
|
|
|
|
*/
|
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/CppUnitLite/TestHarness.h>
|
2010-01-10 14:35:16 +08:00
|
|
|
#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-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/nonlinear/LieConfig-inl.h>
|
2010-08-24 03:44:17 +08:00
|
|
|
#include <gtsam/base/LieVector.h>
|
2010-01-10 14:35:16 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
typedef TypedSymbol<Vector, 'v'> VecKey;
|
|
|
|
typedef LieConfig<VecKey> Config;
|
|
|
|
|
|
|
|
VecKey key1(1), key2(2), key3(3), key4(4);
|
|
|
|
|
2010-01-10 14:35:16 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST( LieConfig, equals1 )
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config expected;
|
2010-01-10 14:35:16 +08:00
|
|
|
Vector v = Vector_(3, 5.0, 6.0, 7.0);
|
2010-08-24 03:44:17 +08:00
|
|
|
expected.insert(key1,v);
|
|
|
|
Config actual;
|
|
|
|
actual.insert(key1,v);
|
2010-01-10 14:35:16 +08:00
|
|
|
CHECK(assert_equal(expected,actual));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST( LieConfig, equals2 )
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config 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);
|
2010-08-24 03:44:17 +08:00
|
|
|
cfg1.insert(key1, v1);
|
|
|
|
cfg2.insert(key1, v2);
|
2010-01-10 14:35:16 +08:00
|
|
|
CHECK(!cfg1.equals(cfg2));
|
|
|
|
CHECK(!cfg2.equals(cfg1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST( LieConfig, equals_nan )
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config 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-08-24 03:44:17 +08:00
|
|
|
cfg1.insert(key1, v1);
|
|
|
|
cfg2.insert(key1, v2);
|
2010-01-10 14:35:16 +08:00
|
|
|
CHECK(!cfg1.equals(cfg2));
|
|
|
|
CHECK(!cfg2.equals(cfg1));
|
|
|
|
}
|
|
|
|
|
2010-02-25 10:50:01 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST( LieConfig, insert_config )
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config cfg1, cfg2, expected;
|
2010-02-25 10:50:01 +08:00
|
|
|
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);
|
2010-08-24 03:44:17 +08:00
|
|
|
cfg1.insert(key1, v1);
|
|
|
|
cfg1.insert(key2, v2);
|
|
|
|
cfg2.insert(key2, v3);
|
|
|
|
cfg2.insert(key3, v4);
|
2010-02-25 10:50:01 +08:00
|
|
|
|
|
|
|
cfg1.insert(cfg2);
|
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
expected.insert(key1, v1);
|
|
|
|
expected.insert(key2, v2);
|
|
|
|
expected.insert(key2, v3);
|
|
|
|
expected.insert(key3, v4);
|
2010-02-25 10:50:01 +08:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config cfg;
|
2010-05-04 02:07:27 +08:00
|
|
|
Vector v1 = Vector_(3, 5.0, 6.0, 7.0);
|
|
|
|
Vector v2 = Vector_(3, 8.0, 9.0, 1.0);
|
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
cfg.insert(key1, v1);
|
2010-05-04 02:07:27 +08:00
|
|
|
CHECK(cfg.size() == 1);
|
2010-08-24 03:44:17 +08:00
|
|
|
CHECK(assert_equal(v1, cfg.at(key1)));
|
2010-05-04 02:07:27 +08:00
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
cfg.update(key1, v2);
|
2010-05-04 02:07:27 +08:00
|
|
|
CHECK(cfg.size() == 1);
|
2010-08-24 03:44:17 +08:00
|
|
|
CHECK(assert_equal(v2, cfg.at(key1)));
|
2010-05-04 02:07:27 +08:00
|
|
|
}
|
|
|
|
|
2010-03-10 08:20:12 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST(LieConfig, dim_zero)
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config config0;
|
|
|
|
config0.insert(key1, Vector_(2, 2.0, 3.0));
|
|
|
|
config0.insert(key2, Vector_(3, 5.0, 6.0, 7.0));
|
2010-03-10 08:20:12 +08:00
|
|
|
LONGS_EQUAL(5,config0.dim());
|
|
|
|
|
|
|
|
VectorConfig expected;
|
2010-08-24 03:44:17 +08:00
|
|
|
expected.insert(key1, zero(2));
|
|
|
|
expected.insert(key2, zero(3));
|
2010-03-10 08:20:12 +08:00
|
|
|
CHECK(assert_equal(expected, config0.zero()));
|
|
|
|
}
|
|
|
|
|
2010-01-10 14:35:16 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST(LieConfig, expmap_a)
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config config0;
|
|
|
|
config0.insert(key1, Vector_(3, 1.0, 2.0, 3.0));
|
|
|
|
config0.insert(key2, Vector_(3, 5.0, 6.0, 7.0));
|
2010-01-10 14:35:16 +08:00
|
|
|
|
|
|
|
VectorConfig increment;
|
2010-08-24 03:44:17 +08:00
|
|
|
increment.insert(key1, Vector_(3, 1.0, 1.1, 1.2));
|
|
|
|
increment.insert(key2, Vector_(3, 1.3, 1.4, 1.5));
|
2010-01-10 14:35:16 +08:00
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
Config expected;
|
|
|
|
expected.insert(key1, Vector_(3, 2.0, 3.1, 4.2));
|
|
|
|
expected.insert(key2, Vector_(3, 6.3, 7.4, 8.5));
|
2010-01-10 14:35:16 +08:00
|
|
|
|
|
|
|
CHECK(assert_equal(expected, expmap(config0, increment)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST(LieConfig, expmap_b)
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config config0;
|
|
|
|
config0.insert(key1, Vector_(3, 1.0, 2.0, 3.0));
|
|
|
|
config0.insert(key2, Vector_(3, 5.0, 6.0, 7.0));
|
2010-01-10 14:35:16 +08:00
|
|
|
|
|
|
|
VectorConfig increment;
|
2010-08-24 03:44:17 +08:00
|
|
|
increment.insert(key2, Vector_(3, 1.3, 1.4, 1.5));
|
2010-01-10 14:35:16 +08:00
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
Config expected;
|
|
|
|
expected.insert(key1, Vector_(3, 1.0, 2.0, 3.0));
|
|
|
|
expected.insert(key2, Vector_(3, 6.3, 7.4, 8.5));
|
2010-01-10 14:35:16 +08:00
|
|
|
|
|
|
|
CHECK(assert_equal(expected, expmap(config0, increment)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST(LieConfig, expmap_c)
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config config0;
|
|
|
|
config0.insert(key1, Vector_(3, 1.0, 2.0, 3.0));
|
|
|
|
config0.insert(key2, Vector_(3, 5.0, 6.0, 7.0));
|
2010-01-10 14:35:16 +08:00
|
|
|
|
|
|
|
Vector increment = Vector_(6,
|
|
|
|
1.0, 1.1, 1.2,
|
|
|
|
1.3, 1.4, 1.5);
|
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
Config expected;
|
|
|
|
expected.insert(key1, Vector_(3, 2.0, 3.1, 4.2));
|
|
|
|
expected.insert(key2, Vector_(3, 6.3, 7.4, 8.5));
|
2010-01-10 14:35:16 +08:00
|
|
|
|
|
|
|
CHECK(assert_equal(expected, expmap(config0, increment)));
|
|
|
|
}
|
|
|
|
|
2010-07-11 06:59:50 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
/*TEST(LieConfig, expmap_d)
|
2010-01-10 14:35:16 +08:00
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config config0;
|
|
|
|
config0.insert(key1, Vector_(3, 1.0, 2.0, 3.0));
|
|
|
|
config0.insert(key2, 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-07-11 06:59:50 +08:00
|
|
|
}*/
|
2010-01-10 14:35:16 +08:00
|
|
|
|
2010-07-11 06:59:50 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
/*TEST(LieConfig, extract_keys)
|
2010-03-04 21:21:48 +08:00
|
|
|
{
|
|
|
|
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-07-11 06:59:50 +08:00
|
|
|
}*/
|
2010-03-04 21:21:48 +08:00
|
|
|
|
2010-04-29 10:16:18 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST(LieConfig, exists_)
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config config0;
|
|
|
|
config0.insert(key1, Vector_(1, 1.));
|
|
|
|
config0.insert(key2, Vector_(1, 2.));
|
2010-04-29 10:16:18 +08:00
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
boost::optional<Vector> v = config0.exists_(key1);
|
2010-04-29 10:16:18 +08:00
|
|
|
CHECK(assert_equal(Vector_(1, 1.),*v));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST(LieConfig, update)
|
|
|
|
{
|
2010-08-24 03:44:17 +08:00
|
|
|
Config config0;
|
|
|
|
config0.insert(key1, Vector_(1, 1.));
|
|
|
|
config0.insert(key2, Vector_(1, 2.));
|
|
|
|
|
|
|
|
Config superset;
|
|
|
|
superset.insert(key1, Vector_(1, -1.));
|
|
|
|
superset.insert(key2, Vector_(1, -2.));
|
|
|
|
superset.insert(key3, Vector_(1, -3.));
|
2010-04-29 10:16:18 +08:00
|
|
|
config0.update(superset);
|
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
Config expected;
|
|
|
|
expected.insert(key1, Vector_(1, -1.));
|
|
|
|
expected.insert(key2, Vector_(1, -2.));
|
2010-04-29 10:16:18 +08:00
|
|
|
CHECK(assert_equal(expected,config0));
|
|
|
|
}
|
2010-08-14 03:51:04 +08:00
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST(LieConfig, dummy_initialization)
|
|
|
|
{
|
|
|
|
typedef TypedSymbol<Vector, 'z'> Key;
|
2010-08-24 03:44:17 +08:00
|
|
|
typedef LieConfig<Key> Config1;
|
2010-08-14 03:51:04 +08:00
|
|
|
|
|
|
|
Config1 init1;
|
|
|
|
init1.insert(Key(1), Vector_(2, 1.0, 2.0));
|
|
|
|
init1.insert(Key(2), Vector_(2, 4.0, 3.0));
|
|
|
|
|
2010-08-24 03:44:17 +08:00
|
|
|
Config init2;
|
|
|
|
init2.insert(key1, Vector_(2, 1.0, 2.0));
|
|
|
|
init2.insert(key2, Vector_(2, 4.0, 3.0));
|
2010-08-14 03:51:04 +08:00
|
|
|
|
|
|
|
Config1 actual1(init2);
|
2010-08-24 03:44:17 +08:00
|
|
|
Config actual2(init1);
|
2010-08-14 03:51:04 +08:00
|
|
|
|
|
|
|
EXPECT(actual1.empty());
|
|
|
|
EXPECT(actual2.empty());
|
|
|
|
}
|
|
|
|
|
2010-01-10 14:35:16 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
|
|
|
/* ************************************************************************* */
|