size() now returns correct nr. of cliques, not number of keys
parent
d0efe2da5e
commit
f40182518a
|
@ -44,6 +44,15 @@ namespace gtsam {
|
||||||
cout << endl;
|
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>
|
template<class Conditional>
|
||||||
void BayesTree<Conditional>::Clique::printTree(const string& indent) const {
|
void BayesTree<Conditional>::Clique::printTree(const string& indent) const {
|
||||||
|
@ -178,7 +187,7 @@ namespace gtsam {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class Conditional>
|
template<class Conditional>
|
||||||
void BayesTree<Conditional>::print(const string& s) const {
|
void BayesTree<Conditional>::print(const string& s) const {
|
||||||
cout << s << ": size == " << nodes_.size() << endl;
|
cout << s << ": size == " << size() << endl;
|
||||||
if (nodes_.empty()) return;
|
if (nodes_.empty()) return;
|
||||||
root_->printTree("");
|
root_->printTree("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,9 @@ namespace gtsam {
|
||||||
/** is this the root of a Bayes tree ? */
|
/** is this the root of a Bayes tree ? */
|
||||||
inline bool isRoot() const { return parent_==NULL;}
|
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 */
|
/** print this node and entire subtree below it */
|
||||||
void printTree(const std::string& indent) const;
|
void printTree(const std::string& indent) const;
|
||||||
|
|
||||||
|
@ -124,7 +127,7 @@ namespace gtsam {
|
||||||
|
|
||||||
/** number of cliques */
|
/** number of cliques */
|
||||||
inline size_t size() const {
|
inline size_t size() const {
|
||||||
return nodes_.size();
|
return root_->treeSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** return root clique */
|
/** return root clique */
|
||||||
|
|
|
@ -53,7 +53,7 @@ TEST( BayesTree, constructor )
|
||||||
bayesTree.insert(X);
|
bayesTree.insert(X);
|
||||||
|
|
||||||
// Check Size
|
// Check Size
|
||||||
LONGS_EQUAL(6,bayesTree.size());
|
LONGS_EQUAL(4,bayesTree.size());
|
||||||
|
|
||||||
// Check root
|
// Check root
|
||||||
BayesNet<SymbolicConditional> expected_root;
|
BayesNet<SymbolicConditional> expected_root;
|
||||||
|
@ -106,7 +106,7 @@ TEST( BayesTree, linear_smoother_shortcuts )
|
||||||
|
|
||||||
// Create the Bayes tree
|
// Create the Bayes tree
|
||||||
GaussianBayesTree bayesTree(chordalBayesNet);
|
GaussianBayesTree bayesTree(chordalBayesNet);
|
||||||
LONGS_EQUAL(7,bayesTree.size());
|
LONGS_EQUAL(6,bayesTree.size());
|
||||||
|
|
||||||
// Check the conditional P(Root|Root)
|
// Check the conditional P(Root|Root)
|
||||||
GaussianBayesNet empty;
|
GaussianBayesNet empty;
|
||||||
|
@ -175,7 +175,7 @@ TEST( BayesTree, balanced_smoother_marginals )
|
||||||
|
|
||||||
// Create the Bayes tree
|
// Create the Bayes tree
|
||||||
GaussianBayesTree bayesTree(chordalBayesNet);
|
GaussianBayesTree bayesTree(chordalBayesNet);
|
||||||
LONGS_EQUAL(7,bayesTree.size());
|
LONGS_EQUAL(4,bayesTree.size());
|
||||||
|
|
||||||
// Check marginal on x1
|
// Check marginal on x1
|
||||||
GaussianBayesNet expected1 = simpleGaussian("x1", zero(2), sigmax1);
|
GaussianBayesNet expected1 = simpleGaussian("x1", zero(2), sigmax1);
|
||||||
|
|
Loading…
Reference in New Issue