2013-02-07 17:50:02 +00:00
|
|
|
#ifndef YAP_PACKAGES_CLPBN_HORUS_BAYESBALL_H_
|
|
|
|
#define YAP_PACKAGES_CLPBN_HORUS_BAYESBALL_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <queue>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#include "FactorGraph.h"
|
2012-06-19 14:32:12 +01:00
|
|
|
#include "BayesBallGraph.h"
|
2012-05-23 14:56:01 +01:00
|
|
|
#include "Horus.h"
|
|
|
|
|
2013-02-16 16:17:14 +00:00
|
|
|
|
2013-02-08 21:12:46 +00:00
|
|
|
namespace Horus {
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-13 14:26:47 +00:00
|
|
|
struct ScheduleInfo {
|
2012-12-20 23:19:10 +00:00
|
|
|
ScheduleInfo (BBNode* n, bool vfp, bool vfc)
|
|
|
|
: node(n), visitedFromParent(vfp), visitedFromChild(vfc) { }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-06-19 14:32:12 +01:00
|
|
|
BBNode* node;
|
|
|
|
bool visitedFromParent;
|
|
|
|
bool visitedFromChild;
|
2012-05-23 14:56:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-07 13:37:15 +00:00
|
|
|
typedef std::queue<ScheduleInfo, std::list<ScheduleInfo>> Scheduling;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
|
2013-02-13 14:26:47 +00:00
|
|
|
class BayesBall {
|
2012-05-23 14:56:01 +01:00
|
|
|
public:
|
2013-02-06 00:24:02 +00:00
|
|
|
BayesBall (FactorGraph& fg);
|
2012-06-19 15:30:55 +01:00
|
|
|
|
|
|
|
FactorGraph* getMinimalFactorGraph (const VarIds&);
|
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
static FactorGraph* getMinimalFactorGraph (FactorGraph& fg, VarIds vids);
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void constructGraph (FactorGraph* fg) const;
|
|
|
|
|
2012-06-19 14:32:12 +01:00
|
|
|
void scheduleParents (const BBNode* n, Scheduling& sch) const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-06-19 14:32:12 +01:00
|
|
|
void scheduleChilds (const BBNode* n, Scheduling& sch) const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-16 16:17:14 +00:00
|
|
|
FactorGraph& fg_;
|
|
|
|
BayesBallGraph& dag_;
|
2012-05-23 14:56:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
2012-06-19 14:32:12 +01:00
|
|
|
BayesBall::scheduleParents (const BBNode* n, Scheduling& sch) const
|
2012-05-23 14:56:01 +01:00
|
|
|
{
|
2013-02-07 13:37:15 +00:00
|
|
|
const std::vector<BBNode*>& ps = n->parents();
|
|
|
|
for (std::vector<BBNode*>::const_iterator it = ps.begin();
|
2012-05-28 14:12:18 +01:00
|
|
|
it != ps.end(); ++it) {
|
2012-05-23 14:56:01 +01:00
|
|
|
sch.push (ScheduleInfo (*it, false, true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
2012-06-19 14:32:12 +01:00
|
|
|
BayesBall::scheduleChilds (const BBNode* n, Scheduling& sch) const
|
2012-05-23 14:56:01 +01:00
|
|
|
{
|
2013-02-07 13:37:15 +00:00
|
|
|
const std::vector<BBNode*>& cs = n->childs();
|
|
|
|
for (std::vector<BBNode*>::const_iterator it = cs.begin();
|
2012-05-28 14:12:18 +01:00
|
|
|
it != cs.end(); ++it) {
|
2012-05-23 14:56:01 +01:00
|
|
|
sch.push (ScheduleInfo (*it, true, false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:12:46 +00:00
|
|
|
} // namespace Horus
|
2013-02-07 23:53:13 +00:00
|
|
|
|
2013-02-08 00:20:01 +00:00
|
|
|
#endif // YAP_PACKAGES_CLPBN_HORUS_BAYESBALL_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|