rework the examples and erase the city network in the old format
This commit is contained in:
parent
8697fcd2b4
commit
f2fbbf29d8
@ -132,8 +132,8 @@ BpSolver::runSolver (void)
|
||||
while (!converged() && nIters_ < BpOptions::maxIter) {
|
||||
nIters_ ++;
|
||||
if (Constants::DEBUG >= 2) {
|
||||
Util::printHeader (" Iteration " + nIters_);
|
||||
cout << endl;
|
||||
Util::printHeader (string ("Iteration ") + Util::toString (nIters_));
|
||||
// cout << endl;
|
||||
}
|
||||
switch (BpOptions::schedule) {
|
||||
case BpOptions::Schedule::SEQ_RANDOM:
|
||||
@ -468,6 +468,9 @@ BpSolver::converged (void)
|
||||
if (Constants::DEBUG == 0) break;
|
||||
}
|
||||
}
|
||||
if (Constants::DEBUG >= 2) {
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
return converged;
|
||||
}
|
||||
|
@ -263,21 +263,22 @@ CFactorGraph::getGroundFactorGraph (void) const
|
||||
fg->addEdge (static_cast<VarNode*> (myGroundVars[j]), fn);
|
||||
}
|
||||
}
|
||||
fg->print();
|
||||
return fg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned
|
||||
CFactorGraph::getGroundEdgeCount (
|
||||
CFactorGraph::getEdgeCount (
|
||||
const FacCluster* fc,
|
||||
const VarCluster* vc) const
|
||||
{
|
||||
const FacNodes& clusterGroundFactors = fc->getGroundFactors();
|
||||
VarNode* varNode = vc->getGroundVarNodes()[0];
|
||||
unsigned count = 0;
|
||||
VarId vid = vc->getGroundVarNodes().front()->varId();
|
||||
const FacNodes& clusterGroundFactors = fc->getGroundFactors();
|
||||
for (unsigned i = 0; i < clusterGroundFactors.size(); i++) {
|
||||
if (clusterGroundFactors[i]->factor().indexOf (varNode->varId()) != -1) {
|
||||
if (clusterGroundFactors[i]->factor().contains (vid)) {
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ class CFactorGraph
|
||||
|
||||
FactorGraph* getGroundFactorGraph (void) const;
|
||||
|
||||
unsigned getGroundEdgeCount (const FacCluster*, const VarCluster*) const;
|
||||
unsigned getEdgeCount (const FacCluster*, const VarCluster*) const;
|
||||
|
||||
static bool checkForIdenticalFactors;
|
||||
|
||||
|
@ -99,7 +99,7 @@ CbpSolver::createLinks (void)
|
||||
for (unsigned i = 0; i < fcs.size(); i++) {
|
||||
const VarClusters& vcs = fcs[i]->getVarClusters();
|
||||
for (unsigned j = 0; j < vcs.size(); j++) {
|
||||
unsigned c = cfg_->getGroundEdgeCount (fcs[i], vcs[j]);
|
||||
unsigned c = cfg_->getEdgeCount (fcs[i], vcs[j]);
|
||||
links_.push_back (new CbpSolverLink (
|
||||
fcs[i]->getRepresentativeFactor(),
|
||||
vcs[j]->getRepresentativeVariable(), c));
|
||||
|
@ -43,6 +43,14 @@ CTNode::removeChild (CTNode* child)
|
||||
|
||||
|
||||
|
||||
void
|
||||
CTNode::removeChilds (void)
|
||||
{
|
||||
childs_.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
CTNode::removeAndDeleteChild (CTNode* child)
|
||||
{
|
||||
@ -897,19 +905,19 @@ ConstraintTree::getNodesAtLevel (unsigned level) const
|
||||
void
|
||||
ConstraintTree::swapLogVar (LogVar X)
|
||||
{
|
||||
TupleSet before = tupleSet();
|
||||
LogVars::iterator it =
|
||||
std::find (logVars_.begin(),logVars_.end(), X);
|
||||
assert (it != logVars_.end());
|
||||
unsigned pos = std::distance (logVars_.begin(), it);
|
||||
|
||||
const CTNodes& nodes = getNodesAtLevel (pos);
|
||||
for (unsigned i = 0; i < nodes.size(); i++) {
|
||||
const CTNodes childs = nodes[i]->childs();
|
||||
for (unsigned j = 0; j < childs.size(); j++) {
|
||||
nodes[i]->removeChild (childs[j]);
|
||||
const CTNodes grandsons = childs[j]->childs();
|
||||
CTNodes childsCopy = nodes[i]->childs();
|
||||
nodes[i]->removeChilds();
|
||||
for (unsigned j = 0; j < childsCopy.size(); j++) {
|
||||
const CTNodes grandsons = childsCopy[j]->childs();
|
||||
for (unsigned k = 0; k < grandsons.size(); k++) {
|
||||
CTNode* childCopy = new CTNode (*childs[j]);
|
||||
CTNode* childCopy = new CTNode (*childsCopy[j]);
|
||||
const CTNodes greatGrandsons = grandsons[k]->childs();
|
||||
for (unsigned t = 0; t < greatGrandsons.size(); t++) {
|
||||
grandsons[k]->removeChild (greatGrandsons[t]);
|
||||
@ -920,10 +928,9 @@ ConstraintTree::swapLogVar (LogVar X)
|
||||
grandsons[k]->setLevel (grandsons[k]->level() - 1);
|
||||
nodes[i]->addChild (grandsons[k], false);
|
||||
}
|
||||
delete childs[j];
|
||||
delete childsCopy[j];
|
||||
}
|
||||
}
|
||||
|
||||
std::swap (logVars_[pos], logVars_[pos + 1]);
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,8 @@ class CTNode
|
||||
|
||||
void removeChild (CTNode*);
|
||||
|
||||
void removeChilds (void);
|
||||
|
||||
void removeAndDeleteChild (CTNode*);
|
||||
|
||||
void removeAndDeleteAllChilds (void);
|
||||
|
@ -455,7 +455,7 @@ FoveSolver::absorveEvidence (
|
||||
}
|
||||
pfList.add (newPfs);
|
||||
}
|
||||
if (Constants::DEBUG > 1 && obsFormulas.empty() == false) {
|
||||
if (Constants::DEBUG >= 2 && obsFormulas.empty() == false) {
|
||||
Util::printAsteriskLine();
|
||||
cout << "AFTER EVIDENCE ABSORVED" << endl;
|
||||
for (unsigned i = 0; i < obsFormulas.size(); i++) {
|
||||
@ -493,7 +493,7 @@ FoveSolver::runSolver (const Grounds& query)
|
||||
shatterAgainstQuery (query);
|
||||
runWeakBayesBall (query);
|
||||
while (true) {
|
||||
if (Constants::DEBUG > 1) {
|
||||
if (Constants::DEBUG >= 2) {
|
||||
Util::printDashedLine();
|
||||
pfList_.print();
|
||||
LiftedOperator::printValidOps (pfList_, query);
|
||||
@ -502,7 +502,7 @@ FoveSolver::runSolver (const Grounds& query)
|
||||
if (op == 0) {
|
||||
break;
|
||||
}
|
||||
if (Constants::DEBUG > 1) {
|
||||
if (Constants::DEBUG >= 2) {
|
||||
cout << "best operation: " << op->toString() << endl;
|
||||
}
|
||||
op->apply();
|
||||
@ -594,7 +594,7 @@ FoveSolver::runWeakBayesBall (const Grounds& query)
|
||||
}
|
||||
}
|
||||
|
||||
if (Constants::DEBUG > 1) {
|
||||
if (Constants::DEBUG >= 2) {
|
||||
Util::printHeader ("REQUIRED PARFACTORS");
|
||||
pfList_.print();
|
||||
}
|
||||
@ -605,15 +605,16 @@ FoveSolver::runWeakBayesBall (const Grounds& query)
|
||||
void
|
||||
FoveSolver::shatterAgainstQuery (const Grounds& query)
|
||||
{
|
||||
return ;
|
||||
for (unsigned i = 0; i < query.size(); i++) {
|
||||
if (query[i].isAtom()) {
|
||||
continue;
|
||||
}
|
||||
bool found = false;
|
||||
Parfactors newPfs;
|
||||
ParfactorList::iterator it = pfList_.begin();
|
||||
while (it != pfList_.end()) {
|
||||
if ((*it)->containsGround (query[i])) {
|
||||
found = true;
|
||||
std::pair<ConstraintTree*, ConstraintTree*> split =
|
||||
(*it)->constr()->split (query[i].args(), query[i].arity());
|
||||
ConstraintTree* commCt = split.first;
|
||||
@ -629,9 +630,14 @@ FoveSolver::shatterAgainstQuery (const Grounds& query)
|
||||
++ it;
|
||||
}
|
||||
}
|
||||
if (found == false) {
|
||||
cerr << "error: could not find a parfactor with ground " ;
|
||||
cerr << "`" << query[i] << "'" << endl;
|
||||
exit (0);
|
||||
}
|
||||
pfList_.add (newPfs);
|
||||
}
|
||||
if (Constants::DEBUG > 1) {
|
||||
if (Constants::DEBUG >= 2) {
|
||||
cout << endl;
|
||||
Util::printAsteriskLine();
|
||||
cout << "SHATTERED AGAINST THE QUERY" << endl;
|
||||
|
@ -16,15 +16,15 @@ class Factor;
|
||||
class VarNode;
|
||||
class FacNode;
|
||||
|
||||
typedef vector<double> Params;
|
||||
typedef unsigned VarId;
|
||||
typedef vector<VarId> VarIds;
|
||||
typedef vector<Var*> Vars;
|
||||
typedef vector<VarNode*> VarNodes;
|
||||
typedef vector<FacNode*> FacNodes;
|
||||
typedef vector<Factor*> Factors;
|
||||
typedef vector<string> States;
|
||||
typedef vector<unsigned> Ranges;
|
||||
typedef vector<double> Params;
|
||||
typedef unsigned VarId;
|
||||
typedef vector<VarId> VarIds;
|
||||
typedef vector<Var*> Vars;
|
||||
typedef vector<VarNode*> VarNodes;
|
||||
typedef vector<FacNode*> FacNodes;
|
||||
typedef vector<Factor*> Factors;
|
||||
typedef vector<string> States;
|
||||
typedef vector<unsigned> Ranges;
|
||||
|
||||
|
||||
enum InfAlgorithms
|
||||
@ -47,7 +47,7 @@ extern InfAlgorithms infAlgorithm;
|
||||
namespace Constants {
|
||||
|
||||
// level of debug information
|
||||
const unsigned DEBUG = 1;
|
||||
const unsigned DEBUG = 5;
|
||||
|
||||
const int NO_EVIDENCE = -1;
|
||||
|
||||
|
@ -64,20 +64,17 @@ int createLiftedNetwork (void)
|
||||
}
|
||||
|
||||
// LiftedUtils::printSymbolDictionary();
|
||||
if (Constants::DEBUG > 1) {
|
||||
if (Constants::DEBUG > 2) {
|
||||
// Util::printHeader ("INITIAL PARFACTORS");
|
||||
// for (unsigned i = 0; i < parfactors.size(); i++) {
|
||||
// parfactors[i]->print();
|
||||
// cout << endl;
|
||||
// }
|
||||
// parfactors[0]->countConvert (LogVar (0));
|
||||
//parfactors[1]->fullExpand (LogVar (1));
|
||||
Util::printHeader ("SHATTERED PARFACTORS");
|
||||
}
|
||||
|
||||
ParfactorList* pfList = new ParfactorList (parfactors);
|
||||
|
||||
if (Constants::DEBUG > 1) {
|
||||
if (Constants::DEBUG >= 2) {
|
||||
Util::printHeader ("SHATTERED PARFACTORS");
|
||||
pfList->print();
|
||||
}
|
||||
|
||||
@ -257,7 +254,8 @@ Params
|
||||
readParameters (YAP_Term paramL)
|
||||
{
|
||||
Params params;
|
||||
while (paramL!= YAP_TermNil()) {
|
||||
assert (YAP_IsPairTerm (paramL));
|
||||
while (paramL != YAP_TermNil()) {
|
||||
params.push_back ((double) YAP_FloatOfTerm (YAP_HeadOfTerm (paramL)));
|
||||
paramL = YAP_TailOfTerm (paramL);
|
||||
}
|
||||
|
@ -528,11 +528,13 @@ Parfactor::print (bool printParams) const
|
||||
cout << args_[i];
|
||||
}
|
||||
cout << endl;
|
||||
vector<string> groups;
|
||||
for (unsigned i = 0; i < args_.size(); i++) {
|
||||
groups.push_back (string ("g") + Util::toString (args_[i].group()));
|
||||
if (args_[0].group() != Util::maxUnsigned()) {
|
||||
vector<string> groups;
|
||||
for (unsigned i = 0; i < args_.size(); i++) {
|
||||
groups.push_back (string ("g") + Util::toString (args_[i].group()));
|
||||
}
|
||||
cout << "Groups: " << groups << endl;
|
||||
}
|
||||
cout << "Groups: " << groups << endl;
|
||||
cout << "LogVars: " << constr_->logVarSet() << endl;
|
||||
cout << "Ranges: " << ranges_ << endl;
|
||||
if (printParams == false) {
|
||||
|
@ -116,7 +116,6 @@ ParfactorList::print (void) const
|
||||
list<Parfactor*>::const_iterator it;
|
||||
for (it = pfList_.begin(); it != pfList_.end(); ++it) {
|
||||
(*it)->print();
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,7 +218,7 @@ ParfactorList::shatter (
|
||||
ProbFormula& f1 = g1->argument (fIdx1);
|
||||
ProbFormula& f2 = g2->argument (fIdx2);
|
||||
// cout << endl;
|
||||
// Util::printDashLine();
|
||||
// Util::printDashedLine();
|
||||
// cout << "-> SHATTERING (#" << g1 << ", #" << g2 << ")" << endl;
|
||||
// g1->print();
|
||||
// cout << "-> WITH" << endl;
|
||||
@ -228,7 +227,7 @@ ParfactorList::shatter (
|
||||
// cout << g1->constr()->tupleSet (f1.logVars()) << endl;
|
||||
// cout << "-> ON: " << f2 << "|" ;
|
||||
// cout << g2->constr()->tupleSet (f2.logVars()) << endl;
|
||||
// Util::printDashLine();
|
||||
// Util::printDashedLine();
|
||||
if (f1.isAtom()) {
|
||||
unsigned group = (f1.group() < f2.group()) ? f1.group() : f2.group();
|
||||
f1.setGroup (group);
|
||||
@ -265,18 +264,19 @@ ParfactorList::shatter (
|
||||
assert (commCt1->tupleSet (f1.arity()) ==
|
||||
commCt2->tupleSet (f2.arity()));
|
||||
|
||||
// stringstream ss1; ss1 << "" << count << "_A.dot" ;
|
||||
// stringstream ss2; ss2 << "" << count << "_B.dot" ;
|
||||
// stringstream ss3; ss3 << "" << count << "_A_comm.dot" ;
|
||||
// stringstream ss4; ss4 << "" << count << "_A_excl.dot" ;
|
||||
// stringstream ss5; ss5 << "" << count << "_B_comm.dot" ;
|
||||
// stringstream ss6; ss6 << "" << count << "_B_excl.dot" ;
|
||||
// ct1->exportToGraphViz (ss1.str().c_str(), true);
|
||||
// ct2->exportToGraphViz (ss2.str().c_str(), true);
|
||||
// commCt1->exportToGraphViz (ss3.str().c_str(), true);
|
||||
// exclCt1->exportToGraphViz (ss4.str().c_str(), true);
|
||||
// commCt2->exportToGraphViz (ss5.str().c_str(), true);
|
||||
// exclCt2->exportToGraphViz (ss6.str().c_str(), true);
|
||||
// unsigned static count = 0; count ++;
|
||||
// stringstream ss1; ss1 << "" << count << "_A.dot" ;
|
||||
// stringstream ss2; ss2 << "" << count << "_B.dot" ;
|
||||
// stringstream ss3; ss3 << "" << count << "_A_comm.dot" ;
|
||||
// stringstream ss4; ss4 << "" << count << "_A_excl.dot" ;
|
||||
// stringstream ss5; ss5 << "" << count << "_B_comm.dot" ;
|
||||
// stringstream ss6; ss6 << "" << count << "_B_excl.dot" ;
|
||||
// g1->constr()->exportToGraphViz (ss1.str().c_str(), true);
|
||||
// g2->constr()->exportToGraphViz (ss2.str().c_str(), true);
|
||||
// commCt1->exportToGraphViz (ss3.str().c_str(), true);
|
||||
// exclCt1->exportToGraphViz (ss4.str().c_str(), true);
|
||||
// commCt2->exportToGraphViz (ss5.str().c_str(), true);
|
||||
// exclCt2->exportToGraphViz (ss6.str().c_str(), true);
|
||||
|
||||
if (exclCt1->empty() && exclCt2->empty()) {
|
||||
unsigned group = (f1.group() < f2.group())
|
||||
|
@ -1,5 +1,4 @@
|
||||
TODO
|
||||
|
||||
- add way to calculate combinations and factorials with large numbers
|
||||
- add a way to calculate combinations and factorials with large numbers
|
||||
- refactor sumOut in parfactor -> is really ugly code
|
||||
- Indexer: start receiving ranges as constant reference
|
||||
|
@ -155,7 +155,8 @@ getStateLines (const Vars& vars)
|
||||
|
||||
|
||||
|
||||
void printHeader (string header, std::ostream& os)
|
||||
void
|
||||
printHeader (string header, std::ostream& os)
|
||||
{
|
||||
printAsteriskLine (os);
|
||||
os << header << endl;
|
||||
@ -164,7 +165,8 @@ void printHeader (string header, std::ostream& os)
|
||||
|
||||
|
||||
|
||||
void printSubHeader (string header, std::ostream& os)
|
||||
void
|
||||
printSubHeader (string header, std::ostream& os)
|
||||
{
|
||||
printDashedLine (os);
|
||||
os << header << endl;
|
||||
@ -173,7 +175,8 @@ void printSubHeader (string header, std::ostream& os)
|
||||
|
||||
|
||||
|
||||
void printAsteriskLine (std::ostream& os)
|
||||
void
|
||||
printAsteriskLine (std::ostream& os)
|
||||
{
|
||||
os << "********************************" ;
|
||||
os << "********************************" ;
|
||||
@ -182,7 +185,8 @@ void printAsteriskLine (std::ostream& os)
|
||||
|
||||
|
||||
|
||||
void printDashedLine (std::ostream& os)
|
||||
void
|
||||
printDashedLine (std::ostream& os)
|
||||
{
|
||||
os << "--------------------------------" ;
|
||||
os << "--------------------------------" ;
|
||||
@ -382,13 +386,13 @@ Statistics::writeStatistics (const char* fileName)
|
||||
|
||||
void
|
||||
Statistics::updateCompressingStatistics (
|
||||
unsigned nGroundVars,
|
||||
unsigned nGroundFactors,
|
||||
unsigned nClusterVars,
|
||||
unsigned nClusterFactors,
|
||||
unsigned nWithoutNeighs) {
|
||||
compressInfo_.push_back (CompressInfo (nGroundVars, nGroundFactors,
|
||||
nClusterVars, nClusterFactors, nWithoutNeighs));
|
||||
unsigned nrGroundVars,
|
||||
unsigned nrGroundFactors,
|
||||
unsigned nrClusterVars,
|
||||
unsigned nrClusterFactors,
|
||||
unsigned nrNeighborless) {
|
||||
compressInfo_.push_back (CompressInfo (nrGroundVars, nrGroundFactors,
|
||||
nrClusterVars, nrClusterFactors, nrNeighborless));
|
||||
}
|
||||
|
||||
|
||||
@ -460,17 +464,17 @@ Statistics::getStatisticString (void)
|
||||
ss3 << "Ground Cluster Ground Cluster Neighborless" << endl;
|
||||
ss3 << "Vars Vars Factors Factors Vars" << endl;
|
||||
for (unsigned i = 0; i < compressInfo_.size(); i++) {
|
||||
ss3 << setw (9) << compressInfo_[i].nGroundVars;
|
||||
ss3 << setw (10) << compressInfo_[i].nClusterVars;
|
||||
ss3 << setw (10) << compressInfo_[i].nGroundFactors;
|
||||
ss3 << setw (10) << compressInfo_[i].nClusterFactors;
|
||||
ss3 << setw (10) << compressInfo_[i].nWithoutNeighs;
|
||||
ss3 << setw (9) << compressInfo_[i].nrGroundVars;
|
||||
ss3 << setw (10) << compressInfo_[i].nrClusterVars;
|
||||
ss3 << setw (10) << compressInfo_[i].nrGroundFactors;
|
||||
ss3 << setw (10) << compressInfo_[i].nrClusterFactors;
|
||||
ss3 << setw (10) << compressInfo_[i].nrNeighborless;
|
||||
ss3 << endl;
|
||||
c1 += compressInfo_[i].nGroundVars - compressInfo_[i].nWithoutNeighs;
|
||||
c2 += compressInfo_[i].nClusterVars;
|
||||
c3 += compressInfo_[i].nGroundFactors - compressInfo_[i].nWithoutNeighs;
|
||||
c4 += compressInfo_[i].nClusterFactors;
|
||||
if (compressInfo_[i].nWithoutNeighs != 0) {
|
||||
c1 += compressInfo_[i].nrGroundVars - compressInfo_[i].nrNeighborless;
|
||||
c2 += compressInfo_[i].nrClusterVars;
|
||||
c3 += compressInfo_[i].nrGroundFactors - compressInfo_[i].nrNeighborless;
|
||||
c4 += compressInfo_[i].nrClusterFactors;
|
||||
if (compressInfo_[i].nrNeighborless != 0) {
|
||||
c2 --;
|
||||
c4 --;
|
||||
}
|
||||
|
@ -332,17 +332,17 @@ struct CompressInfo
|
||||
{
|
||||
CompressInfo (unsigned a, unsigned b, unsigned c, unsigned d, unsigned e)
|
||||
{
|
||||
nGroundVars = a;
|
||||
nGroundFactors = b;
|
||||
nClusterVars = c;
|
||||
nClusterFactors = d;
|
||||
nWithoutNeighs = e;
|
||||
nrGroundVars = a;
|
||||
nrGroundFactors = b;
|
||||
nrClusterVars = c;
|
||||
nrClusterFactors = d;
|
||||
nrNeighborless = e;
|
||||
}
|
||||
unsigned nGroundVars;
|
||||
unsigned nGroundFactors;
|
||||
unsigned nClusterVars;
|
||||
unsigned nClusterFactors;
|
||||
unsigned nWithoutNeighs;
|
||||
unsigned nrGroundVars;
|
||||
unsigned nrGroundFactors;
|
||||
unsigned nrClusterVars;
|
||||
unsigned nrClusterFactors;
|
||||
unsigned nrNeighborless;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
cp ~/bin/yap ~/bin/town_bnbp
|
||||
YAP=~/bin/town_bnbp
|
||||
cp ~/bin/yap ~/bin/town_bp
|
||||
YAP=~/bin/town_bp
|
||||
|
||||
#OUT_FILE_NAME=results`date "+ %H:%M:%S %d-%m-%Y"`.log
|
||||
OUT_FILE_NAME=bnbp.log
|
||||
OUT_FILE_NAME=bp.log
|
||||
rm -f $OUT_FILE_NAME
|
||||
rm -f ignore.$OUT_FILE_NAME
|
||||
|
||||
@ -38,13 +38,13 @@ function run_all_graphs
|
||||
echo "results for solver $2" >> $OUT_FILE_NAME
|
||||
echo "*******************************************************************" >> "$OUT_FILE_NAME"
|
||||
run_solver town_1000 $1 town_1000 $3 $4 $5
|
||||
run_solver town_5000 $1 town_5000 $3 $4 $5
|
||||
run_solver town_10000 $1 town_10000 $3 $4 $5
|
||||
run_solver town_50000 $1 town_50000 $3 $4 $5
|
||||
run_solver town_100000 $1 town_100000 $3 $4 $5
|
||||
run_solver town_500000 $1 town_500000 $3 $4 $5
|
||||
run_solver town_1000000 $1 town_1000000 $3 $4 $5
|
||||
#run_solver town_5000 $1 town_5000 $3 $4 $5
|
||||
#run_solver town_10000 $1 town_10000 $3 $4 $5
|
||||
#run_solver town_50000 $1 town_50000 $3 $4 $5
|
||||
#run_solver town_100000 $1 town_100000 $3 $4 $5
|
||||
#run_solver town_500000 $1 town_500000 $3 $4 $5
|
||||
#run_solver town_1000000 $1 town_1000000 $3 $4 $5
|
||||
}
|
||||
|
||||
run_all_graphs bp "bn_bp(seq_fixed) " bn_bp seq_fixed
|
||||
run_all_graphs bp "bp(seq_fixed) z " bp seq_fixed
|
||||
|
37
packages/CLPBN/clpbn/bp/benchmarks/city/city_generator.sh
Executable file
37
packages/CLPBN/clpbn/bp/benchmarks/city/city_generator.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/home/tiago/bin/yap -L --
|
||||
|
||||
|
||||
:- initialization(main).
|
||||
|
||||
|
||||
main :-
|
||||
unix(argv([H])),
|
||||
generate_town(H).
|
||||
|
||||
|
||||
generate_town(N) :-
|
||||
atomic_concat(['city_', N, '.yap'], FileName),
|
||||
open(FileName, 'write', S),
|
||||
atom_number(N, N2),
|
||||
generate_people(S, N2, 4),
|
||||
write(S, '\n'),
|
||||
generate_query(S, N2, 4),
|
||||
write(S, '\n'),
|
||||
close(S).
|
||||
|
||||
|
||||
generate_people(S, N, Counting) :-
|
||||
Counting > N, !.
|
||||
generate_people(S, N, Counting) :-
|
||||
format(S, 'people(p~w, nyc).~n', [Counting]),
|
||||
Counting1 is Counting + 1,
|
||||
generate_people(S, N, Counting1).
|
||||
|
||||
|
||||
generate_query(S, N, Counting) :-
|
||||
Counting > N, !.
|
||||
generate_query(S, N, Counting) :- !,
|
||||
format(S, 'ev(descn(p~w, t)).~n', [Counting]),
|
||||
Counting1 is Counting + 1,
|
||||
generate_query(S, N, Counting1).
|
||||
|
@ -1,21 +0,0 @@
|
||||
|
||||
bayes conservative_city(C)::[y,n] ; cons_table(C) ; [city(C)].
|
||||
|
||||
bayes gender(P)::[m,f] ; gender_table(P) ; [people(P,_)].
|
||||
|
||||
bayes hair_color(P)::[t,f] , conservative_city(C) ; hair_color_table(P) ; [people(P,C)].
|
||||
|
||||
bayes car_color(P)::[t,f] , hair_color(P) ; car_color_table(P); [people(P,_)].
|
||||
|
||||
bayes height(P)::[t,f] , gender(P) ; height_table(P) ; [people(P,_)].
|
||||
|
||||
bayes shoe_size(P):[t,f] , height(P) ; shoe_size_table(P); [people(P,_)].
|
||||
|
||||
bayes guilty(P)::[y,n] ; guilty_table(P) ; [people(P,_)].
|
||||
|
||||
bayes descn(P)::[t,f] , car_color(P), hair_color(P), height(P), guilty(P) ; descn_table(P) ; [people(P,_)].
|
||||
|
||||
bayes witness(C)::[t,f] , descn(Joe) , descn(P2) ; wit_table ; [city(C), Joe=joe, P2=p2].
|
||||
|
||||
:- ensure_loaded(tables).
|
||||
|
@ -1,65 +0,0 @@
|
||||
|
||||
conservative_city(City, Cons) :-
|
||||
cons_table(City, ConsDist),
|
||||
{ Cons = conservative_city(City) with p([y,n], ConsDist) }.
|
||||
|
||||
|
||||
gender(X, Gender) :-
|
||||
gender_table(X, GenderDist),
|
||||
{ Gender = gender(X) with p([m,f], GenderDist) }.
|
||||
|
||||
|
||||
hair_color(X, Color) :-
|
||||
lives(X, City),
|
||||
conservative_city(City, Cons),
|
||||
hair_color_table(X,ColorTable),
|
||||
{ Color = hair_color(X) with
|
||||
p([t,f], ColorTable,[Cons]) }.
|
||||
|
||||
|
||||
car_color(X, Color) :-
|
||||
hair_color(X, HColor),
|
||||
car_color_table(X,CColorTable),
|
||||
{ Color = car_color(X) with
|
||||
p([t,f], CColorTable,[HColor]) }.
|
||||
|
||||
|
||||
height(X, Height) :-
|
||||
gender(X, Gender),
|
||||
height_table(X,HeightTable),
|
||||
{ Height = height(X) with
|
||||
p([t,f], HeightTable,[Gender]) }.
|
||||
|
||||
|
||||
shoe_size(X, Shoesize) :-
|
||||
height(X, Height),
|
||||
shoe_size_table(X,ShoesizeTable),
|
||||
{ Shoesize = shoe_size(X) with
|
||||
p([t,f], ShoesizeTable,[Height]) }.
|
||||
|
||||
|
||||
guilty(X, Guilt) :-
|
||||
guilty_table(X, GuiltDist),
|
||||
{ Guilt = guilty(X) with p([y,n], GuiltDist) }.
|
||||
|
||||
|
||||
descn(X, Descn) :-
|
||||
car_color(X, Car),
|
||||
hair_color(X, Hair),
|
||||
height(X, Height),
|
||||
guilty(X, Guilt),
|
||||
descn_table(X, DescTable),
|
||||
{ Descn = descn(X) with
|
||||
p([t,f], DescTable,[Car,Hair,Height,Guilt]) }.
|
||||
|
||||
|
||||
witness(City, Witness) :-
|
||||
descn(joe, DescnJ),
|
||||
descn(p2, Descn2),
|
||||
wit_table(WitTable),
|
||||
{ Witness = witness(City) with
|
||||
p([t,f], WitTable,[DescnJ, Descn2]) }.
|
||||
|
||||
|
||||
:- ensure_loaded(tables).
|
||||
|
@ -1,46 +0,0 @@
|
||||
|
||||
cons_table(amsterdam, [0.2, 0.8]) :- !.
|
||||
cons_table(_, [0.8, 0.2]).
|
||||
|
||||
|
||||
gender_table(_, [0.55, 0.44]).
|
||||
|
||||
|
||||
hair_color_table(_,
|
||||
/* conservative_city */
|
||||
/* y n */
|
||||
[ 0.05, 0.1,
|
||||
0.95, 0.9 ]).
|
||||
|
||||
|
||||
car_color_table(_,
|
||||
/* t f */
|
||||
[ 0.9, 0.2,
|
||||
0.1, 0.8 ]).
|
||||
|
||||
|
||||
height_table(_,
|
||||
/* m f */
|
||||
[ 0.6, 0.4,
|
||||
0.4, 0.6 ]).
|
||||
|
||||
|
||||
shoe_size_table(_,
|
||||
/* t f */
|
||||
[ 0.9, 0.1,
|
||||
0.1, 0.9 ]).
|
||||
|
||||
|
||||
guilty_table(_, [0.23, 0.77]).
|
||||
|
||||
|
||||
descn_table(_,
|
||||
/* color, hair, height, guilt */
|
||||
/* ttttt tttf ttft ttff tfttt tftf tfft tfff ttttt fttf ftft ftff ffttt fftf ffft ffff */
|
||||
[ 0.99, 0.5, 0.23, 0.88, 0.41, 0.3, 0.76, 0.87, 0.44, 0.43, 0.29, 0.72, 0.33, 0.91, 0.95, 0.92,
|
||||
0.01, 0.5, 0.77, 0.12, 0.59, 0.7, 0.24, 0.13, 0.56, 0.57, 0.61, 0.28, 0.77, 0.09, 0.05, 0.08]).
|
||||
|
||||
|
||||
wit_table([0.2, 0.45, 0.24, 0.34,
|
||||
0.8, 0.55, 0.76, 0.66]).
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,47 +0,0 @@
|
||||
:- source.
|
||||
:- style_check(all).
|
||||
:- yap_flag(unknown,error).
|
||||
:- yap_flag(write_strings,on).
|
||||
:- use_module(library(clpbn)).
|
||||
%:- set_clpbn_flag(solver, bp).
|
||||
|
||||
:- set_clpbn_flag(solver,fove).
|
||||
|
||||
:- [-parschema].
|
||||
|
||||
run_query(Guilty) :-
|
||||
guilty(joe, Guilty),
|
||||
witness(nyc, t).
|
||||
%runall(X, ev(X)).
|
||||
|
||||
|
||||
runall(G, Wrapper) :-
|
||||
findall(G, Wrapper, L),
|
||||
execute_all(L).
|
||||
|
||||
|
||||
execute_all([]).
|
||||
execute_all(G.L) :-
|
||||
call(G),
|
||||
execute_all(L).
|
||||
|
||||
|
||||
%ev(descn(p2, t)).
|
||||
%ev(descn(p3, t)).
|
||||
|
||||
|
||||
city(nyc).
|
||||
city(oporto).
|
||||
|
||||
people(joe,nyc).
|
||||
people(p2,nyc).
|
||||
people(p3,nyc).
|
||||
%people(p4,nyc).
|
||||
%people(p5,nyc).
|
||||
%people(p6,nyc).
|
||||
%people(p7,nyc).
|
||||
%people(p8,nyc).
|
||||
%people(p9,nyc).
|
||||
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
:- source.
|
||||
:- style_check(all).
|
||||
:- yap_flag(unknown,error).
|
||||
:- yap_flag(write_strings,on).
|
||||
:- use_module(library(clpbn)).
|
||||
:- set_clpbn_flag(solver, bp).
|
||||
:- [-schema].
|
||||
|
||||
lives(_joe, nyc).
|
||||
|
||||
run_query(Guilty) :-
|
||||
guilty(joe, Guilty),
|
||||
witness(nyc, t),
|
||||
runall(X, ev(X)).
|
||||
|
||||
|
||||
runall(G, Wrapper) :-
|
||||
findall(G, Wrapper, L),
|
||||
execute_all(L).
|
||||
|
||||
|
||||
execute_all([]).
|
||||
execute_all(G.L) :-
|
||||
call(G),
|
||||
execute_all(L).
|
||||
|
||||
|
||||
ev(descn(p2, t)).
|
||||
ev(descn(p3, t)).
|
File diff suppressed because it is too large
Load Diff
@ -1,59 +0,0 @@
|
||||
#!/home/tiago/bin/yap -L --
|
||||
|
||||
/*
|
||||
Steps:
|
||||
1. generate N facts lives(I, nyc), 0 <= I < N.
|
||||
2. generate evidence on descn for N people, *** except for 1 ***
|
||||
3. Run query ?- guilty(joe, Guilty), witness(joe, t), descn(2,t), descn(3, f), descn(4, f) ...
|
||||
*/
|
||||
|
||||
:- initialization(main).
|
||||
|
||||
|
||||
main :-
|
||||
unix(argv([H])),
|
||||
generate_town(H).
|
||||
|
||||
|
||||
generate_town(N) :-
|
||||
atomic_concat(['town_', N, '.yap'], FileName),
|
||||
open(FileName, 'write', S),
|
||||
write(S, ':- source.\n'),
|
||||
write(S, ':- style_check(all).\n'),
|
||||
write(S, ':- yap_flag(unknown,error).\n'),
|
||||
write(S, ':- yap_flag(write_strings,on).\n'),
|
||||
write(S, ':- use_module(library(clpbn)).\n'),
|
||||
write(S, ':- set_clpbn_flag(solver, bp).\n'),
|
||||
write(S, ':- [-schema].\n\n'),
|
||||
write(S, 'lives(_joe, nyc).\n'),
|
||||
atom_number(N, N2),
|
||||
generate_people(S, N2, 2),
|
||||
write(S, '\nrun_query(Guilty) :- \n'),
|
||||
write(S, '\tguilty(joe, Guilty),\n'),
|
||||
write(S, '\twitness(nyc, t),\n'),
|
||||
write(S, '\trunall(X, ev(X)).\n\n\n'),
|
||||
write(S, 'runall(G, Wrapper) :-\n'),
|
||||
write(S, '\tfindall(G, Wrapper, L),\n'),
|
||||
write(S, '\texecute_all(L).\n\n\n'),
|
||||
write(S, 'execute_all([]).\n'),
|
||||
write(S, 'execute_all(G.L) :-\n'),
|
||||
write(S, '\tcall(G),\n'),
|
||||
write(S, '\texecute_all(L).\n\n\n'),
|
||||
generate_query(S, N2, 2),
|
||||
close(S).
|
||||
|
||||
|
||||
generate_people(_, N, Counting1) :- !.
|
||||
generate_people(S, N, Counting) :-
|
||||
format(S, 'lives(p~w, nyc).~n', [Counting]),
|
||||
Counting1 is Counting + 1,
|
||||
generate_people(S, N, Counting1).
|
||||
|
||||
|
||||
generate_query(S, N, Counting) :-
|
||||
Counting > N, !.
|
||||
generate_query(S, N, Counting) :- !,
|
||||
format(S, 'ev(descn(p~w, t)).~n', [Counting]),
|
||||
Counting1 is Counting + 1,
|
||||
generate_query(S, N, Counting1).
|
||||
|
@ -1,18 +0,0 @@
|
||||
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
:- set_clpbn_flag(solver,fove).
|
||||
|
||||
|
||||
c(x1,y1,z1).
|
||||
c(x1,y1,z2).
|
||||
c(x2,y2,z1).
|
||||
c(x3,y2,z1).
|
||||
|
||||
bayes p(X)::[t,f] ; [0.2, 0.4] ; [c(X,_,_)].
|
||||
|
||||
bayes q(Y)::[t,f] ; [0.5, 0.6] ; [c(_,Y,_)].
|
||||
|
||||
bayes s(Z)::[t,f] , p(X) , q(Y) ; [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8] ; [c(X,Y,Z)].
|
||||
|
||||
% bayes series::[t,f] , attends(X) ; [0.5, 0.6, 0.7, 0.8] ; [c(X,_)].
|
@ -1,3 +1,5 @@
|
||||
# example in counting belief propagation paper
|
||||
|
||||
MARKOV
|
||||
3
|
||||
2 2 2
|
||||
@ -5,7 +7,6 @@ MARKOV
|
||||
2 0 1
|
||||
2 2 1
|
||||
|
||||
|
||||
4
|
||||
1.2 1.4 2.0 0.4
|
||||
|
||||
|
98
packages/CLPBN/clpbn/bp/examples/city.yap
Normal file
98
packages/CLPBN/clpbn/bp/examples/city.yap
Normal file
@ -0,0 +1,98 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
:- set_pfl_flag(solver,fove).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,ve).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,bp).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,cbp).
|
||||
|
||||
|
||||
people(joe,nyc).
|
||||
people(p2, nyc).
|
||||
people(p3, nyc).
|
||||
|
||||
|
||||
ev(descn(p2, t)).
|
||||
ev(descn(p3, t)).
|
||||
|
||||
|
||||
:- [city_7].
|
||||
|
||||
|
||||
bayes city_conservativeness(C)::[y,n] ; cons_table(C) ; [people(_,C)].
|
||||
|
||||
bayes gender(P)::[m,f] ; gender_table(P) ; [people(P,_)].
|
||||
|
||||
bayes hair_color(P)::[t,f] , city_conservativeness(C) ; hair_color_table(P) ; [people(P,C)].
|
||||
|
||||
bayes car_color(P)::[t,f] , hair_color(P) ; car_color_table(P); [people(P,_)].
|
||||
|
||||
bayes height(P)::[t,f] , gender(P) ; height_table(P) ; [people(P,_)].
|
||||
|
||||
bayes shoe_size(P):[t,f] , height(P) ; shoe_size_table(P); [people(P,_)].
|
||||
|
||||
bayes guilty(P)::[y,n] ; guilty_table(P) ; [people(P,_)].
|
||||
|
||||
bayes descn(P)::[t,f] , car_color(P), hair_color(P), height(P), guilty(P) ; descn_table(P) ; [people(P,_)].
|
||||
|
||||
bayes witness(C)::[t,f] , descn(Joe) , descn(P2) ; wit_table ; [people(_,C), Joe=joe, P2=p2].
|
||||
|
||||
|
||||
cons_table(amsterdam, [0.2, 0.8]) :- !.
|
||||
cons_table(_, [0.8, 0.2]).
|
||||
|
||||
|
||||
gender_table(_, [0.55, 0.44]).
|
||||
|
||||
|
||||
hair_color_table(_,
|
||||
/* conservative_city */
|
||||
/* y n */
|
||||
[ 0.05, 0.1,
|
||||
0.95, 0.9 ]).
|
||||
|
||||
|
||||
car_color_table(_,
|
||||
/* t f */
|
||||
[ 0.9, 0.2,
|
||||
0.1, 0.8 ]).
|
||||
|
||||
|
||||
height_table(_,
|
||||
/* m f */
|
||||
[ 0.6, 0.4,
|
||||
0.4, 0.6 ]).
|
||||
|
||||
|
||||
shoe_size_table(_,
|
||||
/* t f */
|
||||
[ 0.9, 0.1,
|
||||
0.1, 0.9 ]).
|
||||
|
||||
|
||||
guilty_table(_, [0.23, 0.77]).
|
||||
|
||||
|
||||
descn_table(_,
|
||||
/* color, hair, height, guilt */
|
||||
/* ttttt tttf ttft ttff tfttt tftf tfft tfff ttttt fttf ftft ftff ffttt fftf ffft ffff */
|
||||
[ 0.99, 0.5, 0.23, 0.88, 0.41, 0.3, 0.76, 0.87, 0.44, 0.43, 0.29, 0.72, 0.33, 0.91, 0.95, 0.92,
|
||||
0.01, 0.5, 0.77, 0.12, 0.59, 0.7, 0.24, 0.13, 0.56, 0.57, 0.61, 0.28, 0.77, 0.09, 0.05, 0.08]).
|
||||
|
||||
|
||||
wit_table([0.2, 0.45, 0.24, 0.34,
|
||||
0.8, 0.55, 0.76, 0.66]).
|
||||
|
||||
|
||||
runall(G, Wrapper) :-
|
||||
findall(G, Wrapper, L),
|
||||
execute_all(L).
|
||||
|
||||
|
||||
execute_all([]).
|
||||
execute_all(G.L) :-
|
||||
call(G),
|
||||
execute_all(L).
|
||||
|
||||
|
||||
?- witness(nyc, t), runall(X, ev(X)), guilty(joe, Guilty).
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
||||
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_clpbn_flag(solver,ve).
|
||||
%:- set_clpbn_flag(solver,bp), clpbn_bp:set_horus_flag(inf_alg,ve).
|
||||
:- set_clpbn_flag(solver,fove).
|
||||
:- set_pfl_flag(solver,fove).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,ve).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,bp).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,cbp).
|
||||
|
||||
c(p1,w1).
|
||||
c(p1,w2).
|
||||
@ -25,8 +25,5 @@ markov attends(P)::[t,f] , hot(W)::[t,f] ; [0.1, 0.2, 0.3, 0.4] ; [c(P,W)].
|
||||
|
||||
markov attends(P)::[t,f], series::[t,f] ; [0.5, 0.6, 0.7, 0.8] ; [c(P,_)].
|
||||
|
||||
:- clpbn_horus:set_horus_flag(use_logarithms,true).
|
||||
|
||||
?- series(X).
|
||||
|
||||
|
||||
|
@ -2,7 +2,9 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
:- set_pfl_flag(solver,fove).
|
||||
%:- set_pfl_flag(solver,fove).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,ve).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,bp).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,cbp).
|
||||
|
||||
|
||||
t(ann).
|
||||
@ -10,10 +12,10 @@ t(dave).
|
||||
|
||||
% p(ann,t).
|
||||
|
||||
bayes p(X)::[t,f] ; [0.1, 0.3] ; [t(X)].
|
||||
markov p(X)::[t,f] ; [0.1, 0.3] ; [t(X)].
|
||||
|
||||
% use standard Prolog queries: provide evidence first.
|
||||
|
||||
?- p(dave,t), p(ann,X).
|
||||
?- p(ann,t), p(ann,X).
|
||||
% ?- p(ann,X).
|
||||
|
||||
|
@ -1,39 +1,23 @@
|
||||
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_pfl_flag(solver,ve).
|
||||
:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,ve).
|
||||
% :- set_pfl_flag(solver,fove).
|
||||
:- set_pfl_flag(solver,fove).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,ve).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,bp).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,cbp).
|
||||
|
||||
:- yap_flag(write_strings, off).
|
||||
|
||||
|
||||
friends(P1, P2) :-
|
||||
person(P1),
|
||||
person(P2),
|
||||
P1 \= P2.
|
||||
person(P1),
|
||||
person(P2),
|
||||
P1 \= P2.
|
||||
|
||||
person(john).
|
||||
person(maggie).
|
||||
%person(harry).
|
||||
%person(bill).
|
||||
%person(matt).
|
||||
%person(diana).
|
||||
%person(bob).
|
||||
%person(dick).
|
||||
%person(burr).
|
||||
%person(ann).
|
||||
|
||||
% person @ 2.
|
||||
person @ 3.
|
||||
|
||||
markov smokes(P)::[t,f] , cancer(P)::[t,f] ; [0.1, 0.2, 0.3, 0.4] ; [person(P)].
|
||||
|
||||
markov friend(P1,P2)::[t,f], smokes(P1)::[t,f], smokes(P2)::[t,f] ; [0.5, 0.6, 0.7, 0.8, 0.5, 0.6, 0.7, 0.8] ; [friends(P1, P2)].
|
||||
|
||||
% ?- smokes(person_0, t), smokes(person_1, t), friend(person_0, person_1, F).
|
||||
|
||||
% ?- smokes(john, t), smokes(maggie, f), friend(john, maggie, X).
|
||||
|
||||
?- smokes(john, t), friend(john, maggie, X).
|
||||
|
||||
% ?- friend(john, maggie, X).
|
||||
?- smokes(person_1, t), smokes(person_2, f), friend(person_1, person_2, X).
|
||||
|
||||
|
@ -1,120 +0,0 @@
|
||||
14
|
||||
|
||||
1
|
||||
6
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
7
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
4
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
5
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
0
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
2
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
3
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
2
|
||||
4 6
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
5 7
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
0 4
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
||||
3
|
||||
2 5 4
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
1 4 5
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
2
|
||||
3 5
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
@ -1,239 +0,0 @@
|
||||
27
|
||||
|
||||
1
|
||||
12
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
13
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
14
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
9
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
10
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
11
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
0
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
3
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
6
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
4
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
7
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
2
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
5
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
8
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
2
|
||||
9 12
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
10 13
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
11 14
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
0 9
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
||||
3
|
||||
3 10 9
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
6 11 9
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
1 9 10
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
2
|
||||
4 10
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
||||
3
|
||||
7 11 10
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
2 9 11
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
5 10 11
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
2
|
||||
8 11
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
@ -1,398 +0,0 @@
|
||||
44
|
||||
|
||||
1
|
||||
20
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
21
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
22
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
23
|
||||
2
|
||||
2
|
||||
0 9.974182
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
16
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
17
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
18
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
19
|
||||
2
|
||||
2
|
||||
0 4.055200
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
0
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
4
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
8
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
12
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
5
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
9
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
13
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
2
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
6
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
10
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
14
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
3
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
7
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
11
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
1
|
||||
15
|
||||
2
|
||||
2
|
||||
0 7.389056
|
||||
1 1.000000
|
||||
|
||||
2
|
||||
16 20
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
17 21
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
18 22
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
19 23
|
||||
2 2
|
||||
4
|
||||
0 4.481689
|
||||
1 1.000000
|
||||
2 4.481689
|
||||
3 4.481689
|
||||
|
||||
2
|
||||
0 16
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
||||
3
|
||||
4 17 16
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
8 18 16
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
12 19 16
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
1 16 17
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
2
|
||||
5 17
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
||||
3
|
||||
9 18 17
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
13 19 17
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
2 16 18
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
6 17 18
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
2
|
||||
10 18
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
||||
3
|
||||
14 19 18
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
3 16 19
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
7 17 19
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
3
|
||||
11 18 19
|
||||
2 2 2
|
||||
8
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 1.000000
|
||||
4 3.004166
|
||||
5 1.000000
|
||||
6 3.004166
|
||||
7 3.004166
|
||||
|
||||
2
|
||||
15 19
|
||||
2 2
|
||||
4
|
||||
0 3.004166
|
||||
1 3.004166
|
||||
2 3.004166
|
||||
3 3.004166
|
||||
|
@ -1,9 +1,9 @@
|
||||
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_clpbn_flag(solver,ve).
|
||||
%:- set_clpbn_flag(solver,bp), clpbn_bp:set_horus_flag(inf_alg,ve).
|
||||
:- set_clpbn_flag(solver,fove).
|
||||
:- set_pfl_flag(solver,fove).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,ve).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,bp).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,cbp).
|
||||
|
||||
c(p1).
|
||||
c(p2).
|
||||
@ -26,7 +26,5 @@ markov attends(P)::[t,f] , attr6::[t,f] ; [0.1, 0.2, 0.3, 0.4] ; [c(P)].
|
||||
|
||||
markov attends(P)::[t,f], series::[t,f] ; [0.5, 0.6, 0.7, 0.8] ; [c(P)].
|
||||
|
||||
%:- clpbn_horus:set_horus_flag(use_logarithms,true).
|
||||
|
||||
?- series(X).
|
||||
|
||||
|
@ -50,7 +50,7 @@ init_fove_solver(_, AllAttVars, _, fove(ParfactorList, DistIds)) :-
|
||||
get_dist_ids(Parfactors, DistIds0),
|
||||
sort(DistIds0, DistIds),
|
||||
get_observed_vars(AllAttVars, ObservedVars),
|
||||
writeln(factors:Parfactors:'\n'),
|
||||
writeln(parfactors:Parfactors:'\n'),
|
||||
writeln(evidence:ObservedVars:'\n'),
|
||||
create_lifted_network(Parfactors,ObservedVars,ParfactorList).
|
||||
|
||||
@ -139,11 +139,11 @@ get_dists_parameters([Id|Ids], [dist(Id, Params)|DistsInfo]) :-
|
||||
|
||||
|
||||
run_fove_solver(QueryVarsAtts, Solutions, fove(ParfactorList, DistIds)) :-
|
||||
get_dists_parameters(DistIds, DistsParams),
|
||||
writeln(distParams:DistsParams),
|
||||
set_parfactors_params(ParfactorList, DistsParams),
|
||||
get_query_vars(QueryVarsAtts, QueryVars),
|
||||
writeln(queryVars:QueryVars), writeln(''),
|
||||
get_dists_parameters(DistIds, DistsParams),
|
||||
writeln(dists:DistsParams), writeln(''),
|
||||
set_parfactors_params(ParfactorList, DistsParams),
|
||||
run_lifted_solver(ParfactorList, QueryVars, Solutions).
|
||||
|
||||
|
||||
|
@ -28,10 +28,8 @@ warning :-
|
||||
:- catch(load_foreign_files([horus], [], init_predicates), _, patch_things_up) -> true ; warning.
|
||||
|
||||
|
||||
|
||||
%:- set_horus_flag(inf_alg, ve).
|
||||
:- set_horus_flag(inf_alg, bn_bp).
|
||||
%:- set_horus_flag(inf_alg, fg_bp).
|
||||
:- set_horus_flag(inf_alg, ve).
|
||||
%:- set_horus_flag(inf_alg, bp).
|
||||
%: -set_horus_flag(inf_alg, cbp).
|
||||
|
||||
:- set_horus_flag(schedule, seq_fixed).
|
||||
|
@ -145,7 +145,7 @@ add_evidence(Sk,Var) :-
|
||||
|
||||
get_pfl_parameters(Id,Out) :-
|
||||
factor(_Type,Id,_FList,_FV,Phi,_Constraints),
|
||||
writeln(factor(_Type,Id,_FList,_FV,_Phi,_Constraints)),
|
||||
%writeln(factor(_Type,Id,_FList,_FV,_Phi,_Constraints)),
|
||||
( is_list(Phi) -> Out = Phi ; call(user:Phi, Out) ).
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user