some renamings

This commit is contained in:
Tiago Gomes 2012-06-19 14:32:12 +01:00
parent 942bc8041e
commit 9a8464d0f0
7 changed files with 62 additions and 63 deletions

View File

@ -16,13 +16,13 @@ BayesBall::getMinimalFactorGraph (const VarIds& queryIds)
Scheduling scheduling;
for (size_t i = 0; i < queryIds.size(); i++) {
assert (dag_.getNode (queryIds[i]));
DAGraphNode* n = dag_.getNode (queryIds[i]);
BBNode* n = dag_.getNode (queryIds[i]);
scheduling.push (ScheduleInfo (n, false, true));
}
while (!scheduling.empty()) {
ScheduleInfo& sch = scheduling.front();
DAGraphNode* n = sch.node;
BBNode* n = sch.node;
n->setAsVisited();
if (n->hasEvidence() == false && sch.visitedFromChild) {
if (n->isMarkedOnTop() == false) {
@ -59,7 +59,7 @@ BayesBall::constructGraph (FactorGraph* fg) const
{
const FacNodes& facNodes = fg_.facNodes();
for (size_t i = 0; i < facNodes.size(); i++) {
const DAGraphNode* n = dag_.getNode (
const BBNode* n = dag_.getNode (
facNodes[i]->factor().argument (0));
if (n->isMarkedOnTop()) {
fg->addFactor (facNodes[i]->factor());

View File

@ -7,7 +7,7 @@
#include <map>
#include "FactorGraph.h"
#include "BayesNet.h"
#include "BayesBallGraph.h"
#include "Horus.h"
using namespace std;
@ -15,12 +15,12 @@ using namespace std;
struct ScheduleInfo
{
ScheduleInfo (DAGraphNode* n, bool vfp, bool vfc) :
ScheduleInfo (BBNode* n, bool vfp, bool vfc) :
node(n), visitedFromParent(vfp), visitedFromChild(vfc) { }
DAGraphNode* node;
bool visitedFromParent;
bool visitedFromChild;
BBNode* node;
bool visitedFromParent;
bool visitedFromChild;
};
@ -48,22 +48,22 @@ class BayesBall
void constructGraph (FactorGraph* fg) const;
void scheduleParents (const DAGraphNode* n, Scheduling& sch) const;
void scheduleParents (const BBNode* n, Scheduling& sch) const;
void scheduleChilds (const DAGraphNode* n, Scheduling& sch) const;
void scheduleChilds (const BBNode* n, Scheduling& sch) const;
FactorGraph& fg_;
DAGraph& dag_;
BayesBallGraph& dag_;
};
inline void
BayesBall::scheduleParents (const DAGraphNode* n, Scheduling& sch) const
BayesBall::scheduleParents (const BBNode* n, Scheduling& sch) const
{
const vector<DAGraphNode*>& ps = n->parents();
for (vector<DAGraphNode*>::const_iterator it = ps.begin();
const vector<BBNode*>& ps = n->parents();
for (vector<BBNode*>::const_iterator it = ps.begin();
it != ps.end(); ++it) {
sch.push (ScheduleInfo (*it, false, true));
}
@ -72,10 +72,10 @@ BayesBall::scheduleParents (const DAGraphNode* n, Scheduling& sch) const
inline void
BayesBall::scheduleChilds (const DAGraphNode* n, Scheduling& sch) const
BayesBall::scheduleChilds (const BBNode* n, Scheduling& sch) const
{
const vector<DAGraphNode*>& cs = n->childs();
for (vector<DAGraphNode*>::const_iterator it = cs.begin();
const vector<BBNode*>& cs = n->childs();
for (vector<BBNode*>::const_iterator it = cs.begin();
it != cs.end(); ++it) {
sch.push (ScheduleInfo (*it, true, false));
}

View File

@ -5,12 +5,12 @@
#include <fstream>
#include <sstream>
#include "BayesNet.h"
#include "BayesBallGraph.h"
#include "Util.h"
void
DAGraph::addNode (DAGraphNode* n)
BayesBallGraph::addNode (BBNode* n)
{
assert (Util::contains (varMap_, n->varId()) == false);
nodes_.push_back (n);
@ -20,10 +20,10 @@ DAGraph::addNode (DAGraphNode* n)
void
DAGraph::addEdge (VarId vid1, VarId vid2)
BayesBallGraph::addEdge (VarId vid1, VarId vid2)
{
unordered_map<VarId, DAGraphNode*>::iterator it1;
unordered_map<VarId, DAGraphNode*>::iterator it2;
unordered_map<VarId, BBNode*>::iterator it1;
unordered_map<VarId, BBNode*>::iterator it2;
it1 = varMap_.find (vid1);
it2 = varMap_.find (vid2);
assert (it1 != varMap_.end());
@ -34,20 +34,20 @@ DAGraph::addEdge (VarId vid1, VarId vid2)
const DAGraphNode*
DAGraph::getNode (VarId vid) const
const BBNode*
BayesBallGraph::getNode (VarId vid) const
{
unordered_map<VarId, DAGraphNode*>::const_iterator it;
unordered_map<VarId, BBNode*>::const_iterator it;
it = varMap_.find (vid);
return it != varMap_.end() ? it->second : 0;
}
DAGraphNode*
DAGraph::getNode (VarId vid)
BBNode*
BayesBallGraph::getNode (VarId vid)
{
unordered_map<VarId, DAGraphNode*>::const_iterator it;
unordered_map<VarId, BBNode*>::const_iterator it;
it = varMap_.find (vid);
return it != varMap_.end() ? it->second : 0;
}
@ -55,7 +55,7 @@ DAGraph::getNode (VarId vid)
void
DAGraph::setIndexes (void)
BayesBallGraph::setIndexes (void)
{
for (size_t i = 0; i < nodes_.size(); i++) {
nodes_[i]->setIndex (i);
@ -65,7 +65,7 @@ DAGraph::setIndexes (void)
void
DAGraph::clear (void)
BayesBallGraph::clear (void)
{
for (size_t i = 0; i < nodes_.size(); i++) {
nodes_[i]->clear();
@ -75,12 +75,12 @@ DAGraph::clear (void)
void
DAGraph::exportToGraphViz (const char* fileName)
BayesBallGraph::exportToGraphViz (const char* fileName)
{
ofstream out (fileName);
if (!out.is_open()) {
cerr << "error: cannot open file to write at " ;
cerr << "DAGraph::exportToDotFile()" << endl;
cerr << "BayesBallGraph::exportToDotFile()" << endl;
abort();
}
out << "digraph {" << endl;
@ -95,7 +95,7 @@ DAGraph::exportToGraphViz (const char* fileName)
out << "]" << endl;
}
for (size_t i = 0; i < nodes_.size(); i++) {
const vector<DAGraphNode*>& childs = nodes_[i]->childs();
const vector<BBNode*>& childs = nodes_[i]->childs();
for (size_t j = 0; j < childs.size(); j++) {
out << nodes_[i]->varId() << " -> " << childs[j]->varId();
out << " [style=bold]" << endl ;

View File

@ -1,5 +1,5 @@
#ifndef HORUS_BAYESNET_H
#define HORUS_BAYESNET_H
#ifndef HORUS_BAYESBALLGRAPH_H
#define HORUS_BAYESBALLGRAPH_H
#include <vector>
#include <queue>
@ -15,23 +15,23 @@ using namespace std;
class Var;
class DAGraphNode : public Var
class BBNode : public Var
{
public:
DAGraphNode (Var* v) : Var (v) , visited_(false),
BBNode (Var* v) : Var (v) , visited_(false),
markedOnTop_(false), markedOnBottom_(false) { }
const vector<DAGraphNode*>& childs (void) const { return childs_; }
const vector<BBNode*>& childs (void) const { return childs_; }
vector<DAGraphNode*>& childs (void) { return childs_; }
vector<BBNode*>& childs (void) { return childs_; }
const vector<DAGraphNode*>& parents (void) const { return parents_; }
const vector<BBNode*>& parents (void) const { return parents_; }
vector<DAGraphNode*>& parents (void) { return parents_; }
vector<BBNode*>& parents (void) { return parents_; }
void addParent (DAGraphNode* p) { parents_.push_back (p); }
void addParent (BBNode* p) { parents_.push_back (p); }
void addChild (DAGraphNode* c) { childs_.push_back (c); }
void addChild (BBNode* c) { childs_.push_back (c); }
bool isVisited (void) const { return visited_; }
@ -52,23 +52,23 @@ class DAGraphNode : public Var
bool markedOnTop_;
bool markedOnBottom_;
vector<DAGraphNode*> childs_;
vector<DAGraphNode*> parents_;
vector<BBNode*> childs_;
vector<BBNode*> parents_;
};
class DAGraph
class BayesBallGraph
{
public:
DAGraph (void) { }
BayesBallGraph (void) { }
void addNode (DAGraphNode* n);
void addNode (BBNode* n);
void addEdge (VarId vid1, VarId vid2);
const DAGraphNode* getNode (VarId vid) const;
const BBNode* getNode (VarId vid) const;
DAGraphNode* getNode (VarId vid);
BBNode* getNode (VarId vid);
bool empty (void) const { return nodes_.empty(); }
@ -79,10 +79,10 @@ class DAGraph
void exportToGraphViz (const char*);
private:
vector<DAGraphNode*> nodes_;
vector<BBNode*> nodes_;
unordered_map<VarId, DAGraphNode*> varMap_;
unordered_map<VarId, BBNode*> varMap_;
};
#endif // HORUS_BAYESNET_H
#endif // HORUS_BAYESBALLGRAPH_H

View File

@ -8,7 +8,6 @@
#include "FactorGraph.h"
#include "Factor.h"
#include "BayesNet.h"
#include "BayesBall.h"
#include "Util.h"
@ -236,13 +235,13 @@ FactorGraph::isTree (void) const
DAGraph&
BayesBallGraph&
FactorGraph::getStructure (void)
{
assert (bayesFactors_);
if (structure_.empty()) {
for (size_t i = 0; i < varNodes_.size(); i++) {
structure_.addNode (new DAGraphNode (varNodes_[i]));
structure_.addNode (new BBNode (varNodes_[i]));
}
for (size_t i = 0; i < facNodes_.size(); i++) {
const VarIds& vids = facNodes_[i]->factor().arguments();

View File

@ -4,7 +4,7 @@
#include <vector>
#include "Factor.h"
#include "BayesNet.h"
#include "BayesBallGraph.h"
#include "Horus.h"
using namespace std;
@ -103,7 +103,7 @@ class FactorGraph
bool isTree (void) const;
DAGraph& getStructure (void);
BayesBallGraph& getStructure (void);
void print (void) const;
@ -129,7 +129,7 @@ class FactorGraph
VarNodes varNodes_;
FacNodes facNodes_;
DAGraph structure_;
BayesBallGraph structure_;
bool bayesFactors_;
typedef unordered_map<unsigned, VarNode*> VarMap;

View File

@ -46,7 +46,7 @@ CWD=$(PWD)
HEADERS = \
$(srcdir)/BayesBall.h \
$(srcdir)/BayesNet.h \
$(srcdir)/BayesBallGraph.h \
$(srcdir)/BeliefProp.h \
$(srcdir)/ConstraintTree.h \
$(srcdir)/CountingBp.h \
@ -71,7 +71,7 @@ HEADERS = \
CPP_SOURCES = \
$(srcdir)/BayesBall.cpp \
$(srcdir)/BayesNet.cpp \
$(srcdir)/BayesBallGraph.cpp \
$(srcdir)/BeliefProp.cpp \
$(srcdir)/ConstraintTree.cpp \
$(srcdir)/CountingBp.cpp \
@ -95,7 +95,7 @@ CPP_SOURCES = \
OBJS = \
BayesBall.o \
BayesNet.o \
BayesBallGraph.o \
BeliefProp.o \
ConstraintTree.o \
CountingBp.o \
@ -118,7 +118,7 @@ OBJS = \
HCLI_OBJS = \
BayesBall.o \
BayesNet.o \
BayesBallGraph.o \
BeliefProp.o \
CountingBp.o \
ElimGraph.o \