gtsam
Loading...
Searching...
No Matches
testLie.h
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
12/*
13 * @file testLie.h
14 * @brief Test utilities for Lie groups
15 * @date November, 2014
16 * @author Paul Furgale
17 */
18
19#pragma once
20
21#include <gtsam/base/Lie.h>
23
24#include <CppUnitLite/TestResult.h>
25#include <CppUnitLite/Test.h>
26#include <CppUnitLite/Failure.h>
27
28namespace gtsam {
29
30// Do a comprehensive test of Lie Group derivatives
31template<typename G>
32void testLieGroupDerivatives(TestResult& result_, const std::string& name_,
33 const G& t1, const G& t2) {
34
35 Matrix H1, H2;
36 typedef traits<G> T;
38
39 // Inverse
40 OJ none;
41 EXPECT(assert_equal<G>(t1.inverse(),T::Inverse(t1, H1)));
42 EXPECT(assert_equal(numericalDerivative21<G,G,OJ>(T::Inverse, t1, none),H1));
43
44 EXPECT(assert_equal<G>(t2.inverse(),T::Inverse(t2, H1)));
45 EXPECT(assert_equal(numericalDerivative21<G,G,OJ>(T::Inverse, t2, none),H1));
46
47 // Compose
48 EXPECT(assert_equal<G>(t1 * t2,T::Compose(t1, t2, H1, H2)));
49 EXPECT(assert_equal(numericalDerivative41<G,G,G,OJ,OJ>(T::Compose, t1, t2, none, none), H1));
50 EXPECT(assert_equal(numericalDerivative42<G,G,G,OJ,OJ>(T::Compose, t1, t2, none, none), H2));
51
52 // Between
53 EXPECT(assert_equal<G>(t1.inverse() * t2,T::Between(t1, t2, H1, H2)));
54 EXPECT(assert_equal(numericalDerivative41<G,G,G,OJ,OJ>(T::Between, t1, t2, none, none), H1));
55 EXPECT(assert_equal(numericalDerivative42<G,G,G,OJ,OJ>(T::Between, t1, t2, none, none), H2));
56}
57
58// Do a comprehensive test of Lie Group Chart derivatives
59template<typename G>
60void testChartDerivatives(TestResult& result_, const std::string& name_,
61 const G& t1, const G& t2) {
62
63 Matrix H1, H2;
64 typedef traits<G> T;
65 typedef typename T::TangentVector V;
67
68 // Retract
69 OJ none;
70 V w12 = T::Local(t1, t2);
71 EXPECT(assert_equal<G>(t2, T::Retract(t1,w12, H1, H2)));
72 const auto retract = [](const G& origin, const V& v, const OJ& H1,
73 const OJ& H2) { return T::Retract(origin, v, H1, H2); };
74 EXPECT(assert_equal(numericalDerivative41<G,G,V,OJ,OJ>(retract, t1, w12, none, none), H1));
75 EXPECT(assert_equal(numericalDerivative42<G,G,V,OJ,OJ>(retract, t1, w12, none, none), H2));
76
77 // Local
78 EXPECT(assert_equal(w12, T::Local(t1, t2, H1, H2)));
79 const auto local = [](const G& origin, const G& other, const OJ& H1,
80 const OJ& H2) { return T::Local(origin, other, H1, H2); };
81 EXPECT(assert_equal(numericalDerivative41<V,G,G,OJ,OJ>(local, t1, t2, none, none), H1));
82 EXPECT(assert_equal(numericalDerivative42<V,G,G,OJ,OJ>(local, t1, t2, none, none), H2));
83}
84} // namespace gtsam
85
86#define CHECK_LIE_GROUP_DERIVATIVES(t1,t2) \
87 { gtsam::testLieGroupDerivatives(result_, name_, t1, t2); }
88
89#define CHECK_CHART_DERIVATIVES(t1,t2) \
90 { gtsam::testChartDerivatives(result_, name_, t1, t2); }
Numerical derivative helpers for manifold-valued functions.
Base class and basic functions for Lie types.
internal::MatrixMN< traits< internal::OutputType< Y, F, X1, X2 > >::dimension, N >::type numericalDerivative21(F &&h, const X1 &x1, const X2 &x2, double delta=1e-5)
Compute numerical derivative in argument 1 of binary function.
Definition numericalDerivative.h:236
internal::MatrixMN< traits< internal::OutputType< Y, F, X1, X2, X3, X4 > >::dimension, N >::type numericalDerivative42(F &&h, const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, double delta=1e-5)
Compute numerical derivative in argument 2 of 4-argument function.
Definition numericalDerivative.h:417
internal::MatrixMN< traits< internal::OutputType< Y, F, X1, X2, X3, X4 > >::dimension, N >::type numericalDerivative41(F &&h, const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, double delta=1e-5)
Compute numerical derivative in argument 1 of 4-argument function.
Definition numericalDerivative.h:384
Global functions in a separate testing namespace.
Definition chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition Matrix.cpp:39
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40