SymbolicBayesTreeUnordered shortcut and marginal unit tests pass
parent
aef3ba5e56
commit
65657916ab
|
|
@ -212,7 +212,7 @@ namespace gtsam {
|
||||||
{
|
{
|
||||||
// Traverse the BayesTree and add all conditionals to this graph
|
// Traverse the BayesTree and add all conditionals to this graph
|
||||||
int data = 0; // Unused
|
int data = 0; // Unused
|
||||||
treeTraversal::DepthFirstForest(*this, data, boost::bind(&_pushClique<FactorType,CLIQUE>, graph, _1));
|
treeTraversal::DepthFirstForest(*this, data, boost::bind(&_pushClique<FactorType,CLIQUE>, boost::ref(graph), _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
@ -474,6 +474,8 @@ namespace gtsam {
|
||||||
++p2;
|
++p2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!B)
|
||||||
|
throw std::invalid_argument("BayesTree::jointBayesNet does not yet work for joints across a forest");
|
||||||
gttoc(Lowest_common_ancestor);
|
gttoc(Lowest_common_ancestor);
|
||||||
|
|
||||||
// Compute marginal on lowest common ancestor clique
|
// Compute marginal on lowest common ancestor clique
|
||||||
|
|
|
||||||
|
|
@ -135,12 +135,12 @@ namespace gtsam {
|
||||||
{
|
{
|
||||||
// An ordering was also provided for the unmarginalized variables, so we can also
|
// An ordering was also provided for the unmarginalized variables, so we can also
|
||||||
// eliminate them in the order requested.
|
// eliminate them in the order requested.
|
||||||
return eliminateSequential(*varsAsOrdering, function, *variableIndex);
|
return eliminated.second->eliminateSequential(*varsAsOrdering, function);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// No ordering was provided for the unmarginalized variables, so order them with COLAMD.
|
// No ordering was provided for the unmarginalized variables, so order them with COLAMD.
|
||||||
return eliminateSequential(boost::none, function, *variableIndex);
|
return eliminated.second->eliminateSequential(boost::none, function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST_UNSAFE( SymbolicBayesTree, constructor )
|
TEST( SymbolicBayesTree, constructor )
|
||||||
{
|
{
|
||||||
// Create using insert
|
// Create using insert
|
||||||
//SymbolicBayesTreeUnordered bayesTree = createAsiaSymbolicBayesTree();
|
//SymbolicBayesTreeUnordered bayesTree = createAsiaSymbolicBayesTree();
|
||||||
|
|
@ -244,7 +244,6 @@ TEST( BayesTree, shortcutCheck )
|
||||||
SymbolicBayesTreeUnordered bayesTree = *chain.eliminateMultifrontal(
|
SymbolicBayesTreeUnordered bayesTree = *chain.eliminateMultifrontal(
|
||||||
OrderingUnordered(list_of(_G_)(_F_)(_E_)(_D_)(_C_)(_B_)(_A_)));
|
OrderingUnordered(list_of(_G_)(_F_)(_E_)(_D_)(_C_)(_B_)(_A_)));
|
||||||
|
|
||||||
bayesTree.print("BayesTree");
|
|
||||||
//bayesTree.saveGraph("BT1.dot");
|
//bayesTree.saveGraph("BT1.dot");
|
||||||
|
|
||||||
SymbolicBayesTreeUnordered::sharedClique rootClique = bayesTree.roots().front();
|
SymbolicBayesTreeUnordered::sharedClique rootClique = bayesTree.roots().front();
|
||||||
|
|
@ -458,6 +457,8 @@ TEST( SymbolicBayesTreeUnordered, thinTree ) {
|
||||||
bayesNet.push_back(boost::make_shared<SymbolicConditionalUnordered>(1, 8, 12));
|
bayesNet.push_back(boost::make_shared<SymbolicConditionalUnordered>(1, 8, 12));
|
||||||
bayesNet.push_back(boost::make_shared<SymbolicConditionalUnordered>(0, 8, 12));
|
bayesNet.push_back(boost::make_shared<SymbolicConditionalUnordered>(0, 8, 12));
|
||||||
|
|
||||||
|
bayesNet.print("bayesNet: ");
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
GTSAM_PRINT(bayesNet);
|
GTSAM_PRINT(bayesNet);
|
||||||
bayesNet.saveGraph("/tmp/symbolicBayesNet.dot");
|
bayesNet.saveGraph("/tmp/symbolicBayesNet.dot");
|
||||||
|
|
@ -486,8 +487,7 @@ TEST( SymbolicBayesTreeUnordered, thinTree ) {
|
||||||
// check shortcut P(S8||R) to root
|
// check shortcut P(S8||R) to root
|
||||||
SymbolicBayesTreeUnordered::Clique::shared_ptr c = bayesTree[8];
|
SymbolicBayesTreeUnordered::Clique::shared_ptr c = bayesTree[8];
|
||||||
SymbolicBayesNetUnordered shortcut = c->shortcut(R);
|
SymbolicBayesNetUnordered shortcut = c->shortcut(R);
|
||||||
SymbolicBayesNetUnordered expected;
|
SymbolicBayesNetUnordered expected = list_of(SymbolicConditionalUnordered(12, 14));
|
||||||
expected.push_back(boost::make_shared<SymbolicConditionalUnordered>(12, 14));
|
|
||||||
EXPECT(assert_equal(expected, shortcut));
|
EXPECT(assert_equal(expected, shortcut));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -544,8 +544,8 @@ TEST( SymbolicBayesTreeUnordered, thinTree ) {
|
||||||
if (true) {
|
if (true) {
|
||||||
actualJoint = bayesTree.jointBayesNet(2, 6);
|
actualJoint = bayesTree.jointBayesNet(2, 6);
|
||||||
SymbolicBayesNetUnordered expected;
|
SymbolicBayesNetUnordered expected;
|
||||||
expected.push_back(boost::make_shared<SymbolicConditionalUnordered>(6));
|
|
||||||
expected.push_back(boost::make_shared<SymbolicConditionalUnordered>(2, 6));
|
expected.push_back(boost::make_shared<SymbolicConditionalUnordered>(2, 6));
|
||||||
|
expected.push_back(boost::make_shared<SymbolicConditionalUnordered>(6));
|
||||||
EXPECT(assert_equal(expected, *actualJoint));
|
EXPECT(assert_equal(expected, *actualJoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -562,20 +562,20 @@ TEST( SymbolicBayesTreeUnordered, thinTree ) {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST(SymbolicBayesTreeUnordered, forest_joint)
|
TEST(SymbolicBayesTreeUnordered, forest_joint)
|
||||||
{
|
{
|
||||||
//// Create forest
|
// Create forest
|
||||||
//SymbolicBayesTreeCliqueUnordered::shared_ptr root1 = MakeClique(list_of(1), 1);
|
SymbolicBayesTreeCliqueUnordered::shared_ptr root1 = MakeClique(list_of(1), 1);
|
||||||
//SymbolicBayesTreeCliqueUnordered::shared_ptr root2 = MakeClique(list_of(2), 1);
|
SymbolicBayesTreeCliqueUnordered::shared_ptr root2 = MakeClique(list_of(2), 1);
|
||||||
//SymbolicBayesTreeUnordered bayesTree;
|
SymbolicBayesTreeUnordered bayesTree;
|
||||||
//bayesTree.insertRoot(root1);
|
bayesTree.insertRoot(root1);
|
||||||
//bayesTree.insertRoot(root2);
|
bayesTree.insertRoot(root2);
|
||||||
|
|
||||||
//// Check joint
|
// Check joint
|
||||||
//SymbolicBayesNetUnordered expected = list_of
|
SymbolicBayesNetUnordered expected = list_of
|
||||||
// (SymbolicConditionalUnordered(1))
|
(SymbolicConditionalUnordered(1))
|
||||||
// (SymbolicConditionalUnordered(2));
|
(SymbolicConditionalUnordered(2));
|
||||||
//SymbolicBayesNetUnordered actual = *bayesTree.jointBayesNet(1, 2);
|
SymbolicBayesNetUnordered actual = *bayesTree.jointBayesNet(1, 2);
|
||||||
|
|
||||||
//EXPECT(assert_equal(expected, actual));
|
EXPECT(assert_equal(expected, actual));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* *
|
/* ************************************************************************* *
|
||||||
|
|
@ -588,7 +588,7 @@ TEST(SymbolicBayesTreeUnordered, forest_joint)
|
||||||
C6 0 : 1
|
C6 0 : 1
|
||||||
**************************************************************************** */
|
**************************************************************************** */
|
||||||
|
|
||||||
TEST_UNSAFE( SymbolicBayesTreeUnordered, linear_smoother_shortcuts ) {
|
TEST( SymbolicBayesTreeUnordered, linear_smoother_shortcuts ) {
|
||||||
// Create smoother with 7 nodes
|
// Create smoother with 7 nodes
|
||||||
SymbolicFactorGraphUnordered smoother;
|
SymbolicFactorGraphUnordered smoother;
|
||||||
smoother.push_factor(0);
|
smoother.push_factor(0);
|
||||||
|
|
@ -651,25 +651,22 @@ TEST(SymbolicBayesTreeUnordered, complicatedMarginal)
|
||||||
SymbolicBayesTreeCliqueUnordered::shared_ptr root = MakeClique(list_of(11)(12), 2);
|
SymbolicBayesTreeCliqueUnordered::shared_ptr root = MakeClique(list_of(11)(12), 2);
|
||||||
cur = root;
|
cur = root;
|
||||||
|
|
||||||
cur->children += MakeClique(list_of(9)(10)(11)(12), 2);
|
root->children += MakeClique(list_of(9)(10)(11)(12), 2);
|
||||||
cur->children.front()->parent_ = cur;
|
root->children.back()->parent_ = root;
|
||||||
cur = root->children.front();
|
|
||||||
|
|
||||||
cur->children += MakeClique(list_of(7)(8)(11), 2);
|
root->children += MakeClique(list_of(7)(8)(11), 2);
|
||||||
cur->children.front()->parent_ = cur;
|
root->children.back()->parent_ = root;
|
||||||
cur = root->children.front();
|
cur = root->children.back();
|
||||||
|
|
||||||
cur->children += MakeClique(list_of(5)(6)(7)(8), 2);
|
cur->children += MakeClique(list_of(5)(6)(7)(8), 2);
|
||||||
cur->children.front()->parent_ = cur;
|
cur->children.back()->parent_ = cur;
|
||||||
cur = root->children.front();
|
cur = cur->children.back();
|
||||||
|
|
||||||
cur->children += MakeClique(list_of(3)(4)(6), 2);
|
cur->children += MakeClique(list_of(3)(4)(6), 2);
|
||||||
cur->children.front()->parent_ = cur;
|
cur->children.back()->parent_ = cur;
|
||||||
cur = root->children.front();
|
|
||||||
|
|
||||||
cur->children += MakeClique(list_of(1)(2)(5), 2);
|
cur->children += MakeClique(list_of(1)(2)(5), 2);
|
||||||
cur->children.front()->parent_ = cur;
|
cur->children.back()->parent_ = cur;
|
||||||
cur = root->children.front();
|
|
||||||
|
|
||||||
// Create Bayes Tree
|
// Create Bayes Tree
|
||||||
SymbolicBayesTreeUnordered bt;
|
SymbolicBayesTreeUnordered bt;
|
||||||
|
|
@ -679,6 +676,8 @@ TEST(SymbolicBayesTreeUnordered, complicatedMarginal)
|
||||||
bt.saveGraph("/tmp/SymbolicBayesTreeUnordered.dot");
|
bt.saveGraph("/tmp/SymbolicBayesTreeUnordered.dot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bt.print("bt: ");
|
||||||
|
|
||||||
// Shortcut on 9
|
// Shortcut on 9
|
||||||
{
|
{
|
||||||
SymbolicBayesTreeUnordered::Clique::shared_ptr c = bt[9];
|
SymbolicBayesTreeUnordered::Clique::shared_ptr c = bt[9];
|
||||||
|
|
@ -698,8 +697,8 @@ TEST(SymbolicBayesTreeUnordered, complicatedMarginal)
|
||||||
SymbolicBayesTreeUnordered::Clique::shared_ptr c = bt[5];
|
SymbolicBayesTreeUnordered::Clique::shared_ptr c = bt[5];
|
||||||
SymbolicBayesNetUnordered shortcut = c->shortcut(root);
|
SymbolicBayesNetUnordered shortcut = c->shortcut(root);
|
||||||
SymbolicBayesNetUnordered expected = list_of
|
SymbolicBayesNetUnordered expected = list_of
|
||||||
(SymbolicConditionalUnordered(8, 11))
|
(SymbolicConditionalUnordered(7, 8, 11))
|
||||||
(SymbolicConditionalUnordered(7, 8, 11));
|
(SymbolicConditionalUnordered(8, 11));
|
||||||
EXPECT(assert_equal(expected, shortcut));
|
EXPECT(assert_equal(expected, shortcut));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue