/** * @file testInference.cpp * @brief Unit tests for functionality declared in inference.h * @author Frank Dellaert */ #include #define GTSAM_MAGIC_KEY #include "Ordering.h" #include "smallExample.h" #include "inference-inl.h" using namespace std; using namespace gtsam; using namespace example; /* ************************************************************************* */ // The tests below test the *generic* inference algorithms. Some of these have // specialized versions in the derived classes GaussianFactorGraph etc... /* ************************************************************************* */ /* ************************************************************************* */ TEST(GaussianFactorGraph, createSmoother) { GaussianFactorGraph fg2 = createSmoother(3); LONGS_EQUAL(5,fg2.size()); // eliminate Ordering ordering; GaussianBayesNet bayesNet = fg2.eliminate(ordering); FactorGraph p_x3 = marginalize(bayesNet, Ordering("x3")); FactorGraph p_x1 = marginalize(bayesNet, Ordering("x1")); CHECK(assert_equal(p_x1,p_x3)); // should be the same because of symmetry } /* ************************************************************************* */ TEST( Inference, marginals ) { // create and marginalize a small Bayes net on "x" GaussianBayesNet cbn = createSmallGaussianBayesNet(); Ordering keys("x"); FactorGraph fg = marginalize(cbn,keys); // turn into Bayes net to test easily BayesNet actual = eliminate(fg,keys); // expected is just scalar Gaussian on x GaussianBayesNet expected = scalarGaussian("x", 4, sqrt(2)); CHECK(assert_equal(expected,actual)); } /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr);} /* ************************************************************************* */