improve the way the factor graph is constructed from a set from factors

This commit is contained in:
Tiago Gomes 2012-04-14 17:57:24 +01:00
parent f6e3bb4481
commit 401ad145a5
2 changed files with 9 additions and 10 deletions

View File

@ -13,7 +13,7 @@
#include "Util.h"
bool FactorGraph::orderFactorVariables = false;
bool FactorGraph::orderVariables = false;
FactorGraph::FactorGraph (const FactorGraph& fg)
@ -31,6 +31,7 @@ FactorGraph::FactorGraph (const FactorGraph& fg)
addEdge (varNodes_[neighs[j]->getIndex()], facNode);
}
}
fromBayesNet_ = fg.isFromBayesNetwork();
}
@ -101,6 +102,7 @@ FactorGraph::readFromUaiFormat (const char* fileName)
if (Globals::logDomain) {
Util::toLog (params);
}
// TODO order vars is flag on
addFactor (Factor (factorVarIds[i], factorRanges[i], params));
}
is.close();
@ -160,6 +162,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName)
if (Globals::logDomain) {
Util::toLog (params);
}
// TODO order vars is flag on
addFactor (Factor (vids, ranges, params));
}
is.close();
@ -186,14 +189,10 @@ FactorGraph::addFactor (const Factor& factor)
addFacNode (fn);
const VarIds& vids = factor.arguments();
for (unsigned i = 0; i < vids.size(); i++) {
bool found = false;
for (unsigned j = 0; j < varNodes_.size(); j++) {
if (varNodes_[j]->varId() == vids[i]) {
addEdge (varNodes_[j], fn);
found = true;
}
}
if (found == false) {
VarMap::const_iterator it = varMap_.find (vids[i]);
if (it != varMap_.end()) {
addEdge (it->second, fn);
} else {
VarNode* vn = new VarNode (vids[i], factor.range (i));
addVarNode (vn);
addEdge (vn, fn);

View File

@ -113,7 +113,7 @@ class FactorGraph
void exportToLibDaiFormat (const char*) const;
static bool orderFactorVariables;
static bool orderVariables;
private:
// DISALLOW_COPY_AND_ASSIGN (FactorGraph);