improve the way the factor graph is constructed from a set from factors
This commit is contained in:
parent
f6e3bb4481
commit
401ad145a5
@ -13,7 +13,7 @@
|
|||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
|
||||||
bool FactorGraph::orderFactorVariables = false;
|
bool FactorGraph::orderVariables = false;
|
||||||
|
|
||||||
|
|
||||||
FactorGraph::FactorGraph (const FactorGraph& fg)
|
FactorGraph::FactorGraph (const FactorGraph& fg)
|
||||||
@ -31,6 +31,7 @@ FactorGraph::FactorGraph (const FactorGraph& fg)
|
|||||||
addEdge (varNodes_[neighs[j]->getIndex()], facNode);
|
addEdge (varNodes_[neighs[j]->getIndex()], facNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fromBayesNet_ = fg.isFromBayesNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ FactorGraph::readFromUaiFormat (const char* fileName)
|
|||||||
if (Globals::logDomain) {
|
if (Globals::logDomain) {
|
||||||
Util::toLog (params);
|
Util::toLog (params);
|
||||||
}
|
}
|
||||||
|
// TODO order vars is flag on
|
||||||
addFactor (Factor (factorVarIds[i], factorRanges[i], params));
|
addFactor (Factor (factorVarIds[i], factorRanges[i], params));
|
||||||
}
|
}
|
||||||
is.close();
|
is.close();
|
||||||
@ -160,6 +162,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName)
|
|||||||
if (Globals::logDomain) {
|
if (Globals::logDomain) {
|
||||||
Util::toLog (params);
|
Util::toLog (params);
|
||||||
}
|
}
|
||||||
|
// TODO order vars is flag on
|
||||||
addFactor (Factor (vids, ranges, params));
|
addFactor (Factor (vids, ranges, params));
|
||||||
}
|
}
|
||||||
is.close();
|
is.close();
|
||||||
@ -186,14 +189,10 @@ FactorGraph::addFactor (const Factor& factor)
|
|||||||
addFacNode (fn);
|
addFacNode (fn);
|
||||||
const VarIds& vids = factor.arguments();
|
const VarIds& vids = factor.arguments();
|
||||||
for (unsigned i = 0; i < vids.size(); i++) {
|
for (unsigned i = 0; i < vids.size(); i++) {
|
||||||
bool found = false;
|
VarMap::const_iterator it = varMap_.find (vids[i]);
|
||||||
for (unsigned j = 0; j < varNodes_.size(); j++) {
|
if (it != varMap_.end()) {
|
||||||
if (varNodes_[j]->varId() == vids[i]) {
|
addEdge (it->second, fn);
|
||||||
addEdge (varNodes_[j], fn);
|
} else {
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found == false) {
|
|
||||||
VarNode* vn = new VarNode (vids[i], factor.range (i));
|
VarNode* vn = new VarNode (vids[i], factor.range (i));
|
||||||
addVarNode (vn);
|
addVarNode (vn);
|
||||||
addEdge (vn, fn);
|
addEdge (vn, fn);
|
||||||
|
@ -113,7 +113,7 @@ class FactorGraph
|
|||||||
|
|
||||||
void exportToLibDaiFormat (const char*) const;
|
void exportToLibDaiFormat (const char*) const;
|
||||||
|
|
||||||
static bool orderFactorVariables;
|
static bool orderVariables;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// DISALLOW_COPY_AND_ASSIGN (FactorGraph);
|
// DISALLOW_COPY_AND_ASSIGN (FactorGraph);
|
||||||
|
Reference in New Issue
Block a user