29 using namespace gtsam;
31 using Dims = std::vector<Eigen::Index>;
36 using Terms = vector<pair<Key, Matrix> >;
37 const Terms terms{{5, I_3x3}, {10, 2 * I_3x3}, {15, 3 * I_3x3}};
42 noiseModel::Diagonal::Sigmas(
Vector3(0.5, 0.5, 0.5));
60 EXPECT(!actual.get_model());
67 LONGS_EQUAL((
long)terms[0].first, (
long)actual.keys().back());
72 EXPECT(noise == actual.get_model());
78 terms[1].first, terms[1].second, b, noise);
80 LONGS_EQUAL((
long)terms[1].first, (
long)actual.keys().back());
85 EXPECT(noise == actual.get_model());
91 terms[1].first, terms[1].second, terms[2].first, terms[2].second, b, noise);
93 LONGS_EQUAL((
long)terms[2].first, (
long)actual.keys().back());
98 EXPECT(noise == actual.get_model());
103 map<Key,Matrix> mapTerms;
105 mapTerms.insert(terms[2]);
106 mapTerms.insert(terms[1]);
107 mapTerms.insert(terms[0]);
121 blockMatrix(0) = terms[0].second;
122 blockMatrix(1) = terms[1].second;
123 blockMatrix(2) = terms[2].second;
127 for (
const auto& term : terms)
128 keys.push_back(term.first);
141 TEST(JabobianFactor, Hessian_conversion) {
143 1.57, 2.695, -1.1, -2.35,
144 2.695, 11.3125, -0.65, -10.225,
146 -2.35, -10.225, 0.5, 9.25).finished(),
147 (
Vector(4) << -7.885, -28.5175, 2.75, 25.675).finished(),
151 1.2530, 2.1508, -0.8779, -1.8755,
152 0, 2.5858, 0.4789, -2.3943).finished(),
159 TEST(JabobianFactor, Hessian_conversion2) {
170 TEST(JabobianFactor, Hessian_conversion3) {
173 0, 3, 2, 1).finished(),
187 auto factor1 = std::make_shared<JacobianFactor>(
188 keyX,
A11,
b1, noiseModel::Isotropic::Sigma(2, sigma1));
194 auto factor2 = std::make_shared<JacobianFactor>(
201 auto factor3 = std::make_shared<JacobianFactor>(
215 Matrix A3(6,2); A3 << Matrix::Zero(4,2),
A33;
232 values.
insert(5, Vector::Constant(3, 1.0));
233 values.
insert(10, Vector::Constant(3, 0.5));
234 values.
insert(15, Vector::Constant(3, 1.0/3.0));
236 Vector expected_unwhitened(3); expected_unwhitened << 2.0, 1.0, 0.0;
240 Vector expected_whitened(3); expected_whitened << 4.0, 2.0, 0.0;
244 double expected_error = 0.5 * expected_whitened.squaredNorm();
245 double actual_error = factor.
error(values);
255 Matrix jacobianExpected(3, 9);
256 jacobianExpected << simple::terms[0].second, simple::terms[1].second, simple::terms[2].second;
258 Matrix augmentedJacobianExpected(3, 10);
259 augmentedJacobianExpected << jacobianExpected, rhsExpected;
261 Matrix augmentedHessianExpected =
262 augmentedJacobianExpected.transpose() * augmentedJacobianExpected;
280 expectDiagonal.
insert(5, Vector::Ones(3));
281 expectDiagonal.
insert(10, 4*Vector::Ones(3));
282 expectDiagonal.
insert(15, 9*Vector::Ones(3));
299 Matrix jacobianExpected(3, 9);
300 jacobianExpected << simple::terms[0].second, simple::terms[1].second, simple::terms[2].second;
302 Matrix augmentedJacobianExpected(3, 10);
303 augmentedJacobianExpected << jacobianExpected, rhsExpected;
305 Matrix augmentedHessianExpected =
306 augmentedJacobianExpected.transpose() * simple::noise->R().transpose()
307 * simple::noise->R() * augmentedJacobianExpected;
342 const double sigma = 0.1;
361 const double alpha = 0.5;
362 expectedX.
insert(1, - alpha * expectedE /sigma);
363 expectedX.
insert(2, alpha * expectedE /sigma);
401 0.0, 0.0, 1.0).finished();
408 0.0, 0.0, 2.0).finished();
412 0.0, 0.0, -2.0).finished();
419 0.0, 0.0, 3.0).finished();
424 gfg.
add(1, A01, b0, noiseModel::Diagonal::Sigmas(s0,
true));
425 gfg.
add(0, A10, 1, A11, b1, noiseModel::Diagonal::Sigmas(s1,
true));
426 gfg.
add(1, A21, b2, noiseModel::Diagonal::Sigmas(s2,
true));
428 Matrix zero3x3 = Matrix::Zero(3,3);
431 Vector9
b; b <<
b1, b0,
b2;
432 Vector9
sigmas; sigmas << s1, s0, s2;
434 JacobianFactor combinedFactor(0, A0, 1, A1, b, noiseModel::Diagonal::Sigmas(sigmas,
true));
436 JacobianFactor::shared_ptr expectedJacobian = std::dynamic_pointer_cast<
440 JacobianFactor::shared_ptr actualJacobian = std::dynamic_pointer_cast<
479 vector<pair<Key, Matrix> > meas;
480 meas.push_back(make_pair(2, Ax2));
481 meas.push_back(make_pair(11, Al1x1));
482 JacobianFactor combined(meas, b2, noiseModel::Diagonal::Sigmas(sigmas));
485 pair<GaussianConditional::shared_ptr, JacobianFactor::shared_ptr>
489 double oldSigma = 0.0894427;
493 ).finished()/oldSigma;
495 -0.20, 0.00,-0.80, 0.00,
496 +0.00,-0.20,+0.00,-0.80
497 ).finished()/oldSigma;
504 double sigma = 0.2236;
507 1.00, 0.00, -1.00, 0.00,
508 0.00, 1.00, +0.00, -1.00
511 JacobianFactor expectedLF(11, Bl1x1, b1, noiseModel::Unit::Create(2));
520 4., 0., 1., 4., 1., 0., 3., 6., 8., 8., 1.,
521 9., 2., 0., 1., 6., 3., 9., 6., 6., 9., 4.,
522 5., 3., 7., 9., 5., 5., 9., 1., 3., 7., 0.,
523 5., 6., 5., 7., 9., 4., 0., 1., 1., 3., 5.,
524 0., 0., 4., 5., 6., 6., 7., 9., 4., 5., 4.,
525 0., 0., 9., 4., 8., 6., 2., 1., 4., 1., 6.,
526 0., 0., 6., 0., 4., 2., 4., 0., 1., 9., 6.,
527 0., 0., 6., 6., 4., 4., 5., 5., 5., 8., 6.,
528 0., 0., 0., 0., 8., 0., 9., 8., 2., 8., 0.,
529 0., 0., 0., 0., 0., 9., 4., 6., 3., 2., 0.,
530 0., 0., 0., 0., 1., 1., 9., 1., 5., 5., 3.,
531 0., 0., 0., 0., 1., 1., 3., 3., 2., 0., 5.,
532 0., 0., 0., 0., 0., 0., 0., 0., 2., 4., 6.,
533 0., 0., 0., 0., 0., 0., 0., 0., 6., 3., 4.).finished();
536 const SharedDiagonal sig_4D = noiseModel::Isotropic::Sigma(4, 0.5);
537 const SharedDiagonal sig_2D = noiseModel::Isotropic::Sigma(2, 0.5);
539 std::make_shared<JacobianFactor>(
KeyVector{3, 5, 7, 9, 11},
VerticalBlockMatrix(
Dims{2, 2, 2, 2, 2, 1}, Ab.block(0, 0, 4, 11)), sig_4D),
540 std::make_shared<JacobianFactor>(
KeyVector{5, 7, 9, 11},
VerticalBlockMatrix(
Dims{2, 2, 2, 2, 1}, Ab.block(4, 2, 4, 9)), sig_4D),
541 std::make_shared<JacobianFactor>(
KeyVector{7, 9, 11},
VerticalBlockMatrix(
Dims{2, 2, 2, 1}, Ab.block(8, 4, 4, 7)), sig_4D),
550 -12.1244, -5.1962, -5.2786, -8.6603, -10.5573, -5.9385, -11.3820, -7.2581, -8.7427, -13.4440, -5.3611,
551 0., 4.6904, 5.0254, 5.5432, 5.5737, 3.0153, -3.0153, -3.5635, -3.9290, -2.7412, 2.1625,
552 0., 0., -13.8160, -8.7166, -10.2245, -8.8666, -8.7632, -5.2544, -6.9192, -10.5537, -9.3250,
553 0., 0., 0., 6.5033, -1.1453, 1.3179, 2.5768, 5.5503, 3.6524, 1.3491, -2.5676,
554 0., 0., 0., 0., -9.6242, -2.1148, -9.3509, -10.5846, -3.5366, -6.8561, -3.2277,
555 0., 0., 0., 0., 0., 9.7887, 4.3551, 5.7572, 2.7876, 0.1611, 1.1769,
556 0., 0., 0., 0., 0., 0., -11.1139, -0.6521, -2.1943, -7.5529, -0.9081,
557 0., 0., 0., 0., 0., 0., 0., -4.6479, -1.9367, -6.5170, -3.7685,
558 0., 0., 0., 0., 0., 0., 0., 0., 8.2503, 3.3757, 6.8476,
559 0., 0., 0., 0., 0., 0., 0., 0., 0., -5.7095, -0.0090).finished();
563 noiseModel::Unit::Create(6));
576 EXPECT(
assert_equal(*noiseModel::Diagonal::Sigmas(Vector4::Ones()), *actualJF.get_model(), 0.001));
587 pair<GaussianConditional::shared_ptr, JacobianFactor::shared_ptr>
591 EXPECT(actual.second->empty());
607 Matrix2
A1; A1 << 2,4, 2,1;
610 Matrix2 A2; A2 << 2,4, 2,4;
612 JacobianFactor lc(1, A1, 2, A2, b, noiseModel::Constrained::All(2));
615 pair<GaussianConditional::shared_ptr, JacobianFactor::shared_ptr>
621 Matrix Aempty = m.topRows(0);
622 Vector bempty = m.block(0,0,0,1);
623 JacobianFactor expectedLF(2, Aempty, bempty, noiseModel::Constrained::All(0));
627 Matrix2
R; R << 1,2, 0,1;
628 Matrix2
S; S << 1,2, 0,0;
643 Vector9
sigmas = Vector9::Ones();
650 expectedRd << -2.64575131, -2.64575131, -2.64575131, -2.64575131,
654 noiseModel::Unit::Create(3));
656 EXPECT(actual.second->empty());
void transposeMultiplyAdd(double alpha, const Vector &e, VectorValues &x) const
bool empty() const
Whether the factor is empty (involves zero variables).
Provides additional testing facilities for common data structures.
std::pair< std::shared_ptr< GaussianConditional >, shared_ptr > eliminate(const Ordering &keys)
static int runAllTests(TestResult &result)
double error(const VectorValues &c) const override
Matrix augmentedInformation() const override
TEST(JacobianFactor, constructors_and_accessors)
#define DOUBLES_EQUAL(expected, actual, threshold)
std::vector< Eigen::Index > Dims
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
void diagonal(const MatrixType &m)
Rot2 R(Rot2::fromAngle(0.1))
const GaussianFactorGraph factors
Matrix information() const override
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
iterator insert(const std::pair< Key, Vector > &key_value)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Matrix augmentedJacobian() const override
static enum @1107 ordering
std::pair< Matrix, Vector > jacobianUnweighted() const
Returns (dense) A,b pair associated with factor, does not bake in weights.
Vector unweighted_error(const VectorValues &c) const
VariableSlots describes the structure of a combined factor in terms of where each block comes from in...
const_iterator end() const
std::pair< Matrix, Vector > jacobian() const override
Returns (dense) A,b pair associated with factor, bakes in the weights.
void add(const GaussianFactor &factor)
void hessianDiagonal(double *d) const override
Raw memory access version of hessianDiagonal.
Vector error_vector(const VectorValues &c) const
Matrix stack(size_t nrMatrices,...)
#define EXPECT(condition)
Array< int, Dynamic, 1 > v
const constBVector getb() const
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Conditional Gaussian Base class.
Linear Factor Graph where all factors are Gaussians.
std::pair< GaussianConditional::shared_ptr, JacobianFactor::shared_ptr > EliminateQR(const GaussianFactorGraph &factors, const Ordering &keys)
Matrix augmentedJacobian(const Ordering &ordering) const
#define LONGS_EQUAL(expected, actual)
noiseModel::Diagonal::shared_ptr SharedDiagonal
VectorValues gradientAtZero() const override
A'*b for Jacobian.
Matrix augmentedJacobianUnweighted() const
#define EXPECT_LONGS_EQUAL(expected, actual)
A Gaussian factor using the canonical parameters (information form)
const KeyVector & keys() const
Access the factor's involved variable keys.
static const double sigma
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
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 x
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
std::uint64_t Key
Integer nonlinear key type.
const SharedDiagonal & get_model() const
std::map< Key, Matrix > hessianBlockDiagonal() const override
Return the block diagonal of the Hessian for this factor.
constABlock getA(const_iterator variable) const