Continuing updating unit tests
parent
71dd480b95
commit
af90ece44c
|
|
@ -1,65 +0,0 @@
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
* 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
|
|
||||||
|
|
||||||
* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file testFactorgraph.cpp
|
|
||||||
* @brief Unit tests for IndexFactor Graphs
|
|
||||||
* @author Christian Potthast
|
|
||||||
**/
|
|
||||||
|
|
||||||
/*STL/C++*/
|
|
||||||
#include <list>
|
|
||||||
#include <iostream>
|
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
#include <boost/tuple/tuple.hpp>
|
|
||||||
#include <boost/assign/std/set.hpp> // for operator +=
|
|
||||||
#include <boost/assign/std/vector.hpp>
|
|
||||||
using namespace boost::assign;
|
|
||||||
|
|
||||||
#include <CppUnitLite/TestHarness.h>
|
|
||||||
|
|
||||||
#include <gtsam/inference/IndexConditional.h>
|
|
||||||
#include <gtsam/inference/SymbolicFactorGraph.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace gtsam;
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
TEST(FactorGraph, eliminateFrontals) {
|
|
||||||
|
|
||||||
SymbolicFactorGraph sfgOrig;
|
|
||||||
sfgOrig.push_factor(0,1);
|
|
||||||
sfgOrig.push_factor(0,2);
|
|
||||||
sfgOrig.push_factor(1,3);
|
|
||||||
sfgOrig.push_factor(1,4);
|
|
||||||
sfgOrig.push_factor(2,3);
|
|
||||||
sfgOrig.push_factor(4,5);
|
|
||||||
|
|
||||||
IndexConditional::shared_ptr actualCond;
|
|
||||||
SymbolicFactorGraph actualSfg;
|
|
||||||
boost::tie(actualCond, actualSfg) = sfgOrig.eliminateFrontals(2);
|
|
||||||
|
|
||||||
vector<Index> condIndices;
|
|
||||||
condIndices += 0,1,2,3,4;
|
|
||||||
IndexConditional expectedCond(condIndices, 2);
|
|
||||||
|
|
||||||
SymbolicFactorGraph expectedSfg;
|
|
||||||
expectedSfg.push_factor(2,3);
|
|
||||||
expectedSfg.push_factor(4,5);
|
|
||||||
expectedSfg.push_factor(2,3,4);
|
|
||||||
|
|
||||||
EXPECT(assert_equal(expectedSfg, actualSfg));
|
|
||||||
EXPECT(assert_equal(expectedCond, *actualCond));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
|
||||||
/* ************************************************************************* */
|
|
||||||
|
|
@ -71,24 +71,21 @@ public:
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// Conditionals for ASIA example from the tutorial with A and D evidence
|
// Keys for ASIA example from the tutorial with A and D evidence
|
||||||
const Key _X_=X(0), _T_=T(0), _S_=S(0), _E_=E(0), _L_=L(0), _B_=B(0);
|
const Key _X_=X(0), _T_=T(0), _S_=S(0), _E_=E(0), _L_=L(0), _B_=B(0);
|
||||||
|
|
||||||
// Bayes Tree for Asia example
|
// Factor graph for Asia example
|
||||||
SymbolicFactorGraphUnordered createAsiaGraph() {
|
const SymbolicFactorGraphUnordered asiaGraph = list_of
|
||||||
SymbolicFactorGraphUnordered asiaGraph;
|
(boost::make_shared<SymbolicFactorUnordered>(_T_))
|
||||||
asiaGraph.push_factor(_T_);
|
(boost::make_shared<SymbolicFactorUnordered>(_S_))
|
||||||
asiaGraph.push_factor(_S_);
|
(boost::make_shared<SymbolicFactorUnordered>(_T_, _E_, _L_))
|
||||||
asiaGraph.push_factor(_T_, _E_, _L_);
|
(boost::make_shared<SymbolicFactorUnordered>(_L_, _S_))
|
||||||
asiaGraph.push_factor(_L_, _S_);
|
(boost::make_shared<SymbolicFactorUnordered>(_S_, _B_))
|
||||||
asiaGraph.push_factor(_S_, _B_);
|
(boost::make_shared<SymbolicFactorUnordered>(_E_, _B_))
|
||||||
asiaGraph.push_factor(_E_, _B_);
|
(boost::make_shared<SymbolicFactorUnordered>(_E_, _X_));
|
||||||
asiaGraph.push_factor(_E_, _X_);
|
|
||||||
return asiaGraph;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
OrderingUnordered asiaOrdering = list_of(_X_)(_T_)(_S_)(_E_)(_L_)(_B_);
|
const OrderingUnordered asiaOrdering = list_of(_X_)(_T_)(_S_)(_E_)(_L_)(_B_);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* 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
|
||||||
|
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file testSymbolicFactor.cpp
|
||||||
|
* @brief Unit tests for a symbolic IndexFactor
|
||||||
|
* @author Frank Dellaert
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
#include <gtsam/base/TestableAssertions.h>
|
||||||
|
#include <gtsam/symbolic/SymbolicFactorUnordered.h>
|
||||||
|
#include <gtsam/symbolic/SymbolicConditionalUnordered.h>
|
||||||
|
|
||||||
|
#include <boost/assign/std/vector.hpp>
|
||||||
|
#include <boost/assign/list_of.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/tuple/tuple.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace gtsam;
|
||||||
|
using namespace boost::assign;
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
#ifdef TRACK_ELIMINATE
|
||||||
|
TEST(SymbolicFactor, eliminate) {
|
||||||
|
vector<Index> keys; keys += 2, 3, 4, 6, 7, 9, 10, 11;
|
||||||
|
IndexFactor actual(keys.begin(), keys.end());
|
||||||
|
BayesNet<IndexConditional> fragment = *actual.eliminate(3);
|
||||||
|
|
||||||
|
IndexFactor expected(keys.begin()+3, keys.end());
|
||||||
|
IndexConditional::shared_ptr expected0 = IndexConditional::FromRange(keys.begin(), keys.end(), 1);
|
||||||
|
IndexConditional::shared_ptr expected1 = IndexConditional::FromRange(keys.begin()+1, keys.end(), 1);
|
||||||
|
IndexConditional::shared_ptr expected2 = IndexConditional::FromRange(keys.begin()+2, keys.end(), 1);
|
||||||
|
|
||||||
|
CHECK(assert_equal(fragment.size(), size_t(3)));
|
||||||
|
CHECK(assert_equal(expected, actual));
|
||||||
|
BayesNet<IndexConditional>::const_iterator fragmentCond = fragment.begin();
|
||||||
|
CHECK(assert_equal(**fragmentCond++, *expected0));
|
||||||
|
CHECK(assert_equal(**fragmentCond++, *expected1));
|
||||||
|
CHECK(assert_equal(**fragmentCond++, *expected2));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST(SymbolicFactor, EliminateSymbolic)
|
||||||
|
{
|
||||||
|
const vector<SymbolicFactorUnordered::shared_ptr> factors = list_of
|
||||||
|
(boost::make_shared<SymbolicFactorUnordered>(2,4,6))
|
||||||
|
(boost::make_shared<SymbolicFactorUnordered>(1,2,5))
|
||||||
|
(boost::make_shared<SymbolicFactorUnordered>(0,3));
|
||||||
|
|
||||||
|
const SymbolicFactorUnordered expectedFactor(4,5,6);
|
||||||
|
const SymbolicConditionalUnordered expectedConditional =
|
||||||
|
SymbolicConditionalUnordered::FromKeys(list_of(0)(1)(2)(3)(4)(5)(6), 4);
|
||||||
|
|
||||||
|
SymbolicFactorUnordered::shared_ptr actualFactor;
|
||||||
|
SymbolicConditionalUnordered::shared_ptr actualConditional;
|
||||||
|
boost::tie(actualConditional, actualFactor) =
|
||||||
|
EliminateSymbolicUnordered(factors, list_of(0)(1)(2)(3));
|
||||||
|
|
||||||
|
CHECK(assert_equal(expectedConditional, *actualConditional));
|
||||||
|
CHECK(assert_equal(expectedFactor, *actualFactor));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
int main() {
|
||||||
|
TestResult tr;
|
||||||
|
return TestRegistry::runAllTests(tr);
|
||||||
|
}
|
||||||
|
/* ************************************************************************* */
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
* 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
|
|
||||||
|
|
||||||
* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file testSymbolicFactor.cpp
|
|
||||||
* @brief Unit tests for a symbolic IndexFactor
|
|
||||||
* @author Frank Dellaert
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <CppUnitLite/TestHarness.h>
|
|
||||||
#include <gtsam/base/TestableAssertions.h>
|
|
||||||
#include <gtsam/inference/IndexFactor.h>
|
|
||||||
#include <gtsam/inference/IndexConditional.h>
|
|
||||||
#include <gtsam/inference/SymbolicFactorGraph.h>
|
|
||||||
|
|
||||||
#include <boost/assign/std/vector.hpp>
|
|
||||||
#include <boost/tuple/tuple.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace gtsam;
|
|
||||||
using namespace boost::assign;
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
TEST(SymbolicFactor, constructor) {
|
|
||||||
|
|
||||||
// Frontals sorted, parents not sorted
|
|
||||||
vector<Index> keys1; keys1 += 3, 4, 5, 9, 7, 8;
|
|
||||||
(void)IndexConditional(keys1, 3);
|
|
||||||
|
|
||||||
// // Frontals not sorted
|
|
||||||
// vector<Index> keys2; keys2 += 3, 5, 4, 9, 7, 8;
|
|
||||||
// (void)IndexConditional::FromRange(keys2.begin(), keys2.end(), 3);
|
|
||||||
|
|
||||||
// // Frontals not before parents
|
|
||||||
// vector<Index> keys3; keys3 += 3, 4, 5, 1, 7, 8;
|
|
||||||
// (void)IndexConditional::FromRange(keys3.begin(), keys3.end(), 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
#ifdef TRACK_ELIMINATE
|
|
||||||
TEST(SymbolicFactor, eliminate) {
|
|
||||||
vector<Index> keys; keys += 2, 3, 4, 6, 7, 9, 10, 11;
|
|
||||||
IndexFactor actual(keys.begin(), keys.end());
|
|
||||||
BayesNet<IndexConditional> fragment = *actual.eliminate(3);
|
|
||||||
|
|
||||||
IndexFactor expected(keys.begin()+3, keys.end());
|
|
||||||
IndexConditional::shared_ptr expected0 = IndexConditional::FromRange(keys.begin(), keys.end(), 1);
|
|
||||||
IndexConditional::shared_ptr expected1 = IndexConditional::FromRange(keys.begin()+1, keys.end(), 1);
|
|
||||||
IndexConditional::shared_ptr expected2 = IndexConditional::FromRange(keys.begin()+2, keys.end(), 1);
|
|
||||||
|
|
||||||
CHECK(assert_equal(fragment.size(), size_t(3)));
|
|
||||||
CHECK(assert_equal(expected, actual));
|
|
||||||
BayesNet<IndexConditional>::const_iterator fragmentCond = fragment.begin();
|
|
||||||
CHECK(assert_equal(**fragmentCond++, *expected0));
|
|
||||||
CHECK(assert_equal(**fragmentCond++, *expected1));
|
|
||||||
CHECK(assert_equal(**fragmentCond++, *expected2));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/* ************************************************************************* */
|
|
||||||
TEST(SymbolicFactor, EliminateSymbolic) {
|
|
||||||
SymbolicFactorGraph factors;
|
|
||||||
factors.push_factor(2,4,6);
|
|
||||||
factors.push_factor(1,2,5);
|
|
||||||
factors.push_factor(0,3);
|
|
||||||
|
|
||||||
IndexFactor expectedFactor(4,5,6);
|
|
||||||
std::vector<Index> keys; keys += 0,1,2,3,4,5,6;
|
|
||||||
IndexConditional::shared_ptr expectedConditional(new IndexConditional(keys, 4));
|
|
||||||
|
|
||||||
IndexFactor::shared_ptr actualFactor;
|
|
||||||
IndexConditional::shared_ptr actualConditional;
|
|
||||||
boost::tie(actualConditional, actualFactor) = EliminateSymbolic(factors, 4);
|
|
||||||
|
|
||||||
CHECK(assert_equal(*expectedConditional, *actualConditional));
|
|
||||||
CHECK(assert_equal(expectedFactor, *actualFactor));
|
|
||||||
|
|
||||||
// BayesNet<IndexConditional> expected_bn;
|
|
||||||
// vector<Index> parents;
|
|
||||||
//
|
|
||||||
// parents.clear(); parents += 1,2,3,4,5,6;
|
|
||||||
// expected_bn.push_back(IndexConditional::shared_ptr(new IndexConditional(0, parents)));
|
|
||||||
//
|
|
||||||
// parents.clear(); parents += 2,3,4,5,6;
|
|
||||||
// expected_bn.push_back(IndexConditional::shared_ptr(new IndexConditional(1, parents)));
|
|
||||||
//
|
|
||||||
// parents.clear(); parents += 3,4,5,6;
|
|
||||||
// expected_bn.push_back(IndexConditional::shared_ptr(new IndexConditional(2, parents)));
|
|
||||||
//
|
|
||||||
// parents.clear(); parents += 4,5,6;
|
|
||||||
// expected_bn.push_back(IndexConditional::shared_ptr(new IndexConditional(3, parents)));
|
|
||||||
//
|
|
||||||
// BayesNet<IndexConditional>::shared_ptr actual_bn;
|
|
||||||
// IndexFactor::shared_ptr actual_factor;
|
|
||||||
// boost::tie(actual_bn, actual_factor) = EliminateSymbolic(factors, 4);
|
|
||||||
//
|
|
||||||
// CHECK(assert_equal(expected_bn, *actual_bn));
|
|
||||||
// CHECK(assert_equal(expected_factor, *actual_factor));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
int main() {
|
|
||||||
TestResult tr;
|
|
||||||
return TestRegistry::runAllTests(tr);
|
|
||||||
}
|
|
||||||
/* ************************************************************************* */
|
|
||||||
|
|
@ -23,6 +23,34 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gtsam;
|
using namespace gtsam;
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST(FactorGraph, eliminateFrontals) {
|
||||||
|
|
||||||
|
SymbolicFactorGraph sfgOrig;
|
||||||
|
sfgOrig.push_factor(0,1);
|
||||||
|
sfgOrig.push_factor(0,2);
|
||||||
|
sfgOrig.push_factor(1,3);
|
||||||
|
sfgOrig.push_factor(1,4);
|
||||||
|
sfgOrig.push_factor(2,3);
|
||||||
|
sfgOrig.push_factor(4,5);
|
||||||
|
|
||||||
|
IndexConditional::shared_ptr actualCond;
|
||||||
|
SymbolicFactorGraph actualSfg;
|
||||||
|
boost::tie(actualCond, actualSfg) = sfgOrig.eliminateFrontals(2);
|
||||||
|
|
||||||
|
vector<Index> condIndices;
|
||||||
|
condIndices += 0,1,2,3,4;
|
||||||
|
IndexConditional expectedCond(condIndices, 2);
|
||||||
|
|
||||||
|
SymbolicFactorGraph expectedSfg;
|
||||||
|
expectedSfg.push_factor(2,3);
|
||||||
|
expectedSfg.push_factor(4,5);
|
||||||
|
expectedSfg.push_factor(2,3,4);
|
||||||
|
|
||||||
|
EXPECT(assert_equal(expectedSfg, actualSfg));
|
||||||
|
EXPECT(assert_equal(expectedCond, *actualCond));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
//TEST(SymbolicFactorGraph, eliminateFrontals) {
|
//TEST(SymbolicFactorGraph, eliminateFrontals) {
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue