Added two more removePath tests and fixed bug in removeTop. But orphan list is still incorrect.

release/4.3a0
Frank Dellaert 2009-11-22 18:06:28 +00:00
parent 45292f7bd6
commit d4aaa5d114
3 changed files with 84 additions and 4 deletions

View File

@ -174,9 +174,9 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
template<class Conditional> template<class Conditional>
void BayesTree<Conditional>::Cliques::print(const std::string& s) const { void BayesTree<Conditional>::Cliques::print(const std::string& s) const {
cout << s << " Cliques: "; cout << s << ":\n";
BOOST_FOREACH(sharedClique clique, *this) BOOST_FOREACH(sharedClique clique, *this)
clique->print(); clique->printTree();
} }
/* ************************************************************************* */ /* ************************************************************************* */
@ -388,6 +388,7 @@ namespace gtsam {
} }
/* ************************************************************************* */ /* ************************************************************************* */
template<class Conditional> template<class Conditional>
template<class Factor> template<class Factor>
pair<FactorGraph<Factor>, typename BayesTree<Conditional>::Cliques> pair<FactorGraph<Factor>, typename BayesTree<Conditional>::Cliques>
@ -406,7 +407,7 @@ namespace gtsam {
// remove path above this clique // remove path above this clique
FactorGraph<Factor> factors1; Cliques orphans1; FactorGraph<Factor> factors1; Cliques orphans1;
boost::tie(factors1,orphans1) = removePath<Factor>(clique->parent_); boost::tie(factors1,orphans1) = removePath<Factor>(clique);
// add to global factors and orphans // add to global factors and orphans
factors.push_back(factors1); factors.push_back(factors1);

View File

@ -65,7 +65,7 @@ namespace gtsam {
size_t treeSize() const; size_t treeSize() const;
/** print this node and entire subtree below it */ /** print this node and entire subtree below it */
void printTree(const std::string& indent) const; void printTree(const std::string& indent="") const;
/** return the conditional P(S|Root) on the separator given the root */ /** return the conditional P(S|Root) on the separator given the root */
// TODO: create a cached version // TODO: create a cached version

View File

@ -351,6 +351,81 @@ TEST( BayesTree, removePath )
CHECK(assert_equal(expectedOrphans2, orphans)); CHECK(assert_equal(expectedOrphans2, orphans));
} }
/* ************************************************************************* */
TEST( BayesTree, removePath2 )
{
// Conditionals for ASIA example from the tutorial with A and D evidence
SymbolicConditional::shared_ptr
B(new SymbolicConditional("B")),
L(new SymbolicConditional("L", "B")),
E(new SymbolicConditional("E", "B", "L")),
S(new SymbolicConditional("S", "L", "B")),
T(new SymbolicConditional("T", "E", "L")),
X(new SymbolicConditional("X", "E"));
// Create using insert
SymbolicBayesTree bayesTree;
bayesTree.insert(B);
bayesTree.insert(L);
bayesTree.insert(E);
bayesTree.insert(S);
bayesTree.insert(T);
bayesTree.insert(X);
// Call remove-path with clique S
FactorGraph<SymbolicFactor> factors;
SymbolicBayesTree::Cliques orphans;
boost::tie(factors,orphans) = bayesTree.removePath<SymbolicFactor>(bayesTree["B"]);
// Check expected outcome
SymbolicFactorGraph expected;
expected.push_factor("B","L","E");
expected.push_factor("B","L");
expected.push_factor("B");
CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected, factors));
SymbolicBayesTree::Cliques expectedOrphans;
expectedOrphans += bayesTree["S"], bayesTree["T"], bayesTree["X"];
CHECK(assert_equal(expectedOrphans, orphans));
}
/* ************************************************************************* */
TEST( BayesTree, removePath3 )
{
// Conditionals for ASIA example from the tutorial with A and D evidence
SymbolicConditional::shared_ptr
B(new SymbolicConditional("B")),
L(new SymbolicConditional("L", "B")),
E(new SymbolicConditional("E", "B", "L")),
S(new SymbolicConditional("S", "L", "B")),
T(new SymbolicConditional("T", "E", "L")),
X(new SymbolicConditional("X", "E"));
// Create using insert
SymbolicBayesTree bayesTree;
bayesTree.insert(B);
bayesTree.insert(L);
bayesTree.insert(E);
bayesTree.insert(S);
bayesTree.insert(T);
bayesTree.insert(X);
// Call remove-path with clique S
FactorGraph<SymbolicFactor> factors;
SymbolicBayesTree::Cliques orphans;
boost::tie(factors,orphans) = bayesTree.removePath<SymbolicFactor>(bayesTree["S"]);
// Check expected outcome
SymbolicFactorGraph expected;
expected.push_factor("B","L","E");
expected.push_factor("B","L");
expected.push_factor("B");
expected.push_factor("L","B","S");
CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected, factors));
SymbolicBayesTree::Cliques expectedOrphans;
expectedOrphans += bayesTree["T"], bayesTree["X"];
CHECK(assert_equal(expectedOrphans, orphans));
}
/* ************************************************************************* */ /* ************************************************************************* */
TEST( BayesTree, removeTop ) TEST( BayesTree, removeTop )
{ {
@ -387,8 +462,12 @@ TEST( BayesTree, removeTop )
expected.push_factor("B","L","E"); expected.push_factor("B","L","E");
expected.push_factor("B","L"); expected.push_factor("B","L");
expected.push_factor("B"); expected.push_factor("B");
expected.push_factor("L","B","S");
expected.push_factor("B","S"); expected.push_factor("B","S");
CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected, factors)); CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected, factors));
SymbolicBayesTree::Cliques expectedOrphans;
expectedOrphans += bayesTree["T"], bayesTree["X"];
//CHECK(assert_equal(expectedOrphans, orphans));
} }
/* ************************************************************************* */ /* ************************************************************************* */