f(void) vs f()
"In fact, the f(void) style has been called an "abomination" by Bjarne Stroustrup, the creator of C++, Dennis Ritchie, the co-creator of C, and Doug McIlroy, head of the research department where Unix was born."
This commit is contained in:
parent
c8b639f495
commit
902624f557
@ -56,7 +56,7 @@ BayesBallGraph::getNode (VarId vid)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BayesBallGraph::setIndexes (void)
|
BayesBallGraph::setIndexes()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < nodes_.size(); i++) {
|
for (size_t i = 0; i < nodes_.size(); i++) {
|
||||||
nodes_[i]->setIndex (i);
|
nodes_[i]->setIndex (i);
|
||||||
@ -66,7 +66,7 @@ BayesBallGraph::setIndexes (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BayesBallGraph::clear (void)
|
BayesBallGraph::clear()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < nodes_.size(); i++) {
|
for (size_t i = 0; i < nodes_.size(); i++) {
|
||||||
nodes_[i]->clear();
|
nodes_[i]->clear();
|
||||||
|
@ -15,31 +15,31 @@ class BBNode : public Var {
|
|||||||
BBNode (Var* v) : Var (v), visited_(false),
|
BBNode (Var* v) : Var (v), visited_(false),
|
||||||
markedAbove_(false), markedBelow_(false) { }
|
markedAbove_(false), markedBelow_(false) { }
|
||||||
|
|
||||||
const std::vector<BBNode*>& childs (void) const { return childs_; }
|
const std::vector<BBNode*>& childs() const { return childs_; }
|
||||||
|
|
||||||
std::vector<BBNode*>& childs (void) { return childs_; }
|
std::vector<BBNode*>& childs() { return childs_; }
|
||||||
|
|
||||||
const std::vector<BBNode*>& parents (void) const { return parents_; }
|
const std::vector<BBNode*>& parents() const { return parents_; }
|
||||||
|
|
||||||
std::vector<BBNode*>& parents (void) { return parents_; }
|
std::vector<BBNode*>& parents() { return parents_; }
|
||||||
|
|
||||||
void addParent (BBNode* p) { parents_.push_back (p); }
|
void addParent (BBNode* p) { parents_.push_back (p); }
|
||||||
|
|
||||||
void addChild (BBNode* c) { childs_.push_back (c); }
|
void addChild (BBNode* c) { childs_.push_back (c); }
|
||||||
|
|
||||||
bool isVisited (void) const { return visited_; }
|
bool isVisited() const { return visited_; }
|
||||||
|
|
||||||
void setAsVisited (void) { visited_ = true; }
|
void setAsVisited() { visited_ = true; }
|
||||||
|
|
||||||
bool isMarkedAbove (void) const { return markedAbove_; }
|
bool isMarkedAbove() const { return markedAbove_; }
|
||||||
|
|
||||||
void markAbove (void) { markedAbove_ = true; }
|
void markAbove() { markedAbove_ = true; }
|
||||||
|
|
||||||
bool isMarkedBelow (void) const { return markedBelow_; }
|
bool isMarkedBelow() const { return markedBelow_; }
|
||||||
|
|
||||||
void markBelow (void) { markedBelow_ = true; }
|
void markBelow() { markedBelow_ = true; }
|
||||||
|
|
||||||
void clear (void) { visited_ = markedAbove_ = markedBelow_ = false; }
|
void clear() { visited_ = markedAbove_ = markedBelow_ = false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool visited_;
|
bool visited_;
|
||||||
@ -53,9 +53,9 @@ class BBNode : public Var {
|
|||||||
|
|
||||||
class BayesBallGraph {
|
class BayesBallGraph {
|
||||||
public:
|
public:
|
||||||
BayesBallGraph (void) { }
|
BayesBallGraph() { }
|
||||||
|
|
||||||
bool empty (void) const { return nodes_.empty(); }
|
bool empty() const { return nodes_.empty(); }
|
||||||
|
|
||||||
void addNode (BBNode* n);
|
void addNode (BBNode* n);
|
||||||
|
|
||||||
@ -65,9 +65,9 @@ class BayesBallGraph {
|
|||||||
|
|
||||||
BBNode* getNode (VarId vid);
|
BBNode* getNode (VarId vid);
|
||||||
|
|
||||||
void setIndexes (void);
|
void setIndexes();
|
||||||
|
|
||||||
void clear (void);
|
void clear();
|
||||||
|
|
||||||
void exportToGraphViz (const char*);
|
void exportToGraphViz (const char*);
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ BeliefProp::BeliefProp (const FactorGraph& fg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
BeliefProp::~BeliefProp (void)
|
BeliefProp::~BeliefProp()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < varsI_.size(); i++) {
|
for (size_t i = 0; i < varsI_.size(); i++) {
|
||||||
delete varsI_[i];
|
delete varsI_[i];
|
||||||
@ -54,7 +54,7 @@ BeliefProp::solveQuery (VarIds queryVids)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::printSolverFlags (void) const
|
BeliefProp::printSolverFlags() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "belief propagation [" ;
|
ss << "belief propagation [" ;
|
||||||
@ -172,7 +172,7 @@ BeliefProp::BpLink::BpLink (FacNode* fn, VarNode* vn)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::BpLink::clearResidual (void)
|
BeliefProp::BpLink::clearResidual()
|
||||||
{
|
{
|
||||||
residual_ = 0.0;
|
residual_ = 0.0;
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ BeliefProp::BpLink::clearResidual (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::BpLink::updateResidual (void)
|
BeliefProp::BpLink::updateResidual()
|
||||||
{
|
{
|
||||||
residual_ = LogAware::getMaxNorm (v1_, v2_);
|
residual_ = LogAware::getMaxNorm (v1_, v2_);
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ BeliefProp::BpLink::updateResidual (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::BpLink::updateMessage (void)
|
BeliefProp::BpLink::updateMessage()
|
||||||
{
|
{
|
||||||
swap (currMsg_, nextMsg_);
|
swap (currMsg_, nextMsg_);
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ BeliefProp::BpLink::updateMessage (void)
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
BeliefProp::BpLink::toString (void) const
|
BeliefProp::BpLink::toString() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << fac_->getLabel();
|
ss << fac_->getLabel();
|
||||||
@ -251,7 +251,7 @@ BeliefProp::updateMessage (BpLink* link)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::runSolver (void)
|
BeliefProp::runSolver()
|
||||||
{
|
{
|
||||||
initializeSolver();
|
initializeSolver();
|
||||||
nIters_ = 0;
|
nIters_ = 0;
|
||||||
@ -299,7 +299,7 @@ BeliefProp::runSolver (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::createLinks (void)
|
BeliefProp::createLinks()
|
||||||
{
|
{
|
||||||
const FacNodes& facNodes = fg.facNodes();
|
const FacNodes& facNodes = fg.facNodes();
|
||||||
for (size_t i = 0; i < facNodes.size(); i++) {
|
for (size_t i = 0; i < facNodes.size(); i++) {
|
||||||
@ -313,7 +313,7 @@ BeliefProp::createLinks (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::maxResidualSchedule (void)
|
BeliefProp::maxResidualSchedule()
|
||||||
{
|
{
|
||||||
if (nIters_ == 1) {
|
if (nIters_ == 1) {
|
||||||
for (size_t i = 0; i < links_.size(); i++) {
|
for (size_t i = 0; i < links_.size(); i++) {
|
||||||
@ -487,7 +487,7 @@ BeliefProp::getJointByConditioning (const VarIds& jointVarIds) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::initializeSolver (void)
|
BeliefProp::initializeSolver()
|
||||||
{
|
{
|
||||||
const VarNodes& varNodes = fg.varNodes();
|
const VarNodes& varNodes = fg.varNodes();
|
||||||
varsI_.reserve (varNodes.size());
|
varsI_.reserve (varNodes.size());
|
||||||
@ -511,7 +511,7 @@ BeliefProp::initializeSolver (void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BeliefProp::converged (void)
|
BeliefProp::converged()
|
||||||
{
|
{
|
||||||
if (links_.empty()) {
|
if (links_.empty()) {
|
||||||
return true;
|
return true;
|
||||||
@ -560,7 +560,7 @@ BeliefProp::converged (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BeliefProp::printLinkInformation (void) const
|
BeliefProp::printLinkInformation() const
|
||||||
{
|
{
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
@ -25,11 +25,11 @@ class BeliefProp : public GroundSolver {
|
|||||||
|
|
||||||
BeliefProp (const FactorGraph&);
|
BeliefProp (const FactorGraph&);
|
||||||
|
|
||||||
virtual ~BeliefProp (void);
|
virtual ~BeliefProp();
|
||||||
|
|
||||||
Params solveQuery (VarIds);
|
Params solveQuery (VarIds);
|
||||||
|
|
||||||
virtual void printSolverFlags (void) const;
|
virtual void printSolverFlags() const;
|
||||||
|
|
||||||
virtual Params getPosterioriOf (VarId);
|
virtual Params getPosterioriOf (VarId);
|
||||||
|
|
||||||
@ -37,15 +37,15 @@ class BeliefProp : public GroundSolver {
|
|||||||
|
|
||||||
Params getFactorJoint (FacNode* fn, const VarIds&);
|
Params getFactorJoint (FacNode* fn, const VarIds&);
|
||||||
|
|
||||||
static double accuracy (void) { return accuracy_; }
|
static double accuracy() { return accuracy_; }
|
||||||
|
|
||||||
static void setAccuracy (double acc) { accuracy_ = acc; }
|
static void setAccuracy (double acc) { accuracy_ = acc; }
|
||||||
|
|
||||||
static unsigned maxIterations (void) { return maxIter_; }
|
static unsigned maxIterations() { return maxIter_; }
|
||||||
|
|
||||||
static void setMaxIterations (unsigned mi) { maxIter_ = mi; }
|
static void setMaxIterations (unsigned mi) { maxIter_ = mi; }
|
||||||
|
|
||||||
static MsgSchedule msgSchedule (void) { return schedule_; }
|
static MsgSchedule msgSchedule() { return schedule_; }
|
||||||
|
|
||||||
static void setMsgSchedule (MsgSchedule sch) { schedule_ = sch; }
|
static void setMsgSchedule (MsgSchedule sch) { schedule_ = sch; }
|
||||||
|
|
||||||
@ -54,25 +54,25 @@ class BeliefProp : public GroundSolver {
|
|||||||
public:
|
public:
|
||||||
BpLink (FacNode* fn, VarNode* vn);
|
BpLink (FacNode* fn, VarNode* vn);
|
||||||
|
|
||||||
virtual ~BpLink (void) { };
|
virtual ~BpLink() { };
|
||||||
|
|
||||||
FacNode* facNode (void) const { return fac_; }
|
FacNode* facNode() const { return fac_; }
|
||||||
|
|
||||||
VarNode* varNode (void) const { return var_; }
|
VarNode* varNode() const { return var_; }
|
||||||
|
|
||||||
const Params& message (void) const { return *currMsg_; }
|
const Params& message() const { return *currMsg_; }
|
||||||
|
|
||||||
Params& nextMessage (void) { return *nextMsg_; }
|
Params& nextMessage() { return *nextMsg_; }
|
||||||
|
|
||||||
double residual (void) const { return residual_; }
|
double residual() const { return residual_; }
|
||||||
|
|
||||||
void clearResidual (void);
|
void clearResidual();
|
||||||
|
|
||||||
void updateResidual (void);
|
void updateResidual();
|
||||||
|
|
||||||
virtual void updateMessage (void);
|
virtual void updateMessage();
|
||||||
|
|
||||||
std::string toString (void) const;
|
std::string toString() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FacNode* fac_;
|
FacNode* fac_;
|
||||||
@ -106,11 +106,11 @@ class BeliefProp : public GroundSolver {
|
|||||||
|
|
||||||
void updateMessage (BpLink* link);
|
void updateMessage (BpLink* link);
|
||||||
|
|
||||||
void runSolver (void);
|
void runSolver();
|
||||||
|
|
||||||
virtual void createLinks (void);
|
virtual void createLinks();
|
||||||
|
|
||||||
virtual void maxResidualSchedule (void);
|
virtual void maxResidualSchedule();
|
||||||
|
|
||||||
virtual void calcFactorToVarMsg (BpLink*);
|
virtual void calcFactorToVarMsg (BpLink*);
|
||||||
|
|
||||||
@ -133,11 +133,11 @@ class BeliefProp : public GroundSolver {
|
|||||||
private:
|
private:
|
||||||
class SPNodeInfo {
|
class SPNodeInfo {
|
||||||
public:
|
public:
|
||||||
SPNodeInfo (void) { }
|
SPNodeInfo() { }
|
||||||
|
|
||||||
void addBpLink (BeliefProp::BpLink* link) { links_.push_back (link); }
|
void addBpLink (BeliefProp::BpLink* link) { links_.push_back (link); }
|
||||||
|
|
||||||
const BpLinks& getLinks (void) { return links_; }
|
const BpLinks& getLinks() { return links_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BpLinks links_;
|
BpLinks links_;
|
||||||
@ -145,11 +145,11 @@ class BeliefProp : public GroundSolver {
|
|||||||
DISALLOW_COPY_AND_ASSIGN (SPNodeInfo);
|
DISALLOW_COPY_AND_ASSIGN (SPNodeInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
void initializeSolver (void);
|
void initializeSolver();
|
||||||
|
|
||||||
bool converged (void);
|
bool converged();
|
||||||
|
|
||||||
virtual void printLinkInformation (void) const;
|
virtual void printLinkInformation() const;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN (BeliefProp);
|
DISALLOW_COPY_AND_ASSIGN (BeliefProp);
|
||||||
};
|
};
|
||||||
|
@ -41,7 +41,7 @@ CTNode::removeChild (CTNode* child)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CTNode::removeChilds (void)
|
CTNode::removeChilds()
|
||||||
{
|
{
|
||||||
childs_.clear();
|
childs_.clear();
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ CTNode::removeAndDeleteChild (CTNode* child)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CTNode::removeAndDeleteAllChilds (void)
|
CTNode::removeAndDeleteAllChilds()
|
||||||
{
|
{
|
||||||
for (CTChilds::const_iterator chIt = childs_.begin();
|
for (CTChilds::const_iterator chIt = childs_.begin();
|
||||||
chIt != childs_.end(); ++ chIt) {
|
chIt != childs_.end(); ++ chIt) {
|
||||||
@ -70,7 +70,7 @@ CTNode::removeAndDeleteAllChilds (void)
|
|||||||
|
|
||||||
|
|
||||||
SymbolSet
|
SymbolSet
|
||||||
CTNode::childSymbols (void) const
|
CTNode::childSymbols() const
|
||||||
{
|
{
|
||||||
SymbolSet symbols;
|
SymbolSet symbols;
|
||||||
for (CTChilds::const_iterator chIt = childs_.begin();
|
for (CTChilds::const_iterator chIt = childs_.begin();
|
||||||
@ -232,7 +232,7 @@ ConstraintTree::ConstraintTree (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConstraintTree::~ConstraintTree (void)
|
ConstraintTree::~ConstraintTree()
|
||||||
{
|
{
|
||||||
CTNode::deleteSubtree (root_);
|
CTNode::deleteSubtree (root_);
|
||||||
}
|
}
|
||||||
@ -464,7 +464,7 @@ ConstraintTree::ConstraintTree::isSingleton (LogVar X)
|
|||||||
|
|
||||||
|
|
||||||
LogVarSet
|
LogVarSet
|
||||||
ConstraintTree::singletons (void)
|
ConstraintTree::singletons()
|
||||||
{
|
{
|
||||||
LogVarSet singletons;
|
LogVarSet singletons;
|
||||||
for (size_t i = 0; i < logVars_.size(); i++) {
|
for (size_t i = 0; i < logVars_.size(); i++) {
|
||||||
@ -1115,7 +1115,7 @@ ConstraintTree::getTuples (
|
|||||||
|
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
ConstraintTree::size (void) const
|
ConstraintTree::size() const
|
||||||
{
|
{
|
||||||
return countTuples (root_);
|
return countTuples (root_);
|
||||||
}
|
}
|
||||||
|
@ -38,23 +38,23 @@ class CTNode {
|
|||||||
CTNode (Symbol s, unsigned l, const CTChilds& chs = CTChilds())
|
CTNode (Symbol s, unsigned l, const CTChilds& chs = CTChilds())
|
||||||
: symbol_(s), childs_(chs), level_(l) { }
|
: symbol_(s), childs_(chs), level_(l) { }
|
||||||
|
|
||||||
unsigned level (void) const { return level_; }
|
unsigned level() const { return level_; }
|
||||||
|
|
||||||
void setLevel (unsigned level) { level_ = level; }
|
void setLevel (unsigned level) { level_ = level; }
|
||||||
|
|
||||||
Symbol symbol (void) const { return symbol_; }
|
Symbol symbol() const { return symbol_; }
|
||||||
|
|
||||||
void setSymbol (Symbol s) { symbol_ = s; }
|
void setSymbol (Symbol s) { symbol_ = s; }
|
||||||
|
|
||||||
CTChilds& childs (void) { return childs_; }
|
CTChilds& childs() { return childs_; }
|
||||||
|
|
||||||
const CTChilds& childs (void) const { return childs_; }
|
const CTChilds& childs() const { return childs_; }
|
||||||
|
|
||||||
size_t nrChilds (void) const { return childs_.size(); }
|
size_t nrChilds() const { return childs_.size(); }
|
||||||
|
|
||||||
bool isRoot (void) const { return level_ == 0; }
|
bool isRoot() const { return level_ == 0; }
|
||||||
|
|
||||||
bool isLeaf (void) const { return childs_.empty(); }
|
bool isLeaf() const { return childs_.empty(); }
|
||||||
|
|
||||||
CTChilds::iterator findSymbol (Symbol symb);
|
CTChilds::iterator findSymbol (Symbol symb);
|
||||||
|
|
||||||
@ -62,13 +62,13 @@ class CTNode {
|
|||||||
|
|
||||||
void removeChild (CTNode*);
|
void removeChild (CTNode*);
|
||||||
|
|
||||||
void removeChilds (void);
|
void removeChilds();
|
||||||
|
|
||||||
void removeAndDeleteChild (CTNode*);
|
void removeAndDeleteChild (CTNode*);
|
||||||
|
|
||||||
void removeAndDeleteAllChilds (void);
|
void removeAndDeleteAllChilds();
|
||||||
|
|
||||||
SymbolSet childSymbols (void) const;
|
SymbolSet childSymbols() const;
|
||||||
|
|
||||||
static CTNode* copySubtree (const CTNode*);
|
static CTNode* copySubtree (const CTNode*);
|
||||||
|
|
||||||
@ -113,17 +113,17 @@ class ConstraintTree {
|
|||||||
|
|
||||||
ConstraintTree (const CTChilds& rootChilds, const LogVars& logVars);
|
ConstraintTree (const CTChilds& rootChilds, const LogVars& logVars);
|
||||||
|
|
||||||
~ConstraintTree (void);
|
~ConstraintTree();
|
||||||
|
|
||||||
CTNode* root (void) const { return root_; }
|
CTNode* root() const { return root_; }
|
||||||
|
|
||||||
bool empty (void) const { return root_->childs().empty(); }
|
bool empty() const { return root_->childs().empty(); }
|
||||||
|
|
||||||
const LogVars& logVars (void) const;
|
const LogVars& logVars() const;
|
||||||
|
|
||||||
const LogVarSet& logVarSet (void) const;
|
const LogVarSet& logVarSet() const;
|
||||||
|
|
||||||
size_t nrLogVars (void) const;
|
size_t nrLogVars() const;
|
||||||
|
|
||||||
void addTuple (const Tuple&);
|
void addTuple (const Tuple&);
|
||||||
|
|
||||||
@ -149,13 +149,13 @@ class ConstraintTree {
|
|||||||
|
|
||||||
bool isSingleton (LogVar);
|
bool isSingleton (LogVar);
|
||||||
|
|
||||||
LogVarSet singletons (void);
|
LogVarSet singletons();
|
||||||
|
|
||||||
TupleSet tupleSet (unsigned = 0) const;
|
TupleSet tupleSet (unsigned = 0) const;
|
||||||
|
|
||||||
TupleSet tupleSet (const LogVars&);
|
TupleSet tupleSet (const LogVars&);
|
||||||
|
|
||||||
unsigned size (void) const;
|
unsigned size() const;
|
||||||
|
|
||||||
unsigned nrSymbols (LogVar);
|
unsigned nrSymbols (LogVar);
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ class ConstraintTree {
|
|||||||
|
|
||||||
|
|
||||||
inline const LogVars&
|
inline const LogVars&
|
||||||
ConstraintTree::logVars (void) const
|
ConstraintTree::logVars() const
|
||||||
{
|
{
|
||||||
assert (LogVarSet (logVars_) == logVarSet_);
|
assert (LogVarSet (logVars_) == logVarSet_);
|
||||||
return logVars_;
|
return logVars_;
|
||||||
@ -226,7 +226,7 @@ ConstraintTree::logVars (void) const
|
|||||||
|
|
||||||
|
|
||||||
inline const LogVarSet&
|
inline const LogVarSet&
|
||||||
ConstraintTree::logVarSet (void) const
|
ConstraintTree::logVarSet() const
|
||||||
{
|
{
|
||||||
assert (LogVarSet (logVars_) == logVarSet_);
|
assert (LogVarSet (logVars_) == logVarSet_);
|
||||||
return logVarSet_;
|
return logVarSet_;
|
||||||
@ -235,7 +235,7 @@ ConstraintTree::logVarSet (void) const
|
|||||||
|
|
||||||
|
|
||||||
inline size_t
|
inline size_t
|
||||||
ConstraintTree::nrLogVars (void) const
|
ConstraintTree::nrLogVars() const
|
||||||
{
|
{
|
||||||
assert (LogVarSet (logVars_) == logVarSet_);
|
assert (LogVarSet (logVars_) == logVarSet_);
|
||||||
return logVars_.size();
|
return logVars_.size();
|
||||||
|
@ -13,11 +13,11 @@ class VarCluster {
|
|||||||
public:
|
public:
|
||||||
VarCluster (const VarNodes& vs) : members_(vs) { }
|
VarCluster (const VarNodes& vs) : members_(vs) { }
|
||||||
|
|
||||||
const VarNode* first (void) const { return members_.front(); }
|
const VarNode* first() const { return members_.front(); }
|
||||||
|
|
||||||
const VarNodes& members (void) const { return members_; }
|
const VarNodes& members() const { return members_; }
|
||||||
|
|
||||||
VarNode* representative (void) const { return repr_; }
|
VarNode* representative() const { return repr_; }
|
||||||
|
|
||||||
void setRepresentative (VarNode* vn) { repr_ = vn; }
|
void setRepresentative (VarNode* vn) { repr_ = vn; }
|
||||||
|
|
||||||
@ -38,15 +38,15 @@ class FacCluster {
|
|||||||
FacCluster (const FacNodes& fcs, const VarClusters& vcs)
|
FacCluster (const FacNodes& fcs, const VarClusters& vcs)
|
||||||
: members_(fcs), varClusters_(vcs) { }
|
: members_(fcs), varClusters_(vcs) { }
|
||||||
|
|
||||||
const FacNode* first (void) const { return members_.front(); }
|
const FacNode* first() const { return members_.front(); }
|
||||||
|
|
||||||
const FacNodes& members (void) const { return members_; }
|
const FacNodes& members() const { return members_; }
|
||||||
|
|
||||||
FacNode* representative (void) const { return repr_; }
|
FacNode* representative() const { return repr_; }
|
||||||
|
|
||||||
void setRepresentative (FacNode* fn) { repr_ = fn; }
|
void setRepresentative (FacNode* fn) { repr_ = fn; }
|
||||||
|
|
||||||
VarClusters& varClusters (void) { return varClusters_; }
|
VarClusters& varClusters() { return varClusters_; }
|
||||||
|
|
||||||
FacNodes members_;
|
FacNodes members_;
|
||||||
FacNode* repr_;
|
FacNode* repr_;
|
||||||
@ -72,7 +72,7 @@ CountingBp::CountingBp (const FactorGraph& fg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
CountingBp::~CountingBp (void)
|
CountingBp::~CountingBp()
|
||||||
{
|
{
|
||||||
delete solver_;
|
delete solver_;
|
||||||
delete compressedFg_;
|
delete compressedFg_;
|
||||||
@ -87,7 +87,7 @@ CountingBp::~CountingBp (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CountingBp::printSolverFlags (void) const
|
CountingBp::printSolverFlags() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "counting bp [" ;
|
ss << "counting bp [" ;
|
||||||
@ -179,7 +179,7 @@ CountingBp::findIdenticalFactors()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CountingBp::setInitialColors (void)
|
CountingBp::setInitialColors()
|
||||||
{
|
{
|
||||||
varColors_.resize (fg.nrVarNodes());
|
varColors_.resize (fg.nrVarNodes());
|
||||||
facColors_.resize (fg.nrFacNodes());
|
facColors_.resize (fg.nrFacNodes());
|
||||||
@ -219,7 +219,7 @@ CountingBp::setInitialColors (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CountingBp::createGroups (void)
|
CountingBp::createGroups()
|
||||||
{
|
{
|
||||||
VarSignMap varGroups;
|
VarSignMap varGroups;
|
||||||
FacSignMap facGroups;
|
FacSignMap facGroups;
|
||||||
@ -373,7 +373,7 @@ CountingBp::getRepresentative (FacNode* fn)
|
|||||||
|
|
||||||
|
|
||||||
FactorGraph*
|
FactorGraph*
|
||||||
CountingBp::getCompressedFactorGraph (void)
|
CountingBp::getCompressedFactorGraph()
|
||||||
{
|
{
|
||||||
FactorGraph* fg = new FactorGraph();
|
FactorGraph* fg = new FactorGraph();
|
||||||
for (size_t i = 0; i < varClusters_.size(); i++) {
|
for (size_t i = 0; i < varClusters_.size(); i++) {
|
||||||
@ -402,7 +402,7 @@ CountingBp::getCompressedFactorGraph (void)
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::vector<unsigned>>
|
std::vector<std::vector<unsigned>>
|
||||||
CountingBp::getWeights (void) const
|
CountingBp::getWeights() const
|
||||||
{
|
{
|
||||||
std::vector<std::vector<unsigned>> weights;
|
std::vector<std::vector<unsigned>> weights;
|
||||||
weights.reserve (facClusters_.size());
|
weights.reserve (facClusters_.size());
|
||||||
|
@ -55,9 +55,9 @@ class CountingBp : public GroundSolver {
|
|||||||
public:
|
public:
|
||||||
CountingBp (const FactorGraph& fg);
|
CountingBp (const FactorGraph& fg);
|
||||||
|
|
||||||
~CountingBp (void);
|
~CountingBp();
|
||||||
|
|
||||||
void printSolverFlags (void) const;
|
void printSolverFlags() const;
|
||||||
|
|
||||||
Params solveQuery (VarIds);
|
Params solveQuery (VarIds);
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ class CountingBp : public GroundSolver {
|
|||||||
typedef std::unordered_map<FacSignature, FacNodes> FacSignMap;
|
typedef std::unordered_map<FacSignature, FacNodes> FacSignMap;
|
||||||
typedef std::unordered_map<VarId, VarCluster*> VarClusterMap;
|
typedef std::unordered_map<VarId, VarCluster*> VarClusterMap;
|
||||||
|
|
||||||
Color getNewColor (void);
|
Color getNewColor();
|
||||||
|
|
||||||
Color getColor (const VarNode* vn) const;
|
Color getColor (const VarNode* vn) const;
|
||||||
|
|
||||||
@ -89,11 +89,11 @@ class CountingBp : public GroundSolver {
|
|||||||
|
|
||||||
void setColor (const FacNode* fn, Color c);
|
void setColor (const FacNode* fn, Color c);
|
||||||
|
|
||||||
void findIdenticalFactors (void);
|
void findIdenticalFactors();
|
||||||
|
|
||||||
void setInitialColors (void);
|
void setInitialColors();
|
||||||
|
|
||||||
void createGroups (void);
|
void createGroups();
|
||||||
|
|
||||||
void createClusters (const VarSignMap&, const FacSignMap&);
|
void createClusters (const VarSignMap&, const FacSignMap&);
|
||||||
|
|
||||||
@ -107,9 +107,9 @@ class CountingBp : public GroundSolver {
|
|||||||
|
|
||||||
FacNode* getRepresentative (FacNode*);
|
FacNode* getRepresentative (FacNode*);
|
||||||
|
|
||||||
FactorGraph* getCompressedFactorGraph (void);
|
FactorGraph* getCompressedFactorGraph();
|
||||||
|
|
||||||
std::vector<std::vector<unsigned>> getWeights (void) const;
|
std::vector<std::vector<unsigned>> getWeights() const;
|
||||||
|
|
||||||
unsigned getWeight (const FacCluster*, const VarCluster*,
|
unsigned getWeight (const FacCluster*, const VarCluster*,
|
||||||
size_t index) const;
|
size_t index) const;
|
||||||
@ -131,7 +131,7 @@ class CountingBp : public GroundSolver {
|
|||||||
|
|
||||||
|
|
||||||
inline CountingBp::Color
|
inline CountingBp::Color
|
||||||
CountingBp::getNewColor (void)
|
CountingBp::getNewColor()
|
||||||
{
|
{
|
||||||
++ freeColor_;
|
++ freeColor_;
|
||||||
return freeColor_ - 1;
|
return freeColor_ - 1;
|
||||||
|
@ -41,7 +41,7 @@ ElimGraph::ElimGraph (const std::vector<Factor*>& factors)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ElimGraph::~ElimGraph (void)
|
ElimGraph::~ElimGraph()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < nodes_.size(); i++) {
|
for (size_t i = 0; i < nodes_.size(); i++) {
|
||||||
delete nodes_[i];
|
delete nodes_[i];
|
||||||
@ -77,7 +77,7 @@ ElimGraph::getEliminatingOrder (const VarIds& excludedVids)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ElimGraph::print (void) const
|
ElimGraph::print() const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < nodes_.size(); i++) {
|
for (size_t i = 0; i < nodes_.size(); i++) {
|
||||||
std::cout << "node " << nodes_[i]->label() << " neighs:" ;
|
std::cout << "node " << nodes_[i]->label() << " neighs:" ;
|
||||||
@ -177,7 +177,7 @@ ElimGraph::getEGNode (VarId vid) const
|
|||||||
|
|
||||||
|
|
||||||
ElimGraph::EGNode*
|
ElimGraph::EGNode*
|
||||||
ElimGraph::getLowestCostNode (void) const
|
ElimGraph::getLowestCostNode() const
|
||||||
{
|
{
|
||||||
EGNode* bestNode = 0;
|
EGNode* bestNode = 0;
|
||||||
unsigned minCost = Util::maxUnsigned();
|
unsigned minCost = Util::maxUnsigned();
|
||||||
|
@ -25,18 +25,18 @@ class ElimGraph {
|
|||||||
|
|
||||||
ElimGraph (const Factors&);
|
ElimGraph (const Factors&);
|
||||||
|
|
||||||
~ElimGraph (void);
|
~ElimGraph();
|
||||||
|
|
||||||
VarIds getEliminatingOrder (const VarIds&);
|
VarIds getEliminatingOrder (const VarIds&);
|
||||||
|
|
||||||
void print (void) const;
|
void print() const;
|
||||||
|
|
||||||
void exportToGraphViz (const char*, bool = true,
|
void exportToGraphViz (const char*, bool = true,
|
||||||
const VarIds& = VarIds()) const;
|
const VarIds& = VarIds()) const;
|
||||||
|
|
||||||
static VarIds getEliminationOrder (const Factors&, VarIds);
|
static VarIds getEliminationOrder (const Factors&, VarIds);
|
||||||
|
|
||||||
static ElimHeuristic elimHeuristic (void) { return elimHeuristic_; }
|
static ElimHeuristic elimHeuristic() { return elimHeuristic_; }
|
||||||
|
|
||||||
static void setElimHeuristic (ElimHeuristic eh) { elimHeuristic_ = eh; }
|
static void setElimHeuristic (ElimHeuristic eh) { elimHeuristic_ = eh; }
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class ElimGraph {
|
|||||||
|
|
||||||
bool isNeighbor (EGNode* n) const { return neighs_.contains (n); }
|
bool isNeighbor (EGNode* n) const { return neighs_.contains (n); }
|
||||||
|
|
||||||
const EGNeighs& neighbors (void) const { return neighs_; }
|
const EGNeighs& neighbors() const { return neighs_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EGNeighs neighs_;
|
EGNeighs neighs_;
|
||||||
@ -77,7 +77,7 @@ class ElimGraph {
|
|||||||
|
|
||||||
EGNode* getEGNode (VarId) const;
|
EGNode* getEGNode (VarId) const;
|
||||||
|
|
||||||
EGNode* getLowestCostNode (void) const;
|
EGNode* getLowestCostNode() const;
|
||||||
|
|
||||||
void connectAllNeighbors (const EGNode*);
|
void connectAllNeighbors (const EGNode*);
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ Factor::multiply (Factor& g)
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Factor::getLabel (void) const
|
Factor::getLabel() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "f(" ;
|
ss << "f(" ;
|
||||||
@ -125,7 +125,7 @@ Factor::getLabel (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Factor::print (void) const
|
Factor::print() const
|
||||||
{
|
{
|
||||||
Vars vars;
|
Vars vars;
|
||||||
for (size_t i = 0; i < args_.size(); i++) {
|
for (size_t i = 0; i < args_.size(); i++) {
|
||||||
@ -146,7 +146,7 @@ Factor::print (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Factor::sumOutFirstVariable (void)
|
Factor::sumOutFirstVariable()
|
||||||
{
|
{
|
||||||
size_t sep = params_.size() / 2;
|
size_t sep = params_.size() / 2;
|
||||||
if (Globals::logDomain) {
|
if (Globals::logDomain) {
|
||||||
@ -169,7 +169,7 @@ Factor::sumOutFirstVariable (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Factor::sumOutLastVariable (void)
|
Factor::sumOutLastVariable()
|
||||||
{
|
{
|
||||||
Params::iterator first1 = params_.begin();
|
Params::iterator first1 = params_.begin();
|
||||||
Params::iterator first2 = params_.begin();
|
Params::iterator first2 = params_.begin();
|
||||||
|
@ -15,27 +15,27 @@ namespace Horus {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class TFactor {
|
class TFactor {
|
||||||
public:
|
public:
|
||||||
const std::vector<T>& arguments (void) const { return args_; }
|
const std::vector<T>& arguments() const { return args_; }
|
||||||
|
|
||||||
std::vector<T>& arguments (void) { return args_; }
|
std::vector<T>& arguments() { return args_; }
|
||||||
|
|
||||||
const Ranges& ranges (void) const { return ranges_; }
|
const Ranges& ranges() const { return ranges_; }
|
||||||
|
|
||||||
const Params& params (void) const { return params_; }
|
const Params& params() const { return params_; }
|
||||||
|
|
||||||
Params& params (void) { return params_; }
|
Params& params() { return params_; }
|
||||||
|
|
||||||
size_t nrArguments (void) const { return args_.size(); }
|
size_t nrArguments() const { return args_.size(); }
|
||||||
|
|
||||||
size_t size (void) const { return params_.size(); }
|
size_t size() const { return params_.size(); }
|
||||||
|
|
||||||
unsigned distId (void) const { return distId_; }
|
unsigned distId() const { return distId_; }
|
||||||
|
|
||||||
void setDistId (unsigned id) { distId_ = id; }
|
void setDistId (unsigned id) { distId_ = id; }
|
||||||
|
|
||||||
void normalize (void) { LogAware::normalize (params_); }
|
void normalize() { LogAware::normalize (params_); }
|
||||||
|
|
||||||
void randomize (void);
|
void randomize();
|
||||||
|
|
||||||
void setParams (const Params& newParams);
|
void setParams (const Params& newParams);
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class TFactor {
|
|||||||
|
|
||||||
|
|
||||||
template <typename T> inline void
|
template <typename T> inline void
|
||||||
TFactor<T>::randomize (void)
|
TFactor<T>::randomize()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < params_.size(); ++i) {
|
for (size_t i = 0; i < params_.size(); ++i) {
|
||||||
params_[i] = (double) std::rand() / RAND_MAX;
|
params_[i] = (double) std::rand() / RAND_MAX;
|
||||||
@ -328,7 +328,7 @@ TFactor<T>::cartesianProduct (
|
|||||||
|
|
||||||
class Factor : public TFactor<VarId> {
|
class Factor : public TFactor<VarId> {
|
||||||
public:
|
public:
|
||||||
Factor (void) { }
|
Factor() { }
|
||||||
|
|
||||||
Factor (const Factor&);
|
Factor (const Factor&);
|
||||||
|
|
||||||
@ -348,14 +348,14 @@ class Factor : public TFactor<VarId> {
|
|||||||
|
|
||||||
void multiply (Factor&);
|
void multiply (Factor&);
|
||||||
|
|
||||||
std::string getLabel (void) const;
|
std::string getLabel() const;
|
||||||
|
|
||||||
void print (void) const;
|
void print() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sumOutFirstVariable (void);
|
void sumOutFirstVariable();
|
||||||
|
|
||||||
void sumOutLastVariable (void);
|
void sumOutLastVariable();
|
||||||
|
|
||||||
void sumOutArgs (const std::vector<bool>& mask);
|
void sumOutArgs (const std::vector<bool>& mask);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ FactorGraph::FactorGraph (const FactorGraph& fg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
FactorGraph::~FactorGraph (void)
|
FactorGraph::~FactorGraph()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < varNodes_.size(); i++) {
|
for (size_t i = 0; i < varNodes_.size(); i++) {
|
||||||
delete varNodes_[i];
|
delete varNodes_[i];
|
||||||
@ -246,7 +246,7 @@ FactorGraph::addEdge (VarNode* vn, FacNode* fn)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FactorGraph::isTree (void) const
|
FactorGraph::isTree() const
|
||||||
{
|
{
|
||||||
return !containsCycle();
|
return !containsCycle();
|
||||||
}
|
}
|
||||||
@ -254,7 +254,7 @@ FactorGraph::isTree (void) const
|
|||||||
|
|
||||||
|
|
||||||
BayesBallGraph&
|
BayesBallGraph&
|
||||||
FactorGraph::getStructure (void)
|
FactorGraph::getStructure()
|
||||||
{
|
{
|
||||||
assert (bayesFactors_);
|
assert (bayesFactors_);
|
||||||
if (structure_.empty()) {
|
if (structure_.empty()) {
|
||||||
@ -274,7 +274,7 @@ FactorGraph::getStructure (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FactorGraph::print (void) const
|
FactorGraph::print() const
|
||||||
{
|
{
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@ -422,7 +422,7 @@ FactorGraph::ignoreLines (std::ifstream& is) const
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FactorGraph::containsCycle (void) const
|
FactorGraph::containsCycle() const
|
||||||
{
|
{
|
||||||
std::vector<bool> visitedVars (varNodes_.size(), false);
|
std::vector<bool> visitedVars (varNodes_.size(), false);
|
||||||
std::vector<bool> visitedFactors (facNodes_.size(), false);
|
std::vector<bool> visitedFactors (facNodes_.size(), false);
|
||||||
|
@ -26,7 +26,7 @@ class VarNode : public Var {
|
|||||||
|
|
||||||
void addNeighbor (FacNode* fn) { neighs_.push_back (fn); }
|
void addNeighbor (FacNode* fn) { neighs_.push_back (fn); }
|
||||||
|
|
||||||
const FacNodes& neighbors (void) const { return neighs_; }
|
const FacNodes& neighbors() const { return neighs_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FacNodes neighs_;
|
FacNodes neighs_;
|
||||||
@ -40,19 +40,19 @@ class FacNode {
|
|||||||
public:
|
public:
|
||||||
FacNode (const Factor& f) : factor_(f), index_(-1) { }
|
FacNode (const Factor& f) : factor_(f), index_(-1) { }
|
||||||
|
|
||||||
const Factor& factor (void) const { return factor_; }
|
const Factor& factor() const { return factor_; }
|
||||||
|
|
||||||
Factor& factor (void) { return factor_; }
|
Factor& factor() { return factor_; }
|
||||||
|
|
||||||
void addNeighbor (VarNode* vn) { neighs_.push_back (vn); }
|
void addNeighbor (VarNode* vn) { neighs_.push_back (vn); }
|
||||||
|
|
||||||
const VarNodes& neighbors (void) const { return neighs_; }
|
const VarNodes& neighbors() const { return neighs_; }
|
||||||
|
|
||||||
size_t getIndex (void) const { return index_; }
|
size_t getIndex() const { return index_; }
|
||||||
|
|
||||||
void setIndex (size_t index) { index_ = index; }
|
void setIndex (size_t index) { index_ = index; }
|
||||||
|
|
||||||
std::string getLabel (void) { return factor_.getLabel(); }
|
std::string getLabel() { return factor_.getLabel(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VarNodes neighs_;
|
VarNodes neighs_;
|
||||||
@ -66,23 +66,23 @@ class FacNode {
|
|||||||
|
|
||||||
class FactorGraph {
|
class FactorGraph {
|
||||||
public:
|
public:
|
||||||
FactorGraph (void) : bayesFactors_(false) { }
|
FactorGraph() : bayesFactors_(false) { }
|
||||||
|
|
||||||
FactorGraph (const FactorGraph&);
|
FactorGraph (const FactorGraph&);
|
||||||
|
|
||||||
~FactorGraph (void);
|
~FactorGraph();
|
||||||
|
|
||||||
const VarNodes& varNodes (void) const { return varNodes_; }
|
const VarNodes& varNodes() const { return varNodes_; }
|
||||||
|
|
||||||
const FacNodes& facNodes (void) const { return facNodes_; }
|
const FacNodes& facNodes() const { return facNodes_; }
|
||||||
|
|
||||||
void setFactorsAsBayesian (void) { bayesFactors_ = true; }
|
void setFactorsAsBayesian() { bayesFactors_ = true; }
|
||||||
|
|
||||||
bool bayesianFactors (void) const { return bayesFactors_; }
|
bool bayesianFactors() const { return bayesFactors_; }
|
||||||
|
|
||||||
size_t nrVarNodes (void) const { return varNodes_.size(); }
|
size_t nrVarNodes() const { return varNodes_.size(); }
|
||||||
|
|
||||||
size_t nrFacNodes (void) const { return facNodes_.size(); }
|
size_t nrFacNodes() const { return facNodes_.size(); }
|
||||||
|
|
||||||
VarNode* getVarNode (VarId vid) const;
|
VarNode* getVarNode (VarId vid) const;
|
||||||
|
|
||||||
@ -98,11 +98,11 @@ class FactorGraph {
|
|||||||
|
|
||||||
void addEdge (VarNode*, FacNode*);
|
void addEdge (VarNode*, FacNode*);
|
||||||
|
|
||||||
bool isTree (void) const;
|
bool isTree() const;
|
||||||
|
|
||||||
BayesBallGraph& getStructure (void);
|
BayesBallGraph& getStructure();
|
||||||
|
|
||||||
void print (void) const;
|
void print() const;
|
||||||
|
|
||||||
void exportToLibDai (const char*) const;
|
void exportToLibDai (const char*) const;
|
||||||
|
|
||||||
@ -110,36 +110,36 @@ class FactorGraph {
|
|||||||
|
|
||||||
void exportToGraphViz (const char*) const;
|
void exportToGraphViz (const char*) const;
|
||||||
|
|
||||||
static bool exportToLibDai (void) { return exportLd_; }
|
static bool exportToLibDai() { return exportLd_; }
|
||||||
|
|
||||||
static bool exportToUai (void) { return exportUai_; }
|
static bool exportToUai() { return exportUai_; }
|
||||||
|
|
||||||
static bool exportGraphViz (void) { return exportGv_; }
|
static bool exportGraphViz() { return exportGv_; }
|
||||||
|
|
||||||
static bool printFactorGraph (void) { return printFg_; }
|
static bool printFactorGraph() { return printFg_; }
|
||||||
|
|
||||||
static void enableExportToLibDai (void) { exportLd_ = true; }
|
static void enableExportToLibDai() { exportLd_ = true; }
|
||||||
|
|
||||||
static void disableExportToLibDai (void) { exportLd_ = false; }
|
static void disableExportToLibDai() { exportLd_ = false; }
|
||||||
|
|
||||||
static void enableExportToUai (void) { exportUai_ = true; }
|
static void enableExportToUai() { exportUai_ = true; }
|
||||||
|
|
||||||
static void disableExportToUai (void) { exportUai_ = false; }
|
static void disableExportToUai() { exportUai_ = false; }
|
||||||
|
|
||||||
static void enableExportToGraphViz (void) { exportGv_ = true; }
|
static void enableExportToGraphViz() { exportGv_ = true; }
|
||||||
|
|
||||||
static void disableExportToGraphViz (void) { exportGv_ = false; }
|
static void disableExportToGraphViz() { exportGv_ = false; }
|
||||||
|
|
||||||
static void enablePrintFactorGraph (void) { printFg_ = true; }
|
static void enablePrintFactorGraph() { printFg_ = true; }
|
||||||
|
|
||||||
static void disablePrintFactorGraph (void) { printFg_ = false; }
|
static void disablePrintFactorGraph() { printFg_ = false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::unordered_map<unsigned, VarNode*> VarMap;
|
typedef std::unordered_map<unsigned, VarNode*> VarMap;
|
||||||
|
|
||||||
void ignoreLines (std::ifstream&) const;
|
void ignoreLines (std::ifstream&) const;
|
||||||
|
|
||||||
bool containsCycle (void) const;
|
bool containsCycle() const;
|
||||||
|
|
||||||
bool containsCycle (const VarNode*, const FacNode*,
|
bool containsCycle (const VarNode*, const FacNode*,
|
||||||
std::vector<bool>&, std::vector<bool>&) const;
|
std::vector<bool>&, std::vector<bool>&) const;
|
||||||
|
@ -42,7 +42,7 @@ GroundSolver::printAnswer (const VarIds& vids)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GroundSolver::printAllPosterioris (void)
|
GroundSolver::printAllPosterioris()
|
||||||
{
|
{
|
||||||
VarNodes vars = fg.varNodes();
|
VarNodes vars = fg.varNodes();
|
||||||
std::sort (vars.begin(), vars.end(), sortByVarId());
|
std::sort (vars.begin(), vars.end(), sortByVarId());
|
||||||
|
@ -15,11 +15,11 @@ class GroundSolver {
|
|||||||
|
|
||||||
virtual Params solveQuery (VarIds queryVids) = 0;
|
virtual Params solveQuery (VarIds queryVids) = 0;
|
||||||
|
|
||||||
virtual void printSolverFlags (void) const = 0;
|
virtual void printSolverFlags() const = 0;
|
||||||
|
|
||||||
void printAnswer (const VarIds& vids);
|
void printAnswer (const VarIds& vids);
|
||||||
|
|
||||||
void printAllPosterioris (void);
|
void printAllPosterioris();
|
||||||
|
|
||||||
static Params getJointByConditioning (GroundSolverType,
|
static Params getJointByConditioning (GroundSolverType,
|
||||||
FactorGraph, const VarIds& jointVarIds);
|
FactorGraph, const VarIds& jointVarIds);
|
||||||
|
@ -19,7 +19,7 @@ HistogramSet::HistogramSet (unsigned size, unsigned range)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
HistogramSet::nextHistogram (void)
|
HistogramSet::nextHistogram()
|
||||||
{
|
{
|
||||||
for (size_t i = hist_.size() - 1; i-- > 0; ) {
|
for (size_t i = hist_.size() - 1; i-- > 0; ) {
|
||||||
if (hist_[i] > 0) {
|
if (hist_[i] > 0) {
|
||||||
@ -45,7 +45,7 @@ HistogramSet::operator[] (size_t idx) const
|
|||||||
|
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
HistogramSet::nrHistograms (void) const
|
HistogramSet::nrHistograms() const
|
||||||
{
|
{
|
||||||
return HistogramSet::nrHistograms (size_, hist_.size());
|
return HistogramSet::nrHistograms (size_, hist_.size());
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ HistogramSet::nrHistograms (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
HistogramSet::reset (void)
|
HistogramSet::reset()
|
||||||
{
|
{
|
||||||
std::fill (hist_.begin() + 1, hist_.end(), 0);
|
std::fill (hist_.begin() + 1, hist_.end(), 0);
|
||||||
hist_[0] = size_;
|
hist_[0] = size_;
|
||||||
|
@ -15,13 +15,13 @@ class HistogramSet {
|
|||||||
public:
|
public:
|
||||||
HistogramSet (unsigned, unsigned);
|
HistogramSet (unsigned, unsigned);
|
||||||
|
|
||||||
void nextHistogram (void);
|
void nextHistogram();
|
||||||
|
|
||||||
unsigned operator[] (size_t idx) const;
|
unsigned operator[] (size_t idx) const;
|
||||||
|
|
||||||
unsigned nrHistograms (void) const;
|
unsigned nrHistograms() const;
|
||||||
|
|
||||||
void reset (void);
|
void reset();
|
||||||
|
|
||||||
static std::vector<Histogram> getHistograms (unsigned, unsigned);
|
static std::vector<Histogram> getHistograms (unsigned, unsigned);
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ typedef std::pair<ParfactorList*, ObservedFormulas*> LiftedNetwork;
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
createLiftedNetwork (void)
|
createLiftedNetwork()
|
||||||
{
|
{
|
||||||
Parfactors parfactors;
|
Parfactors parfactors;
|
||||||
YAP_Term parfactorList = YAP_ARG1;
|
YAP_Term parfactorList = YAP_ARG1;
|
||||||
@ -80,7 +80,7 @@ createLiftedNetwork (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
createGroundNetwork (void)
|
createGroundNetwork()
|
||||||
{
|
{
|
||||||
std::string factorsType ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG1)));
|
std::string factorsType ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG1)));
|
||||||
FactorGraph* fg = new FactorGraph();
|
FactorGraph* fg = new FactorGraph();
|
||||||
@ -136,7 +136,7 @@ createGroundNetwork (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
runLiftedSolver (void)
|
runLiftedSolver()
|
||||||
{
|
{
|
||||||
LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1);
|
LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1);
|
||||||
ParfactorList copy (*network->first);
|
ParfactorList copy (*network->first);
|
||||||
@ -194,7 +194,7 @@ runLiftedSolver (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
runGroundSolver (void)
|
runGroundSolver()
|
||||||
{
|
{
|
||||||
FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
|
FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ runGroundSolver (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
setParfactorsParams (void)
|
setParfactorsParams()
|
||||||
{
|
{
|
||||||
LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1);
|
LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1);
|
||||||
ParfactorList* pfList = network->first;
|
ParfactorList* pfList = network->first;
|
||||||
@ -272,7 +272,7 @@ setParfactorsParams (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
setFactorsParams (void)
|
setFactorsParams()
|
||||||
{
|
{
|
||||||
FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
|
FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
|
||||||
YAP_Term distIdsList = YAP_ARG2;
|
YAP_Term distIdsList = YAP_ARG2;
|
||||||
@ -298,7 +298,7 @@ setFactorsParams (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
setVarsInformation (void)
|
setVarsInformation()
|
||||||
{
|
{
|
||||||
Var::clearVarsInfo();
|
Var::clearVarsInfo();
|
||||||
std::vector<std::string> labels;
|
std::vector<std::string> labels;
|
||||||
@ -328,7 +328,7 @@ setVarsInformation (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
setHorusFlag (void)
|
setHorusFlag()
|
||||||
{
|
{
|
||||||
std::string option ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG1)));
|
std::string option ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG1)));
|
||||||
std::string value;
|
std::string value;
|
||||||
@ -353,7 +353,7 @@ setHorusFlag (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
freeGroundNetwork (void)
|
freeGroundNetwork()
|
||||||
{
|
{
|
||||||
delete (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
|
delete (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -362,7 +362,7 @@ freeGroundNetwork (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
freeLiftedNetwork (void)
|
freeLiftedNetwork()
|
||||||
{
|
{
|
||||||
LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1);
|
LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1);
|
||||||
delete network->first;
|
delete network->first;
|
||||||
@ -557,7 +557,7 @@ fillSolutionList (const std::vector<Params>& results)
|
|||||||
|
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
init_predicates (void)
|
init_predicates()
|
||||||
{
|
{
|
||||||
YAP_UserCPredicate ("cpp_create_lifted_network",
|
YAP_UserCPredicate ("cpp_create_lifted_network",
|
||||||
createLiftedNetwork, 3);
|
createLiftedNetwork, 3);
|
||||||
|
@ -14,28 +14,28 @@ class Indexer {
|
|||||||
public:
|
public:
|
||||||
Indexer (const Ranges& ranges, bool calcOffsets = true);
|
Indexer (const Ranges& ranges, bool calcOffsets = true);
|
||||||
|
|
||||||
void increment (void);
|
void increment();
|
||||||
|
|
||||||
void incrementDimension (size_t dim);
|
void incrementDimension (size_t dim);
|
||||||
|
|
||||||
void incrementExceptDimension (size_t dim);
|
void incrementExceptDimension (size_t dim);
|
||||||
|
|
||||||
Indexer& operator++ (void);
|
Indexer& operator++();
|
||||||
|
|
||||||
operator size_t (void) const;
|
operator size_t() const;
|
||||||
|
|
||||||
unsigned operator[] (size_t dim) const;
|
unsigned operator[] (size_t dim) const;
|
||||||
|
|
||||||
bool valid (void) const;
|
bool valid() const;
|
||||||
|
|
||||||
void reset (void);
|
void reset();
|
||||||
|
|
||||||
void resetDimension (size_t dim);
|
void resetDimension (size_t dim);
|
||||||
|
|
||||||
size_t size (void) const;
|
size_t size() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void calculateOffsets (void);
|
void calculateOffsets();
|
||||||
|
|
||||||
friend std::ostream& operator<< (std::ostream&, const Indexer&);
|
friend std::ostream& operator<< (std::ostream&, const Indexer&);
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ Indexer::Indexer (const Ranges& ranges, bool calcOffsets)
|
|||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
Indexer::increment (void)
|
Indexer::increment()
|
||||||
{
|
{
|
||||||
for (size_t i = ranges_.size(); i-- > 0; ) {
|
for (size_t i = ranges_.size(); i-- > 0; ) {
|
||||||
indices_[i] ++;
|
indices_[i] ++;
|
||||||
@ -112,7 +112,7 @@ Indexer::incrementExceptDimension (size_t dim)
|
|||||||
|
|
||||||
|
|
||||||
inline Indexer&
|
inline Indexer&
|
||||||
Indexer::operator++ (void)
|
Indexer::operator++()
|
||||||
{
|
{
|
||||||
increment();
|
increment();
|
||||||
return *this;
|
return *this;
|
||||||
@ -121,7 +121,7 @@ Indexer::operator++ (void)
|
|||||||
|
|
||||||
|
|
||||||
inline
|
inline
|
||||||
Indexer::operator size_t (void) const
|
Indexer::operator size_t() const
|
||||||
{
|
{
|
||||||
return index_;
|
return index_;
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ Indexer::operator[] (size_t dim) const
|
|||||||
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
Indexer::valid (void) const
|
Indexer::valid() const
|
||||||
{
|
{
|
||||||
return index_ < size_;
|
return index_ < size_;
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ Indexer::valid (void) const
|
|||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
Indexer::reset (void)
|
Indexer::reset()
|
||||||
{
|
{
|
||||||
index_ = 0;
|
index_ = 0;
|
||||||
std::fill (indices_.begin(), indices_.end(), 0);
|
std::fill (indices_.begin(), indices_.end(), 0);
|
||||||
@ -165,7 +165,7 @@ Indexer::resetDimension (size_t dim)
|
|||||||
|
|
||||||
|
|
||||||
inline size_t
|
inline size_t
|
||||||
Indexer::size (void) const
|
Indexer::size() const
|
||||||
{
|
{
|
||||||
return size_ ;
|
return size_ ;
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ Indexer::size (void) const
|
|||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
Indexer::calculateOffsets (void)
|
Indexer::calculateOffsets()
|
||||||
{
|
{
|
||||||
size_t prod = 1;
|
size_t prod = 1;
|
||||||
offsets_.resize (ranges_.size());
|
offsets_.resize (ranges_.size());
|
||||||
@ -198,15 +198,15 @@ class MapIndexer {
|
|||||||
const std::vector<T>& wantedArgs,
|
const std::vector<T>& wantedArgs,
|
||||||
const Ranges& wantedRanges);
|
const Ranges& wantedRanges);
|
||||||
|
|
||||||
MapIndexer& operator++ (void);
|
MapIndexer& operator++();
|
||||||
|
|
||||||
operator size_t (void) const;
|
operator size_t() const;
|
||||||
|
|
||||||
unsigned operator[] (size_t dim) const;
|
unsigned operator[] (size_t dim) const;
|
||||||
|
|
||||||
bool valid (void) const;
|
bool valid() const;
|
||||||
|
|
||||||
void reset (void);
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::ostream& operator<< (std::ostream&, const MapIndexer&);
|
friend std::ostream& operator<< (std::ostream&, const MapIndexer&);
|
||||||
@ -284,7 +284,7 @@ MapIndexer::MapIndexer (
|
|||||||
|
|
||||||
|
|
||||||
inline MapIndexer&
|
inline MapIndexer&
|
||||||
MapIndexer::operator++ (void)
|
MapIndexer::operator++()
|
||||||
{
|
{
|
||||||
assert (valid_);
|
assert (valid_);
|
||||||
for (size_t i = ranges_.size(); i-- > 0; ) {
|
for (size_t i = ranges_.size(); i-- > 0; ) {
|
||||||
@ -304,7 +304,7 @@ MapIndexer::operator++ (void)
|
|||||||
|
|
||||||
|
|
||||||
inline
|
inline
|
||||||
MapIndexer::operator size_t (void) const
|
MapIndexer::operator size_t() const
|
||||||
{
|
{
|
||||||
assert (valid());
|
assert (valid());
|
||||||
return index_;
|
return index_;
|
||||||
@ -323,7 +323,7 @@ MapIndexer::operator[] (size_t dim) const
|
|||||||
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
MapIndexer::valid (void) const
|
MapIndexer::valid() const
|
||||||
{
|
{
|
||||||
return valid_;
|
return valid_;
|
||||||
}
|
}
|
||||||
@ -331,7 +331,7 @@ MapIndexer::valid (void) const
|
|||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
MapIndexer::reset (void)
|
MapIndexer::reset()
|
||||||
{
|
{
|
||||||
index_ = 0;
|
index_ = 0;
|
||||||
std::fill (indices_.begin(), indices_.end(), 0);
|
std::fill (indices_.begin(), indices_.end(), 0);
|
||||||
|
@ -20,7 +20,7 @@ LiftedBp::LiftedBp (const ParfactorList& parfactorList)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
LiftedBp::~LiftedBp (void)
|
LiftedBp::~LiftedBp()
|
||||||
{
|
{
|
||||||
delete solver_;
|
delete solver_;
|
||||||
delete fg_;
|
delete fg_;
|
||||||
@ -64,7 +64,7 @@ LiftedBp::solveQuery (const Grounds& query)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LiftedBp::printSolverFlags (void) const
|
LiftedBp::printSolverFlags() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "lifted bp [" ;
|
ss << "lifted bp [" ;
|
||||||
@ -86,7 +86,7 @@ LiftedBp::printSolverFlags (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LiftedBp::refineParfactors (void)
|
LiftedBp::refineParfactors()
|
||||||
{
|
{
|
||||||
pfList_ = parfactorList;
|
pfList_ = parfactorList;
|
||||||
while (iterate() == false);
|
while (iterate() == false);
|
||||||
@ -100,7 +100,7 @@ LiftedBp::refineParfactors (void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LiftedBp::iterate (void)
|
LiftedBp::iterate()
|
||||||
{
|
{
|
||||||
ParfactorList::iterator it = pfList_.begin();
|
ParfactorList::iterator it = pfList_.begin();
|
||||||
while (it != pfList_.end()) {
|
while (it != pfList_.end()) {
|
||||||
@ -141,7 +141,7 @@ LiftedBp::getQueryGroups (const Grounds& query)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LiftedBp::createFactorGraph (void)
|
LiftedBp::createFactorGraph()
|
||||||
{
|
{
|
||||||
fg_ = new FactorGraph();
|
fg_ = new FactorGraph();
|
||||||
ParfactorList::const_iterator it = pfList_.begin();
|
ParfactorList::const_iterator it = pfList_.begin();
|
||||||
@ -158,7 +158,7 @@ LiftedBp::createFactorGraph (void)
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::vector<unsigned>>
|
std::vector<std::vector<unsigned>>
|
||||||
LiftedBp::getWeights (void) const
|
LiftedBp::getWeights() const
|
||||||
{
|
{
|
||||||
std::vector<std::vector<unsigned>> weights;
|
std::vector<std::vector<unsigned>> weights;
|
||||||
weights.reserve (pfList_.size());
|
weights.reserve (pfList_.size());
|
||||||
|
@ -16,22 +16,22 @@ class LiftedBp : public LiftedSolver{
|
|||||||
public:
|
public:
|
||||||
LiftedBp (const ParfactorList& pfList);
|
LiftedBp (const ParfactorList& pfList);
|
||||||
|
|
||||||
~LiftedBp (void);
|
~LiftedBp();
|
||||||
|
|
||||||
Params solveQuery (const Grounds&);
|
Params solveQuery (const Grounds&);
|
||||||
|
|
||||||
void printSolverFlags (void) const;
|
void printSolverFlags() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void refineParfactors (void);
|
void refineParfactors();
|
||||||
|
|
||||||
bool iterate (void);
|
bool iterate();
|
||||||
|
|
||||||
std::vector<PrvGroup> getQueryGroups (const Grounds&);
|
std::vector<PrvGroup> getQueryGroups (const Grounds&);
|
||||||
|
|
||||||
void createFactorGraph (void);
|
void createFactorGraph();
|
||||||
|
|
||||||
std::vector<std::vector<unsigned>> getWeights (void) const;
|
std::vector<std::vector<unsigned>> getWeights() const;
|
||||||
|
|
||||||
unsigned rangeOfGround (const Ground&);
|
unsigned rangeOfGround (const Ground&);
|
||||||
|
|
||||||
|
@ -30,25 +30,25 @@ enum CircuitNodeType {
|
|||||||
|
|
||||||
class CircuitNode {
|
class CircuitNode {
|
||||||
public:
|
public:
|
||||||
CircuitNode (void) { }
|
CircuitNode() { }
|
||||||
|
|
||||||
virtual ~CircuitNode (void) { }
|
virtual ~CircuitNode() { }
|
||||||
|
|
||||||
virtual double weight (void) const = 0;
|
virtual double weight() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OrNode : public CircuitNode {
|
class OrNode : public CircuitNode {
|
||||||
public:
|
public:
|
||||||
OrNode (void) : CircuitNode(), leftBranch_(0), rightBranch_(0) { }
|
OrNode() : CircuitNode(), leftBranch_(0), rightBranch_(0) { }
|
||||||
|
|
||||||
~OrNode (void);
|
~OrNode();
|
||||||
|
|
||||||
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
CircuitNode** leftBranch () { return &leftBranch_; }
|
||||||
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
CircuitNode** rightBranch() { return &rightBranch_; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CircuitNode* leftBranch_;
|
CircuitNode* leftBranch_;
|
||||||
@ -59,17 +59,17 @@ class OrNode : public CircuitNode {
|
|||||||
|
|
||||||
class AndNode : public CircuitNode {
|
class AndNode : public CircuitNode {
|
||||||
public:
|
public:
|
||||||
AndNode (void) : CircuitNode(), leftBranch_(0), rightBranch_(0) { }
|
AndNode() : CircuitNode(), leftBranch_(0), rightBranch_(0) { }
|
||||||
|
|
||||||
AndNode (CircuitNode* leftBranch, CircuitNode* rightBranch)
|
AndNode (CircuitNode* leftBranch, CircuitNode* rightBranch)
|
||||||
: CircuitNode(), leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
: CircuitNode(), leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
||||||
|
|
||||||
~AndNode (void);
|
~AndNode();
|
||||||
|
|
||||||
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
CircuitNode** leftBranch () { return &leftBranch_; }
|
||||||
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
CircuitNode** rightBranch() { return &rightBranch_; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CircuitNode* leftBranch_;
|
CircuitNode* leftBranch_;
|
||||||
@ -83,17 +83,17 @@ class SetOrNode : public CircuitNode {
|
|||||||
SetOrNode (unsigned nrGroundings)
|
SetOrNode (unsigned nrGroundings)
|
||||||
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
||||||
|
|
||||||
~SetOrNode (void);
|
~SetOrNode();
|
||||||
|
|
||||||
CircuitNode** follow (void) { return &follow_; }
|
CircuitNode** follow() { return &follow_; }
|
||||||
|
|
||||||
static unsigned nrPositives (void) { return nrPos_; }
|
static unsigned nrPositives() { return nrPos_; }
|
||||||
|
|
||||||
static unsigned nrNegatives (void) { return nrNeg_; }
|
static unsigned nrNegatives() { return nrNeg_; }
|
||||||
|
|
||||||
static bool isSet (void) { return nrPos_ >= 0; }
|
static bool isSet() { return nrPos_ >= 0; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CircuitNode* follow_;
|
CircuitNode* follow_;
|
||||||
@ -109,11 +109,11 @@ class SetAndNode : public CircuitNode {
|
|||||||
SetAndNode (unsigned nrGroundings)
|
SetAndNode (unsigned nrGroundings)
|
||||||
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
||||||
|
|
||||||
~SetAndNode (void);
|
~SetAndNode();
|
||||||
|
|
||||||
CircuitNode** follow (void) { return &follow_; }
|
CircuitNode** follow() { return &follow_; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CircuitNode* follow_;
|
CircuitNode* follow_;
|
||||||
@ -124,16 +124,16 @@ class SetAndNode : public CircuitNode {
|
|||||||
|
|
||||||
class IncExcNode : public CircuitNode {
|
class IncExcNode : public CircuitNode {
|
||||||
public:
|
public:
|
||||||
IncExcNode (void)
|
IncExcNode()
|
||||||
: CircuitNode(), plus1Branch_(0), plus2Branch_(0), minusBranch_(0) { }
|
: CircuitNode(), plus1Branch_(0), plus2Branch_(0), minusBranch_(0) { }
|
||||||
|
|
||||||
~IncExcNode (void);
|
~IncExcNode();
|
||||||
|
|
||||||
CircuitNode** plus1Branch (void) { return &plus1Branch_; }
|
CircuitNode** plus1Branch() { return &plus1Branch_; }
|
||||||
CircuitNode** plus2Branch (void) { return &plus2Branch_; }
|
CircuitNode** plus2Branch() { return &plus2Branch_; }
|
||||||
CircuitNode** minusBranch (void) { return &minusBranch_; }
|
CircuitNode** minusBranch() { return &minusBranch_; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CircuitNode* plus1Branch_;
|
CircuitNode* plus1Branch_;
|
||||||
@ -148,13 +148,13 @@ class LeafNode : public CircuitNode {
|
|||||||
LeafNode (Clause* clause, const LiftedWCNF& lwcnf)
|
LeafNode (Clause* clause, const LiftedWCNF& lwcnf)
|
||||||
: CircuitNode(), clause_(clause), lwcnf_(lwcnf) { }
|
: CircuitNode(), clause_(clause), lwcnf_(lwcnf) { }
|
||||||
|
|
||||||
~LeafNode (void);
|
~LeafNode();
|
||||||
|
|
||||||
const Clause* clause (void) const { return clause_; }
|
const Clause* clause() const { return clause_; }
|
||||||
|
|
||||||
Clause* clause (void) { return clause_; }
|
Clause* clause() { return clause_; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Clause* clause_;
|
Clause* clause_;
|
||||||
@ -168,13 +168,13 @@ class SmoothNode : public CircuitNode {
|
|||||||
SmoothNode (const Clauses& clauses, const LiftedWCNF& lwcnf)
|
SmoothNode (const Clauses& clauses, const LiftedWCNF& lwcnf)
|
||||||
: CircuitNode(), clauses_(clauses), lwcnf_(lwcnf) { }
|
: CircuitNode(), clauses_(clauses), lwcnf_(lwcnf) { }
|
||||||
|
|
||||||
~SmoothNode (void);
|
~SmoothNode();
|
||||||
|
|
||||||
const Clauses& clauses (void) const { return clauses_; }
|
const Clauses& clauses() const { return clauses_; }
|
||||||
|
|
||||||
Clauses clauses (void) { return clauses_; }
|
Clauses clauses() { return clauses_; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Clauses clauses_;
|
Clauses clauses_;
|
||||||
@ -185,18 +185,18 @@ class SmoothNode : public CircuitNode {
|
|||||||
|
|
||||||
class TrueNode : public CircuitNode {
|
class TrueNode : public CircuitNode {
|
||||||
public:
|
public:
|
||||||
TrueNode (void) : CircuitNode() { }
|
TrueNode() : CircuitNode() { }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CompilationFailedNode : public CircuitNode {
|
class CompilationFailedNode : public CircuitNode {
|
||||||
public:
|
public:
|
||||||
CompilationFailedNode (void) : CircuitNode() { }
|
CompilationFailedNode() : CircuitNode() { }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -205,11 +205,11 @@ class LiftedCircuit {
|
|||||||
public:
|
public:
|
||||||
LiftedCircuit (const LiftedWCNF* lwcnf);
|
LiftedCircuit (const LiftedWCNF* lwcnf);
|
||||||
|
|
||||||
~LiftedCircuit (void);
|
~LiftedCircuit();
|
||||||
|
|
||||||
bool isCompilationSucceeded (void) const;
|
bool isCompilationSucceeded() const;
|
||||||
|
|
||||||
double getWeightedModelCount (void) const;
|
double getWeightedModelCount() const;
|
||||||
|
|
||||||
void exportToGraphViz (const char*);
|
void exportToGraphViz (const char*);
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ class LiftedCircuit {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
OrNode::~OrNode (void)
|
OrNode::~OrNode()
|
||||||
{
|
{
|
||||||
delete leftBranch_;
|
delete leftBranch_;
|
||||||
delete rightBranch_;
|
delete rightBranch_;
|
||||||
@ -284,7 +284,7 @@ OrNode::~OrNode (void)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
OrNode::weight (void) const
|
OrNode::weight() const
|
||||||
{
|
{
|
||||||
double lw = leftBranch_->weight();
|
double lw = leftBranch_->weight();
|
||||||
double rw = rightBranch_->weight();
|
double rw = rightBranch_->weight();
|
||||||
@ -293,7 +293,7 @@ OrNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AndNode::~AndNode (void)
|
AndNode::~AndNode()
|
||||||
{
|
{
|
||||||
delete leftBranch_;
|
delete leftBranch_;
|
||||||
delete rightBranch_;
|
delete rightBranch_;
|
||||||
@ -302,7 +302,7 @@ AndNode::~AndNode (void)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
AndNode::weight (void) const
|
AndNode::weight() const
|
||||||
{
|
{
|
||||||
double lw = leftBranch_->weight();
|
double lw = leftBranch_->weight();
|
||||||
double rw = rightBranch_->weight();
|
double rw = rightBranch_->weight();
|
||||||
@ -316,7 +316,7 @@ int SetOrNode::nrNeg_ = -1;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
SetOrNode::~SetOrNode (void)
|
SetOrNode::~SetOrNode()
|
||||||
{
|
{
|
||||||
delete follow_;
|
delete follow_;
|
||||||
}
|
}
|
||||||
@ -324,7 +324,7 @@ SetOrNode::~SetOrNode (void)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
SetOrNode::weight (void) const
|
SetOrNode::weight() const
|
||||||
{
|
{
|
||||||
double weightSum = LogAware::addIdenty();
|
double weightSum = LogAware::addIdenty();
|
||||||
for (unsigned i = 0; i < nrGroundings_ + 1; i++) {
|
for (unsigned i = 0; i < nrGroundings_ + 1; i++) {
|
||||||
@ -346,7 +346,7 @@ SetOrNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
SetAndNode::~SetAndNode (void)
|
SetAndNode::~SetAndNode()
|
||||||
{
|
{
|
||||||
delete follow_;
|
delete follow_;
|
||||||
}
|
}
|
||||||
@ -354,14 +354,14 @@ SetAndNode::~SetAndNode (void)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
SetAndNode::weight (void) const
|
SetAndNode::weight() const
|
||||||
{
|
{
|
||||||
return LogAware::pow (follow_->weight(), nrGroundings_);
|
return LogAware::pow (follow_->weight(), nrGroundings_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IncExcNode::~IncExcNode (void)
|
IncExcNode::~IncExcNode()
|
||||||
{
|
{
|
||||||
delete plus1Branch_;
|
delete plus1Branch_;
|
||||||
delete plus2Branch_;
|
delete plus2Branch_;
|
||||||
@ -371,7 +371,7 @@ IncExcNode::~IncExcNode (void)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
IncExcNode::weight (void) const
|
IncExcNode::weight() const
|
||||||
{
|
{
|
||||||
double w = 0.0;
|
double w = 0.0;
|
||||||
if (Globals::logDomain) {
|
if (Globals::logDomain) {
|
||||||
@ -386,7 +386,7 @@ IncExcNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
LeafNode::~LeafNode (void)
|
LeafNode::~LeafNode()
|
||||||
{
|
{
|
||||||
delete clause_;
|
delete clause_;
|
||||||
}
|
}
|
||||||
@ -394,7 +394,7 @@ LeafNode::~LeafNode (void)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
LeafNode::weight (void) const
|
LeafNode::weight() const
|
||||||
{
|
{
|
||||||
assert (clause_->isUnit());
|
assert (clause_->isUnit());
|
||||||
if (clause_->posCountedLogVars().empty() == false
|
if (clause_->posCountedLogVars().empty() == false
|
||||||
@ -431,7 +431,7 @@ LeafNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
SmoothNode::~SmoothNode (void)
|
SmoothNode::~SmoothNode()
|
||||||
{
|
{
|
||||||
Clause::deleteClauses (clauses_);
|
Clause::deleteClauses (clauses_);
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ SmoothNode::~SmoothNode (void)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
SmoothNode::weight (void) const
|
SmoothNode::weight() const
|
||||||
{
|
{
|
||||||
Clauses cs = clauses();
|
Clauses cs = clauses();
|
||||||
double totalWeight = LogAware::multIdenty();
|
double totalWeight = LogAware::multIdenty();
|
||||||
@ -474,7 +474,7 @@ SmoothNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
TrueNode::weight (void) const
|
TrueNode::weight() const
|
||||||
{
|
{
|
||||||
return LogAware::multIdenty();
|
return LogAware::multIdenty();
|
||||||
}
|
}
|
||||||
@ -482,7 +482,7 @@ TrueNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
CompilationFailedNode::weight (void) const
|
CompilationFailedNode::weight() const
|
||||||
{
|
{
|
||||||
// weighted model counting in compilation
|
// weighted model counting in compilation
|
||||||
// failed nodes should give NaN
|
// failed nodes should give NaN
|
||||||
@ -515,7 +515,7 @@ LiftedCircuit::LiftedCircuit (const LiftedWCNF* lwcnf)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
LiftedCircuit::~LiftedCircuit (void)
|
LiftedCircuit::~LiftedCircuit()
|
||||||
{
|
{
|
||||||
delete root_;
|
delete root_;
|
||||||
std::unordered_map<CircuitNode*, Clauses>::iterator it
|
std::unordered_map<CircuitNode*, Clauses>::iterator it
|
||||||
@ -529,7 +529,7 @@ LiftedCircuit::~LiftedCircuit (void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LiftedCircuit::isCompilationSucceeded (void) const
|
LiftedCircuit::isCompilationSucceeded() const
|
||||||
{
|
{
|
||||||
return compilationSucceeded_;
|
return compilationSucceeded_;
|
||||||
}
|
}
|
||||||
@ -537,7 +537,7 @@ LiftedCircuit::isCompilationSucceeded (void) const
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
LiftedCircuit::getWeightedModelCount (void) const
|
LiftedCircuit::getWeightedModelCount() const
|
||||||
{
|
{
|
||||||
assert (compilationSucceeded_);
|
assert (compilationSucceeded_);
|
||||||
return root_->weight();
|
return root_->weight();
|
||||||
@ -1568,7 +1568,7 @@ LiftedKc::solveQuery (const Grounds& query)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LiftedKc::printSolverFlags (void) const
|
LiftedKc::printSolverFlags() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "lifted kc [" ;
|
ss << "lifted kc [" ;
|
||||||
|
@ -14,7 +14,7 @@ class LiftedKc : public LiftedSolver {
|
|||||||
|
|
||||||
Params solveQuery (const Grounds&);
|
Params solveQuery (const Grounds&);
|
||||||
|
|
||||||
void printSolverFlags (void) const;
|
void printSolverFlags() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN (LiftedKc);
|
DISALLOW_COPY_AND_ASSIGN (LiftedKc);
|
||||||
|
@ -15,7 +15,7 @@ class LiftedSolver {
|
|||||||
|
|
||||||
virtual Params solveQuery (const Grounds& query) = 0;
|
virtual Params solveQuery (const Grounds& query) = 0;
|
||||||
|
|
||||||
virtual void printSolverFlags (void) const = 0;
|
virtual void printSolverFlags() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const ParfactorList& parfactorList;
|
const ParfactorList& parfactorList;
|
||||||
|
@ -28,7 +28,7 @@ getSymbol (const std::string& symbolName)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
printSymbolDictionary (void)
|
printSymbolDictionary()
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, unsigned>::const_iterator it
|
std::unordered_map<std::string, unsigned>::const_iterator it
|
||||||
= symbolDict.begin();
|
= symbolDict.begin();
|
||||||
@ -98,7 +98,7 @@ operator<< (std::ostream& os, const Ground& gr)
|
|||||||
|
|
||||||
|
|
||||||
LogVars
|
LogVars
|
||||||
Substitution::getDiscardedLogVars (void) const
|
Substitution::getDiscardedLogVars() const
|
||||||
{
|
{
|
||||||
LogVars discardedLvs;
|
LogVars discardedLvs;
|
||||||
std::set<LogVar> doneLvs;
|
std::set<LogVar> doneLvs;
|
||||||
|
@ -14,15 +14,15 @@ namespace Horus {
|
|||||||
|
|
||||||
class Symbol {
|
class Symbol {
|
||||||
public:
|
public:
|
||||||
Symbol (void) : id_(Util::maxUnsigned()) { }
|
Symbol() : id_(Util::maxUnsigned()) { }
|
||||||
|
|
||||||
Symbol (unsigned id) : id_(id) { }
|
Symbol (unsigned id) : id_(id) { }
|
||||||
|
|
||||||
operator unsigned (void) const { return id_; }
|
operator unsigned() const { return id_; }
|
||||||
|
|
||||||
bool valid (void) const { return id_ != Util::maxUnsigned(); }
|
bool valid() const { return id_ != Util::maxUnsigned(); }
|
||||||
|
|
||||||
static Symbol invalid (void) { return Symbol(); }
|
static Symbol invalid() { return Symbol(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::ostream& operator<< (std::ostream&, const Symbol&);
|
friend std::ostream& operator<< (std::ostream&, const Symbol&);
|
||||||
@ -33,15 +33,15 @@ class Symbol {
|
|||||||
|
|
||||||
class LogVar {
|
class LogVar {
|
||||||
public:
|
public:
|
||||||
LogVar (void) : id_(Util::maxUnsigned()) { }
|
LogVar() : id_(Util::maxUnsigned()) { }
|
||||||
|
|
||||||
LogVar (unsigned id) : id_(id) { }
|
LogVar (unsigned id) : id_(id) { }
|
||||||
|
|
||||||
operator unsigned (void) const { return id_; }
|
operator unsigned() const { return id_; }
|
||||||
|
|
||||||
LogVar& operator++ (void);
|
LogVar& operator++();
|
||||||
|
|
||||||
bool valid (void) const;
|
bool valid() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::ostream& operator<< (std::ostream&, const LogVar&);
|
friend std::ostream& operator<< (std::ostream&, const LogVar&);
|
||||||
@ -52,7 +52,7 @@ class LogVar {
|
|||||||
|
|
||||||
|
|
||||||
inline LogVar&
|
inline LogVar&
|
||||||
LogVar::operator++ (void)
|
LogVar::operator++()
|
||||||
{
|
{
|
||||||
assert (valid());
|
assert (valid());
|
||||||
id_ ++;
|
id_ ++;
|
||||||
@ -62,7 +62,7 @@ LogVar::operator++ (void)
|
|||||||
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
LogVar::valid (void) const
|
LogVar::valid() const
|
||||||
{
|
{
|
||||||
return id_ != Util::maxUnsigned();
|
return id_ != Util::maxUnsigned();
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ namespace LiftedUtils {
|
|||||||
|
|
||||||
Symbol getSymbol (const std::string&);
|
Symbol getSymbol (const std::string&);
|
||||||
|
|
||||||
void printSymbolDictionary (void);
|
void printSymbolDictionary();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,13 +116,13 @@ class Ground {
|
|||||||
Ground (Symbol f, const Symbols& args)
|
Ground (Symbol f, const Symbols& args)
|
||||||
: functor_(f), args_(args) { }
|
: functor_(f), args_(args) { }
|
||||||
|
|
||||||
Symbol functor (void) const { return functor_; }
|
Symbol functor() const { return functor_; }
|
||||||
|
|
||||||
Symbols args (void) const { return args_; }
|
Symbols args() const { return args_; }
|
||||||
|
|
||||||
size_t arity (void) const { return args_.size(); }
|
size_t arity() const { return args_.size(); }
|
||||||
|
|
||||||
bool isAtom (void) const { return args_.empty(); }
|
bool isAtom() const { return args_.empty(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::ostream& operator<< (std::ostream&, const Ground&);
|
friend std::ostream& operator<< (std::ostream&, const Ground&);
|
||||||
@ -145,9 +145,9 @@ class Substitution {
|
|||||||
|
|
||||||
bool containsReplacementFor (LogVar X) const;
|
bool containsReplacementFor (LogVar X) const;
|
||||||
|
|
||||||
size_t nrReplacements (void) const;
|
size_t nrReplacements() const;
|
||||||
|
|
||||||
LogVars getDiscardedLogVars (void) const;
|
LogVars getDiscardedLogVars() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::ostream& operator<< (
|
friend std::ostream& operator<< (
|
||||||
@ -199,7 +199,7 @@ Substitution::containsReplacementFor (LogVar X) const
|
|||||||
|
|
||||||
|
|
||||||
inline size_t
|
inline size_t
|
||||||
Substitution::nrReplacements (void) const
|
Substitution::nrReplacements() const
|
||||||
{
|
{
|
||||||
return subs_.size();
|
return subs_.size();
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,13 @@ namespace Horus {
|
|||||||
|
|
||||||
class LiftedOperator {
|
class LiftedOperator {
|
||||||
public:
|
public:
|
||||||
virtual ~LiftedOperator (void) { }
|
virtual ~LiftedOperator() { }
|
||||||
|
|
||||||
virtual double getLogCost (void) = 0;
|
virtual double getLogCost() = 0;
|
||||||
|
|
||||||
virtual void apply (void) = 0;
|
virtual void apply() = 0;
|
||||||
|
|
||||||
virtual std::string toString (void) = 0;
|
virtual std::string toString() = 0;
|
||||||
|
|
||||||
static std::vector<LiftedOperator*> getValidOps (
|
static std::vector<LiftedOperator*> getValidOps (
|
||||||
ParfactorList&, const Grounds&);
|
ParfactorList&, const Grounds&);
|
||||||
@ -48,13 +48,13 @@ class ProductOperator : public LiftedOperator {
|
|||||||
ParfactorList& pfList)
|
ParfactorList& pfList)
|
||||||
: g1_(g1), g2_(g2), pfList_(pfList) { }
|
: g1_(g1), g2_(g2), pfList_(pfList) { }
|
||||||
|
|
||||||
double getLogCost (void);
|
double getLogCost();
|
||||||
|
|
||||||
void apply (void);
|
void apply();
|
||||||
|
|
||||||
static std::vector<ProductOperator*> getValidOps (ParfactorList&);
|
static std::vector<ProductOperator*> getValidOps (ParfactorList&);
|
||||||
|
|
||||||
std::string toString (void);
|
std::string toString();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool validOp (Parfactor*, Parfactor*);
|
static bool validOp (Parfactor*, Parfactor*);
|
||||||
@ -73,14 +73,14 @@ class SumOutOperator : public LiftedOperator {
|
|||||||
SumOutOperator (PrvGroup group, ParfactorList& pfList)
|
SumOutOperator (PrvGroup group, ParfactorList& pfList)
|
||||||
: group_(group), pfList_(pfList) { }
|
: group_(group), pfList_(pfList) { }
|
||||||
|
|
||||||
double getLogCost (void);
|
double getLogCost();
|
||||||
|
|
||||||
void apply (void);
|
void apply();
|
||||||
|
|
||||||
static std::vector<SumOutOperator*> getValidOps (
|
static std::vector<SumOutOperator*> getValidOps (
|
||||||
ParfactorList&, const Grounds&);
|
ParfactorList&, const Grounds&);
|
||||||
|
|
||||||
std::string toString (void);
|
std::string toString();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool validOp (PrvGroup, ParfactorList&, const Grounds&);
|
static bool validOp (PrvGroup, ParfactorList&, const Grounds&);
|
||||||
@ -103,13 +103,13 @@ class CountingOperator : public LiftedOperator {
|
|||||||
ParfactorList& pfList)
|
ParfactorList& pfList)
|
||||||
: pfIter_(pfIter), X_(X), pfList_(pfList) { }
|
: pfIter_(pfIter), X_(X), pfList_(pfList) { }
|
||||||
|
|
||||||
double getLogCost (void);
|
double getLogCost();
|
||||||
|
|
||||||
void apply (void);
|
void apply();
|
||||||
|
|
||||||
static std::vector<CountingOperator*> getValidOps (ParfactorList&);
|
static std::vector<CountingOperator*> getValidOps (ParfactorList&);
|
||||||
|
|
||||||
std::string toString (void);
|
std::string toString();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool validOp (Parfactor*, LogVar);
|
static bool validOp (Parfactor*, LogVar);
|
||||||
@ -131,16 +131,16 @@ class GroundOperator : public LiftedOperator {
|
|||||||
ParfactorList& pfList)
|
ParfactorList& pfList)
|
||||||
: group_(group), lvIndex_(lvIndex), pfList_(pfList) { }
|
: group_(group), lvIndex_(lvIndex), pfList_(pfList) { }
|
||||||
|
|
||||||
double getLogCost (void);
|
double getLogCost();
|
||||||
|
|
||||||
void apply (void);
|
void apply();
|
||||||
|
|
||||||
static std::vector<GroundOperator*> getValidOps (ParfactorList&);
|
static std::vector<GroundOperator*> getValidOps (ParfactorList&);
|
||||||
|
|
||||||
std::string toString (void);
|
std::string toString();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::pair<PrvGroup, unsigned>> getAffectedFormulas (void);
|
std::vector<std::pair<PrvGroup, unsigned>> getAffectedFormulas();
|
||||||
|
|
||||||
PrvGroup group_;
|
PrvGroup group_;
|
||||||
unsigned lvIndex_;
|
unsigned lvIndex_;
|
||||||
@ -212,7 +212,7 @@ LiftedOperator::getParfactorsWithGroup (
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
ProductOperator::getLogCost (void)
|
ProductOperator::getLogCost()
|
||||||
{
|
{
|
||||||
return std::log (0.0);
|
return std::log (0.0);
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ ProductOperator::getLogCost (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ProductOperator::apply (void)
|
ProductOperator::apply()
|
||||||
{
|
{
|
||||||
Parfactor* g1 = *g1_;
|
Parfactor* g1 = *g1_;
|
||||||
Parfactor* g2 = *g2_;
|
Parfactor* g2 = *g2_;
|
||||||
@ -272,7 +272,7 @@ ProductOperator::getValidOps (ParfactorList& pfList)
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
ProductOperator::toString (void)
|
ProductOperator::toString()
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "just multiplicate " ;
|
ss << "just multiplicate " ;
|
||||||
@ -311,7 +311,7 @@ ProductOperator::validOp (Parfactor* g1, Parfactor* g2)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
SumOutOperator::getLogCost (void)
|
SumOutOperator::getLogCost()
|
||||||
{
|
{
|
||||||
TinySet<PrvGroup> groupSet;
|
TinySet<PrvGroup> groupSet;
|
||||||
ParfactorList::const_iterator pfIter = pfList_.begin();
|
ParfactorList::const_iterator pfIter = pfList_.begin();
|
||||||
@ -346,7 +346,7 @@ SumOutOperator::getLogCost (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SumOutOperator::apply (void)
|
SumOutOperator::apply()
|
||||||
{
|
{
|
||||||
std::vector<ParfactorList::iterator> iters;
|
std::vector<ParfactorList::iterator> iters;
|
||||||
iters = getParfactorsWithGroup (pfList_, group_);
|
iters = getParfactorsWithGroup (pfList_, group_);
|
||||||
@ -405,7 +405,7 @@ SumOutOperator::getValidOps (
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
SumOutOperator::toString (void)
|
SumOutOperator::toString()
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::vector<ParfactorList::iterator> pfIters;
|
std::vector<ParfactorList::iterator> pfIters;
|
||||||
@ -478,7 +478,7 @@ SumOutOperator::isToEliminate (
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
CountingOperator::getLogCost (void)
|
CountingOperator::getLogCost()
|
||||||
{
|
{
|
||||||
double cost = 0.0;
|
double cost = 0.0;
|
||||||
size_t fIdx = (*pfIter_)->indexOfLogVar (X_);
|
size_t fIdx = (*pfIter_)->indexOfLogVar (X_);
|
||||||
@ -513,7 +513,7 @@ CountingOperator::getLogCost (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CountingOperator::apply (void)
|
CountingOperator::apply()
|
||||||
{
|
{
|
||||||
if ((*pfIter_)->constr()->isCountNormalized (X_)) {
|
if ((*pfIter_)->constr()->isCountNormalized (X_)) {
|
||||||
(*pfIter_)->countConvert (X_);
|
(*pfIter_)->countConvert (X_);
|
||||||
@ -558,7 +558,7 @@ CountingOperator::getValidOps (ParfactorList& pfList)
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
CountingOperator::toString (void)
|
CountingOperator::toString()
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "count convert " << X_ << " in " ;
|
ss << "count convert " << X_ << " in " ;
|
||||||
@ -598,7 +598,7 @@ CountingOperator::validOp (Parfactor* g, LogVar X)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
GroundOperator::getLogCost (void)
|
GroundOperator::getLogCost()
|
||||||
{
|
{
|
||||||
std::vector<std::pair<PrvGroup, unsigned>> affectedFormulas;
|
std::vector<std::pair<PrvGroup, unsigned>> affectedFormulas;
|
||||||
affectedFormulas = getAffectedFormulas();
|
affectedFormulas = getAffectedFormulas();
|
||||||
@ -651,7 +651,7 @@ GroundOperator::getLogCost (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GroundOperator::apply (void)
|
GroundOperator::apply()
|
||||||
{
|
{
|
||||||
ParfactorList::iterator pfIter;
|
ParfactorList::iterator pfIter;
|
||||||
pfIter = getParfactorsWithGroup (pfList_, group_).front();
|
pfIter = getParfactorsWithGroup (pfList_, group_).front();
|
||||||
@ -708,7 +708,7 @@ GroundOperator::getValidOps (ParfactorList& pfList)
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
GroundOperator::toString (void)
|
GroundOperator::toString()
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::vector<ParfactorList::iterator> pfIters;
|
std::vector<ParfactorList::iterator> pfIters;
|
||||||
@ -736,7 +736,7 @@ GroundOperator::toString (void)
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::pair<PrvGroup, unsigned>>
|
std::vector<std::pair<PrvGroup, unsigned>>
|
||||||
GroundOperator::getAffectedFormulas (void)
|
GroundOperator::getAffectedFormulas()
|
||||||
{
|
{
|
||||||
std::vector<std::pair<PrvGroup, unsigned>> affectedFormulas;
|
std::vector<std::pair<PrvGroup, unsigned>> affectedFormulas;
|
||||||
affectedFormulas.push_back (std::make_pair (group_, lvIndex_));
|
affectedFormulas.push_back (std::make_pair (group_, lvIndex_));
|
||||||
@ -788,7 +788,7 @@ LiftedVe::solveQuery (const Grounds& query)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LiftedVe::printSolverFlags (void) const
|
LiftedVe::printSolverFlags() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "lve [" ;
|
ss << "lve [" ;
|
||||||
|
@ -17,7 +17,7 @@ class LiftedVe : public LiftedSolver {
|
|||||||
|
|
||||||
Params solveQuery (const Grounds&);
|
Params solveQuery (const Grounds&);
|
||||||
|
|
||||||
void printSolverFlags (void) const;
|
void printSolverFlags() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void runSolver (const Grounds&);
|
void runSolver (const Grounds&);
|
||||||
|
@ -226,7 +226,7 @@ Clause::isIpgLogVar (LogVar X) const
|
|||||||
|
|
||||||
|
|
||||||
TinySet<LiteralId>
|
TinySet<LiteralId>
|
||||||
Clause::lidSet (void) const
|
Clause::lidSet() const
|
||||||
{
|
{
|
||||||
TinySet<LiteralId> lidSet;
|
TinySet<LiteralId> lidSet;
|
||||||
for (size_t i = 0; i < literals_.size(); i++) {
|
for (size_t i = 0; i < literals_.size(); i++) {
|
||||||
@ -238,7 +238,7 @@ Clause::lidSet (void) const
|
|||||||
|
|
||||||
|
|
||||||
LogVarSet
|
LogVarSet
|
||||||
Clause::ipgCandidates (void) const
|
Clause::ipgCandidates() const
|
||||||
{
|
{
|
||||||
LogVarSet candidates;
|
LogVarSet candidates;
|
||||||
LogVarSet allLvs = constr_.logVarSet();
|
LogVarSet allLvs = constr_.logVarSet();
|
||||||
@ -396,7 +396,7 @@ operator<< (std::ostream& os, const LitLvTypes& lit)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LitLvTypes::setAllFullLogVars (void)
|
LitLvTypes::setAllFullLogVars()
|
||||||
{
|
{
|
||||||
std::fill (lvTypes_.begin(), lvTypes_.end(), LogVarType::fullLvt);
|
std::fill (lvTypes_.begin(), lvTypes_.end(), LogVarType::fullLvt);
|
||||||
}
|
}
|
||||||
@ -470,7 +470,7 @@ LiftedWCNF::LiftedWCNF (const ParfactorList& pfList)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
LiftedWCNF::~LiftedWCNF (void)
|
LiftedWCNF::~LiftedWCNF()
|
||||||
{
|
{
|
||||||
Clause::deleteClauses (clauses_);
|
Clause::deleteClauses (clauses_);
|
||||||
}
|
}
|
||||||
@ -624,7 +624,7 @@ LiftedWCNF::addParameterClauses (const ParfactorList& pfList)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LiftedWCNF::printFormulaIndicators (void) const
|
LiftedWCNF::printFormulaIndicators() const
|
||||||
{
|
{
|
||||||
if (map_.empty()) {
|
if (map_.empty()) {
|
||||||
return;
|
return;
|
||||||
@ -653,7 +653,7 @@ LiftedWCNF::printFormulaIndicators (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LiftedWCNF::printWeights (void) const
|
LiftedWCNF::printWeights() const
|
||||||
{
|
{
|
||||||
std::unordered_map<LiteralId, std::pair<double,double>>::const_iterator it
|
std::unordered_map<LiteralId, std::pair<double,double>>::const_iterator it
|
||||||
= weights_.begin();
|
= weights_.begin();
|
||||||
@ -668,7 +668,7 @@ LiftedWCNF::printWeights (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LiftedWCNF::printClauses (void) const
|
LiftedWCNF::printClauses() const
|
||||||
{
|
{
|
||||||
Clause::printClauses (clauses_);
|
Clause::printClauses (clauses_);
|
||||||
}
|
}
|
||||||
|
@ -33,19 +33,19 @@ class Literal {
|
|||||||
Literal (const Literal& lit, bool negated)
|
Literal (const Literal& lit, bool negated)
|
||||||
: lid_(lit.lid_), logVars_(lit.logVars_), negated_(negated) { }
|
: lid_(lit.lid_), logVars_(lit.logVars_), negated_(negated) { }
|
||||||
|
|
||||||
LiteralId lid (void) const { return lid_; }
|
LiteralId lid() const { return lid_; }
|
||||||
|
|
||||||
LogVars logVars (void) const { return logVars_; }
|
LogVars logVars() const { return logVars_; }
|
||||||
|
|
||||||
size_t nrLogVars (void) const { return logVars_.size(); }
|
size_t nrLogVars() const { return logVars_.size(); }
|
||||||
|
|
||||||
LogVarSet logVarSet (void) const { return LogVarSet (logVars_); }
|
LogVarSet logVarSet() const { return LogVarSet (logVars_); }
|
||||||
|
|
||||||
void complement (void) { negated_ = !negated_; }
|
void complement() { negated_ = !negated_; }
|
||||||
|
|
||||||
bool isPositive (void) const { return negated_ == false; }
|
bool isPositive() const { return negated_ == false; }
|
||||||
|
|
||||||
bool isNegative (void) const { return negated_; }
|
bool isNegative() const { return negated_; }
|
||||||
|
|
||||||
bool isGround (ConstraintTree constr, const LogVarSet& ipgLogVars) const;
|
bool isGround (ConstraintTree constr, const LogVarSet& ipgLogVars) const;
|
||||||
|
|
||||||
@ -77,19 +77,19 @@ class Clause {
|
|||||||
|
|
||||||
void addLiteral (const Literal& l) { literals_.push_back (l); }
|
void addLiteral (const Literal& l) { literals_.push_back (l); }
|
||||||
|
|
||||||
const Literals& literals (void) const { return literals_; }
|
const Literals& literals() const { return literals_; }
|
||||||
|
|
||||||
Literals& literals (void) { return literals_; }
|
Literals& literals() { return literals_; }
|
||||||
|
|
||||||
size_t nrLiterals (void) const { return literals_.size(); }
|
size_t nrLiterals() const { return literals_.size(); }
|
||||||
|
|
||||||
const ConstraintTree& constr (void) const { return constr_; }
|
const ConstraintTree& constr() const { return constr_; }
|
||||||
|
|
||||||
ConstraintTree constr (void) { return constr_; }
|
ConstraintTree constr() { return constr_; }
|
||||||
|
|
||||||
bool isUnit (void) const { return literals_.size() == 1; }
|
bool isUnit() const { return literals_.size() == 1; }
|
||||||
|
|
||||||
LogVarSet ipgLogVars (void) const { return ipgLvs_; }
|
LogVarSet ipgLogVars() const { return ipgLvs_; }
|
||||||
|
|
||||||
void addIpgLogVar (LogVar X) { ipgLvs_.insert (X); }
|
void addIpgLogVar (LogVar X) { ipgLvs_.insert (X); }
|
||||||
|
|
||||||
@ -97,13 +97,13 @@ class Clause {
|
|||||||
|
|
||||||
void addNegCountedLogVar (LogVar X) { negCountedLvs_.insert (X); }
|
void addNegCountedLogVar (LogVar X) { negCountedLvs_.insert (X); }
|
||||||
|
|
||||||
LogVarSet posCountedLogVars (void) const { return posCountedLvs_; }
|
LogVarSet posCountedLogVars() const { return posCountedLvs_; }
|
||||||
|
|
||||||
LogVarSet negCountedLogVars (void) const { return negCountedLvs_; }
|
LogVarSet negCountedLogVars() const { return negCountedLvs_; }
|
||||||
|
|
||||||
unsigned nrPosCountedLogVars (void) const { return posCountedLvs_.size(); }
|
unsigned nrPosCountedLogVars() const { return posCountedLvs_.size(); }
|
||||||
|
|
||||||
unsigned nrNegCountedLogVars (void) const { return negCountedLvs_.size(); }
|
unsigned nrNegCountedLogVars() const { return negCountedLvs_.size(); }
|
||||||
|
|
||||||
void addLiteralComplemented (const Literal& lit);
|
void addLiteralComplemented (const Literal& lit);
|
||||||
|
|
||||||
@ -127,9 +127,9 @@ class Clause {
|
|||||||
|
|
||||||
bool isIpgLogVar (LogVar X) const;
|
bool isIpgLogVar (LogVar X) const;
|
||||||
|
|
||||||
TinySet<LiteralId> lidSet (void) const;
|
TinySet<LiteralId> lidSet() const;
|
||||||
|
|
||||||
LogVarSet ipgCandidates (void) const;
|
LogVarSet ipgCandidates() const;
|
||||||
|
|
||||||
LogVarTypes logVarTypes (size_t litIdx) const;
|
LogVarTypes logVarTypes (size_t litIdx) const;
|
||||||
|
|
||||||
@ -167,11 +167,11 @@ class LitLvTypes {
|
|||||||
LitLvTypes (LiteralId lid, const LogVarTypes& lvTypes) :
|
LitLvTypes (LiteralId lid, const LogVarTypes& lvTypes) :
|
||||||
lid_(lid), lvTypes_(lvTypes) { }
|
lid_(lid), lvTypes_(lvTypes) { }
|
||||||
|
|
||||||
LiteralId lid (void) const { return lid_; }
|
LiteralId lid() const { return lid_; }
|
||||||
|
|
||||||
const LogVarTypes& logVarTypes (void) const { return lvTypes_; }
|
const LogVarTypes& logVarTypes() const { return lvTypes_; }
|
||||||
|
|
||||||
void setAllFullLogVars (void);
|
void setAllFullLogVars();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend std::ostream& operator<< (std::ostream&, const LitLvTypes&);
|
friend std::ostream& operator<< (std::ostream&, const LitLvTypes&);
|
||||||
@ -206,9 +206,9 @@ class LiftedWCNF {
|
|||||||
public:
|
public:
|
||||||
LiftedWCNF (const ParfactorList& pfList);
|
LiftedWCNF (const ParfactorList& pfList);
|
||||||
|
|
||||||
~LiftedWCNF (void);
|
~LiftedWCNF();
|
||||||
|
|
||||||
const Clauses& clauses (void) const { return clauses_; }
|
const Clauses& clauses() const { return clauses_; }
|
||||||
|
|
||||||
void addWeight (LiteralId lid, double posW, double negW);
|
void addWeight (LiteralId lid, double posW, double negW);
|
||||||
|
|
||||||
@ -220,11 +220,11 @@ class LiftedWCNF {
|
|||||||
|
|
||||||
Clause* createClause (LiteralId lid) const;
|
Clause* createClause (LiteralId lid) const;
|
||||||
|
|
||||||
void printFormulaIndicators (void) const;
|
void printFormulaIndicators() const;
|
||||||
|
|
||||||
void printWeights (void) const;
|
void printWeights() const;
|
||||||
|
|
||||||
void printClauses (void) const;
|
void printClauses() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LiteralId getLiteralId (PrvGroup prvGroup, unsigned range);
|
LiteralId getLiteralId (PrvGroup prvGroup, unsigned range);
|
||||||
|
@ -91,7 +91,7 @@ Parfactor::Parfactor (const Parfactor& g)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Parfactor::~Parfactor (void)
|
Parfactor::~Parfactor()
|
||||||
{
|
{
|
||||||
delete constr_;
|
delete constr_;
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ Parfactor::~Parfactor (void)
|
|||||||
|
|
||||||
|
|
||||||
LogVarSet
|
LogVarSet
|
||||||
Parfactor::countedLogVars (void) const
|
Parfactor::countedLogVars() const
|
||||||
{
|
{
|
||||||
LogVarSet set;
|
LogVarSet set;
|
||||||
for (size_t i = 0; i < args_.size(); i++) {
|
for (size_t i = 0; i < args_.size(); i++) {
|
||||||
@ -113,7 +113,7 @@ Parfactor::countedLogVars (void) const
|
|||||||
|
|
||||||
|
|
||||||
LogVarSet
|
LogVarSet
|
||||||
Parfactor::uncountedLogVars (void) const
|
Parfactor::uncountedLogVars() const
|
||||||
{
|
{
|
||||||
return constr_->logVarSet() - countedLogVars();
|
return constr_->logVarSet() - countedLogVars();
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ Parfactor::uncountedLogVars (void) const
|
|||||||
|
|
||||||
|
|
||||||
LogVarSet
|
LogVarSet
|
||||||
Parfactor::elimLogVars (void) const
|
Parfactor::elimLogVars() const
|
||||||
{
|
{
|
||||||
LogVarSet requiredToElim = constr_->logVarSet();
|
LogVarSet requiredToElim = constr_->logVarSet();
|
||||||
requiredToElim -= constr_->singletons();
|
requiredToElim -= constr_->singletons();
|
||||||
@ -398,7 +398,7 @@ Parfactor::absorveEvidence (const ProbFormula& formula, unsigned evidence)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Parfactor::setNewGroups (void)
|
Parfactor::setNewGroups()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < args_.size(); i++) {
|
for (size_t i = 0; i < args_.size(); i++) {
|
||||||
args_[i].setGroup (ProbFormula::getNewGroup());
|
args_[i].setGroup (ProbFormula::getNewGroup());
|
||||||
@ -573,7 +573,7 @@ Parfactor::nrFormulasWithGroup (PrvGroup group) const
|
|||||||
|
|
||||||
|
|
||||||
std::vector<PrvGroup>
|
std::vector<PrvGroup>
|
||||||
Parfactor::getAllGroups (void) const
|
Parfactor::getAllGroups() const
|
||||||
{
|
{
|
||||||
std::vector<PrvGroup> groups (args_.size());
|
std::vector<PrvGroup> groups (args_.size());
|
||||||
for (size_t i = 0; i < args_.size(); i++) {
|
for (size_t i = 0; i < args_.size(); i++) {
|
||||||
@ -585,7 +585,7 @@ Parfactor::getAllGroups (void) const
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Parfactor::getLabel (void) const
|
Parfactor::getLabel() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "phi(" ;
|
ss << "phi(" ;
|
||||||
@ -642,7 +642,7 @@ Parfactor::print (bool printParams) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Parfactor::printParameters (void) const
|
Parfactor::printParameters() const
|
||||||
{
|
{
|
||||||
std::vector<std::string> jointStrings;
|
std::vector<std::string> jointStrings;
|
||||||
Indexer indexer (ranges_);
|
Indexer indexer (ranges_);
|
||||||
@ -676,7 +676,7 @@ Parfactor::printParameters (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Parfactor::printProjections (void) const
|
Parfactor::printProjections() const
|
||||||
{
|
{
|
||||||
ConstraintTree copy (*constr_);
|
ConstraintTree copy (*constr_);
|
||||||
|
|
||||||
@ -768,7 +768,7 @@ Parfactor::simplifyCountingFormulas (size_t fIdx)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Parfactor::simplifyGrounds (void)
|
Parfactor::simplifyGrounds()
|
||||||
{
|
{
|
||||||
if (args_.size() == 1) {
|
if (args_.size() == 1) {
|
||||||
return;
|
return;
|
||||||
|
@ -24,21 +24,21 @@ class Parfactor : public TFactor<ProbFormula> {
|
|||||||
|
|
||||||
Parfactor (const Parfactor&);
|
Parfactor (const Parfactor&);
|
||||||
|
|
||||||
~Parfactor (void);
|
~Parfactor();
|
||||||
|
|
||||||
ConstraintTree* constr (void) { return constr_; }
|
ConstraintTree* constr() { return constr_; }
|
||||||
|
|
||||||
const ConstraintTree* constr (void) const { return constr_; }
|
const ConstraintTree* constr() const { return constr_; }
|
||||||
|
|
||||||
const LogVars& logVars (void) const { return constr_->logVars(); }
|
const LogVars& logVars() const { return constr_->logVars(); }
|
||||||
|
|
||||||
const LogVarSet& logVarSet (void) const { return constr_->logVarSet(); }
|
const LogVarSet& logVarSet() const { return constr_->logVarSet(); }
|
||||||
|
|
||||||
LogVarSet countedLogVars (void) const;
|
LogVarSet countedLogVars() const;
|
||||||
|
|
||||||
LogVarSet uncountedLogVars (void) const;
|
LogVarSet uncountedLogVars() const;
|
||||||
|
|
||||||
LogVarSet elimLogVars (void) const;
|
LogVarSet elimLogVars() const;
|
||||||
|
|
||||||
LogVarSet exclusiveLogVars (size_t fIdx) const;
|
LogVarSet exclusiveLogVars (size_t fIdx) const;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ class Parfactor : public TFactor<ProbFormula> {
|
|||||||
|
|
||||||
void absorveEvidence (const ProbFormula&, unsigned);
|
void absorveEvidence (const ProbFormula&, unsigned);
|
||||||
|
|
||||||
void setNewGroups (void);
|
void setNewGroups();
|
||||||
|
|
||||||
void applySubstitution (const Substitution&);
|
void applySubstitution (const Substitution&);
|
||||||
|
|
||||||
@ -82,17 +82,17 @@ class Parfactor : public TFactor<ProbFormula> {
|
|||||||
|
|
||||||
unsigned nrFormulasWithGroup (PrvGroup) const;
|
unsigned nrFormulasWithGroup (PrvGroup) const;
|
||||||
|
|
||||||
std::vector<PrvGroup> getAllGroups (void) const;
|
std::vector<PrvGroup> getAllGroups() const;
|
||||||
|
|
||||||
void print (bool = false) const;
|
void print (bool = false) const;
|
||||||
|
|
||||||
void printParameters (void) const;
|
void printParameters() const;
|
||||||
|
|
||||||
void printProjections (void) const;
|
void printProjections() const;
|
||||||
|
|
||||||
std::string getLabel (void) const;
|
std::string getLabel() const;
|
||||||
|
|
||||||
void simplifyGrounds (void);
|
void simplifyGrounds();
|
||||||
|
|
||||||
static bool canMultiply (Parfactor*, Parfactor*);
|
static bool canMultiply (Parfactor*, Parfactor*);
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ ParfactorList::ParfactorList (const Parfactors& pfs)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ParfactorList::~ParfactorList (void)
|
ParfactorList::~ParfactorList()
|
||||||
{
|
{
|
||||||
ParfactorList::const_iterator it = pfList_.begin();
|
ParfactorList::const_iterator it = pfList_.begin();
|
||||||
while (it != pfList_.end()) {
|
while (it != pfList_.end()) {
|
||||||
@ -97,7 +97,7 @@ ParfactorList::removeAndDelete (std::list<Parfactor*>::iterator it)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ParfactorList::isAllShattered (void) const
|
ParfactorList::isAllShattered() const
|
||||||
{
|
{
|
||||||
if (pfList_.size() <= 1) {
|
if (pfList_.size() <= 1) {
|
||||||
return true;
|
return true;
|
||||||
@ -119,7 +119,7 @@ ParfactorList::isAllShattered (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ParfactorList::print (void) const
|
ParfactorList::print() const
|
||||||
{
|
{
|
||||||
struct sortByParams {
|
struct sortByParams {
|
||||||
bool operator() (const Parfactor* pf1, const Parfactor* pf2)
|
bool operator() (const Parfactor* pf1, const Parfactor* pf2)
|
||||||
|
@ -14,31 +14,31 @@ class Parfactor;
|
|||||||
|
|
||||||
class ParfactorList {
|
class ParfactorList {
|
||||||
public:
|
public:
|
||||||
ParfactorList (void) { }
|
ParfactorList() { }
|
||||||
|
|
||||||
ParfactorList (const ParfactorList&);
|
ParfactorList (const ParfactorList&);
|
||||||
|
|
||||||
ParfactorList (const Parfactors&);
|
ParfactorList (const Parfactors&);
|
||||||
|
|
||||||
~ParfactorList (void);
|
~ParfactorList();
|
||||||
|
|
||||||
const std::list<Parfactor*>& parfactors (void) const { return pfList_; }
|
const std::list<Parfactor*>& parfactors() const { return pfList_; }
|
||||||
|
|
||||||
void clear (void) { pfList_.clear(); }
|
void clear() { pfList_.clear(); }
|
||||||
|
|
||||||
size_t size (void) const { return pfList_.size(); }
|
size_t size() const { return pfList_.size(); }
|
||||||
|
|
||||||
typedef std::list<Parfactor*>::iterator iterator;
|
typedef std::list<Parfactor*>::iterator iterator;
|
||||||
|
|
||||||
iterator begin (void) { return pfList_.begin(); }
|
iterator begin() { return pfList_.begin(); }
|
||||||
|
|
||||||
iterator end (void) { return pfList_.end(); }
|
iterator end() { return pfList_.end(); }
|
||||||
|
|
||||||
typedef std::list<Parfactor*>::const_iterator const_iterator;
|
typedef std::list<Parfactor*>::const_iterator const_iterator;
|
||||||
|
|
||||||
const_iterator begin (void) const { return pfList_.begin(); }
|
const_iterator begin() const { return pfList_.begin(); }
|
||||||
|
|
||||||
const_iterator end (void) const { return pfList_.end(); }
|
const_iterator end() const { return pfList_.end(); }
|
||||||
|
|
||||||
void add (Parfactor* pf);
|
void add (Parfactor* pf);
|
||||||
|
|
||||||
@ -55,9 +55,9 @@ class ParfactorList {
|
|||||||
std::list<Parfactor*>::iterator removeAndDelete (
|
std::list<Parfactor*>::iterator removeAndDelete (
|
||||||
std::list<Parfactor*>::iterator);
|
std::list<Parfactor*>::iterator);
|
||||||
|
|
||||||
bool isAllShattered (void) const;
|
bool isAllShattered() const;
|
||||||
|
|
||||||
void print (void) const;
|
void print() const;
|
||||||
|
|
||||||
ParfactorList& operator= (const ParfactorList& pfList);
|
ParfactorList& operator= (const ParfactorList& pfList);
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ ProbFormula::indexOf (LogVar X) const
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ProbFormula::isAtom (void) const
|
ProbFormula::isAtom() const
|
||||||
{
|
{
|
||||||
return logVars_.empty();
|
return logVars_.empty();
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ ProbFormula::isAtom (void) const
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ProbFormula::isCounting (void) const
|
ProbFormula::isCounting() const
|
||||||
{
|
{
|
||||||
return countedLogVar_.valid();
|
return countedLogVar_.valid();
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ ProbFormula::isCounting (void) const
|
|||||||
|
|
||||||
|
|
||||||
LogVar
|
LogVar
|
||||||
ProbFormula::countedLogVar (void) const
|
ProbFormula::countedLogVar() const
|
||||||
{
|
{
|
||||||
assert (isCounting());
|
assert (isCounting());
|
||||||
return countedLogVar_;
|
return countedLogVar_;
|
||||||
@ -78,7 +78,7 @@ ProbFormula::setCountedLogVar (LogVar lv)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ProbFormula::clearCountedLogVar (void)
|
ProbFormula::clearCountedLogVar()
|
||||||
{
|
{
|
||||||
countedLogVar_ = LogVar();
|
countedLogVar_ = LogVar();
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ operator<< (std::ostream& os, const ProbFormula& f)
|
|||||||
|
|
||||||
|
|
||||||
PrvGroup
|
PrvGroup
|
||||||
ProbFormula::getNewGroup (void)
|
ProbFormula::getNewGroup()
|
||||||
{
|
{
|
||||||
freeGroup_ ++;
|
freeGroup_ ++;
|
||||||
assert (freeGroup_ != std::numeric_limits<PrvGroup>::max());
|
assert (freeGroup_ != std::numeric_limits<PrvGroup>::max());
|
||||||
|
@ -24,19 +24,19 @@ class ProbFormula {
|
|||||||
: functor_(f), range_(r),
|
: functor_(f), range_(r),
|
||||||
group_(std::numeric_limits<PrvGroup>::max()) { }
|
group_(std::numeric_limits<PrvGroup>::max()) { }
|
||||||
|
|
||||||
Symbol functor (void) const { return functor_; }
|
Symbol functor() const { return functor_; }
|
||||||
|
|
||||||
unsigned arity (void) const { return logVars_.size(); }
|
unsigned arity() const { return logVars_.size(); }
|
||||||
|
|
||||||
unsigned range (void) const { return range_; }
|
unsigned range() const { return range_; }
|
||||||
|
|
||||||
LogVars& logVars (void) { return logVars_; }
|
LogVars& logVars() { return logVars_; }
|
||||||
|
|
||||||
const LogVars& logVars (void) const { return logVars_; }
|
const LogVars& logVars() const { return logVars_; }
|
||||||
|
|
||||||
LogVarSet logVarSet (void) const { return LogVarSet (logVars_); }
|
LogVarSet logVarSet() const { return LogVarSet (logVars_); }
|
||||||
|
|
||||||
PrvGroup group (void) const { return group_; }
|
PrvGroup group() const { return group_; }
|
||||||
|
|
||||||
void setGroup (PrvGroup g) { group_ = g; }
|
void setGroup (PrvGroup g) { group_ = g; }
|
||||||
|
|
||||||
@ -48,19 +48,19 @@ class ProbFormula {
|
|||||||
|
|
||||||
size_t indexOf (LogVar) const;
|
size_t indexOf (LogVar) const;
|
||||||
|
|
||||||
bool isAtom (void) const;
|
bool isAtom() const;
|
||||||
|
|
||||||
bool isCounting (void) const;
|
bool isCounting() const;
|
||||||
|
|
||||||
LogVar countedLogVar (void) const;
|
LogVar countedLogVar() const;
|
||||||
|
|
||||||
void setCountedLogVar (LogVar);
|
void setCountedLogVar (LogVar);
|
||||||
|
|
||||||
void clearCountedLogVar (void);
|
void clearCountedLogVar();
|
||||||
|
|
||||||
void rename (LogVar, LogVar);
|
void rename (LogVar, LogVar);
|
||||||
|
|
||||||
static PrvGroup getNewGroup (void);
|
static PrvGroup getNewGroup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend bool operator== (
|
friend bool operator== (
|
||||||
@ -86,17 +86,17 @@ class ObservedFormula {
|
|||||||
|
|
||||||
ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple);
|
ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple);
|
||||||
|
|
||||||
Symbol functor (void) const { return functor_; }
|
Symbol functor() const { return functor_; }
|
||||||
|
|
||||||
unsigned arity (void) const { return arity_; }
|
unsigned arity() const { return arity_; }
|
||||||
|
|
||||||
unsigned evidence (void) const { return evidence_; }
|
unsigned evidence() const { return evidence_; }
|
||||||
|
|
||||||
void setEvidence (unsigned ev) { evidence_ = ev; }
|
void setEvidence (unsigned ev) { evidence_ = ev; }
|
||||||
|
|
||||||
ConstraintTree& constr (void) { return constr_; }
|
ConstraintTree& constr() { return constr_; }
|
||||||
|
|
||||||
bool isAtom (void) const { return arity_ == 0; }
|
bool isAtom() const { return arity_ == 0; }
|
||||||
|
|
||||||
void addTuple (const Tuple& tuple) { constr_.addTuple (tuple); }
|
void addTuple (const Tuple& tuple) { constr_.addTuple (tuple); }
|
||||||
|
|
||||||
|
@ -62,33 +62,33 @@ class TinySet {
|
|||||||
|
|
||||||
T& operator[] (typename std::vector<T>::size_type i);
|
T& operator[] (typename std::vector<T>::size_type i);
|
||||||
|
|
||||||
T front (void) const;
|
T front() const;
|
||||||
|
|
||||||
T& front (void);
|
T& front();
|
||||||
|
|
||||||
T back (void) const;
|
T back() const;
|
||||||
|
|
||||||
T& back (void);
|
T& back();
|
||||||
|
|
||||||
const std::vector<T>& elements (void) const;
|
const std::vector<T>& elements() const;
|
||||||
|
|
||||||
bool empty (void) const;
|
bool empty() const;
|
||||||
|
|
||||||
typename std::vector<T>::size_type size (void) const;
|
typename std::vector<T>::size_type size() const;
|
||||||
|
|
||||||
void clear (void);
|
void clear();
|
||||||
|
|
||||||
void reserve (typename std::vector<T>::size_type size);
|
void reserve (typename std::vector<T>::size_type size);
|
||||||
|
|
||||||
iterator begin (void) { return vec_.begin(); }
|
iterator begin() { return vec_.begin(); }
|
||||||
iterator end (void) { return vec_.end(); }
|
iterator end () { return vec_.end(); }
|
||||||
const_iterator begin (void) const { return vec_.begin(); }
|
const_iterator begin() const { return vec_.begin(); }
|
||||||
const_iterator end (void) const { return vec_.end(); }
|
const_iterator end () const { return vec_.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
iterator unique_cmp (iterator first, iterator last);
|
iterator unique_cmp (iterator first, iterator last);
|
||||||
|
|
||||||
bool consistent (void) const;
|
bool consistent() const;
|
||||||
|
|
||||||
friend bool operator== (const TinySet& s1, const TinySet& s2)
|
friend bool operator== (const TinySet& s1, const TinySet& s2)
|
||||||
{
|
{
|
||||||
@ -303,7 +303,7 @@ TinySet<T,C>::operator[] (typename std::vector<T>::size_type i)
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline T
|
template <typename T, typename C> inline T
|
||||||
TinySet<T,C>::front (void) const
|
TinySet<T,C>::front() const
|
||||||
{
|
{
|
||||||
return vec_.front();
|
return vec_.front();
|
||||||
}
|
}
|
||||||
@ -311,7 +311,7 @@ TinySet<T,C>::front (void) const
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline T&
|
template <typename T, typename C> inline T&
|
||||||
TinySet<T,C>::front (void)
|
TinySet<T,C>::front()
|
||||||
{
|
{
|
||||||
return vec_.front();
|
return vec_.front();
|
||||||
}
|
}
|
||||||
@ -319,7 +319,7 @@ TinySet<T,C>::front (void)
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline T
|
template <typename T, typename C> inline T
|
||||||
TinySet<T,C>::back (void) const
|
TinySet<T,C>::back() const
|
||||||
{
|
{
|
||||||
return vec_.back();
|
return vec_.back();
|
||||||
}
|
}
|
||||||
@ -327,7 +327,7 @@ TinySet<T,C>::back (void) const
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline T&
|
template <typename T, typename C> inline T&
|
||||||
TinySet<T,C>::back (void)
|
TinySet<T,C>::back()
|
||||||
{
|
{
|
||||||
return vec_.back();
|
return vec_.back();
|
||||||
}
|
}
|
||||||
@ -335,7 +335,7 @@ TinySet<T,C>::back (void)
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline const std::vector<T>&
|
template <typename T, typename C> inline const std::vector<T>&
|
||||||
TinySet<T,C>::elements (void) const
|
TinySet<T,C>::elements() const
|
||||||
{
|
{
|
||||||
return vec_;
|
return vec_;
|
||||||
}
|
}
|
||||||
@ -343,7 +343,7 @@ TinySet<T,C>::elements (void) const
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline bool
|
template <typename T, typename C> inline bool
|
||||||
TinySet<T,C>::empty (void) const
|
TinySet<T,C>::empty() const
|
||||||
{
|
{
|
||||||
return vec_.empty();
|
return vec_.empty();
|
||||||
}
|
}
|
||||||
@ -351,7 +351,7 @@ TinySet<T,C>::empty (void) const
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline typename std::vector<T>::size_type
|
template <typename T, typename C> inline typename std::vector<T>::size_type
|
||||||
TinySet<T,C>::size (void) const
|
TinySet<T,C>::size() const
|
||||||
{
|
{
|
||||||
return vec_.size();
|
return vec_.size();
|
||||||
}
|
}
|
||||||
@ -359,7 +359,7 @@ TinySet<T,C>::size (void) const
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline void
|
template <typename T, typename C> inline void
|
||||||
TinySet<T,C>::clear (void)
|
TinySet<T,C>::clear()
|
||||||
{
|
{
|
||||||
vec_.clear();
|
vec_.clear();
|
||||||
}
|
}
|
||||||
@ -392,7 +392,7 @@ TinySet<T,C>::unique_cmp (iterator first, iterator last)
|
|||||||
|
|
||||||
|
|
||||||
template <typename T, typename C> inline bool
|
template <typename T, typename C> inline bool
|
||||||
TinySet<T,C>::consistent (void) const
|
TinySet<T,C>::consistent() const
|
||||||
{
|
{
|
||||||
typename std::vector<T>::size_type i;
|
typename std::vector<T>::size_type i;
|
||||||
for (i = 0; i < vec_.size() - 1; i++) {
|
for (i = 0; i < vec_.size() - 1; i++) {
|
||||||
|
@ -68,7 +68,7 @@ toString (const bool&);
|
|||||||
|
|
||||||
double logSum (double, double);
|
double logSum (double, double);
|
||||||
|
|
||||||
unsigned maxUnsigned (void);
|
unsigned maxUnsigned();
|
||||||
|
|
||||||
unsigned stringToUnsigned (std::string);
|
unsigned stringToUnsigned (std::string);
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ Util::logSum (double x, double y)
|
|||||||
|
|
||||||
|
|
||||||
inline unsigned
|
inline unsigned
|
||||||
Util::maxUnsigned (void)
|
Util::maxUnsigned()
|
||||||
{
|
{
|
||||||
return std::numeric_limits<unsigned>::max();
|
return std::numeric_limits<unsigned>::max();
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ Var::setEvidence (int evidence)
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Var::label (void) const
|
Var::label() const
|
||||||
{
|
{
|
||||||
if (Var::varsHaveInfo()) {
|
if (Var::varsHaveInfo()) {
|
||||||
return Var::getVarInfo (varId_).label;
|
return Var::getVarInfo (varId_).label;
|
||||||
@ -61,7 +61,7 @@ Var::label (void) const
|
|||||||
|
|
||||||
|
|
||||||
States
|
States
|
||||||
Var::states (void) const
|
Var::states() const
|
||||||
{
|
{
|
||||||
if (Var::varsHaveInfo()) {
|
if (Var::varsHaveInfo()) {
|
||||||
return Var::getVarInfo (varId_).states;
|
return Var::getVarInfo (varId_).states;
|
||||||
@ -97,7 +97,7 @@ Var::getVarInfo (VarId vid)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Var::varsHaveInfo (void)
|
Var::varsHaveInfo()
|
||||||
{
|
{
|
||||||
return varsInfo_.empty() == false;
|
return varsInfo_.empty() == false;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ Var::varsHaveInfo (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Var::clearVarsInfo (void)
|
Var::clearVarsInfo()
|
||||||
{
|
{
|
||||||
varsInfo_.clear();
|
varsInfo_.clear();
|
||||||
}
|
}
|
||||||
|
@ -26,21 +26,21 @@ class Var {
|
|||||||
|
|
||||||
Var (VarId, unsigned, int = Constants::unobserved);
|
Var (VarId, unsigned, int = Constants::unobserved);
|
||||||
|
|
||||||
virtual ~Var (void) { };
|
virtual ~Var() { };
|
||||||
|
|
||||||
VarId varId (void) const { return varId_; }
|
VarId varId() const { return varId_; }
|
||||||
|
|
||||||
unsigned range (void) const { return range_; }
|
unsigned range() const { return range_; }
|
||||||
|
|
||||||
int getEvidence (void) const { return evidence_; }
|
int getEvidence() const { return evidence_; }
|
||||||
|
|
||||||
size_t getIndex (void) const { return index_; }
|
size_t getIndex() const { return index_; }
|
||||||
|
|
||||||
void setIndex (size_t idx) { index_ = idx; }
|
void setIndex (size_t idx) { index_ = idx; }
|
||||||
|
|
||||||
bool hasEvidence (void) const;
|
bool hasEvidence() const;
|
||||||
|
|
||||||
operator size_t (void) const;
|
operator size_t() const;
|
||||||
|
|
||||||
bool operator== (const Var& var) const;
|
bool operator== (const Var& var) const;
|
||||||
|
|
||||||
@ -50,18 +50,18 @@ class Var {
|
|||||||
|
|
||||||
void setEvidence (int);
|
void setEvidence (int);
|
||||||
|
|
||||||
std::string label (void) const;
|
std::string label() const;
|
||||||
|
|
||||||
States states (void) const;
|
States states() const;
|
||||||
|
|
||||||
static void addVarInfo (
|
static void addVarInfo (
|
||||||
VarId vid, std::string label, const States& states);
|
VarId vid, std::string label, const States& states);
|
||||||
|
|
||||||
static VarInfo getVarInfo (VarId vid);
|
static VarInfo getVarInfo (VarId vid);
|
||||||
|
|
||||||
static bool varsHaveInfo (void);
|
static bool varsHaveInfo();
|
||||||
|
|
||||||
static void clearVarsInfo (void);
|
static void clearVarsInfo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VarId varId_;
|
VarId varId_;
|
||||||
@ -77,7 +77,7 @@ class Var {
|
|||||||
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
Var::hasEvidence (void) const
|
Var::hasEvidence() const
|
||||||
{
|
{
|
||||||
return evidence_ != Constants::unobserved;
|
return evidence_ != Constants::unobserved;
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ Var::hasEvidence (void) const
|
|||||||
|
|
||||||
|
|
||||||
inline
|
inline
|
||||||
Var::operator size_t (void) const
|
Var::operator size_t() const
|
||||||
{
|
{
|
||||||
return index_;
|
return index_;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ VarElim::solveQuery (VarIds queryVids)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VarElim::printSolverFlags (void) const
|
VarElim::printSolverFlags() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "variable elimination [" ;
|
ss << "variable elimination [" ;
|
||||||
@ -58,7 +58,7 @@ VarElim::printSolverFlags (void) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VarElim::createFactorList (void)
|
VarElim::createFactorList()
|
||||||
{
|
{
|
||||||
const FacNodes& facNodes = fg.facNodes();
|
const FacNodes& facNodes = fg.facNodes();
|
||||||
factorList_.reserve (facNodes.size() * 2);
|
factorList_.reserve (facNodes.size() * 2);
|
||||||
@ -80,7 +80,7 @@ VarElim::createFactorList (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VarElim::absorveEvidence (void)
|
VarElim::absorveEvidence()
|
||||||
{
|
{
|
||||||
if (Globals::verbosity > 2) {
|
if (Globals::verbosity > 2) {
|
||||||
Util::printDashedLine();
|
Util::printDashedLine();
|
||||||
@ -190,7 +190,7 @@ VarElim::eliminate (VarId vid)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
VarElim::printActiveFactors (void)
|
VarElim::printActiveFactors()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < factorList_.size(); i++) {
|
for (size_t i = 0; i < factorList_.size(); i++) {
|
||||||
if (factorList_[i]) {
|
if (factorList_[i]) {
|
||||||
|
@ -15,22 +15,22 @@ class VarElim : public GroundSolver {
|
|||||||
public:
|
public:
|
||||||
VarElim (const FactorGraph& fg) : GroundSolver (fg) { }
|
VarElim (const FactorGraph& fg) : GroundSolver (fg) { }
|
||||||
|
|
||||||
~VarElim (void) { }
|
~VarElim() { }
|
||||||
|
|
||||||
Params solveQuery (VarIds);
|
Params solveQuery (VarIds);
|
||||||
|
|
||||||
void printSolverFlags (void) const;
|
void printSolverFlags() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createFactorList (void);
|
void createFactorList();
|
||||||
|
|
||||||
void absorveEvidence (void);
|
void absorveEvidence();
|
||||||
|
|
||||||
Params processFactorList (const VarIds&);
|
Params processFactorList (const VarIds&);
|
||||||
|
|
||||||
void eliminate (VarId);
|
void eliminate (VarId);
|
||||||
|
|
||||||
void printActiveFactors (void);
|
void printActiveFactors();
|
||||||
|
|
||||||
Factors factorList_;
|
Factors factorList_;
|
||||||
unsigned largestFactorSize_;
|
unsigned largestFactorSize_;
|
||||||
|
@ -18,7 +18,7 @@ WeightedBp::WeightedBp (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
WeightedBp::~WeightedBp (void)
|
WeightedBp::~WeightedBp()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < links_.size(); i++) {
|
for (size_t i = 0; i < links_.size(); i++) {
|
||||||
delete links_[i];
|
delete links_[i];
|
||||||
@ -77,7 +77,7 @@ WeightedBp::WeightedLink::WeightedLink (
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WeightedBp::createLinks (void)
|
WeightedBp::createLinks()
|
||||||
{
|
{
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@ -110,7 +110,7 @@ WeightedBp::createLinks (void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WeightedBp::maxResidualSchedule (void)
|
WeightedBp::maxResidualSchedule()
|
||||||
{
|
{
|
||||||
if (nIters_ == 1) {
|
if (nIters_ == 1) {
|
||||||
for (size_t i = 0; i < links_.size(); i++) {
|
for (size_t i = 0; i < links_.size(); i++) {
|
||||||
@ -314,7 +314,7 @@ WeightedBp::getVarToFactorMsg (const BpLink* _link) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WeightedBp::printLinkInformation (void) const
|
WeightedBp::printLinkInformation() const
|
||||||
{
|
{
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
@ -11,7 +11,7 @@ class WeightedBp : public BeliefProp {
|
|||||||
WeightedBp (const FactorGraph& fg,
|
WeightedBp (const FactorGraph& fg,
|
||||||
const std::vector<std::vector<unsigned>>& weights);
|
const std::vector<std::vector<unsigned>>& weights);
|
||||||
|
|
||||||
~WeightedBp (void);
|
~WeightedBp();
|
||||||
|
|
||||||
Params getPosterioriOf (VarId);
|
Params getPosterioriOf (VarId);
|
||||||
|
|
||||||
@ -21,13 +21,13 @@ class WeightedBp : public BeliefProp {
|
|||||||
WeightedLink (FacNode* fn, VarNode* vn, size_t idx,
|
WeightedLink (FacNode* fn, VarNode* vn, size_t idx,
|
||||||
unsigned weight);
|
unsigned weight);
|
||||||
|
|
||||||
size_t index (void) const { return index_; }
|
size_t index() const { return index_; }
|
||||||
|
|
||||||
unsigned weight (void) const { return weight_; }
|
unsigned weight() const { return weight_; }
|
||||||
|
|
||||||
const Params& powMessage (void) const { return pwdMsg_; }
|
const Params& powMessage() const { return pwdMsg_; }
|
||||||
|
|
||||||
void updateMessage (void);
|
void updateMessage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t index_;
|
size_t index_;
|
||||||
@ -37,15 +37,15 @@ class WeightedBp : public BeliefProp {
|
|||||||
DISALLOW_COPY_AND_ASSIGN (WeightedLink);
|
DISALLOW_COPY_AND_ASSIGN (WeightedLink);
|
||||||
};
|
};
|
||||||
|
|
||||||
void createLinks (void);
|
void createLinks();
|
||||||
|
|
||||||
void maxResidualSchedule (void);
|
void maxResidualSchedule();
|
||||||
|
|
||||||
void calcFactorToVarMsg (BpLink*);
|
void calcFactorToVarMsg (BpLink*);
|
||||||
|
|
||||||
Params getVarToFactorMsg (const BpLink*) const;
|
Params getVarToFactorMsg (const BpLink*) const;
|
||||||
|
|
||||||
void printLinkInformation (void) const;
|
void printLinkInformation() const;
|
||||||
|
|
||||||
std::vector<std::vector<unsigned>> weights_;
|
std::vector<std::vector<unsigned>> weights_;
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class WeightedBp : public BeliefProp {
|
|||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
WeightedBp::WeightedLink::updateMessage (void)
|
WeightedBp::WeightedLink::updateMessage()
|
||||||
{
|
{
|
||||||
pwdMsg_ = *nextMsg_;
|
pwdMsg_ = *nextMsg_;
|
||||||
swap (currMsg_, nextMsg_);
|
swap (currMsg_, nextMsg_);
|
||||||
|
Reference in New Issue
Block a user