diff --git a/cpp/BayesTree.h b/cpp/BayesTree.h index c4ef2d53f..e86d69281 100644 --- a/cpp/BayesTree.h +++ b/cpp/BayesTree.h @@ -96,12 +96,34 @@ namespace gtsam { bool equals(const Cliques& other, double tol = 1e-9) const; }; + /** clique statistics */ + struct CliqueStats { + double avgConditionalSize; + std::size_t maxConditionalSize; + double avgSeparatorSize; + std::size_t maxSeparatorSize; + }; + + /** store all the sizes */ + struct CliqueData { + std::vector conditionalSizes; + std::vector separatorSizes; + CliqueStats getStats() const; + }; + private: /** Map from keys to Clique */ typedef SymbolMap Nodes; Nodes nodes_; + /** private helper method for saving the Tree to a text file in GraphViz format */ + void saveGraph(std::ostream &s, sharedClique clique, + int parentnum = 0) const; + + /** Gather data on a single clique */ + void getCliqueData(CliqueData& stats, sharedClique clique) const; + protected: /** Root clique */ @@ -130,15 +152,23 @@ namespace gtsam { virtual ~BayesTree() { } - /** print */ - void print(const std::string& s = "") const; + /** + * Constructing Bayes trees + */ - /** saves the Tree to a text file in GraphViz format */ - void saveGraph(const std::string& s) const; - private: - void saveGraph(std::ostream &s, sharedClique clique, - int parentnum = 0) const; - public: + /** Insert a new conditional */ + void insert(const sharedConditional& conditional, const IndexTable& index); + + /** Insert a new clique corresponding to the given Bayes net. + * It is the caller's responsibility to decide whether the given Bayes net is a valid clique, + * i.e. all the variables (frontal and separator) are connected + */ + sharedClique insert(const BayesNet& bayesNet, + std::list& children, bool isRootClique = false); + + /** + * Querying Bayes trees + */ /** check equality */ bool equals(const BayesTree& other, double tol = 1e-9) const; @@ -149,15 +179,6 @@ namespace gtsam { */ Symbol findParentClique(const std::list& parents, const IndexTable& index) const; - /** insert a new conditional */ - void insert(const sharedConditional& conditional, const IndexTable& index); - - /** insert a new clique corresponding to the given bayes net. - * it is the caller's responsibility to decide whether the given bayes net is a valid clique, - * i.e. all the variables (frontal and separator) are connected */ - sharedClique insert(const BayesNet& bayesNet, - std::list& children, bool isRootClique = false); - /** number of cliques */ inline size_t size() const { if(root_) @@ -176,24 +197,9 @@ namespace gtsam { return nodes_.at(key); } - /** clique statistics */ - struct CliqueStats { - double avgConditionalSize; - std::size_t maxConditionalSize; - double avgSeparatorSize; - std::size_t maxSeparatorSize; - }; - struct CliqueData { - std::vector conditionalSizes; - std::vector separatorSizes; - CliqueStats getStats() const; - }; + /** Gather data on all cliques */ CliqueData getCliqueData() const; - private: - void getCliqueData(CliqueData& stats, sharedClique clique) const; - public: - /** return marginal on any variable */ template FactorGraph marginal(const Symbol& key) const; @@ -210,6 +216,20 @@ namespace gtsam { template BayesNet jointBayesNet(const Symbol& key1, const Symbol& key2) const; + /** + * Read only with side effects + */ + + /** print */ + void print(const std::string& s = "") const; + + /** saves the Tree to a text file in GraphViz format */ + void saveGraph(const std::string& s) const; + + /** + * Altering Bayes trees + */ + /** * Remove all nodes */ diff --git a/cpp/testBayesTree.cpp b/cpp/testBayesTree.cpp index d4cf87656..9c727f49e 100644 --- a/cpp/testBayesTree.cpp +++ b/cpp/testBayesTree.cpp @@ -69,19 +69,6 @@ SymbolicBayesTree createAsiaSymbolicBayesTree() { return bayesTree; } -/* ************************************************************************* */ -TEST( BayesTree, Front ) -{ - SymbolicBayesNet f1; - f1.push_back(B); - f1.push_back(L); - SymbolicBayesNet f2; - f2.push_back(L); - f2.push_back(B); - CHECK(f1.equals(f1)); - CHECK(!f1.equals(f2)); -} - /* ************************************************************************* */ TEST( BayesTree, constructor ) { diff --git a/cpp/testSymbolicBayesNet.cpp b/cpp/testSymbolicBayesNet.cpp index 766236fb3..53b16d077 100644 --- a/cpp/testSymbolicBayesNet.cpp +++ b/cpp/testSymbolicBayesNet.cpp @@ -21,6 +21,24 @@ using namespace std; using namespace gtsam; using namespace example; +Symbol _B_('B', 0), _L_('L', 0); +SymbolicConditional::shared_ptr + B(new SymbolicConditional(_B_)), + L(new SymbolicConditional(_L_, _B_)); + +/* ************************************************************************* */ +TEST( SymbolicBayesNet, equals ) +{ + SymbolicBayesNet f1; + f1.push_back(B); + f1.push_back(L); + SymbolicBayesNet f2; + f2.push_back(L); + f2.push_back(B); + CHECK(f1.equals(f1)); + CHECK(!f1.equals(f2)); +} + /* ************************************************************************* */ TEST( SymbolicBayesNet, constructor ) {