size() now returns correct nr. of cliques, not number of keys

release/4.3a0
Frank Dellaert 2009-11-18 18:05:12 +00:00
parent d0efe2da5e
commit f40182518a
3 changed files with 21 additions and 9 deletions

View File

@ -44,13 +44,22 @@ namespace gtsam {
cout << endl;
}
/* ************************************************************************* */
template<class Conditional>
size_t BayesTree<Conditional>::Clique::treeSize() const {
size_t size = 1;
BOOST_FOREACH(shared_ptr child, children_)
size += child->treeSize();
return size;
}
/* ************************************************************************* */
template<class Conditional>
void BayesTree<Conditional>::Clique::printTree(const string& indent) const {
print(indent);
BOOST_FOREACH(shared_ptr child, children_)
child->printTree(indent+" ");
}
print(indent);
BOOST_FOREACH(shared_ptr child, children_)
child->printTree(indent+" ");
}
/* ************************************************************************* */
// The shortcut density is a conditional P(S|R) of the separator of this
@ -178,7 +187,7 @@ namespace gtsam {
/* ************************************************************************* */
template<class Conditional>
void BayesTree<Conditional>::print(const string& s) const {
cout << s << ": size == " << nodes_.size() << endl;
cout << s << ": size == " << size() << endl;
if (nodes_.empty()) return;
root_->printTree("");
}

View File

@ -61,6 +61,9 @@ namespace gtsam {
/** is this the root of a Bayes tree ? */
inline bool isRoot() const { return parent_==NULL;}
/** The size of subtree rooted at this clique, i.e., nr of Cliques */
size_t treeSize() const;
/** print this node and entire subtree below it */
void printTree(const std::string& indent) const;
@ -124,7 +127,7 @@ namespace gtsam {
/** number of cliques */
inline size_t size() const {
return nodes_.size();
return root_->treeSize();
}
/** return root clique */

View File

@ -53,7 +53,7 @@ TEST( BayesTree, constructor )
bayesTree.insert(X);
// Check Size
LONGS_EQUAL(6,bayesTree.size());
LONGS_EQUAL(4,bayesTree.size());
// Check root
BayesNet<SymbolicConditional> expected_root;
@ -106,7 +106,7 @@ TEST( BayesTree, linear_smoother_shortcuts )
// Create the Bayes tree
GaussianBayesTree bayesTree(chordalBayesNet);
LONGS_EQUAL(7,bayesTree.size());
LONGS_EQUAL(6,bayesTree.size());
// Check the conditional P(Root|Root)
GaussianBayesNet empty;
@ -175,7 +175,7 @@ TEST( BayesTree, balanced_smoother_marginals )
// Create the Bayes tree
GaussianBayesTree bayesTree(chordalBayesNet);
LONGS_EQUAL(7,bayesTree.size());
LONGS_EQUAL(4,bayesTree.size());
// Check marginal on x1
GaussianBayesNet expected1 = simpleGaussian("x1", zero(2), sigmax1);