- upgrade to latest simplecudd.
- fix paths in learning.
This commit is contained in:
parent
98843bea46
commit
77e947cdae
@ -10,7 +10,7 @@
|
||||
% will run 20 iterations of learning with default settings
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
:- use_module('../learning').
|
||||
:- use_module(library(problog_learning)).
|
||||
|
||||
%%%%
|
||||
% background knowledge
|
||||
|
@ -233,8 +233,8 @@
|
||||
shell/2]).
|
||||
|
||||
% load our own modules
|
||||
:- use_module('learning/logger').
|
||||
:- use_module('learning/flags_learning').
|
||||
:- use_module('problog_learning/logger').
|
||||
:- use_module('problog_learning/flags_learning').
|
||||
:- use_module(problog).
|
||||
|
||||
% used to indicate the state of the system
|
||||
|
@ -142,7 +142,6 @@
|
||||
* *
|
||||
\******************************************************************************/
|
||||
|
||||
|
||||
#include "simplecudd.h"
|
||||
#include <signal.h>
|
||||
|
||||
@ -218,12 +217,18 @@ int main(int argc, char **arg) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (params.method != 0 && arg[params.method][0] != 'g' && arg[params.method][0] != 'p' && arg[params.method][0] != 'o' && arg[params.method][0] != 'l') {
|
||||
if (params.method != 0 && arg[params.method][0] != 'g' && arg[params.method][0] != 'p' && arg[params.method][0] != 'o' && arg[params.method][0] != 'l') {
|
||||
printhelp(argc, arg);
|
||||
fprintf(stderr, "Error: you must choose a calculation method beetween [p]robability, [g]radient, [l]ine search, [o]nline.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (params.method != 0 && (arg[params.method][0] == 'g' || arg[params.method][0] == 'p' || arg[params.method][0] == 'l') && params.inputfile == -1) {
|
||||
printhelp(argc, arg);
|
||||
fprintf(stderr, "Error: an input file is necessary for probability, gradient or line search calculation methods.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (params.debug) DEBUGON;
|
||||
RAPIDLOADON;
|
||||
SETMAXBUFSIZE(params.maxbufsize);
|
||||
@ -247,11 +252,6 @@ int main(int argc, char **arg) {
|
||||
fileheader = ReadFileHeader(arg[params.loadfile]);
|
||||
switch(fileheader.filetype) {
|
||||
case BDDFILE_SCRIPT:
|
||||
if (params.inputfile == -1) {
|
||||
printhelp(argc, arg);
|
||||
fprintf(stderr, "Error: an input file is necessary for this type of loading file.\n");
|
||||
return -1;
|
||||
}
|
||||
MyManager.manager = simpleBDDinit(fileheader.varcnt);
|
||||
MyManager.t = HIGH(MyManager.manager);
|
||||
MyManager.f = LOW(MyManager.manager);
|
||||
@ -260,11 +260,6 @@ int main(int argc, char **arg) {
|
||||
ivarcnt = fileheader.varcnt;
|
||||
break;
|
||||
case BDDFILE_NODEDUMP:
|
||||
if (params.inputfile == -1) {
|
||||
printhelp(argc, arg);
|
||||
fprintf(stderr, "Error: an input file is necessary for this type of loading file.\n");
|
||||
return -1;
|
||||
}
|
||||
MyManager.manager = simpleBDDinit(fileheader.varcnt);
|
||||
MyManager.t = HIGH(MyManager.manager);
|
||||
MyManager.f = LOW(MyManager.manager);
|
||||
@ -301,10 +296,10 @@ int main(int argc, char **arg) {
|
||||
probability = tvalue.probability;
|
||||
double factor = sigmoid(MyManager.varmap.dvalue[i], params.sigmoid_slope) * (1 - sigmoid(MyManager.varmap.dvalue[i], params.sigmoid_slope)) * params.sigmoid_slope;
|
||||
if (varpattern == NULL) {
|
||||
printf("query_gradient(%s,%s,%1.12f).\n", arg[params.queryid], MyManager.varmap.vars[i], tvalue.gradient * factor);
|
||||
printf("query_gradient(%s,%s,%e).\n", arg[params.queryid], MyManager.varmap.vars[i], tvalue.gradient * factor);
|
||||
} else {
|
||||
varpattern[strlen(varpattern) - 2] = '\0';
|
||||
printf("query_gradient(%s,%s,%1.12f).\n", arg[params.queryid], varpattern, tvalue.gradient * factor);
|
||||
printf("query_gradient(%s,%s,%e).\n", arg[params.queryid], varpattern, tvalue.gradient * factor);
|
||||
}
|
||||
ReInitHistory(MyManager.his, MyManager.varmap.varcnt);
|
||||
}
|
||||
@ -318,15 +313,15 @@ int main(int argc, char **arg) {
|
||||
tvalue = CalcGradient(MyManager, bdd, 0 + MyManager.varmap.varstart, NULL);
|
||||
probability = tvalue.probability;
|
||||
}
|
||||
printf("query_probability(%s,%1.12f).\n", arg[params.queryid], probability);
|
||||
printf("query_probability(%s,%e).\n", arg[params.queryid], probability);
|
||||
break;
|
||||
case 'l':
|
||||
tvalue = CalcGradient(MyManager, bdd, 0 + MyManager.varmap.varstart, NULL);
|
||||
probability = tvalue.probability;
|
||||
printf("query_probability(%s,%1.12f).\n", arg[params.queryid], probability);
|
||||
printf("query_probability(%s,%e).\n", arg[params.queryid], probability);
|
||||
break;
|
||||
case 'p':
|
||||
printf("probability(%1.12f).\n", CalcProbability(MyManager, bdd));
|
||||
printf("probability(%e).\n", CalcProbability(MyManager, bdd));
|
||||
break;
|
||||
case 'o':
|
||||
onlinetraverse(MyManager.manager, MyManager.varmap, MyManager.his, bdd);
|
||||
@ -347,7 +342,13 @@ int main(int argc, char **arg) {
|
||||
KillBDD(MyManager.manager);
|
||||
free(MyManager.varmap.dvalue);
|
||||
free(MyManager.varmap.ivalue);
|
||||
free(MyManager.varmap.dynvalue);
|
||||
if (MyManager.varmap.dynvalue != NULL) {
|
||||
for(i = 0; i < MyManager.varmap.varcnt; i++)
|
||||
if (MyManager.varmap.dynvalue[i] != NULL) {
|
||||
free(MyManager.varmap.dynvalue[i]);
|
||||
}
|
||||
free(MyManager.varmap.dynvalue);
|
||||
}
|
||||
for (i = 0; i < MyManager.varmap.varcnt; i++)
|
||||
free(MyManager.varmap.vars[i]);
|
||||
free(MyManager.varmap.vars);
|
||||
@ -386,12 +387,12 @@ void printhelp(int argc, char **arg) {
|
||||
fprintf(stderr, "Optional parameters:\n");
|
||||
fprintf(stderr, "\t-sd [filename]\t->\tfilename to save generated BDD in node dump format (fast loading, traverse valid only)\n");
|
||||
fprintf(stderr, "\t-e [filename]\t->\tfilename to export generated BDD in dot format\n");
|
||||
fprintf(stderr, "\t-m [method]\t->\tthe calculation method to be used: none(default), [p]robability, [g]radient, [o]nline\n");
|
||||
fprintf(stderr, "\t-m [method]\t->\tthe calculation method to be used: none(default), [p]robability, [g]radient, [l]ine search, [o]nline\n");
|
||||
fprintf(stderr, "\t-id [queryid]\t->\tthe queries identity name (used by gradient) default: %s\n", arg[0]);
|
||||
fprintf(stderr, "\t-sl [double]\t->\tthe sigmoid slope (used by gradient) default: 1.0\n");
|
||||
fprintf(stderr, "Extra parameters:\n");
|
||||
fprintf(stderr, "\t-t [seconds]\t->\tthe seconds (int) for BDD generation timeout default 0 = no timeout\n");
|
||||
fprintf(stderr, "\t-pid [pid]\t->\ta process id (int) to check for termination default 0 = no process to check works only under POSIX OS\n");
|
||||
fprintf(stderr, "\t-pid [pid]\t->\ta process id (int) to check for termination default 0 = no process to check\n");
|
||||
fprintf(stderr, "\t-bs [bytes]\t->\tthe bytes (int) to use as a maximum buffer size to read files default 0 = no max\n");
|
||||
fprintf(stderr, "\t-d\t\t->\tRun in debug mode (gives extra messages in stderr)\n");
|
||||
fprintf(stderr, "\t-h\t\t->\tHelp (displays this message)\n\n");
|
||||
@ -580,7 +581,7 @@ void myexpand(extmanager MyManager, DdNode *Current) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Angelikas Algorithm */
|
||||
/* Angelicas Algorithm */
|
||||
|
||||
double CalcProbability(extmanager MyManager, DdNode *Current) {
|
||||
DdNode *h, *l;
|
||||
|
@ -184,49 +184,55 @@ DdNode* LowNodeOf(DdManager *manager, DdNode *node) {
|
||||
|
||||
DdNode* D_BDDAnd(DdManager *manager, DdNode *bdd1, DdNode *bdd2) {
|
||||
DdNode *tmp;
|
||||
Cudd_Ref(bdd1);
|
||||
tmp = Cudd_bddAnd(manager, bdd1, bdd2);
|
||||
Cudd_Ref(tmp);
|
||||
Cudd_RecursiveDeref(manager, bdd2);
|
||||
//Cudd_RecursiveDeref(manager, bdd2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
DdNode* D_BDDNand(DdManager *manager, DdNode *bdd1, DdNode *bdd2) {
|
||||
DdNode *tmp;
|
||||
Cudd_Ref(bdd1);
|
||||
tmp = Cudd_bddNand(manager, bdd1, bdd2);
|
||||
Cudd_Ref(tmp);
|
||||
Cudd_RecursiveDeref(manager, bdd2);
|
||||
//Cudd_RecursiveDeref(manager, bdd2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
DdNode* D_BDDOr(DdManager *manager, DdNode *bdd1, DdNode *bdd2) {
|
||||
DdNode *tmp;
|
||||
Cudd_Ref(bdd1);
|
||||
tmp = Cudd_bddOr(manager, bdd1, bdd2);
|
||||
Cudd_Ref(tmp);
|
||||
Cudd_RecursiveDeref(manager, bdd2);
|
||||
//Cudd_RecursiveDeref(manager, bdd2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
DdNode* D_BDDNor(DdManager *manager, DdNode *bdd1, DdNode *bdd2) {
|
||||
DdNode *tmp;
|
||||
Cudd_Ref(bdd1);
|
||||
tmp = Cudd_bddNor(manager, bdd1, bdd2);
|
||||
Cudd_Ref(tmp);
|
||||
Cudd_RecursiveDeref(manager, bdd2);
|
||||
//Cudd_RecursiveDeref(manager, bdd2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
DdNode* D_BDDXor(DdManager *manager, DdNode *bdd1, DdNode *bdd2) {
|
||||
DdNode *tmp;
|
||||
Cudd_Ref(bdd1);
|
||||
tmp = Cudd_bddXor(manager, bdd1, bdd2);
|
||||
Cudd_Ref(tmp);
|
||||
Cudd_RecursiveDeref(manager, bdd2);
|
||||
//Cudd_RecursiveDeref(manager, bdd2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
DdNode* D_BDDXnor(DdManager *manager, DdNode *bdd1, DdNode *bdd2) {
|
||||
DdNode *tmp;
|
||||
Cudd_Ref(bdd1);
|
||||
tmp = Cudd_bddXnor(manager, bdd1, bdd2);
|
||||
Cudd_Ref(tmp);
|
||||
Cudd_RecursiveDeref(manager, bdd2);
|
||||
//Cudd_RecursiveDeref(manager, bdd2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@ -541,7 +547,7 @@ int LoadVariableData(namedvars varmap, char *filename) {
|
||||
int icur = 0, maxbufsize = 10, hasvar = 0, index = -1, idat = 0, ivalue = 0;
|
||||
dynvalue = NULL;
|
||||
if ((data = fopen(filename, "r")) == NULL) {
|
||||
perror("fopen");
|
||||
perror(filename);
|
||||
return -1;
|
||||
}
|
||||
dataread = (char *) malloc(sizeof(char) * maxbufsize);
|
||||
@ -716,7 +722,7 @@ namedvars InitNamedVars(int varcnt, int varstart) {
|
||||
temp.loaded = (int *) malloc(sizeof(int) * varcnt);
|
||||
temp.dvalue = (double *) malloc(sizeof(double) * varcnt);
|
||||
temp.ivalue = (int *) malloc(sizeof(int) * varcnt);
|
||||
temp.dynvalue = (void **) malloc(sizeof(int) * varcnt);
|
||||
temp.dynvalue = (void **) malloc(sizeof(void *) * varcnt);
|
||||
for (i = 0; i < varcnt; i++) {
|
||||
temp.vars[i] = NULL;
|
||||
temp.loaded[i] = 0;
|
||||
@ -733,7 +739,7 @@ void EnlargeNamedVars(namedvars *varmap, int newvarcnt) {
|
||||
varmap->loaded = (int *) realloc(varmap->loaded, sizeof(int) * newvarcnt);
|
||||
varmap->dvalue = (double *) realloc(varmap->dvalue, sizeof(double) * newvarcnt);
|
||||
varmap->ivalue = (int *) realloc(varmap->ivalue, sizeof(int) * newvarcnt);
|
||||
varmap->dynvalue = (void **) realloc(varmap->dynvalue, sizeof(int) * newvarcnt);
|
||||
varmap->dynvalue = (void **) realloc(varmap->dynvalue, sizeof(void *) * newvarcnt);
|
||||
for (i = varmap->varcnt; i < newvarcnt; i++) {
|
||||
varmap->vars[i] = NULL;
|
||||
varmap->loaded[i] = 0;
|
||||
@ -1483,7 +1489,7 @@ int GetParam(char *inputline, int iParam) {
|
||||
|
||||
void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, DdNode *bdd) {
|
||||
char buf, *inputline;
|
||||
int icur, maxlinesize, iline, index, iloop, ivalue, iQsize, i, inQ;
|
||||
int icur, maxlinesize, iline, index, iloop, ivalue, iQsize, i, inQ, iRoot;
|
||||
double dvalue;
|
||||
DdNode **Q, **Q2, *h_node, *l_node, *curnode;
|
||||
hisqueue *his;
|
||||
@ -1495,6 +1501,7 @@ void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, Dd
|
||||
inputline = (char *) malloc(sizeof(char) * maxlinesize);
|
||||
curnode = bdd;
|
||||
iQsize = 0;
|
||||
iRoot = 1;
|
||||
Q = (DdNode **) malloc(sizeof(DdNode *) * iQsize);
|
||||
Q2 = NULL;
|
||||
his = InitHistory(varmap.varcnt);
|
||||
@ -1505,11 +1512,17 @@ void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, Dd
|
||||
if ((icur > 0) && (inputline[0] == '@') && (inputline[2] == ',' || inputline[2] == '\0')) {
|
||||
switch(inputline[1]) {
|
||||
case 'c':
|
||||
printf("bdd_temp_value('%s', %i).\n", GetNodeVarNameDisp(manager, varmap, curnode), iQsize);
|
||||
if (iRoot) {
|
||||
iRoot = 0;
|
||||
printf("bdd_temp_value('%s', %i).\n", GetNodeVarNameDisp(manager, varmap, curnode), 1);
|
||||
} else {
|
||||
printf("bdd_temp_value('%s', %i).\n", GetNodeVarNameDisp(manager, varmap, curnode), iQsize);
|
||||
}
|
||||
fflush(stdout);
|
||||
break;
|
||||
case 'n':
|
||||
if (curnode != HIGH(manager) && curnode != LOW(manager) && (hnode = GetNode(his, varmap.varstart, curnode)) == NULL) {
|
||||
AddNode(his, varmap.varstart, curnode, 0.0, 0, NULL);
|
||||
//AddNode(his, varmap.varstart, curnode, 0.0, 0, NULL);
|
||||
l_node = LowNodeOf(manager, curnode);
|
||||
h_node = HighNodeOf(manager, curnode);
|
||||
inQ = 0;
|
||||
@ -1519,6 +1532,7 @@ void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, Dd
|
||||
if (inQ & 2 == 0) inQ = inQ + 2 * (GetNode(his, varmap.varstart, h_node) != NULL);
|
||||
if (inQ & 1 == 1) inQ = inQ - (l_node == HIGH(manager) || l_node == LOW(manager));
|
||||
if (inQ & 2 == 2) inQ = inQ - 2 * (h_node == HIGH(manager) || h_node == LOW(manager));
|
||||
inQ = 0;
|
||||
switch(inQ) {
|
||||
case 0:
|
||||
iQsize += 2;
|
||||
@ -1567,14 +1581,17 @@ void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, Dd
|
||||
break;
|
||||
case 'h':
|
||||
printf("bdd_temp_value('%s').\n", GetNodeVarNameDisp(manager, varmap, HighNodeOf(manager, curnode)));
|
||||
fflush(stdout);
|
||||
break;
|
||||
case 'l':
|
||||
printf("bdd_temp_value('%s').\n", GetNodeVarNameDisp(manager, varmap, LowNodeOf(manager, curnode)));
|
||||
fflush(stdout);
|
||||
break;
|
||||
case 'v':
|
||||
index = GetNamedVarIndex(varmap, inputline + 3);
|
||||
if (index >= 0) {
|
||||
fprintf(stdout, "bdd_temp_value([%f,%i,%s]).\n", varmap.dvalue[index], varmap.ivalue[index], (char *) varmap.dynvalue[index]);
|
||||
printf("bdd_temp_value([%f,%i,%s]).\n", varmap.dvalue[index], varmap.ivalue[index], (char *) varmap.dynvalue[index]);
|
||||
fflush(stdout);
|
||||
} else {
|
||||
fprintf(stderr, "Error: Could not find variable: %s, Correct syntax @v,[variable name].\n", inputline + 3);
|
||||
free(Q);
|
||||
|
@ -152,25 +152,26 @@
|
||||
#include "cuddInt.h"
|
||||
#include "general.h"
|
||||
|
||||
#define IsHigh(manager, node) HIGH(manager) == node
|
||||
#define IsLow(manager, node) LOW(manager) == node
|
||||
#define HIGH(manager) Cudd_ReadOne(manager)
|
||||
#define LOW(manager) Cudd_Not(Cudd_ReadOne(manager))
|
||||
#define NOT(node) Cudd_Not(node)
|
||||
#define GetIndex(node) Cudd_NodeReadIndex(node)
|
||||
#define GetVar(manager, index) Cudd_bddIthVar(manager, index)
|
||||
#define NewVar(manager) Cudd_bddNewVar(manager)
|
||||
#define KillBDD(manager) Cudd_Quit(manager)
|
||||
#define GetVarCount(manager) Cudd_ReadSize(manager)
|
||||
#define DEBUGON _debug = 1
|
||||
#define DEBUGOFF _debug = 0
|
||||
#define RAPIDLOADON _RapidLoad = 1
|
||||
#define RAPIDLOADOFF _RapidLoad = 0
|
||||
#define SETMAXBUFSIZE(size) _maxbufsize = size
|
||||
#define BDDFILE_ERROR -1
|
||||
#define BDDFILE_OTHER 0
|
||||
#define BDDFILE_SCRIPT 1
|
||||
#define BDDFILE_NODEDUMP 2
|
||||
#define IsHigh(manager, node) HIGH(manager) == node
|
||||
#define IsLow(manager, node) LOW(manager) == node
|
||||
#define HIGH(manager) Cudd_ReadOne(manager)
|
||||
#define LOW(manager) Cudd_Not(Cudd_ReadOne(manager))
|
||||
#define NOT(node) Cudd_Not(node)
|
||||
#define GetIndex(node) Cudd_NodeReadIndex(node)
|
||||
#define GetOrder(manager, node) Cudd_ReadPerm(manager, GetIndex(node))
|
||||
#define GetVar(manager, index) Cudd_bddIthVar(manager, index)
|
||||
#define NewVar(manager) Cudd_bddNewVar(manager)
|
||||
#define KillBDD(manager) Cudd_Quit(manager)
|
||||
#define GetVarCount(manager) Cudd_ReadSize(manager)
|
||||
#define DEBUGON _debug = 1
|
||||
#define DEBUGOFF _debug = 0
|
||||
#define RAPIDLOADON _RapidLoad = 1
|
||||
#define RAPIDLOADOFF _RapidLoad = 0
|
||||
#define SETMAXBUFSIZE(size) _maxbufsize = size
|
||||
#define BDDFILE_ERROR -1
|
||||
#define BDDFILE_OTHER 0
|
||||
#define BDDFILE_SCRIPT 1
|
||||
#define BDDFILE_NODEDUMP 2
|
||||
|
||||
extern int _RapidLoad;
|
||||
extern int _debug;
|
||||
|
Reference in New Issue
Block a user