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 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
TEST
TEST(ISAM, iSAM_smoother)
Definition: testGaussianISAM.cpp:33
Ordering.h
Variable ordering for the elimination algorithm.
X
#define X
Definition: icosphere.cpp:20
example
Definition: testOrdering.cpp:28
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam::VectorValues
Definition: VectorValues.h:74
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
L
MatrixXd L
Definition: LLT_example.cpp:6
Symbol.h
gtsam::GaussianBayesTree::optimize
VectorValues optimize() const
Definition: GaussianBayesTree.cpp:67
ordering
static enum @1096 ordering
TestResult
Definition: TestResult.h:26
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
gtsam::GaussianBayesTree
Definition: GaussianBayesTree.h:49
gtsam::GaussianISAM
Definition: GaussianISAM.h:27
gtsam::FactorGraph::push_back
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:147
std
Definition: BFloat16.h:88
gtsam::GaussianConditional::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianConditional.h:46
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::ISAM
Definition: ISAM.h:31
GaussianISAM.h
gtsam::ISAM::update
void update(const FactorGraphType &newFactors, const Eliminate &function=EliminationTraitsType::DefaultEliminate)
Definition: ISAM-inst.h:62
align_3::t
Point2 t(10, 10)
main
int main()
Definition: testGaussianISAM.cpp:69
smallExample.h
Create small example with two poses and one landmark.
gtsam::Ordering
Definition: inference/Ordering.h:33
gtsam::example::createSmoother
GaussianFactorGraph createSmoother(int T)
Definition: smallExample.h:465


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:28