26 #define GTSAM_MAGIC_GAUSSIAN 2 37 using namespace gtsam;
61 CHECK(!f0.equals(f1));
62 CHECK(!f1.equals(f0));
72 NonlinearFactorGraph::sharedFactor f0 = fg[0],
f1 = fg[1];
74 CHECK(f0->equals(*f0));
75 CHECK(!f0->equals(*f1));
76 CHECK(!f1->equals(*f0));
89 NonlinearFactorGraph::sharedFactor factor = fg[0];
100 double actual = factor->error(cfg);
116 auto noise = noiseModel::Isotropic::Sigma(2, 0.2);
125 auto gaussian = noiseModel::Isotropic::Sigma(2, 0.2);
130 vector<noiseModel::Robust::shared_ptr> robust_models;
133 auto fair = noiseModel::Robust::Create(
134 noiseModel::mEstimator::Fair::Create(1.3998), gaussian);
135 robust_models.push_back(fair);
138 auto huber = noiseModel::Robust::Create(
139 noiseModel::mEstimator::Huber::Create(1.345), gaussian);
140 robust_models.push_back(huber);
143 auto cauchy = noiseModel::Robust::Create(
144 noiseModel::mEstimator::Cauchy::Create(0.1), gaussian);
145 robust_models.push_back(cauchy);
148 auto tukey = noiseModel::Robust::Create(
149 noiseModel::mEstimator::Tukey::Create(4.6851), gaussian);
150 robust_models.push_back(tukey);
153 auto welsch = noiseModel::Robust::Create(
154 noiseModel::mEstimator::Welsch::Create(2.9846), gaussian);
155 robust_models.push_back(welsch);
158 auto gm = noiseModel::Robust::Create(
159 noiseModel::mEstimator::GemanMcClure::Create(1.0), gaussian);
160 robust_models.push_back(gm);
163 auto dcs = noiseModel::Robust::Create(
164 noiseModel::mEstimator::DCS::Create(1.0), gaussian);
165 robust_models.push_back(dcs);
168 auto l2 = noiseModel::Robust::Create(
169 noiseModel::mEstimator::L2WithDeadZone::Create(1.0), gaussian);
170 robust_models.push_back(
l2);
172 for(
auto&&
model: robust_models) {
187 NonlinearFactorGraph::sharedFactor nlf = nfg[0];
190 GaussianFactor::shared_ptr actual = nlf->
linearize(c);
193 GaussianFactor::shared_ptr
expected = lfg[0];
209 NonlinearFactorGraph::sharedFactor nlf = nfg[1];
212 GaussianFactor::shared_ptr actual = nlf->
linearize(c);
215 GaussianFactor::shared_ptr
expected = lfg[1];
225 NonlinearFactorGraph::sharedFactor nlf = nfg[2];
229 GaussianFactor::shared_ptr actual = nlf->linearize(c);
232 GaussianFactor::shared_ptr
expected = lfg[2];
242 NonlinearFactorGraph::sharedFactor nlf = nfg[3];
246 GaussianFactor::shared_ptr actual = nlf->linearize(c);
249 GaussianFactor::shared_ptr
expected = lfg[3];
264 NonlinearFactorGraph::sharedFactor
factor1 = fg[0],
factor2 = fg[1],
267 CHECK(factor1->size() == 1);
268 CHECK(factor2->size() == 2);
269 CHECK(factor3->size() == 2);
282 GaussianFactor::shared_ptr actual = f0->linearize(config);
287 noiseModel::Constrained::MixedSigmas(
Vector2(1,0)));
302 GaussianFactor::shared_ptr actual = f0.linearize(config);
305 Matrix2
A; A << 5.0, 0.0, 0.0, 1.0;
308 noiseModel::Constrained::MixedSigmas(
Vector2(1,0)));
326 actual.
push_back( std::dynamic_pointer_cast<NoiseModelFactor>(nfg[0])->cloneWithNewNoiseModel(noise2) );
335 static_assert(std::is_same<
This, NoiseModelFactor1<double>>::
value,
339 typedef NoiseModelFactor1<double>
Base;
342 using Base::evaluateError;
350 if (H1) *H1 = (
Matrix(1, 1) << 1.0).finished();
351 return (
Vector(1) << x1).finished();
364 tv.
insert(
L(1),
double((1.0)));
368 *std::dynamic_pointer_cast<JacobianFactor>(tf.linearize(tv)));
371 jf.getA(jf.begin())));
378 std::vector<Matrix>
H = {
Matrix()};
392 NoiseModelFactor4<double, double, double, double>>::
value,
396 typedef NoiseModelFactor4<double, double, double, double>
Base;
399 using Base::evaluateError;
411 *H1 = (
Matrix(1, 1) << 1.0).finished();
412 *H2 = (
Matrix(1, 1) << 2.0).finished();
413 *H3 = (
Matrix(1, 1) << 3.0).finished();
414 *H4 = (
Matrix(1, 1) << 4.0).finished();
416 return (
Vector(1) << x1 + 2.0 * x2 + 3.0 * x3 + 4.0 * x4).finished();
428 tv.
insert(
X(1),
double((1.0)));
429 tv.
insert(
X(2),
double((2.0)));
430 tv.
insert(
X(3),
double((3.0)));
431 tv.
insert(
X(4),
double((4.0)));
434 JacobianFactor jf(*std::dynamic_pointer_cast<JacobianFactor>(tf.linearize(tv)));
447 "X1 type incorrect");
449 "X2 type incorrect");
451 "X3 type incorrect");
453 "X4 type incorrect");
466 static_assert(std::is_same<TestFactor4::ValueType<1>,
double>::
value,
467 "ValueType<1> type incorrect");
468 static_assert(std::is_same<TestFactor4::ValueType<2>,
double>::
value,
469 "ValueType<2> type incorrect");
470 static_assert(std::is_same<TestFactor4::ValueType<3>,
double>::
value,
471 "ValueType<3> type incorrect");
472 static_assert(std::is_same<TestFactor4::ValueType<4>,
double>::
value,
473 "ValueType<4> type incorrect");
481 TestFactor4 tf3(noiseModel::Unit::Create(1), {
L(1),
L(2),
L(3),
L(4)});
483 std::array<Key, 4>{
L(1),
L(2),
L(3),
L(4)});
484 std::vector<Key>
keys = {
L(1),
L(2),
L(3),
L(4)};
485 TestFactor4 tf5(noiseModel::Unit::Create(1), keys);
491 typedef NoiseModelFactor5<double, double, double, double, double>
Base;
494 using Base::evaluateError;
503 *H1 = (
Matrix(1, 1) << 1.0).finished();
504 *H2 = (
Matrix(1, 1) << 2.0).finished();
505 *H3 = (
Matrix(1, 1) << 3.0).finished();
506 *H4 = (
Matrix(1, 1) << 4.0).finished();
507 *H5 = (
Matrix(1, 1) << 5.0).finished();
509 return (
Vector(1) << x1 + 2.0 * x2 + 3.0 * x3 + 4.0 * x4 + 5.0 * x5)
518 tv.
insert(
X(1),
double((1.0)));
519 tv.
insert(
X(2),
double((2.0)));
520 tv.
insert(
X(3),
double((3.0)));
521 tv.
insert(
X(4),
double((4.0)));
522 tv.
insert(
X(5),
double((5.0)));
525 JacobianFactor jf(*std::dynamic_pointer_cast<JacobianFactor>(tf.linearize(tv)));
542 typedef NoiseModelFactor6<double, double, double, double, double, double>
Base;
545 using Base::evaluateError;
554 *H1 = (
Matrix(1, 1) << 1.0).finished();
555 *H2 = (
Matrix(1, 1) << 2.0).finished();
556 *H3 = (
Matrix(1, 1) << 3.0).finished();
557 *H4 = (
Matrix(1, 1) << 4.0).finished();
558 *H5 = (
Matrix(1, 1) << 5.0).finished();
559 *H6 = (
Matrix(1, 1) << 6.0).finished();
561 return (
Vector(1) << x1 + 2.0 * x2 + 3.0 * x3 + 4.0 * x4 + 5.0 * x5 +
572 tv.
insert(
X(1),
double((1.0)));
573 tv.
insert(
X(2),
double((2.0)));
574 tv.
insert(
X(3),
double((3.0)));
575 tv.
insert(
X(4),
double((4.0)));
576 tv.
insert(
X(5),
double((5.0)));
577 tv.
insert(
X(6),
double((6.0)));
580 JacobianFactor jf(*std::dynamic_pointer_cast<JacobianFactor>(tf.linearize(tv)));
603 using Base::evaluateError;
613 if (H1) *H1 = (
Matrix(1, 1) << 1.0).finished();
614 if (H2) *H2 = (
Matrix(1, 1) << 2.0).finished();
615 if (H3) *H3 = (
Matrix(1, 1) << 3.0).finished();
616 if (H4) *H4 = (
Matrix(1, 1) << 4.0).finished();
617 return (
Vector(1) << x1 + 2.0 * x2 + 3.0 * x3 + 4.0 * x4).finished();
627 tv.
insert(
X(1),
double((1.0)));
628 tv.
insert(
X(2),
double((2.0)));
629 tv.
insert(
X(3),
double((3.0)));
630 tv.
insert(
X(4),
double((4.0)));
645 Matrix H1_expected, H2_expected, H3_expected, H4_expected;
647 H3_expected, H4_expected);
649 std::unique_ptr<NoiseModelFactorN<double, double, double, double>> base_ptr(
656 base_ptr->evaluateError(9, 8, 7, 6, H1, H2)));
660 base_ptr->evaluateError(9, 8, 7, 6, H1, H2, H3)));
665 base_ptr->evaluateError(9, 8, 7, 6, H1, H2, H3, H4)));
674 "X1 type incorrect");
680 "ValueType<1> type incorrect");
682 "ValueType<2> type incorrect");
684 "ValueType<3> type incorrect");
686 "ValueType<4> type incorrect");
688 "TestFactorN::Type1 type incorrect");
707 EXPECT(actClone.get() != init.get());
713 EXPECT(actRekey.get() != init.get());
Values createNoisyValues()
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
This is the base class for all measurement types.
Factor Graph consisting of non-linear factors.
GaussianFactorGraph createGaussianFactorGraph()
Eigen::Matrix< double, 1, 1 > Vector1
Point2 prior(const Point2 &x)
Prior on a single pose.
noiseModel::Diagonal::shared_ptr model
TEST(NonlinearFactor, equals)
NoiseModelFactor5< double, double, double, double, double > Base
#define DOUBLES_EQUAL(expected, actual, threshold)
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
A factor with a quadratic error function - a Gaussian.
NonlinearFactorGraph nonlinearFactorGraphWithGivenSigma(const double sigma)
Double_ distance(const OrientedPlane3_ &p)
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
#define NoiseModelFactor4
NoiseModelFactorN< double, double, double, double > Base
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
#define NoiseModelFactor5
NoiseModelFactor6< double, double, double, double, double, double > Base
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
Vector evaluateError(const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, const X5 &x5, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4, OptionalMatrixType H5) const override
Matrix * OptionalMatrixType
NoiseModelFactor4< double, double, double, double > Base
gtsam::NonlinearFactor::shared_ptr clone() const override
#define EXPECT(condition)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
NonlinearFactorGraph createNonlinearFactorGraph(const SharedNoiseModel &noiseModel1=impl::kSigma0_1, const SharedNoiseModel &noiseModel2=impl::kSigma0_2)
double weight(const Values &c) const
std::shared_ptr< GaussianFactor > linearize(const Values &x) const override
#define NoiseModelFactor6
Pose3 x3(Rot3::Ypr(M_PI/4.0, 0.0, 0.0), l2)
#define LONGS_EQUAL(expected, actual)
noiseModel::Diagonal::shared_ptr SharedDiagonal
#define NoiseModelFactor1
Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const override
measurement functions and derivatives for simulated 2D robot
double error(const Values &c) const override
#define EXPECT_LONGS_EQUAL(expected, actual)
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
std::shared_ptr< This > shared_ptr
typename std::tuple_element< I - 1, std::tuple< ValueTypes... > >::type ValueType
Vector evaluateError(const double &x1, const double &x2, const double &x3, const double &x4, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4) const override
Create small example with two poses and one landmark.
static noiseModel::Diagonal::shared_ptr Diagonal(const Matrix &covariance)
gtsam::NonlinearFactor::shared_ptr clone() const override
static const double sigma
void insert(Key j, const Value &val)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
NoiseModelFactor1< double > Base
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
The matrix class, also used for vectors and row-vectors.
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Vector evaluateError(const double &x1, OptionalMatrixType H1) const override
Vector evaluateError(const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, const X5 &x5, const X6 &x6, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4, OptionalMatrixType H5, OptionalMatrixType H6) const override
std::uint64_t Key
Integer nonlinear key type.
std::shared_ptr< NonlinearFactor > shared_nlf
noiseModel::Base::shared_ptr SharedNoiseModel
Vector evaluateError(const double &x1, const double &x2, const double &x3, const double &x4, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4) const override