testGaussianISAM.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* ----------------------------------------------------------------------------
  2. * GTSAM Copyright 2010, Georgia Tech Research Corporation,
  3. * Atlanta, Georgia 30332-0415
  4. * All Rights Reserved
  5. * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
  6. * See LICENSE for the license information
  7. * -------------------------------------------------------------------------- */
  8. /**
  9. * @file testGaussianISAM.cpp
  10. * @brief Unit tests for GaussianISAM
  11. * @author Michael Kaess
  12. */
  13. #include <CppUnitLite/TestHarness.h>
  14. #include <tests/smallExample.h>
  15. #include <gtsam/inference/Symbol.h>
  16. #include <gtsam/linear/GaussianISAM.h>
  17. #include <gtsam/inference/Ordering.h>
  18. #include <boost/assign/std/list.hpp> // for operator +=
  19. using namespace boost::assign;
  20. #include <boost/range/adaptor/map.hpp>
  21. namespace br { using namespace boost::adaptors; using namespace boost::range; }
  22. using namespace std;
  23. using namespace gtsam;
  24. using namespace example;
  25. using symbol_shorthand::X;
  26. using symbol_shorthand::L;
  27. /* ************************************************************************* */
  28. TEST( ISAM, iSAM_smoother )
  29. {
  30. Ordering ordering;
  31. for (int t = 1; t <= 7; t++) ordering += X(t);
  32. // Create smoother with 7 nodes
  33. GaussianFactorGraph smoother = createSmoother(7);
  34. // run iSAM for every factor
  35. GaussianISAM actual;
  36. for(boost::shared_ptr<GaussianFactor> factor: smoother) {
  37. GaussianFactorGraph factorGraph;
  38. factorGraph.push_back(factor);
  39. actual.update(factorGraph);
  40. }
  41. // Create expected Bayes Tree by solving smoother with "natural" ordering
  42. GaussianBayesTree expected = *smoother.eliminateMultifrontal(ordering);
  43. // Verify sigmas in the bayes tree
  44. for(const GaussianBayesTree::sharedClique& clique: expected.nodes() | br::map_values) {
  45. GaussianConditional::shared_ptr conditional = clique->conditional();
  46. EXPECT(!conditional->get_model());
  47. }
  48. // Check whether BayesTree is correct
  49. EXPECT(assert_equal(GaussianFactorGraph(expected).augmentedHessian(), GaussianFactorGraph(actual).augmentedHessian()));
  50. // obtain solution
  51. VectorValues e; // expected solution
  52. for (int t = 1; t <= 7; t++) e.insert(X(t), Vector::Zero(2));
  53. VectorValues optimized = actual.optimize(); // actual solution
  54. EXPECT(assert_equal(e, optimized));
  55. }
  56. /* ************************************************************************* */
  57. int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
  58. /* ************************************************************************* */