added comments

release/4.3a0
Kai Ni 2010-07-07 06:11:19 +00:00
parent 03ca6ccc93
commit 612aca96c6
3 changed files with 71 additions and 46 deletions

View File

@ -96,12 +96,34 @@ namespace gtsam {
bool equals(const Cliques& other, double tol = 1e-9) const; 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<std::size_t> conditionalSizes;
std::vector<std::size_t> separatorSizes;
CliqueStats getStats() const;
};
private: private:
/** Map from keys to Clique */ /** Map from keys to Clique */
typedef SymbolMap<sharedClique> Nodes; typedef SymbolMap<sharedClique> Nodes;
Nodes 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: protected:
/** Root clique */ /** Root clique */
@ -130,15 +152,23 @@ namespace gtsam {
virtual ~BayesTree() { virtual ~BayesTree() {
} }
/** print */ /**
void print(const std::string& s = "") const; * Constructing Bayes trees
*/
/** saves the Tree to a text file in GraphViz format */ /** Insert a new conditional */
void saveGraph(const std::string& s) const; void insert(const sharedConditional& conditional, const IndexTable<Symbol>& index);
private:
void saveGraph(std::ostream &s, sharedClique clique, /** Insert a new clique corresponding to the given Bayes net.
int parentnum = 0) const; * It is the caller's responsibility to decide whether the given Bayes net is a valid clique,
public: * i.e. all the variables (frontal and separator) are connected
*/
sharedClique insert(const BayesNet<Conditional>& bayesNet,
std::list<sharedClique>& children, bool isRootClique = false);
/**
* Querying Bayes trees
*/
/** check equality */ /** check equality */
bool equals(const BayesTree<Conditional>& other, double tol = 1e-9) const; bool equals(const BayesTree<Conditional>& other, double tol = 1e-9) const;
@ -149,15 +179,6 @@ namespace gtsam {
*/ */
Symbol findParentClique(const std::list<Symbol>& parents, const IndexTable<Symbol>& index) const; Symbol findParentClique(const std::list<Symbol>& parents, const IndexTable<Symbol>& index) const;
/** insert a new conditional */
void insert(const sharedConditional& conditional, const IndexTable<Symbol>& 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<Conditional>& bayesNet,
std::list<sharedClique>& children, bool isRootClique = false);
/** number of cliques */ /** number of cliques */
inline size_t size() const { inline size_t size() const {
if(root_) if(root_)
@ -176,24 +197,9 @@ namespace gtsam {
return nodes_.at(key); return nodes_.at(key);
} }
/** clique statistics */ /** Gather data on all cliques */
struct CliqueStats {
double avgConditionalSize;
std::size_t maxConditionalSize;
double avgSeparatorSize;
std::size_t maxSeparatorSize;
};
struct CliqueData {
std::vector<std::size_t> conditionalSizes;
std::vector<std::size_t> separatorSizes;
CliqueStats getStats() const;
};
CliqueData getCliqueData() const; CliqueData getCliqueData() const;
private:
void getCliqueData(CliqueData& stats, sharedClique clique) const;
public:
/** return marginal on any variable */ /** return marginal on any variable */
template<class Factor> template<class Factor>
FactorGraph<Factor> marginal(const Symbol& key) const; FactorGraph<Factor> marginal(const Symbol& key) const;
@ -210,6 +216,20 @@ namespace gtsam {
template<class Factor> template<class Factor>
BayesNet<Conditional> jointBayesNet(const Symbol& key1, const Symbol& key2) const; BayesNet<Conditional> 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 * Remove all nodes
*/ */

View File

@ -69,19 +69,6 @@ SymbolicBayesTree createAsiaSymbolicBayesTree() {
return bayesTree; 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 ) TEST( BayesTree, constructor )
{ {

View File

@ -21,6 +21,24 @@ using namespace std;
using namespace gtsam; using namespace gtsam;
using namespace example; 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 ) TEST( SymbolicBayesNet, constructor )
{ {