Added two more removePath tests and fixed bug in removeTop. But orphan list is still incorrect.
parent
45292f7bd6
commit
d4aaa5d114
|
@ -174,9 +174,9 @@ namespace gtsam {
|
|||
/* ************************************************************************* */
|
||||
template<class Conditional>
|
||||
void BayesTree<Conditional>::Cliques::print(const std::string& s) const {
|
||||
cout << s << " Cliques: ";
|
||||
cout << s << ":\n";
|
||||
BOOST_FOREACH(sharedClique clique, *this)
|
||||
clique->print();
|
||||
clique->printTree();
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
@ -388,6 +388,7 @@ namespace gtsam {
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
||||
template<class Conditional>
|
||||
template<class Factor>
|
||||
pair<FactorGraph<Factor>, typename BayesTree<Conditional>::Cliques>
|
||||
|
@ -406,7 +407,7 @@ namespace gtsam {
|
|||
|
||||
// remove path above this clique
|
||||
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
|
||||
factors.push_back(factors1);
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace gtsam {
|
|||
size_t treeSize() const;
|
||||
|
||||
/** 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 */
|
||||
// TODO: create a cached version
|
||||
|
|
|
@ -351,6 +351,81 @@ TEST( BayesTree, removePath )
|
|||
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 )
|
||||
{
|
||||
|
@ -387,8 +462,12 @@ TEST( BayesTree, removeTop )
|
|||
expected.push_factor("B","L","E");
|
||||
expected.push_factor("B","L");
|
||||
expected.push_factor("B");
|
||||
expected.push_factor("L","B","S");
|
||||
expected.push_factor("B","S");
|
||||
CHECK(assert_equal((FactorGraph<SymbolicFactor>)expected, factors));
|
||||
SymbolicBayesTree::Cliques expectedOrphans;
|
||||
expectedOrphans += bayesTree["T"], bayesTree["X"];
|
||||
//CHECK(assert_equal(expectedOrphans, orphans));
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
Loading…
Reference in New Issue