testGaussianISAM.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 
20 #include <tests/smallExample.h>
21 #include <gtsam/inference/Symbol.h>
24 
25 using namespace std;
26 using namespace gtsam;
27 using namespace example;
28 
31 
32 /* ************************************************************************* */
33 TEST( ISAM, iSAM_smoother )
34 {
36  for (int t = 1; t <= 7; t++) ordering.push_back(X(t));
37 
38  // Create smoother with 7 nodes
39  GaussianFactorGraph smoother = createSmoother(7);
40 
41  // run iSAM for every factor
42  GaussianISAM actual;
43  for(std::shared_ptr<GaussianFactor> factor: smoother) {
44  GaussianFactorGraph factorGraph;
45  factorGraph.push_back(factor);
46  actual.update(factorGraph);
47  }
48 
49  // Create expected Bayes Tree by solving smoother with "natural" ordering
50  GaussianBayesTree expected = *smoother.eliminateMultifrontal(ordering);
51 
52  // Verify sigmas in the bayes tree
53  for (const auto& [key, clique] : expected.nodes()) {
54  GaussianConditional::shared_ptr conditional = clique->conditional();
55  EXPECT(!conditional->get_model());
56  }
57 
58  // Check whether BayesTree is correct
59  EXPECT(assert_equal(GaussianFactorGraph(expected).augmentedHessian(), GaussianFactorGraph(actual).augmentedHessian()));
60 
61  // obtain solution
62  VectorValues e; // expected solution
63  for (int t = 1; t <= 7; t++) e.insert(X(t), Vector::Zero(2));
64  VectorValues optimized = actual.optimize(); // actual solution
65  EXPECT(assert_equal(e, optimized));
66 }
67 
68 /* ************************************************************************* */
69 int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
70 /* ************************************************************************* */
const gtsam::Symbol key('X', 0)
void update(const FactorGraphType &newFactors, const Eliminate &function=EliminationTraitsType::DefaultEliminate)
Definition: ISAM-inst.h:62
GaussianFactorGraph createSmoother(int T)
Definition: smallExample.h:465
static int runAllTests(TestResult &result)
const Nodes & nodes() const
Definition: BayesTree.h:146
Matrix expected
Definition: testMatrix.cpp:971
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:190
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
MatrixXd L
Definition: LLT_example.cpp:6
Definition: BFloat16.h:88
iterator insert(const std::pair< Key, Vector > &key_value)
static enum @1107 ordering
VectorValues optimize() const
#define EXPECT(condition)
Definition: Test.h:150
Array< double, 1, 3 > e(1./3., 0.5, 2.)
traits
Definition: chartTesting.h:28
Create small example with two poses and one landmark.
int main()
#define X
Definition: icosphere.cpp:20
Point2 t(10, 10)
TEST(ISAM, iSAM_smoother)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:38:10