Add test for ManifoldEvaluationFunctor

release/4.3a0
Frank Dellaert 2022-02-26 22:43:55 -05:00
parent 5f9082b536
commit a16f588317
1 changed files with 28 additions and 8 deletions

View File

@ -10,18 +10,20 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
/** /**
* @file testChebyshev.cpp * @file testChebyshev2.cpp
* @date July 4, 2020 * @date July 4, 2020
* @author Varun Agrawal * @author Varun Agrawal
* @brief Unit tests for Chebyshev Basis Decompositions via pseudo-spectral * @brief Unit tests for Chebyshev Basis Decompositions via pseudo-spectral
* methods * methods
*/ */
#include <CppUnitLite/TestHarness.h>
#include <gtsam/base/Testable.h>
#include <gtsam/basis/Chebyshev2.h> #include <gtsam/basis/Chebyshev2.h>
#include <gtsam/basis/FitBasis.h> #include <gtsam/basis/FitBasis.h>
#include <gtsam/geometry/Pose2.h>
#include <gtsam/nonlinear/factorTesting.h> #include <gtsam/nonlinear/factorTesting.h>
#include <gtsam/base/Testable.h>
#include <CppUnitLite/TestHarness.h>
using namespace std; using namespace std;
using namespace gtsam; using namespace gtsam;
@ -123,12 +125,30 @@ TEST(Chebyshev2, InterpolateVector) {
EXPECT(assert_equal(numericalH, actualH, 1e-9)); EXPECT(assert_equal(numericalH, actualH, 1e-9));
} }
//******************************************************************************
// Interpolating poses using the exponential map
TEST(Chebyshev2, InterpolatePose2) {
double t = 30, a = 0, b = 100;
ParameterMatrix<3> X(N);
X.row(0) = Chebyshev2::Points(N, a, b); // slope 1 ramp
X.row(1) = Vector::Zero(N);
X.row(2) = 0.1 * Vector::Ones(N);
Vector xi(3);
xi << t, 0, 0.1;
Chebyshev2::ManifoldEvaluationFunctor<Pose2> fx(N, t, a, b);
// We use xi as canonical coordinates via exponential map
Pose2 expected = Pose2::ChartAtOrigin::Retract(xi);
EXPECT(assert_equal(expected, fx(X)));
}
//****************************************************************************** //******************************************************************************
TEST(Chebyshev2, Decomposition) { TEST(Chebyshev2, Decomposition) {
// Create example sequence // Create example sequence
Sequence sequence; Sequence sequence;
for (size_t i = 0; i < 16; i++) { for (size_t i = 0; i < 16; i++) {
double x = (double)i / 16. - 0.99, y = x; double x = (1.0/ 16)*i - 0.99, y = x;
sequence[x] = y; sequence[x] = y;
} }
@ -146,11 +166,11 @@ TEST(Chebyshev2, DifferentiationMatrix3) {
// Trefethen00book, p.55 // Trefethen00book, p.55
const size_t N = 3; const size_t N = 3;
Matrix expected(N, N); Matrix expected(N, N);
// Differentiation matrix computed from Chebfun // Differentiation matrix computed from chebfun
expected << 1.5000, -2.0000, 0.5000, // expected << 1.5000, -2.0000, 0.5000, //
0.5000, -0.0000, -0.5000, // 0.5000, -0.0000, -0.5000, //
-0.5000, 2.0000, -1.5000; -0.5000, 2.0000, -1.5000;
// multiply by -1 since the cheb points have a phase shift wrt Trefethen // multiply by -1 since the chebyshev points have a phase shift wrt Trefethen
// This was verified with chebfun // This was verified with chebfun
expected = -expected; expected = -expected;
@ -169,7 +189,7 @@ TEST(Chebyshev2, DerivativeMatrix6) {
0.3820, -0.8944, 1.6180, 0.1708, -2.0000, 0.7236, // 0.3820, -0.8944, 1.6180, 0.1708, -2.0000, 0.7236, //
-0.2764, 0.6180, -0.8944, 2.0000, 1.1708, -2.6180, // -0.2764, 0.6180, -0.8944, 2.0000, 1.1708, -2.6180, //
0.5000, -1.1056, 1.5279, -2.8944, 10.4721, -8.5000; 0.5000, -1.1056, 1.5279, -2.8944, 10.4721, -8.5000;
// multiply by -1 since the cheb points have a phase shift wrt Trefethen // multiply by -1 since the chebyshev points have a phase shift wrt Trefethen
// This was verified with chebfun // This was verified with chebfun
expected = -expected; expected = -expected;
@ -254,7 +274,7 @@ TEST(Chebyshev2, DerivativeWeights2) {
Weights dWeights2 = Chebyshev2::DerivativeWeights(N, x2, a, b); Weights dWeights2 = Chebyshev2::DerivativeWeights(N, x2, a, b);
EXPECT_DOUBLES_EQUAL(fprime(x2), dWeights2 * fvals, 1e-8); EXPECT_DOUBLES_EQUAL(fprime(x2), dWeights2 * fvals, 1e-8);
// test if derivative calculation and cheb point is correct // test if derivative calculation and Chebyshev point is correct
double x3 = Chebyshev2::Point(N, 3, a, b); double x3 = Chebyshev2::Point(N, 3, a, b);
Weights dWeights3 = Chebyshev2::DerivativeWeights(N, x3, a, b); Weights dWeights3 = Chebyshev2::DerivativeWeights(N, x3, a, b);
EXPECT_DOUBLES_EQUAL(fprime(x3), dWeights3 * fvals, 1e-8); EXPECT_DOUBLES_EQUAL(fprime(x3), dWeights3 * fvals, 1e-8);