2009-11-12 12:52:40 +08:00
|
|
|
/**
|
|
|
|
* @file testInference.cpp
|
|
|
|
* @brief Unit tests for functionality declared in inference.h
|
|
|
|
* @author Frank Dellaert
|
|
|
|
*/
|
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/CppUnitLite/TestHarness.h>
|
2009-11-12 12:52:40 +08:00
|
|
|
|
2010-01-18 03:34:57 +08:00
|
|
|
#define GTSAM_MAGIC_KEY
|
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/slam/smallExample.h>
|
|
|
|
#include <gtsam/inference/inference-inl.h>
|
2009-11-12 12:52:40 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace gtsam;
|
2010-01-19 13:33:44 +08:00
|
|
|
using namespace example;
|
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
|
|
|
/* ************************************************************************* */
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2009-11-13 00:16:32 +08:00
|
|
|
TEST(GaussianFactorGraph, createSmoother)
|
2009-11-12 12:52:40 +08:00
|
|
|
{
|
2010-10-10 08:51:57 +08:00
|
|
|
GaussianFactorGraph fg2;
|
|
|
|
Ordering ordering;
|
|
|
|
boost::tie(fg2,ordering) = createSmoother(3);
|
2009-11-12 12:52:40 +08:00
|
|
|
LONGS_EQUAL(5,fg2.size());
|
|
|
|
|
|
|
|
// eliminate
|
2010-10-12 05:14:35 +08:00
|
|
|
list<Index> x3var; x3var.push_back(ordering["x3"]);
|
|
|
|
list<Index> x1var; x1var.push_back(ordering["x1"]);
|
2010-10-14 04:41:26 +08:00
|
|
|
GaussianBayesNet p_x3 = *Inference::Eliminate(Inference::Marginal(fg2, x3var));
|
|
|
|
GaussianBayesNet p_x1 = *Inference::Eliminate(Inference::Marginal(fg2, x1var));
|
2010-10-10 08:51:57 +08:00
|
|
|
CHECK(assert_equal(*p_x1.back(),*p_x3.front())); // should be the same because of symmetry
|
2009-11-12 12:52:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
TEST( Inference, marginals )
|
|
|
|
{
|
|
|
|
// create and marginalize a small Bayes net on "x"
|
|
|
|
GaussianBayesNet cbn = createSmallGaussianBayesNet();
|
2010-10-12 05:14:35 +08:00
|
|
|
list<Index> xvar; xvar.push_back(0);
|
2010-10-14 04:41:26 +08:00
|
|
|
GaussianBayesNet actual = *Inference::Eliminate(Inference::Marginal(GaussianFactorGraph(cbn), xvar));
|
2009-11-12 12:52:40 +08:00
|
|
|
|
|
|
|
// expected is just scalar Gaussian on x
|
2010-10-10 08:51:57 +08:00
|
|
|
GaussianBayesNet expected = scalarGaussian(0, 4, sqrt(2));
|
2009-11-12 12:52:40 +08:00
|
|
|
CHECK(assert_equal(expected,actual));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
|
|
|
|
/* ************************************************************************* */
|