2009-10-29 13:39:13 +08:00
|
|
|
/**
|
2009-11-01 03:53:20 +08:00
|
|
|
* @file testSymbolicFactorGraph.cpp
|
|
|
|
|
* @brief Unit tests for a symbolic Factor Graph
|
2009-10-29 13:39:13 +08:00
|
|
|
* @author Frank Dellaert
|
|
|
|
|
*/
|
|
|
|
|
|
2009-10-31 23:24:22 +08:00
|
|
|
#include <boost/assign/std/list.hpp> // for operator +=
|
|
|
|
|
using namespace boost::assign;
|
|
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/CppUnitLite/TestHarness.h>
|
2009-10-29 13:39:13 +08:00
|
|
|
|
2010-01-18 03:34:57 +08:00
|
|
|
#define GTSAM_MAGIC_KEY
|
|
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/inference/Ordering.h>
|
|
|
|
|
#include <gtsam/inference/SymbolicFactorGraph.h>
|
|
|
|
|
#include <gtsam/inference/SymbolicBayesNet.h>
|
|
|
|
|
#include <gtsam/inference/FactorGraph-inl.h>
|
2009-10-29 13:39:13 +08:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace gtsam;
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2010-07-12 15:16:31 +08:00
|
|
|
TEST( SymbolicFactorGraph, eliminate2 )
|
2010-02-13 15:09:56 +08:00
|
|
|
{
|
|
|
|
|
// create a test graph
|
|
|
|
|
SymbolicFactorGraph fg;
|
|
|
|
|
fg.push_factor("x1", "x2");
|
|
|
|
|
|
|
|
|
|
fg.eliminateOne("x1");
|
|
|
|
|
SymbolicFactorGraph expected;
|
|
|
|
|
expected.push_back(boost::shared_ptr<SymbolicFactor>());
|
|
|
|
|
expected.push_factor("x2");
|
|
|
|
|
|
|
|
|
|
CHECK(assert_equal(expected, fg));
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-19 01:27:27 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
TEST( SymbolicFactorGraph, constructFromBayesNet )
|
|
|
|
|
{
|
|
|
|
|
// create expected factor graph
|
2009-11-21 12:59:50 +08:00
|
|
|
SymbolicFactorGraph expected;
|
|
|
|
|
expected.push_factor("l1","x1","x2");
|
|
|
|
|
expected.push_factor("x1","l1");
|
|
|
|
|
expected.push_factor("x1");
|
2009-11-19 01:27:27 +08:00
|
|
|
|
|
|
|
|
// create Bayes Net
|
|
|
|
|
SymbolicConditional::shared_ptr x2(new SymbolicConditional("x2", "l1", "x1"));
|
|
|
|
|
SymbolicConditional::shared_ptr l1(new SymbolicConditional("l1", "x1"));
|
|
|
|
|
SymbolicConditional::shared_ptr x1(new SymbolicConditional("x1"));
|
|
|
|
|
|
|
|
|
|
SymbolicBayesNet bayesNet;
|
|
|
|
|
bayesNet.push_back(x2);
|
|
|
|
|
bayesNet.push_back(l1);
|
|
|
|
|
bayesNet.push_back(x1);
|
|
|
|
|
|
|
|
|
|
// create actual factor graph from a Bayes Net
|
|
|
|
|
FactorGraph<SymbolicFactor> actual(bayesNet);
|
|
|
|
|
|
2009-11-21 12:59:50 +08:00
|
|
|
CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected,actual));
|
2009-11-19 01:27:27 +08:00
|
|
|
}
|
|
|
|
|
|
2009-11-19 14:34:07 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
TEST( SymbolicFactorGraph, push_back )
|
|
|
|
|
{
|
|
|
|
|
// Create two factor graphs and expected combined graph
|
|
|
|
|
SymbolicFactorGraph fg1, fg2, expected;
|
|
|
|
|
|
2009-11-21 12:59:50 +08:00
|
|
|
fg1.push_factor("x1");
|
|
|
|
|
fg1.push_factor("x1","x2");
|
2009-11-19 14:34:07 +08:00
|
|
|
|
2009-11-21 12:59:50 +08:00
|
|
|
fg2.push_factor("l1","x1");
|
|
|
|
|
fg2.push_factor("l1","x2");
|
2009-11-19 14:34:07 +08:00
|
|
|
|
2009-11-21 12:59:50 +08:00
|
|
|
expected.push_factor("x1");
|
|
|
|
|
expected.push_factor("x1","x2");
|
|
|
|
|
expected.push_factor("l1","x1");
|
|
|
|
|
expected.push_factor("l1","x2");
|
2009-11-19 14:34:07 +08:00
|
|
|
|
|
|
|
|
// combine
|
|
|
|
|
SymbolicFactorGraph actual = combine(fg1,fg2);
|
|
|
|
|
CHECK(assert_equal(expected, actual));
|
|
|
|
|
|
|
|
|
|
// combine using push_back
|
|
|
|
|
fg1.push_back(fg2);
|
|
|
|
|
CHECK(assert_equal(expected, fg1));
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-29 13:39:13 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
int main() {
|
|
|
|
|
TestResult tr;
|
|
|
|
|
return TestRegistry::runAllTests(tr);
|
|
|
|
|
}
|
|
|
|
|
/* ************************************************************************* */
|