2011-12-12 15:29:51 +00:00
|
|
|
#ifndef HORUS_BAYESNODE_H
|
|
|
|
#define HORUS_BAYESNODE_H
|
2011-05-17 12:00:33 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2011-12-12 15:29:51 +00:00
|
|
|
#include "VarNode.h"
|
2011-05-17 12:00:33 +01:00
|
|
|
#include "CptEntry.h"
|
|
|
|
#include "Distribution.h"
|
|
|
|
#include "Shared.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2011-12-12 15:29:51 +00:00
|
|
|
class BayesNode : public VarNode
|
2011-05-17 12:00:33 +01:00
|
|
|
{
|
|
|
|
public:
|
2011-12-12 15:29:51 +00:00
|
|
|
BayesNode (const VarNode& v) : VarNode (v) {}
|
|
|
|
BayesNode (VarId, unsigned, int, Distribution*);
|
|
|
|
BayesNode (VarId, unsigned, int, const BnNodeSet&, Distribution*);
|
2011-05-17 12:00:33 +01:00
|
|
|
|
2011-12-12 15:29:51 +00:00
|
|
|
void setParents (const BnNodeSet&);
|
2011-05-17 12:00:33 +01:00
|
|
|
void addChild (BayesNode*);
|
2011-12-12 15:29:51 +00:00
|
|
|
void setDistribution (Distribution*);
|
2011-05-17 12:00:33 +01:00
|
|
|
Distribution* getDistribution (void);
|
|
|
|
const ParamSet& getParameters (void);
|
|
|
|
ParamSet getRow (int) const;
|
|
|
|
void setProbability (int, const CptEntry&, double);
|
|
|
|
bool isRoot (void);
|
|
|
|
bool isLeaf (void);
|
|
|
|
bool hasNeighbors (void) const;
|
|
|
|
int getCptSize (void);
|
|
|
|
const vector<CptEntry>& getCptEntries (void);
|
|
|
|
int getIndexOfParent (const BayesNode*) const;
|
|
|
|
string cptEntryToString (const CptEntry&) const;
|
|
|
|
string cptEntryToString (int, const CptEntry&) const;
|
2011-07-22 21:33:30 +01:00
|
|
|
|
2011-12-12 15:29:51 +00:00
|
|
|
const BnNodeSet& getParents (void) const { return parents_; }
|
|
|
|
const BnNodeSet& getChilds (void) const { return childs_; }
|
2011-07-22 21:33:30 +01:00
|
|
|
|
|
|
|
unsigned getRowSize (void) const
|
|
|
|
{
|
2011-12-12 15:29:51 +00:00
|
|
|
return dist_->params.size() / nrStates();
|
2011-07-22 21:33:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
double getProbability (int row, const CptEntry& entry)
|
|
|
|
{
|
|
|
|
int col = entry.getParameterIndex();
|
|
|
|
int idx = (row * getRowSize()) + col;
|
|
|
|
return dist_->params[idx];
|
|
|
|
}
|
2011-05-17 12:00:33 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN (BayesNode);
|
|
|
|
|
2011-12-12 15:29:51 +00:00
|
|
|
States getDomainHeaders (void) const;
|
2011-05-17 12:00:33 +01:00
|
|
|
friend ostream& operator << (ostream&, const BayesNode&);
|
|
|
|
|
2011-07-22 21:33:30 +01:00
|
|
|
BnNodeSet parents_;
|
|
|
|
BnNodeSet childs_;
|
2011-05-17 12:00:33 +01:00
|
|
|
Distribution* dist_;
|
|
|
|
};
|
|
|
|
|
|
|
|
ostream& operator << (ostream&, const BayesNode&);
|
|
|
|
|
2011-12-12 15:29:51 +00:00
|
|
|
#endif // HORUS_BAYESNODE_H
|
2011-05-17 12:00:33 +01:00
|
|
|
|