Added reporting functions for counting number of cached shortcuts/separatorMarginals in BayesTree
parent
0e60b8cc4d
commit
df2a6bfdee
4
gtsam.h
4
gtsam.h
|
|
@ -810,6 +810,8 @@ virtual class BayesTree {
|
||||||
void clear();
|
void clear();
|
||||||
void deleteCachedShorcuts();
|
void deleteCachedShorcuts();
|
||||||
void insert(const CLIQUE* subtree);
|
void insert(const CLIQUE* subtree);
|
||||||
|
size_t numCachedShortcuts() const;
|
||||||
|
size_t numCachedSeparatorMarginals() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<CONDITIONAL>
|
template<CONDITIONAL>
|
||||||
|
|
@ -822,6 +824,8 @@ virtual class BayesTreeClique {
|
||||||
void print(string s) const;
|
void print(string s) const;
|
||||||
void printTree() const; // Default indent of ""
|
void printTree() const; // Default indent of ""
|
||||||
void printTree(string indent) const;
|
void printTree(string indent) const;
|
||||||
|
size_t numCachedShortcuts() const;
|
||||||
|
size_t numCachedSeparatorMarginals() const;
|
||||||
|
|
||||||
CONDITIONAL* conditional() const;
|
CONDITIONAL* conditional() const;
|
||||||
bool isRoot() const;
|
bool isRoot() const;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,18 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
template<class CONDITIONAL, class CLIQUE>
|
||||||
|
size_t BayesTree<CONDITIONAL,CLIQUE>::numCachedShortcuts() const {
|
||||||
|
return (root_) ? root_->numCachedShortcuts() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
template<class CONDITIONAL, class CLIQUE>
|
||||||
|
size_t BayesTree<CONDITIONAL,CLIQUE>::numCachedSeparatorMarginals() const {
|
||||||
|
return (root_) ? root_->numCachedSeparatorMarginals() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class CONDITIONAL, class CLIQUE>
|
template<class CONDITIONAL, class CLIQUE>
|
||||||
void BayesTree<CONDITIONAL,CLIQUE>::saveGraph(const std::string &s, const IndexFormatter& indexFormatter) const {
|
void BayesTree<CONDITIONAL,CLIQUE>::saveGraph(const std::string &s, const IndexFormatter& indexFormatter) const {
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,12 @@ namespace gtsam {
|
||||||
/** Gather data on all cliques */
|
/** Gather data on all cliques */
|
||||||
CliqueData getCliqueData() const;
|
CliqueData getCliqueData() const;
|
||||||
|
|
||||||
|
/** Collect number of cliques with cached shortcuts */
|
||||||
|
size_t numCachedShortcuts() const;
|
||||||
|
|
||||||
|
/** Collect number of cliques with cached separator marginals */
|
||||||
|
size_t numCachedSeparatorMarginals() const;
|
||||||
|
|
||||||
/** return marginal on any variable */
|
/** return marginal on any variable */
|
||||||
typename FactorType::shared_ptr marginalFactor(Index j, Eliminate function) const;
|
typename FactorType::shared_ptr marginalFactor(Index j, Eliminate function) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,14 +90,40 @@ namespace gtsam {
|
||||||
size_t BayesTreeCliqueBase<DERIVED, CONDITIONAL>::treeSize() const {
|
size_t BayesTreeCliqueBase<DERIVED, CONDITIONAL>::treeSize() const {
|
||||||
size_t size = 1;
|
size_t size = 1;
|
||||||
BOOST_FOREACH(const derived_ptr& child, children_)
|
BOOST_FOREACH(const derived_ptr& child, children_)
|
||||||
size += child->treeSize();
|
size += child->treeSize();
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
template<class DERIVED, class CONDITIONAL>
|
||||||
|
size_t BayesTreeCliqueBase<DERIVED, CONDITIONAL>::numCachedShortcuts() const {
|
||||||
|
if (!cachedShortcut_)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
size_t subtree_count = 1;
|
||||||
|
BOOST_FOREACH(const derived_ptr& child, children_)
|
||||||
|
subtree_count += child->numCachedShortcuts();
|
||||||
|
|
||||||
|
return subtree_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
template<class DERIVED, class CONDITIONAL>
|
||||||
|
size_t BayesTreeCliqueBase<DERIVED, CONDITIONAL>::numCachedSeparatorMarginals() const {
|
||||||
|
if (!cachedSeparatorMarginal_)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
size_t subtree_count = 1;
|
||||||
|
BOOST_FOREACH(const derived_ptr& child, children_)
|
||||||
|
subtree_count += child->numCachedSeparatorMarginals();
|
||||||
|
|
||||||
|
return subtree_count;
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class DERIVED, class CONDITIONAL>
|
template<class DERIVED, class CONDITIONAL>
|
||||||
void BayesTreeCliqueBase<DERIVED, CONDITIONAL>::printTree(
|
void BayesTreeCliqueBase<DERIVED, CONDITIONAL>::printTree(
|
||||||
const std::string& indent, const IndexFormatter& indexFormatter) const {
|
const std::string& indent, const IndexFormatter& indexFormatter) const {
|
||||||
asDerived(this)->print(indent, indexFormatter);
|
asDerived(this)->print(indent, indexFormatter);
|
||||||
BOOST_FOREACH(const derived_ptr& child, children_)
|
BOOST_FOREACH(const derived_ptr& child, children_)
|
||||||
child->printTree(indent + " ", indexFormatter);
|
child->printTree(indent + " ", indexFormatter);
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,12 @@ namespace gtsam {
|
||||||
/** The size of subtree rooted at this clique, i.e., nr of Cliques */
|
/** The size of subtree rooted at this clique, i.e., nr of Cliques */
|
||||||
size_t treeSize() const;
|
size_t treeSize() const;
|
||||||
|
|
||||||
|
/** Collect number of cliques with cached shortcuts in subtree */
|
||||||
|
size_t numCachedShortcuts() const;
|
||||||
|
|
||||||
|
/** Collect number of cliques with cached separator marginals */
|
||||||
|
size_t numCachedSeparatorMarginals() const;
|
||||||
|
|
||||||
/** The arrow operator accesses the conditional */
|
/** The arrow operator accesses the conditional */
|
||||||
const ConditionalType* operator->() const {
|
const ConditionalType* operator->() const {
|
||||||
return conditional_.get();
|
return conditional_.get();
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,8 @@ TEST( BayesTree, shortcutCheck )
|
||||||
bool notCleared = clique->cachedShortcut();
|
bool notCleared = clique->cachedShortcut();
|
||||||
CHECK( notCleared == false);
|
CHECK( notCleared == false);
|
||||||
}
|
}
|
||||||
|
EXPECT_LONGS_EQUAL(0, rootClique->numCachedShortcuts());
|
||||||
|
EXPECT_LONGS_EQUAL(0, rootClique->numCachedSeparatorMarginals());
|
||||||
|
|
||||||
// BOOST_FOREACH(SymbolicBayesTree::sharedClique& clique, allCliques) {
|
// BOOST_FOREACH(SymbolicBayesTree::sharedClique& clique, allCliques) {
|
||||||
// clique->print("Clique#");
|
// clique->print("Clique#");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue