From 198f73a05f45ff7c237ada4d29b95a16af90c12f Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sun, 22 Nov 2009 18:40:55 +0000 Subject: [PATCH] Insert conditionals straight into the topless bayesTree --- cpp/testIncremental.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cpp/testIncremental.cpp b/cpp/testIncremental.cpp index c33ff1593..208e8c2d6 100644 --- a/cpp/testIncremental.cpp +++ b/cpp/testIncremental.cpp @@ -27,13 +27,12 @@ typedef BayesTree GaussianBayesTree; /* ************************************************************************* */ -SymbolicBayesTree update(SymbolicBayesTree& initial, - const boost::shared_ptr& newFactor) { +void update(SymbolicBayesTree& bayesTree, const boost::shared_ptr& newFactor) { // Remove the contaminated part of the Bayes tree FactorGraph factors; SymbolicBayesTree::Cliques orphans; - boost::tie(factors,orphans) = initial.removeTop(newFactor); + boost::tie(factors,orphans) = bayesTree.removeTop(newFactor); // create an ordering BELS Ordering ordering = factors.getOrdering(); @@ -42,13 +41,15 @@ SymbolicBayesTree update(SymbolicBayesTree& initial, SymbolicBayesNet bayesNet = eliminate(factors,ordering); // turn back into a Bayes Tree - BayesTree newTree(bayesNet); + SymbolicBayesNet::const_reverse_iterator rit; + for ( rit=bayesNet.rbegin(); rit != bayesNet.rend(); ++rit ) + bayesTree.insert(*rit); // add orphans to the bottom of the new tree BOOST_FOREACH(SymbolicBayesTree::sharedClique orphan, orphans) { BOOST_FOREACH(string key1, orphan->separator_) { // get clique from new tree to attach to - SymbolicBayesTree::sharedClique candidateParent = newTree[key1]; + SymbolicBayesTree::sharedClique candidateParent = bayesTree[key1]; // check if all conditionals in there, only add once bool is_subset = true; @@ -70,8 +71,6 @@ SymbolicBayesTree update(SymbolicBayesTree& initial, } } } - - return newTree; } /* ************************************************************************* */ @@ -119,10 +118,10 @@ TEST( BayesTree, iSAM ) boost::shared_ptr newFactor(new SymbolicFactor(keys)); // do incremental inference - SymbolicBayesTree actual = update(bayesTree, newFactor); + update(bayesTree, newFactor); // Check whether the same - CHECK(assert_equal(expected,actual)); + CHECK(assert_equal(expected,bayesTree)); } /* ************************************************************************* */