36 using namespace gtsam;
41 const Pose3 poseInitial;
42 const Pose3 poseOdometry( Rot3::RzRyRx(
Vector3(0.05, 0.10, -0.75)),
Point3(1.0, -0.25, 0.10) );
43 const Pose3 poseError( Rot3::RzRyRx(
Vector3(0.01, 0.02, -0.1)),
Point3(0.05, -0.05, 0.02) );
46 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
47 const SharedDiagonal noiseOdometery = noiseModel::Diagonal::Sigmas((
Vector(6) << 0.1, 0.1, 0.1, 0.5, 0.5, 0.5).finished());
48 const SharedDiagonal noiseLoop = noiseModel::Diagonal::Sigmas((
Vector(6) << 0.25, 0.25, 0.25, 1.0, 1.0, 1.0).finished());
107 newFactors1.
addPrior(1, poseInitial, noisePrior);
112 smoother.
update(newFactors1, newValues1);
129 smoother.
update(newFactors2, newValues2);
157 newFactors1.
addPrior(1, poseInitial, noisePrior);
162 smoother.
update(newFactors1, newValues1);
166 expected2.
insert(newValues1);
179 smoother.
update(newFactors2, newValues2);
183 expected3.
insert(newValues1);
184 expected3.
insert(newValues2);
219 newFactors2.
addPrior(1, poseInitial, noisePrior);
224 smoother.
update(newFactors2, newValues2);
230 allValues2.
insert(newValues2);
231 Values expected2 = BatchOptimize(allFactors2, allValues2);
244 smoother.
update(newFactors3, newValues3);
251 allValues3.
insert(newValues2);
252 allValues3.
insert(newValues3);
253 Values expected3 = BatchOptimize(allFactors3, allValues3);
305 newFactors2.
addPrior(1, poseInitial, noisePrior);
310 smoother.
update(newFactors2, newValues2);
316 allValues2.
insert(newValues2);
317 Values expected2 = BatchOptimize(allFactors2, allValues2);
330 smoother.
update(newFactors3, newValues3);
337 allValues3.
insert(newValues2);
338 allValues3.
insert(newValues3);
339 Values expected3 = BatchOptimize(allFactors3, allValues3);
357 Values smootherValues, filterSeparatorValues;
361 Values expectedSmootherSeparatorValues;
365 Values actualSmootherSeparatorValues;
368 smoother.
synchronize(smootherFactors, smootherValues, filterSumarization, filterSeparatorValues);
372 CHECK(
assert_equal(expectedSmootherSummarization, actualSmootherSummarization, 1
e-6));
373 CHECK(
assert_equal(expectedSmootherSeparatorValues, actualSmootherSeparatorValues, 1
e-6));
388 Values smootherValues, filterSeparatorValues;
392 ordering.push_back(1);
393 ordering.push_back(2);
399 Values expectedSmootherSeparatorValues;
402 Values actualSmootherSeparatorValues;
405 smoother.
synchronize(smootherFactors, smootherValues, filterSumarization, filterSeparatorValues);
409 CHECK(
assert_equal(expectedSmootherSummarization, actualSmootherSummarization, 1
e-6));
410 CHECK(
assert_equal(expectedSmootherSeparatorValues, actualSmootherSeparatorValues, 1
e-6));
423 allFactors.
push_back(filterSumarization);
425 allValues.
insert(filterSeparatorValues);
431 Values expectedLinearizationPoint = filterSeparatorValues;
449 Values smootherValues, filterSeparatorValues;
451 ordering.push_back(1);
452 ordering.push_back(2);
464 Values expectedSmootherSeparatorValues;
467 Values actualSmootherSeparatorValues;
470 smoother.
synchronize(smootherFactors, smootherValues, filterSumarization, filterSeparatorValues);
474 CHECK(
assert_equal(expectedSmootherSummarization, actualSmootherSummarization, 1
e-6));
475 CHECK(
assert_equal(expectedSmootherSeparatorValues, actualSmootherSeparatorValues, 1
e-6));
483 expectedFactorGraph.
push_back(smootherFactors);
484 expectedFactorGraph.
push_back(filterSumarization);
490 allFactors.
push_back(filterSumarization);
493 allValues.
insert(filterSeparatorValues);
494 allValues.
insert(smootherValues);
500 Values expectedLinearizationPoint = BatchOptimize(allFactors, allValues, parameters.
maxIterations);
501 expectedLinearizationPoint.
update(filterSeparatorValues);
520 Values smootherValues, filterSeparatorValues;
522 ordering.push_back(1);
523 ordering.push_back(2);
530 smootherFactors.
addPrior(4, poseInitial, noisePrior);
536 Values expectedSmootherSeparatorValues;
539 Values actualSmootherSeparatorValues;
542 smoother.
synchronize(smootherFactors, smootherValues, filterSumarization, filterSeparatorValues);
546 CHECK(
assert_equal(expectedSmootherSummarization, actualSmootherSummarization, 1
e-6));
547 CHECK(
assert_equal(expectedSmootherSeparatorValues, actualSmootherSeparatorValues, 1
e-6));
562 KeySet eliminateKeys = linearFactors->keys();
563 for(
const auto key: filterSeparatorValues.
keys()) {
564 eliminateKeys.erase(
key);
566 KeyVector variables(eliminateKeys.begin(), eliminateKeys.end());
569 expectedSmootherSummarization.
resize(0);
570 for(
const GaussianFactor::shared_ptr& factor: result) {
574 CHECK(
assert_equal(expectedSmootherSummarization, actualSmootherSummarization, 1
e-6));
581 std::cout <<
"*********************** removeFactors_topology_1 ************************" << std::endl;
591 newFactors.
addPrior(1, poseInitial, noisePrior);
605 smoother.
update(newFactors, newValues);
610 std::vector<size_t> removeFactorIndices(1,1);
615 smoother.
update(noFactors, noValues, removeFactorIndices);
620 expectedGraph.
addPrior(1, poseInitial, noisePrior);
623 expectedGraph.
push_back(NonlinearFactor::shared_ptr());
634 std::cout <<
"*********************** removeFactors_topology_2 ************************" << std::endl;
645 newFactors.
addPrior(1, poseInitial, noisePrior);
658 smoother.
update(newFactors, newValues);
663 std::vector<size_t> removeFactorIndices(1,4);
668 smoother.
update(noFactors, noValues, removeFactorIndices);
673 expectedGraph.
addPrior(1, poseInitial, noisePrior);
679 expectedGraph.
push_back(NonlinearFactor::shared_ptr());
688 std::cout <<
"*********************** removeFactors_topology_3 ************************" << std::endl;
697 newFactors.
addPrior(1, poseInitial, noisePrior);
698 newFactors.
addPrior(1, poseInitial, noisePrior);
710 Smoother.
update(newFactors, newValues);
715 std::vector<size_t> removeFactorIndices(1,0);
720 Smoother.
update(noFactors, noValues, removeFactorIndices);
726 expectedGraph.
push_back(NonlinearFactor::shared_ptr());
727 expectedGraph.
addPrior(1, poseInitial, noisePrior);
738 std::cout <<
"*********************** removeFactors_values ************************" << std::endl;
747 newFactors.
addPrior(1, poseInitial, noisePrior);
760 Smoother.
update(newFactors, newValues);
765 std::vector<size_t> removeFactorIndices(1,4);
770 Smoother.
update(noFactors, noValues, removeFactorIndices);
777 expectedGraph.
addPrior(1, poseInitial, noisePrior);
783 expectedGraph.
push_back(NonlinearFactor::shared_ptr());
786 Values expectedValues = BatchOptimize(expectedGraph, newValues);
const gtsam::Symbol key('X', 0)
Provides additional testing facilities for common data structures.
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
static int runAllTests(TestResult &result)
A non-templated config holding any types of Manifold-group elements.
Wrap Jacobian and Hessian linear factors to allow simple injection into a nonlinear graph...
Factor Graph consisting of non-linear factors.
const ValueType at(Key j) const
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)
void update(Key j, const Value &val)
Values calculateEstimate() const
NonlinearFactorGraph graph
static enum @1107 ordering
const Ordering & getOrdering() const
T compose(const T &t1, const T &t2)
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
static std::shared_ptr< Ordering > getOrdering(const vector< GeneralCamera > &cameras, const vector< Point3 > &landmarks)
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
static NonlinearFactorGraph expectedGraph(const SharedNoiseModel &model)
void getSummarizedFactors(NonlinearFactorGraph &summarizedFactors, Values &separatorValues) override
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
virtual Result update(const NonlinearFactorGraph &newFactors=NonlinearFactorGraph(), const Values &newTheta=Values(), const std::optional< std::vector< size_t > > &removeFactorIndices={})
std::pair< std::shared_ptr< GaussianConditional >, std::shared_ptr< HessianFactor > > EliminateCholesky(const GaussianFactorGraph &factors, const Ordering &keys)
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
TEST(ConcurrentBatchSmoother, equals)
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Class compose(const Class &g) const
static ConjugateGradientParameters parameters
A Levenberg-Marquardt Batch Smoother that implements the Concurrent Filtering and Smoothing interface...
noiseModel::Diagonal::shared_ptr SharedDiagonal
virtual void resize(size_t size)
void synchronize(const NonlinearFactorGraph &smootherFactors, const Values &smootherValues, const NonlinearFactorGraph &summarizedFactors, const Values &separatorValues) override
void insert(Key j, const Value &val)
const NonlinearFactorGraph & getFactors() const
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
const Values & getLinearizationPoint() const
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
size_t maxIterations
The maximum iterations to stop iterating (default 100)