added memory profiling calls
removed limit to 1000 variables imposed by createVars beause of the use of tha array of names of variables git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2266 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
87fcf6233c
commit
0ca51355ce
@ -29,7 +29,7 @@ typedef struct
|
||||
} variable;
|
||||
|
||||
|
||||
void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar, char inames[1000][20]);
|
||||
void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar,int create_dot, char inames[1000][20]);
|
||||
void createExpression(array_t * expression, YAP_Term t);
|
||||
void init_my_predicates(void);
|
||||
int compare(char *a, char *b);
|
||||
|
@ -24,7 +24,7 @@ FILE *open_file (char *filename, const char *mode);
|
||||
void reverse(char s[]);
|
||||
static int compute_prob(void);
|
||||
|
||||
void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar, char inames[1000][20])
|
||||
void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar,int create_dot, char inames[1000][20])
|
||||
/* adds the boolean variables to the BDD and returns
|
||||
an array_t containing them (array_t is defined in the util library of glu)
|
||||
returns also the names of the variables to be used to save the ADD in dot format
|
||||
@ -52,12 +52,15 @@ returns also the names of the variables to be used to save the ADD in dot format
|
||||
v.booleanVars=array_alloc(DdNode *,0);
|
||||
for (i=0;i<nVal;i++)
|
||||
{
|
||||
strcpy(inames[b+i],"X");
|
||||
sprintf(numberVar,"%d",varIndex);
|
||||
strcat(inames[b+i],numberVar);
|
||||
strcat(inames[b+i],"_");
|
||||
sprintf(numberBit,"%d",i);
|
||||
strcat(inames[b+i],numberBit);
|
||||
if (create_dot)
|
||||
{
|
||||
strcpy(inames[b+i],"X");
|
||||
sprintf(numberVar,"%d",varIndex);
|
||||
strcat(inames[b+i],numberVar);
|
||||
strcat(inames[b+i],"_");
|
||||
sprintf(numberBit,"%d",i);
|
||||
strcat(inames[b+i],numberBit);
|
||||
}
|
||||
p=YAP_FloatOfTerm(YAP_HeadOfTerm(probTerm));
|
||||
array_insert(double,v.probabilities,i,p);
|
||||
probTerm=YAP_TailOfTerm(probTerm);
|
||||
@ -112,7 +115,7 @@ static int compute_prob(void)
|
||||
array_t * variables,* expression, * bVar2mVar;
|
||||
DdNode * function, * add;
|
||||
DdManager * mgr;
|
||||
int nBVar,i,j,intBits;
|
||||
int nBVar,i,j,intBits,create_dot;
|
||||
FILE * file;
|
||||
DdNode * array[1];
|
||||
char * onames[1];
|
||||
@ -120,20 +123,29 @@ static int compute_prob(void)
|
||||
char * names[1000];
|
||||
GHashTable * nodes; /* hash table that associates nodes with their probability if already
|
||||
computed, it is defined in glib */
|
||||
|
||||
Cudd_ReorderingType order;
|
||||
arg1=YAP_ARG1;
|
||||
arg2=YAP_ARG2;
|
||||
arg3=YAP_ARG3;
|
||||
arg4=YAP_ARG4;
|
||||
|
||||
mgr=Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0);
|
||||
|
||||
variables=array_alloc(variable,0);
|
||||
bVar2mVar=array_alloc(int,0);
|
||||
createVars(variables,arg1,mgr,bVar2mVar,inames);
|
||||
create_dot=YAP_IntOfTerm(arg4);
|
||||
createVars(variables,arg1,mgr,bVar2mVar,create_dot,inames);
|
||||
Cudd_PrintInfo(mgr,stderr);
|
||||
|
||||
/* automatic variable reordering, default method CUDD_REORDER_SIFT used */
|
||||
Cudd_AutodynEnable(mgr,CUDD_REORDER_SAME);
|
||||
printf("status %d\n",Cudd_ReorderingStatus(mgr,&order));
|
||||
printf("order %d\n",order);
|
||||
|
||||
Cudd_AutodynEnable(mgr,CUDD_REORDER_SAME);
|
||||
/* Cudd_AutodynEnable(mgr, CUDD_REORDER_RANDOM_PIVOT);
|
||||
printf("status %d\n",Cudd_ReorderingStatus(mgr,&order));
|
||||
printf("order %d\n",order);
|
||||
printf("%d",CUDD_REORDER_RANDOM_PIVOT);
|
||||
*/
|
||||
|
||||
|
||||
expression=array_alloc(array_t *,0);
|
||||
@ -143,8 +155,9 @@ static int compute_prob(void)
|
||||
/* the BDD build by retFunction is converted to an ADD (algebraic decision diagram)
|
||||
because it is easier to interpret and to print */
|
||||
add=Cudd_BddToAdd(mgr,function);
|
||||
Cudd_PrintInfo(mgr,stderr);
|
||||
|
||||
if (YAP_IntOfTerm(arg4))
|
||||
if (create_dot)
|
||||
/* if specified by the user, a dot file for the BDD is written to cpl.dot */
|
||||
{
|
||||
nBVar=array_n(bVar2mVar);
|
||||
|
@ -115,6 +115,7 @@ solve(GL,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000,
|
||||
print_mem,
|
||||
build_ground_lpad(L2,0,CL),
|
||||
convert_to_clpbn(CL,GL,LV,P),
|
||||
statistics(cputime,[_,CT2]),
|
||||
@ -122,6 +123,7 @@ solve(GL,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
statistics(walltime,[_,WT2]),
|
||||
WallTime2 is WT2/1000
|
||||
;
|
||||
print_mem,
|
||||
P=0.0,
|
||||
statistics(cputime,[_,CT1]),
|
||||
CPUTime1 is CT1/1000,
|
||||
@ -130,7 +132,9 @@ solve(GL,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
CPUTime2 =0.0,
|
||||
statistics(walltime,[_,WT2]),
|
||||
WallTime2 =0.0
|
||||
),!.
|
||||
),!,
|
||||
format(user_error,"Memory after inference~n",[]),
|
||||
print_mem.
|
||||
|
||||
/* sc(GoalsList,EvidenceList,Prob) compute the probability of a list of goals
|
||||
GoalsList given EvidenceList. Both lists can have variables, sc returns in
|
||||
@ -151,6 +155,7 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000,
|
||||
print_mem,
|
||||
build_ground_lpad(LD1,0,CL),
|
||||
convert_to_clpbn(CL,GL,LV,P,GLC),
|
||||
statistics(cputime,[_,CT2]),
|
||||
@ -159,6 +164,8 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
WallTime2 is WT2/1000
|
||||
;
|
||||
P=0.0,
|
||||
print_mem,
|
||||
format(user_error,"Porb 0~n",[]),
|
||||
statistics(cputime,[_,CT1]),
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
@ -168,13 +175,18 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
)
|
||||
;
|
||||
P=undef,
|
||||
print_mem,
|
||||
statistics(cputime,[_,CT1]),
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000,
|
||||
CPUTime2 =0.0,
|
||||
WallTime2 =0.0
|
||||
).
|
||||
WallTime2 =0.0,
|
||||
print_mem,
|
||||
format(user_error,"Undef~n",[])
|
||||
),
|
||||
format(user_error,"Memory after inference~n",[]),
|
||||
print_mem.
|
||||
|
||||
remove_head([],[]).
|
||||
|
||||
@ -435,6 +447,15 @@ find_atoms_head([],[],[]).
|
||||
find_atoms_head([H:P|T],[H|TA],[P|TP]):-
|
||||
find_atoms_head(T,TA,TP).
|
||||
|
||||
print_mem:-
|
||||
statistics(global_stack,[GS,GSF]),
|
||||
statistics(local_stack,[LS,LSF]),
|
||||
statistics(heap,[HP,HPF]),
|
||||
statistics(trail,[TU,TF]),
|
||||
format(user_error,"~nGloabal stack used ~d execution stack free: ~d~n",[GS,GSF]),
|
||||
format(user_error,"Local stack used ~d execution stack free: ~d~n",[LS,LSF]),
|
||||
format(user_error,"Heap used ~d heap free: ~d~n",[HP,HPF]),
|
||||
format(user_error,"Trail used ~d Trail free: ~d~n",[TU,TF]).
|
||||
|
||||
find_deriv(GoalsList,Deriv):-
|
||||
solve(GoalsList,[],DerivDup),
|
||||
|
@ -68,7 +68,11 @@ solve(GoalsList,Prob,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000,
|
||||
build_formula(L,Formula,[],Var),
|
||||
print_mem,
|
||||
build_formula(L,Formula,[],Var,0,Conj),
|
||||
length(L,ND),
|
||||
length(Var,NV),
|
||||
format(user_error,"Disjunctions :~d~nConjunctions: ~d~nVariables ~d~n",[ND,Conj,NV]),
|
||||
var2numbers(Var,0,NewVar),
|
||||
(setting(save_dot,true)->
|
||||
format("Variables: ~p~n",[Var]),
|
||||
@ -81,6 +85,7 @@ solve(GoalsList,Prob,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
statistics(walltime,[_,WT2]),
|
||||
WallTime2 is WT2/1000
|
||||
;
|
||||
print_mem,
|
||||
Prob=0.0,
|
||||
statistics(cputime,[_,CT1]),
|
||||
CPUTime1 is CT1/1000,
|
||||
@ -89,9 +94,19 @@ solve(GoalsList,Prob,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
CPUTime2 =0.0,
|
||||
statistics(walltime,[_,WT2]),
|
||||
WallTime2 =0.0
|
||||
),!.
|
||||
|
||||
),!,
|
||||
format(user_error,"~nMemory after inference~n",[]),
|
||||
print_mem.
|
||||
|
||||
print_mem:-
|
||||
statistics(global_stack,[GS,GSF]),
|
||||
statistics(local_stack,[LS,LSF]),
|
||||
statistics(heap,[HP,HPF]),
|
||||
statistics(trail,[TU,TF]),
|
||||
format(user_error,"~nGloabal stack used ~d execution stack free: ~d~n",[GS,GSF]),
|
||||
format(user_error,"Local stack used ~d execution stack free: ~d~n",[LS,LSF]),
|
||||
format(user_error,"Heap used ~d heap free: ~d~n",[HP,HPF]),
|
||||
format(user_error,"Trail used ~d Trail free: ~d~n",[TU,TF]).
|
||||
|
||||
find_deriv(GoalsList,Deriv):-
|
||||
solve(GoalsList,[],DerivDup),
|
||||
@ -111,6 +126,7 @@ solve_cond(Goals,Evidence,Prob):-
|
||||
(setof(DerivE,find_deriv(Evidence,DerivE),LDupE)->
|
||||
rem_dup_lists(LDupE,[],LE),
|
||||
(setof(DerivGE,find_deriv_GE(LE,Goals,DerivGE),LDupGE)->
|
||||
print_mem,
|
||||
rem_dup_lists(LDupGE,[],LGE),
|
||||
build_formula(LE,FormulaE,[],VarE),
|
||||
var2numbers(VarE,0,NewVarE),
|
||||
@ -120,11 +136,15 @@ solve_cond(Goals,Evidence,Prob):-
|
||||
call_compute_prob(NewVarGE,FormulaGE,ProbGE),
|
||||
Prob is ProbGE/ProbE
|
||||
;
|
||||
print_mem,
|
||||
Prob=0.0
|
||||
)
|
||||
;
|
||||
print_mem,
|
||||
Prob=undefined
|
||||
).
|
||||
),
|
||||
format(user_error,"~nMemory after inference~n",[]),
|
||||
print_mem.
|
||||
|
||||
/* sc(Goals,Evidence,Prob,Time1,Time2) compute the conditional probability of the list of goals
|
||||
Goals given the list of goals Evidence
|
||||
@ -502,6 +522,14 @@ Termi is of the form [Factor1,...,Factorm]
|
||||
Factorj is of the form (Var,Value) where Var is the index of
|
||||
the multivalued variable Var and Value is the index of the value
|
||||
*/
|
||||
build_formula([],[],Var,Var,C,C).
|
||||
|
||||
build_formula([D|TD],[F|TF],VarIn,VarOut,C0,C1):-
|
||||
length(D,NC),
|
||||
C2 is C0+NC,
|
||||
build_term(D,F,VarIn,Var1),
|
||||
build_formula(TD,TF,Var1,VarOut,C2,C1).
|
||||
|
||||
build_formula([],[],Var,Var).
|
||||
|
||||
build_formula([D|TD],[F|TF],VarIn,VarOut):-
|
||||
|
@ -107,20 +107,36 @@ s(GL,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000,
|
||||
print_mem,
|
||||
convert_to_bn(CL,GL,[],P),
|
||||
statistics(cputime,[_,CT2]),
|
||||
CPUTime2 is CT2/1000,
|
||||
statistics(walltime,[_,WT2]),
|
||||
WallTime2 is WT2/1000
|
||||
|
||||
;
|
||||
statistics(cputime,[_,CT1]),
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000,
|
||||
print_mem,
|
||||
CPUTime2=0.0,
|
||||
WallTime2=0.0,
|
||||
P=0.0
|
||||
).
|
||||
),
|
||||
format(user_error,"~nMemory after inference~n",[]),
|
||||
print_mem.
|
||||
|
||||
print_mem:-
|
||||
statistics(global_stack,[GS,GSF]),
|
||||
statistics(local_stack,[LS,LSF]),
|
||||
statistics(heap,[HP,HPF]),
|
||||
statistics(trail,[TU,TF]),
|
||||
format(user_error,"~nGloabal stack used ~d execution stack free: ~d~n",[GS,GSF]),
|
||||
format(user_error,"Local stack used ~d execution stack free: ~d~n",[LS,LSF]),
|
||||
format(user_error,"Heap used ~d heap free: ~d~n",[HP,HPF]),
|
||||
format(user_error,"Trail used ~d Trail free: ~d~n",[TU,TF]).
|
||||
|
||||
|
||||
/* sc(GoalsList,EvidenceList,Prob) compute the probability of a list of goals
|
||||
GoalsList given EvidenceList. Both lists can have variables, sc returns in
|
||||
@ -136,6 +152,7 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000,
|
||||
print_mem,
|
||||
(Undef=yes->
|
||||
P=undef,
|
||||
CPUTime2=0.0,
|
||||
@ -148,6 +165,7 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
WallTime2 is WT2/1000
|
||||
)
|
||||
;
|
||||
print_mem,
|
||||
statistics(cputime,[_,CT1]),
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
@ -155,7 +173,9 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):-
|
||||
CPUTime2=0.0,
|
||||
WallTime2=0.0,
|
||||
P=0.0
|
||||
).
|
||||
),
|
||||
format(user_error,"~nMemory after inference~n",[]),
|
||||
print_mem.
|
||||
|
||||
remove_head([],[]).
|
||||
|
||||
|
Reference in New Issue
Block a user