hack to make ProbLog run faster on very large domains.

This commit is contained in:
Vítor Manuel de Morais Santos Costa 2009-11-11 10:54:05 +00:00
parent 8ecac6c2f9
commit 51f6f509e1
3 changed files with 52 additions and 9 deletions

View File

@ -371,6 +371,7 @@ init_global_params :-
set_problog_flag(bdd_file,example_bdd), set_problog_flag(bdd_file,example_bdd),
set_problog_flag(dir,output), set_problog_flag(dir,output),
set_problog_flag(save_bdd,false), set_problog_flag(save_bdd,false),
set_problog_flag(hacked_proofs,false),
set_problog_flag(verbose,true). set_problog_flag(verbose,true).
% problog_flags, % problog_flags,
% print_sep_line, % print_sep_line,
@ -494,7 +495,7 @@ problog_predicate(Name, Arity, ProblogName) :-
append(Args,[Prob],L1), append(Args,[Prob],L1),
ProbFact =.. [ProblogName,ID|L1], ProbFact =.. [ProblogName,ID|L1],
prolog_load_context(module,Mod), prolog_load_context(module,Mod),
make_add_to_proof(ID2,ProbEval,AddToProof),
assert( (Mod:OriginalGoal :- ProbFact, assert( (Mod:OriginalGoal :- ProbFact,
( (
non_ground_fact(ID) non_ground_fact(ID)
@ -505,7 +506,7 @@ problog_predicate(Name, Arity, ProblogName) :-
), ),
% take the log of the probability (for non ground facts with variable as probability % take the log of the probability (for non ground facts with variable as probability
ProbEval is Prob, ProbEval is Prob,
add_to_proof(ID2,ProbEval) AddToProof
)), )),
assert( (Mod:problog_not(OriginalGoal) :- ProbFact, assert( (Mod:problog_not(OriginalGoal) :- ProbFact,
@ -525,6 +526,14 @@ problog_predicate(Name, Arity, ProblogName) :-
ArityPlus2 is Arity+2, ArityPlus2 is Arity+2,
dynamic(problog:ProblogName/ArityPlus2). dynamic(problog:ProblogName/ArityPlus2).
make_add_to_proof(ID2,ProbEval,O) :-
problog_flag(hacked_proofs,true), !,
O = hacked_add_to_proof(ID2,ProbEval).
make_add_to_proof(ID2,ProbEval,add_to_proof(ID2,ProbEval)).
% generate next global identifier % generate next global identifier
probclause_id(ID) :- probclause_id(ID) :-
nb_getval(probclause_counter,ID), !, nb_getval(probclause_counter,ID), !,
@ -553,7 +562,7 @@ non_ground_fact_grounding_id(Goal,ID) :-
nb_getval(non_ground_fact_grounding_id_counter,ID), nb_getval(non_ground_fact_grounding_id_counter,ID),
ID2 is ID+1, ID2 is ID+1,
nb_setval(non_ground_fact_grounding_id_counter,ID2), nb_setval(non_ground_fact_grounding_id_counter,ID2),
assert(grounding_is_known(Goal,ID)) once(assert(grounding_is_known(Goal,ID)))
) )
). ).
@ -717,6 +726,22 @@ add_to_proof(ID,Prob) :-
) )
). ).
% simpliciation
hacked_add_to_proof(ID,Prob) :-
b_getval(problog_probability, CurrentP),
nb_getval(problog_threshold, CurrentThreshold),
multiply_probabilities(CurrentP, Prob, NProb),
b_getval(problog_current_proof, IDs),
(
NProb < CurrentThreshold
->
upper_bound([ID|IDs]),
fail
;
b_setval(problog_probability, NProb),
b_setval(problog_current_proof, [ID|IDs])
).
%%%% Bernd, changes for negated ground facts %%%% Bernd, changes for negated ground facts
add_to_proof_negated(ID,Prob) :- add_to_proof_negated(ID,Prob) :-
( (
@ -1248,13 +1273,17 @@ update_current_kbest(K,NewLogProb,Cl) :-
(NewLength < K -> (NewLength < K ->
assert(current_kbest(OldThres,NewList,NewLength)) assert(current_kbest(OldThres,NewList,NewLength))
; ;
(NewLength>K -> (NewLength>K
->
First is NewLength-K+1, First is NewLength-K+1,
cutoff(NewList,NewLength,First,FinalList,FinalLength) cutoff(NewList,NewLength,First,FinalList,FinalLength)
; FinalList=NewList, FinalLength=NewLength), ;
FinalList=[NewThres-_|_], FinalList=NewList, FinalLength=NewLength
nb_setval(problog_threshold,NewThres), ),
assert(current_kbest(NewThres,FinalList,FinalLength))). FinalList=[NewThres-_|_],
nb_setval(problog_threshold,NewThres),
assert(current_kbest(NewThres,FinalList,FinalLength))
).
sorted_insert(A,[],[A]). sorted_insert(A,[],[A]).
sorted_insert(A-LA,[B1-LB1|B], [A-LA,B1-LB1|B] ) :- sorted_insert(A-LA,[B1-LB1|B], [A-LA,B1-LB1|B] ) :-

View File

@ -216,7 +216,7 @@
:- ensure_loaded(library(system)). :- ensure_loaded(library(system)).
:- dynamic bdd_time/1, first_threshold/1, last_threshold/1, id_stepsize/1, prunecheck/1, maxsteps/1, mc_batchsize/1, mc_logfile/1, bdd_file/1, bdd_par_file/1, bdd_result/1, work_dir/1, save_bdd/1, problog_verbose/1. :- dynamic bdd_time/1, first_threshold/1, last_threshold/1, id_stepsize/1, prunecheck/1, maxsteps/1, mc_batchsize/1, mc_logfile/1, bdd_file/1, bdd_par_file/1, bdd_result/1, work_dir/1, save_bdd/1, problog_verbose/1, hacked_proofs/1.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% global parameters that can be set using set_problog_flag/2 % global parameters that can be set using set_problog_flag/2
@ -258,6 +258,8 @@ get_problog_flag(save_bdd,X) :-
save_bdd(X). save_bdd(X).
get_problog_flag(verbose,X) :- get_problog_flag(verbose,X) :-
problog_verbose(X). problog_verbose(X).
get_problog_flag(hacked_proofs,X) :-
hacked_proofs(X).
%%%%%%%%%%%% %%%%%%%%%%%%
@ -472,6 +474,16 @@ set_problog_flag(verbose,_) :-
flush_output(user), flush_output(user),
fail. fail.
set_problog_flag(hacked_proofs,true) :-
retractall(hacked_proofs(_)),
assert(hacked_proofs(true)).
set_problog_flag(hacked_proofs,false) :-
retractall(hacked_proofs(_)),
assert(hacked_proofs(true)).
set_problog_flag(hacked_proofs,V) :-
format(user,'\% ERROR: value ~w should be \'true\' or \'false\'!~n',[V]),
flush_output(user),
fail.
%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%
% show values % show values

View File

@ -683,6 +683,8 @@ init_queries :-
( % go over all training examples ( % go over all training examples
current_predicate(user:example/3), current_predicate(user:example/3),
user:example(ID,Query,Prob), user:example(ID,Query,Prob),
% statistics(runtime,[_,T]),
% my_format(3,' training example ~q: ~q ~q~n',[ID,Query,T]),
my_format(3,' training example ~q: ~q~n',[ID,Query]), my_format(3,' training example ~q: ~q~n',[ID,Query]),
flush_output(user), flush_output(user),
init_one_query(ID,Query,training), init_one_query(ID,Query,training),