2010-10-14 12:54:38 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
|
|
|
* Atlanta, Georgia 30332-0415
|
|
|
|
* All Rights Reserved
|
|
|
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
|
|
|
|
|
|
* See LICENSE for the license information
|
|
|
|
|
|
|
|
* -------------------------------------------------------------------------- */
|
|
|
|
|
2009-11-12 12:52:40 +08:00
|
|
|
/**
|
2012-03-15 10:10:37 +08:00
|
|
|
* @file testInferenceB.cpp
|
2009-11-12 12:52:40 +08:00
|
|
|
* @brief Unit tests for functionality declared in inference.h
|
|
|
|
* @author Frank Dellaert
|
|
|
|
*/
|
|
|
|
|
2010-10-26 04:10:33 +08:00
|
|
|
#include <CppUnitLite/TestHarness.h>
|
2009-11-12 12:52:40 +08:00
|
|
|
|
2012-07-24 06:45:46 +08:00
|
|
|
#include <gtsam/slam/PriorFactor.h>
|
|
|
|
#include <gtsam/slam/BetweenFactor.h>
|
|
|
|
#include <gtsam/slam/BearingRangeFactor.h>
|
|
|
|
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
|
|
|
|
#include <gtsam/nonlinear/Values.h>
|
2012-06-03 03:05:38 +08:00
|
|
|
#include <gtsam/nonlinear/Symbol.h>
|
2010-10-22 06:59:54 +08:00
|
|
|
#include <gtsam/linear/GaussianSequentialSolver.h>
|
2012-03-02 00:07:23 +08:00
|
|
|
#include <gtsam/linear/GaussianMultifrontalSolver.h>
|
2012-07-24 06:45:46 +08:00
|
|
|
#include <gtsam/geometry/Pose2.h>
|
|
|
|
#include <gtsam/geometry/Point2.h>
|
|
|
|
#include <gtsam/geometry/Rot2.h>
|
2009-11-12 12:52:40 +08:00
|
|
|
|
2012-06-10 04:15:44 +08:00
|
|
|
#include <tests/smallExample.h>
|
|
|
|
|
2009-11-12 12:52:40 +08:00
|
|
|
using namespace std;
|
|
|
|
using namespace gtsam;
|
|
|
|
|
2012-06-03 00:18:40 +08:00
|
|
|
// Convenience for named keys
|
2012-06-03 03:28:21 +08:00
|
|
|
using symbol_shorthand::X;
|
|
|
|
using symbol_shorthand::L;
|
2012-06-03 00:18:40 +08:00
|
|
|
|
2009-11-12 12:52:40 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
// The tests below test the *generic* inference algorithms. Some of these have
|
2009-11-13 00:16:32 +08:00
|
|
|
// specialized versions in the derived classes GaussianFactorGraph etc...
|
2009-11-12 12:52:40 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2012-03-04 04:23:03 +08:00
|
|
|
TEST( inference, marginals )
|
2009-11-12 12:52:40 +08:00
|
|
|
{
|
2010-12-22 02:23:56 +08:00
|
|
|
using namespace example;
|
2012-10-02 22:40:07 +08:00
|
|
|
// create and marginalize a small Bayes net on "x"
|
2009-11-12 12:52:40 +08:00
|
|
|
GaussianBayesNet cbn = createSmallGaussianBayesNet();
|
2010-10-22 06:59:54 +08:00
|
|
|
vector<Index> xvar; xvar.push_back(0);
|
2011-06-14 00:55:31 +08:00
|
|
|
GaussianBayesNet actual = *GaussianSequentialSolver(
|
2012-10-02 22:40:07 +08:00
|
|
|
*GaussianSequentialSolver(GaussianFactorGraph(cbn)).jointFactorGraph(xvar)).eliminate();
|
2009-11-12 12:52:40 +08:00
|
|
|
|
|
|
|
// expected is just scalar Gaussian on x
|
2012-05-24 02:51:49 +08:00
|
|
|
GaussianBayesNet expected = scalarGaussian(0, 4, sqrt(2.0));
|
2009-11-12 12:52:40 +08:00
|
|
|
CHECK(assert_equal(expected,actual));
|
|
|
|
}
|
|
|
|
|
2010-12-22 02:23:56 +08:00
|
|
|
/* ************************************************************************* */
|
2012-03-04 04:23:03 +08:00
|
|
|
TEST( inference, marginals2)
|
2010-12-22 02:23:56 +08:00
|
|
|
{
|
2012-10-02 22:40:07 +08:00
|
|
|
NonlinearFactorGraph fg;
|
2012-06-23 03:36:49 +08:00
|
|
|
SharedDiagonal poseModel(noiseModel::Isotropic::Sigma(3, 0.1));
|
2012-10-06 07:23:40 +08:00
|
|
|
SharedDiagonal pointModel(noiseModel::Isotropic::Sigma(2, 0.1));
|
2010-12-22 02:23:56 +08:00
|
|
|
|
2012-07-24 06:45:46 +08:00
|
|
|
fg.add(PriorFactor<Pose2>(X(0), Pose2(), poseModel));
|
|
|
|
fg.add(BetweenFactor<Pose2>(X(0), X(1), Pose2(1.0,0.0,0.0), poseModel));
|
|
|
|
fg.add(BetweenFactor<Pose2>(X(1), X(2), Pose2(1.0,0.0,0.0), poseModel));
|
|
|
|
fg.add(BearingRangeFactor<Pose2, Point2>(X(0), L(0), Rot2(), 1.0, pointModel));
|
|
|
|
fg.add(BearingRangeFactor<Pose2, Point2>(X(1), L(0), Rot2(), 1.0, pointModel));
|
|
|
|
fg.add(BearingRangeFactor<Pose2, Point2>(X(2), L(0), Rot2(), 1.0, pointModel));
|
2010-12-22 02:23:56 +08:00
|
|
|
|
2012-02-03 00:16:46 +08:00
|
|
|
Values init;
|
2012-06-03 03:28:21 +08:00
|
|
|
init.insert(X(0), Pose2(0.0,0.0,0.0));
|
|
|
|
init.insert(X(1), Pose2(1.0,0.0,0.0));
|
|
|
|
init.insert(X(2), Pose2(2.0,0.0,0.0));
|
|
|
|
init.insert(L(0), Point2(1.0,1.0));
|
2010-12-22 02:23:56 +08:00
|
|
|
|
|
|
|
Ordering ordering(*fg.orderingCOLAMD(init));
|
2011-04-13 05:18:10 +08:00
|
|
|
FactorGraph<GaussianFactor>::shared_ptr gfg(fg.linearize(init, ordering));
|
2011-06-14 04:01:58 +08:00
|
|
|
GaussianMultifrontalSolver solver(*gfg);
|
2012-06-03 03:28:21 +08:00
|
|
|
solver.marginalFactor(ordering[L(0)]);
|
2010-12-22 02:23:56 +08:00
|
|
|
}
|
|
|
|
|
2009-11-12 12:52:40 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
|
|
|
|
/* ************************************************************************* */
|