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 #include <boost/assign/std/list.hpp> // for operator +=
26 using namespace boost::assign;
27 #include <boost/range/adaptor/map.hpp>
28 namespace br { using namespace boost::adaptors; using namespace boost::range; }
29 
30 using namespace std;
31 using namespace gtsam;
32 using namespace example;
33 
36 
37 /* ************************************************************************* */
38 TEST( ISAM, iSAM_smoother )
39 {
41  for (int t = 1; t <= 7; t++) ordering += X(t);
42 
43  // Create smoother with 7 nodes
44  GaussianFactorGraph smoother = createSmoother(7);
45 
46  // run iSAM for every factor
47  GaussianISAM actual;
48  for(boost::shared_ptr<GaussianFactor> factor: smoother) {
49  GaussianFactorGraph factorGraph;
50  factorGraph.push_back(factor);
51  actual.update(factorGraph);
52  }
53 
54  // Create expected Bayes Tree by solving smoother with "natural" ordering
55  GaussianBayesTree expected = *smoother.eliminateMultifrontal(ordering);
56 
57  // Verify sigmas in the bayes tree
58  for(const GaussianBayesTree::sharedClique& clique: expected.nodes() | br::map_values) {
59  GaussianConditional::shared_ptr conditional = clique->conditional();
60  EXPECT(!conditional->get_model());
61  }
62 
63  // Check whether BayesTree is correct
64  EXPECT(assert_equal(GaussianFactorGraph(expected).augmentedHessian(), GaussianFactorGraph(actual).augmentedHessian()));
65 
66  // obtain solution
67  VectorValues e; // expected solution
68  for (int t = 1; t <= 7; t++) e.insert(X(t), Vector::Zero(2));
69  VectorValues optimized = actual.optimize(); // actual solution
70  EXPECT(assert_equal(e, optimized));
71 }
72 
73 /* ************************************************************************* */
74 int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
75 /* ************************************************************************* */
void update(const FactorGraphType &newFactors, const Eliminate &function=EliminationTraitsType::DefaultEliminate)
Definition: ISAM-inst.h:62
GaussianFactorGraph createSmoother(int T)
Definition: smallExample.h:464
static int runAllTests(TestResult &result)
static enum @843 ordering
Matrix expected
Definition: testMatrix.cpp:974
const Nodes & nodes() const
Definition: BayesTree.h:141
MatrixXd L
Definition: LLT_example.cpp:6
Definition: Half.h:150
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:166
#define EXPECT(condition)
Definition: Test.h:151
Array< double, 1, 3 > e(1./3., 0.5, 2.)
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
VectorValues optimize() const
Create small example with two poses and one landmark.
int main()
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
#define X
Definition: icosphere.cpp:20
iterator insert(const std::pair< Key, Vector > &key_value)
Point2 t(10, 10)
TEST(ISAM, iSAM_smoother)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:47