29 using namespace gtsam;
30 using namespace noiseModel;
39 TEST(NoiseModel, constructors)
45 vector<Gaussian::shared_ptr>
m;
46 m.push_back(Gaussian::SqrtInformation(
R,
false));
47 m.push_back(Gaussian::Covariance(
kCovariance,
false));
48 m.push_back(Gaussian::Information(
kCovariance.inverse(),
false));
49 m.push_back(Diagonal::Sigmas(
kSigmas,
false));
52 m.push_back(Isotropic::Sigma(3,
kSigma,
false));
53 m.push_back(Isotropic::Variance(3,
kVariance,
false));
54 m.push_back(Isotropic::Precision(3,
prc,
false));
71 DOUBLES_EQUAL(distance,mi->squaredMahalanobisDistance(unwhitened),1
e-9);
89 1.0, 0.0, 0.0, 1.0).finished());
95 m[0]->WhitenInPlace(H);
111 g2 = Gaussian::SqrtInformation(I_3x3);
113 d2 = Diagonal::Sigmas(
Vector3(0.1, 0.2, 0.3));
115 i2 = Isotropic::Sigma(3, 0.7);
145 TEST(NoiseModel, ConstrainedConstructors )
152 actual = Constrained::All(d);
159 actual = Constrained::All(d, m);
162 actual = Constrained::All(d, mu);
165 actual = Constrained::MixedSigmas(mu, sigmas);
168 actual = Constrained::MixedSigmas(m, sigmas);
173 TEST(NoiseModel, ConstrainedMixed )
176 infeasible =
Vector3(1.0, 1.0, 1.0);
182 DOUBLES_EQUAL(0.5 * (1000.0 + 0.25 + 0.25),d->loss(d->squaredMahalanobisDistance(infeasible)),1
e-9);
188 TEST(NoiseModel, ConstrainedAll )
191 infeasible =
Vector3(1.0, 1.0, 1.0);
198 DOUBLES_EQUAL(0.5 * 1000.0 * 3.0,i->loss(i->squaredMahalanobisDistance(infeasible)),1
e-9);
199 DOUBLES_EQUAL(0.0, i->squaredMahalanobisDistance(feasible), 1
e-9);
207 -1., 0., 1., 0., 0., 0., -0.2,
208 0., -1., 0., 1., 0., 0., 0.3,
209 1., 0., 0., 0., -1., 0., 0.2,
210 0., 1., 0., 0., 0., -1., -0.1).finished();
215 11.1803, 0.0, -2.23607, 0.0, -8.94427, 0.0, 2.23607,
216 0.0, 11.1803, 0.0, -2.23607, 0.0, -8.94427,-1.56525,
217 0.0, 0.0, 4.47214, 0.0, -4.47214, 0.0, 0.0,
218 0.0, 0.0, 0.0, 4.47214, 0.0, -4.47214, 0.894427).finished();
231 EXPECT(actual1->isUnit());
235 Vector expectedSigmas = (
Vector(4) << 0.0894427, 0.0894427, 0.223607, 0.223607).finished();
236 SharedDiagonal expectedModel = noiseModel::Diagonal::Sigmas(expectedSigmas);
238 1., 0., -0.2, 0., -0.8, 0., 0.2,
239 0., 1., 0.,-0.2, 0., -0.8,-0.14,
240 0., 0., 1., 0., -1., 0., 0.0,
241 0., 0., 0., 1., 0., -1., 0.2).finished();
251 TEST(NoiseModel, OverdeterminedQR) {
259 Vector9 sigmas = Vector9::Ones() ;
262 EXPECT(actual1->isUnit());
264 expectedRd << -2.64575131, -2.64575131, -2.64575131, -2.64575131,
271 Vector3 expectedSigmas(0.377964473, 1, 1);
272 SharedDiagonal expectedModel = noiseModel::Diagonal::Sigmas(expectedSigmas);
275 SharedDiagonal constrained = noiseModel::Constrained::MixedSigmas(sigmas);
278 expectedRd.row(0) *= 0.377964473;
297 Vector mixed_sigmas = (
Vector(5) << 0, 1, 0, 1, 1).finished();
298 SharedDiagonal constrained = noiseModel::Constrained::MixedSigmas(mixed_sigmas);
301 Vector expectedSigmas = (
Vector(5) << 0, 1, 0, 1, 1).finished();
302 SharedDiagonal expectedModel = noiseModel::Diagonal::Sigmas(expectedSigmas);
303 Matrix expectedRd(5, 6+1);
304 expectedRd << 1, 0, 0, 0, 0, 1, 0,
338 SharedDiagonal constrained = noiseModel::Constrained::MixedSigmas(sigmas);
341 Vector3 expectedSigmas(0,0,1.0/3);
342 SharedDiagonal expectedModel = noiseModel::Constrained::MixedSigmas(expectedSigmas);
343 Matrix expectedRd(11, 3+1);
344 expectedRd.setZero();
345 expectedRd.row(0) << -1, 0, 1, 0;
346 expectedRd.row(1) << 0, -1, 1, 0;
347 expectedRd.row(2) << 0, 0, 1, 0;
355 TEST( NoiseModel, FullyConstrained )
367 expectedRd << 1, 0, 0, 0, 0, 1, 2,
381 Matrix Ab = (Matrix25() << 2, 4, 2, 4, 6, 2, 1, 2, 4, 4).finished();
384 Matrix expectedAb = (Matrix25() << 1, 2, 1, 2, 3, 0, 1, 0, 0, 2.0/3).finished();
392 TEST(NoiseModel, SmartSqrtInformation )
401 TEST(NoiseModel, SmartSqrtInformation2 )
410 TEST(NoiseModel, SmartInformation )
421 TEST(NoiseModel, SmartCovariance )
430 TEST(NoiseModel, ScalarOrVector )
439 TEST(NoiseModel, WhitenInPlace)
444 model->WhitenInPlace(A);
459 TEST(NoiseModel, robustFunctionFair)
461 const double k = 5.0, error1 = 1.0, error2 = 10.0, error3 = -10.0, error4 = -1.0;
475 TEST(NoiseModel, robustFunctionHuber)
477 const double k = 5.0, error1 = 1.0, error2 = 10.0, error3 = -10.0, error4 = -1.0;
491 TEST(NoiseModel, robustFunctionCauchy)
493 const double k = 5.0, error1 = 1.0, error2 = 10.0, error3 = -10.0, error4 = -1.0;
507 TEST(NoiseModel, robustFunctionGemanMcClure)
509 const double k = 1.0, error1 = 1.0, error2 = 10.0, error3 = -10.0, error4 = -1.0;
522 TEST(NoiseModel, robustFunctionWelsch)
524 const double k = 5.0, error1 = 1.0, error2 = 10.0, error3 = -10.0, error4 = -1.0;
538 TEST(NoiseModel, robustFunctionTukey)
540 const double k = 5.0, error1 = 1.0, error2 = 10.0, error3 = -10.0, error4 = -1.0;
554 TEST(NoiseModel, robustFunctionDCS)
556 const double k = 1.0, error1 = 1.0, error2 = 10.0;
566 TEST(NoiseModel, robustFunctionL2WithDeadZone)
568 const double k = 1.0, e0 = -10.0, e1 = -1.01, e2 = -0.99, e3 = 0.99, e4 = 1.01, e5 = 10.0;
587 TEST(NoiseModel, robustNoiseHuber)
589 const double k = 10.0, error1 = 1.0, error2 = 100.0;
590 Matrix A = (
Matrix(2, 2) << 1.0, 10.0, 100.0, 1000.0).finished();
596 robust->WhitenSystem(A, b);
607 TEST(NoiseModel, robustNoiseGemanMcClure)
609 const double k = 1.0, error1 = 1.0, error2 = 100.0;
610 const double a00 = 1.0, a01 = 10.0, a10 = 100.0, a11 = 1000.0;
617 robust->WhitenSystem(A, b);
619 const double k2 = k*k;
620 const double k4 = k2*k2;
621 const double k2error = k2 + error2*error2;
623 const double sqrt_weight_error1 =
sqrt(0.25);
624 const double sqrt_weight_error2 =
sqrt(k4/(k2error*k2error));
635 TEST(NoiseModel, robustNoiseDCS)
637 const double k = 1.0, error1 = 1.0, error2 = 100.0;
638 const double a00 = 1.0, a01 = 10.0, a10 = 100.0, a11 = 1000.0;
645 robust->WhitenSystem(A, b);
647 const double sqrt_weight = 2.0*k/(k + error2*error2);
658 TEST(NoiseModel, robustNoiseL2WithDeadZone)
660 double dead_zone_size = 1.0;
661 auto robust = noiseModel::Robust::Create(
662 noiseModel::mEstimator::L2WithDeadZone::Create(dead_zone_size),
665 for (
int i = 0;
i < 5;
i++) {
667 robust->WhitenSystem(error);
669 robust->squaredMahalanobisDistance(error), 1
e-8);
673 TEST(NoiseModel, lossFunctionAtZero)
675 const double k = 5.0;
676 auto fair = mEstimator::Fair::Create(k);
679 auto huber = mEstimator::Huber::Create(k);
682 auto cauchy = mEstimator::Cauchy::Create(k);
685 auto gmc = mEstimator::GemanMcClure::Create(k);
688 auto welsch = mEstimator::Welsch::Create(k);
691 auto tukey = mEstimator::Tukey::Create(k);
694 auto dcs = mEstimator::DCS::Create(k);
697 auto lsdz = mEstimator::L2WithDeadZone::Create(k);
704 #define TEST_GAUSSIAN(gaussian)\ 705 EQUALITY(info, gaussian->information());\ 706 EQUALITY(cov, gaussian->covariance());\ 707 EXPECT(assert_equal(white, gaussian->whiten(e)));\ 708 EXPECT(assert_equal(e, gaussian->unwhiten(white)));\ 709 EXPECT_DOUBLES_EQUAL(251.0, gaussian->squaredMahalanobisDistance(e), 1e-9);\ 710 EXPECT_DOUBLES_EQUAL(0.5 * 251.0, gaussian->loss(251.0), 1e-9);\ 711 Matrix A = R.inverse(); Vector b = e;\ 712 gaussian->WhitenSystem(A, b);\ 713 EXPECT(assert_equal(I, A));\ 714 EXPECT(assert_equal(white, b)); 716 TEST(NoiseModel, NonDiagonalGaussian)
719 R << 6, 5, 4, 0, 3, 2, 0, 0, 1;
720 const Matrix3
info = R.transpose() *
R;
721 const Matrix3 cov = info.inverse();
Provides additional testing facilities for common data structures.
std::shared_ptr< L2WithDeadZone > shared_ptr
std::shared_ptr< DCS > shared_ptr
Matrix< RealScalar, Dynamic, Dynamic > M
static const Matrix kCovariance
std::shared_ptr< Tukey > shared_ptr
static int runAllTests(TestResult &result)
noiseModel::Diagonal::shared_ptr model
#define DOUBLES_EQUAL(expected, actual, threshold)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
void diagonal(const MatrixType &m)
Double_ distance(const OrientedPlane3_ &p)
TEST(NoiseModel, constructors)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange [*:*] noreverse nowriteback set trange [*:*] noreverse nowriteback set urange [*:*] noreverse nowriteback set vrange [*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
static const double kVariance
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmax(const bfloat16 &a, const bfloat16 &b)
static const double kSigma
bool linear_dependent(const Matrix &A, const Matrix &B, double tol)
std::shared_ptr< Constrained > shared_ptr
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
#define EXPECT(condition)
Array< int, Dynamic, 1 > v
static const Vector3 kSigmas(kSigma, kSigma, kSigma)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
#define TEST_GAUSSIAN(gaussian)
std::shared_ptr< Isotropic > shared_ptr
std::shared_ptr< Welsch > shared_ptr
noiseModel::Diagonal::shared_ptr SharedDiagonal
std::shared_ptr< Fair > shared_ptr
std::optional< Vector > checkIfDiagonal(const Matrix &M)
std::shared_ptr< GemanMcClure > shared_ptr
std::shared_ptr< Robust > shared_ptr
Pose3 g1(Rot3(), Point3(100.0, 0.0, 300.0))
std::shared_ptr< Huber > shared_ptr
Jet< T, N > sqrt(const Jet< T, N > &f)
static const double kInverseSigma
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
std::shared_ptr< Gaussian > shared_ptr
std::shared_ptr< Cauchy > shared_ptr
std::shared_ptr< Diagonal > shared_ptr
Pose3 g2(g1.expmap(h *V1_g1))
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
noiseModel::Gaussian::shared_ptr SharedGaussian