allow ProbLog to use lbdd.

This commit is contained in:
Vítor Santos Costa 2012-04-26 13:52:09 +01:00
parent c3eb3db4ed
commit fd755f0b7e
9 changed files with 80 additions and 13 deletions

View File

@ -30,9 +30,11 @@ BIBTEX=bibtex
PROGRAMS= \
$(srcdir)/problog.yap \
$(srcdir)/problog_bddlib.yap \
$(srcdir)/problog_lfi.yap \
$(srcdir)/dtproblog.yap \
$(srcdir)/aproblog.yap \
$(srcdir)/problog_libbdd_learning.yap\
$(srcdir)/problog_learning.yap
PROBLOG_PROGRAMS= \
@ -56,6 +58,7 @@ PROBLOG_PROGRAMS= \
$(srcdir)/problog/version_control.yap \
$(srcdir)/problog/nestedtries.yap \
$(srcdir)/problog/utils.yap \
$(srcdir)/problog/utils_libbdd.yap \
$(srcdir)/problog/ad_converter.yap \
$(srcdir)/problog/termhandling.yap \
$(srcdir)/problog/completion.yap \

View File

@ -233,6 +233,8 @@
problog_max/3,
problog_kbest_explanations/3,
problog_exact/3,
problog_fl_bdd/2,
problog_kbest_bdd/4,
problog_all_explanations/2,
problog_all_explanations_unsorted/2,
problog_exact_save/5,
@ -591,6 +593,7 @@ reset_control :-
grow_atom_table(N):-
generate_atoms(N, 0),
stop_low_level_trace,
garbage_collect_atoms.
generate_atoms(N, N):-!.
generate_atoms(N, A):-
@ -2145,6 +2148,7 @@ init_problog_low(Threshold) :-
nb_setval(problog_completed_proofs, Trie_Completed_Proofs),
init_problog(Threshold).
:- include(problog_lbdd).
% generalizing problog_max to return all explanations, sorted by non-increasing probability
problog_all_explanations(Goal,Expl) :-
@ -2427,7 +2431,7 @@ problog_kbest(Goal, K, Prob, Status) :-
problog_kbest_id(Goal, K),
retract(current_kbest(_,ListFound,_NumFound)),
build_prefixtree(ListFound),
nb_getval(problog_completed_proofs, Trie_Completed_Proofs),
nb_getval(problog_completed_proofs, Trie_Completed_Proofs),
eval_dnf(Trie_Completed_Proofs,Prob,Status),
delete_ptree(Trie_Completed_Proofs).

View File

@ -343,6 +343,12 @@ learning_init_handler(validating, (_,_,_,_,_)).
learning_init_handler(validated, _Value).
learning_init_handler(stored, _Value).
learning_libdd_init_handler(message, '(Q,BDD,Query)').
learning_libdd_init_handler(validating, (_,_,_)).
%learning_init_handler(validate, V_).
learning_libdd_init_handler(validated, _Value).
learning_libdd_init_handler(stored, _Value).
learning_prob_init_handler(message, '(0,1] or uniform(l,h) ').
learning_prob_init_handler(validating, uniform(Low,High)) :-
number(Low),

View File

@ -277,14 +277,8 @@ create_known_values_file_name(_,_) :-
%=
%========================================================================
create_bdd_file_name(QueryID,ClusterID,Absolute_File_Name) :-
problog_flag(bdd_directory,Path),
!,
atomic_concat(['query_',QueryID,'_cluster_',ClusterID],File_Name),
concat_path_with_filename(Path,File_Name,Absolute_File_Name).
create_bdd_file_name(_,_,_) :-
throw(error(problog_flag_does_not_exist(bdd_directory))).
create_bdd_nb_name(QueryID,ClusterID,NB_Name) :-
atomic_concat(['query_',QueryID,'_cluster_',ClusterID],NB_Name).
%========================================================================
%=

View File

@ -99,3 +99,6 @@ test_example(33,path(5,4),0.57).
test_example(34,path(6,4),0.51).
test_example(35,path(6,5),0.69).
:- set_problog_flag(libbdd_init_method,(Query,Bdd,
problog_kbest_bdd(Query,20,_Status))).

View File

@ -0,0 +1,52 @@
%
% ProbLog extension to use an YAP BDD interface module, instead of simplecudd.
%
:- use_module(library(trie_sp)).
:- use_module(library(bdd)).
:- use_module(library(bhash)).
problog_kbest_bdd(Goal, K, Prob, ok) :-
problog_kbest_to_bdd(Goal, K, BDD, MapList),
bind_maplist(MapList, BoundVars),
bdd_to_probability_sum_product(BDD, BoundVars, Prob).
problog_kbest_as_bdd(Goal, K, bdd(Tree, MapList)) :-
problog_kbest_to_bdd(Goal, K, BDD, MapList),
bdd_tree(BDD, bdd(_Dir, Tree, _Vars)),
bdd_close(BDD).
problog_kbest_to_bdd(Goal, K, BDD, MapList) :-
problog_flag(first_threshold,InitT),
init_problog_kbest(InitT),
problog_control(off,up),
problog_kbest_id(Goal, K),
retract(current_kbest(_,ListFound,_NumFound)),
build_prefixtree(ListFound),
nb_getval(problog_completed_proofs, Trie_Completed_Proofs),
trie_to_bdd(Trie_Completed_Proofs, BDD, MapList),
delete_ptree(Trie_Completed_Proofs).
problog_fl_bdd(Goal, _) :-
init_problog_low(0.0),
problog_control(off, up),
timer_start(sld_time),
problog_call(Goal),
add_solution,
fail.
problog_fl_bdd(_,Prob) :-
timer_stop(sld_time,SLD_Time),
problog_var_set(sld_time, SLD_Time),
nb_getval(problog_completed_proofs, Trie_Completed_Proofs),
tabled_trie_to_bdd(Trie_Completed_Proofs, BDD, MapList),
bind_maplist(MapList, BoundVars),
bdd_to_probability_sum_product(BDD, BoundVars, Prob),
(problog_flag(retain_tables, true) -> retain_tabling; true),
clear_tabling.
bind_maplist([], []).
bind_maplist([Node-_|MapList], [ProbFact|BoundVars]) :-
get_fact_probability(Node,ProbFact),
bind_maplist(MapList, BoundVars).

View File

@ -207,6 +207,7 @@
:- module(learning,[do_learning/1,
do_learning/2,
set_problog_flag/2,
reset_learning/0
]).
@ -740,7 +741,9 @@ update_query(QueryID,Symbol,What_To_Update) :-
' > "',
Output_Directory,
'values.pl"'],Command),
shell(Command,Error),
%shell('cat /home/vsc/Yap/bins/devel/outputvalues.pl',_),
(

View File

@ -10,6 +10,7 @@
bdd_size/2,
bdd_print/2,
bdd_to_probability_sum_product/2,
bdd_to_probability_sum_product/3,
bdd_close/1,
mtbdd_close/1]).
@ -129,7 +130,7 @@ bdd_eval(add(M, X, Vars, _), Val) :-
mtbdd_eval(add(M,X, Vars, _), Val) :-
add_eval(M, X, Vars, Val).
bdd_tree(cudd(M, X, Vars, _), bdd(Dir, Tree, Vars)) :-
bdd_tree(cudd(M, X, Vars, _Vs), bdd(Dir, Tree, Vars)) :-
cudd_to_term(M, X, Vars, Dir, Tree).
bdd_tree(add(M, X, Vars, _), mtbdd(Tree, Vars)) :-
add_to_term(M, X, Vars, Tree).
@ -140,6 +141,9 @@ mtbdd_tree(add(M,X,Vars, _), mtbdd(Dir, Tree, Vars)) :-
bdd_to_probability_sum_product(cudd(M,X,_,Probs), Prob) :-
cudd_to_probability_sum_product(M, X, Probs, Prob).
bdd_to_probability_sum_product(cudd(M,X,_,_Probs), Probs, Prob) :-
cudd_to_probability_sum_product(M, X, Probs, Prob).
bdd_close(cudd(M,_,_Vars, _)) :-
cudd_die(M).
bdd_close(add(M,_,_Vars, _)) :-

View File

@ -12,8 +12,7 @@ trie_to_bdd(Trie, BDD, MapList) :-
complex_to_andor(Complex,Map0,Map,Tree),
rb_visit(Map, MapList),
extract_vars(MapList, Vs),
bdd_new(Tree, Vs, BDD),
bdd_tree(BDD, bdd(_, L, _)), length(L,Len), writeln(Len).
bdd_new(Tree, Vs, BDD).
tabled_trie_to_bdd(Trie, BDD, MapList) :-
trie_to_list(Trie, Complex),
@ -21,7 +20,6 @@ tabled_trie_to_bdd(Trie, BDD, MapList) :-
rb_new(Tab0),
Complex = [list(Els)],
tabled_complex_to_andor(Els,Map0,Map,Tab0,_Tab,Tree),
writeln(Complex),
rb_visit(Map, MapList),
extract_vars(MapList, Vs),
bdd_new(Tree, Vs, BDD),