This commit is contained in:
Vitor Santos Costa
2019-03-06 10:49:55 +00:00
parent 21ff73dd70
commit 32a5158c6b
19 changed files with 101 additions and 115 deletions

View File

@@ -4,8 +4,8 @@ set (PROGRAMS
problog_lfi.yap
dtproblog.yap
aproblog.yap
problog_lbfgs.yap
problog_learning.yap
problog_lbfgs.yap
problog_learning_lbdd.yap
)

View File

@@ -517,15 +517,12 @@ every 5th iteration only.
% directory where simplecudd executable is located
% automatically set during loading -- assumes it is in /usr/local/bin or same place where YAP has
% been installed.)
:- getcwd(PD0),
atom_concat(PD0, '../../bin', PD),
set_problog_path(PD).
:- PD = '/usr/local/bin',
set_problog_path(PD).
:- PD = '$HOME/,local/bin',
set_problog_path(PD).
@@ -554,7 +551,10 @@ every 5th iteration only.
%%%%%%%%%%%%
% max number of calls to probabilistic facts per derivation (to ensure termination)
%%%%%%%%%%%%
:- initialization( problog_define_flag(maxsteps, problog_flag_validate_posint, 'max. number of prob. steps per derivation', 1000, inference) ).
:- initialization(
problog_define_flag(maxsteps, problog_flag_validate_posint, 'max. number of prob. steps per derivation', 1000, inference)
).
%%%%%%%%%%%%
% BDD timeout in seconds, used as option in BDD tool
@@ -626,7 +626,6 @@ every 5th iteration only.
problog_dir(PD):- problog_path(PD).
%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1825,7 +1824,7 @@ eval_dnf(OriTrie1, Prob, Status) :-
;
Trie = OriTrie
),
(problog_flag(bdd_static_order, true) ->
(problog_flag(bdd_static_order, true) ->
get_order(Trie, Order),
problog_flag(static_order_file, SOFName),
convert_filename_to_working_path(SOFName, SOFileName),
@@ -2445,7 +2444,7 @@ and the facts used in achieving this explanation.
explanation probability - returns list of facts used or constant 'unprovable' as third argument
problog_max(+Goal,-Prob,-Facts)
uses iterative deepening with samw parameters as bounding algorithm
uses iterative deepening with same parameters as bounding algorithm
threshold gets adapted whenever better proof is found
uses local dynamic predicates max_probability/1 and max_proof/1
@@ -2454,8 +2453,8 @@ uses local dynamic predicates max_probability/1 and max_proof/1
problog_max(Goal, Prob, Facts) :-
problog_flag(first_threshold,InitT),
init_problog_max(InitT),
problog_control(off,up), %
problog_max_id(Goal, Prob, FactIDs), %theo todo
problog_control(off,up),
problog_max_id(Goal, Prob, FactIDs),% theo todo
( FactIDs = [_|_] -> get_fact_list(FactIDs, Facts);
Facts = FactIDs).

View File

@@ -204,7 +204,7 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @file problog/flags.yap
%% @file problog/flags
:-module(flags, [problog_define_flag/4,
problog_define_flag/5,
@@ -218,7 +218,7 @@
:- use_module(gflags).
:- use_module(os).
:- use_module(logger).
:- use_module(library(system), [file_exists/1, delete_file/1,file_property/2]).
:- use_module(library(system), [file_exists/1, delete_file/1]).
/** @defgroup ProbLogMiscellaneous ProbLog Miscellaneous Predicates

View File

@@ -243,7 +243,7 @@
problog_define_flag(refine_anclst, problog_flag_validate_boolean, 'refine the ancestor list with their childs', false, nested_tries),
problog_define_flag(anclst_represent,problog_flag_validate_in_list([list, integer]), 'represent the ancestor list', list, nested_tries)
)).
:- stop_low_level_trace.
trie_replace_entry(_Trie, Entry, E, false):-
trie_get_entry(Entry, Proof),
@@ -486,4 +486,3 @@ get_trie(Trie, Label, Ancestors):-
set_trie(Trie, Label, Ancestors):-
recordz(problog_trie_table, store(Trie, Ancestors, Label), _).

View File

@@ -265,7 +265,7 @@
:- initialization(
( predicate_property(trie_disable_hash, imported_from(_M)) ->
trie_disable_hash
; true % stop_low_level_trace, print_message(warning,'The predicate trie_disable_hash/0 does not exist. Please update trie library.')
; print_message(warning,'The predicate tries:trie_disable_hash/0 does not exist. Please update trie library.')
)
).
@@ -276,7 +276,7 @@
:- initialization((
problog_define_flag(use_db_trie, problog_flag_validate_boolean, 'use the builtin trie 2 trie transformation', false),
problog_define_flag(db_trie_opt_lvl, problog_flag_validate_integer, 'optimization level for the trie 2 trie transformation', 0),
problog_define_flag(compare_opt_lvl, problog_flag_validate_boolean, 'comparison mode for optimizatione level', false),
problog_define_flag(compare_opt_lvl, problog_flag_validate_boolean, 'comparison mode for optimization level', false),
problog_define_flag(db_min_prefix, problog_flag_validate_integer, 'minimum size of prefix for dbtrie to optimize', 2),
problog_define_flag(use_naive_trie, problog_flag_validate_boolean, 'use the naive algorithm to generate bdd scripts', false),
problog_define_flag(use_old_trie, problog_flag_validate_boolean, 'use the old trie 2 trie transformation no nested', true),

View File

@@ -15,31 +15,32 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module(library(matrix)).
:- use_module('../problog_learning').
:- use_module(('../problog_learning')).
:- stop_low_level_trace.
%%%%
% background knowledge
%%%%
%%%%
% definition of acyclic path using list of visited nodes
path(X,Y) :- path(X,Y,[X],_).
path(X,X,A,A).
path(X,Y,A,R) :-
X\==Y,
edge(X,Z),
absent(Z,A),
path(X,Y,A,R) :-
X\==Y,
edge(X,Z),
absent(Z,A),
path(Z,Y,[Z|A],R).
% using directed edges in both directions
edge(X,Y) :- dir_edge(Y,X).
edge(X,Y) :- dir_edge(X,Y).
edge(X,Y) :- problog:dir_edge(Y,X).
edge(X,Y) :- problog:dir_edge(X,Y).
% checking whether node hasn't been visited before
absent(_,[]).
absent(X,[Y|Z]):-X \= Y, absent(X,Z).
%%%%
% probabilistic facts
% probabilistic facts
% - probability represented by t/1 term means learnable parameter
% - argument of t/1 is real value (used to compare against in evaluation when known), use t(_) if unknown
%%%%
@@ -53,7 +54,7 @@ t(0.7)::dir_edge(5,3).
t(0.2)::dir_edge(5,4).
%%%%%%%%%%%%%%
% training examples of form example(ID,Query,DesiredProbability)
% training examples of form example(ID,Query,DesiredProbability)
%%%%%%%%%%%%%%
example(1,path(1,2),0.94).
@@ -79,7 +80,7 @@ example(19,(dir_edge(2,6),dir_edge(6,5)),0.2).
example(20,(dir_edge(1,2),dir_edge(2,3),dir_edge(3,4)),0.432).
%%%%%%%%%%%%%%
% test examples of form test_example(ID,Query,DesiredProbability)
% test examples of form test_example(ID,Query,DesiredProbability)
% note: ID namespace is shared with training example IDs
%%%%%%%%%%%%%%
@@ -99,7 +100,7 @@ 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(init_method,(Query,_,BDD,
problog_exact_lbdd(user:Query,BDD))).
%:- set_problog_flag(init_method,(Query,_,BDD,
% problog_exact(user:Query,_,BDD))).

View File

@@ -14,8 +14,7 @@
% will run 20 iterations of learning with default settings
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module(library(problog)).
:- use_module(library(problog_learning_lbdd)).
:- use_module(library(problog_learning)).
%%%%
% background knowledge

View File

@@ -581,8 +581,7 @@ bdd_input_file(Filename) :-
concat_path_with_filename(Dir,'input.txt',Filename).
init_one_query(QueryID,Query,_Type) :-
writeln(init_one_query(QueryID,Query,_Type)),
% format_learning(3,' ~q example ~q: ~q~n',[Type,QueryID,Query]),
% format_learning(3,' ~q example ~q: ~q~n',[Type,QueryID,Query]),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if BDD file does not exist, call ProbLog
@@ -593,15 +592,13 @@ writeln(init_one_query(QueryID,Query,_Type)),
format_learning(3,' Reuse existing BDD ~q~n~n',[QueryID])
;
b_setval(problog_required_keep_ground_ids,false),
(QueryID mod 100 =:= 0 -> writeln(QueryID) ; true),
problog_flag(init_method,(Query,N,Bdd,G)),
problog_flag(init_method,(Query,N,Bdd,graph2bdd(X,Y,N,Bdd))),
Query =.. [_,X,Y]
->
Bdd = bdd(Dir, Tree, MapList),
(
G
graph2bdd(X,Y,N,Bdd)
->
rb_new(H0),
maplist_to_hash(MapList, H0, Hash),
@@ -611,9 +608,8 @@ writeln(init_one_query(QueryID,Query,_Type)),
% Grad=[]
),
write('.'),
recordz(QueryID,bdd(Dir, Grad, MapList),_)
).
/* ;
recordz(QueryID,bdd(Dir, Grad, MapList),_)
;
problog_flag(init_method,(Query,NOf,Bdd,problog_kbest_as_bdd(Call,NOf,Bdd))) ->
b_setval(problog_required_keep_ground_ids,false),
rb_new(H0),
@@ -628,20 +624,20 @@ writeln(init_one_query(QueryID,Query,_Type)),
tree_to_grad(Tree, Hash, [], Grad),
recordz(QueryID,bdd(Dir, Grad, MapList),_)
;
problog_flag(init_method,(Query,NOf,Bdd,_Call)) ,
Query = gene(X,Y),
problog_flag(init_method,(Query,NOf,Bdd,Call)) ->
b_setval(problog_required_keep_ground_ids,false),
rb_new(H0),
Bdd = bdd(Dir, Tree, MapList),
user:graph2bdd(X,Y,1,Bdd),
% trace,
problog:Call,
maplist_to_hash(MapList, H0, Hash),
Tree \= [],
%put_code(0'.),
tree_to_grad(Tree, Hash, [], Grad),
recordz(QueryID,bdd(Dir, Grad, MapList),_).
recordz(QueryID,bdd(Dir, Grad, MapList),_)
).
*/
%========================================================================

View File

@@ -1487,10 +1487,12 @@ my_5_min(V1,V2,V3,V4,V5,F1,F2,F3,F4,F5,VMin,FMin) :-
%========================================================================
init_flags :-
writeln(10),
prolog_file_name('queries',Queries_Folder), % get absolute file name for './queries'
prolog_file_name('output',Output_Folder), % get absolute file name for './output'
problog_define_flag(bdd_directory, problog_flag_validate_directory, 'directory for BDD scripts', Queries_Folder,learning_general),
problog_define_flag(output_directory, problog_flag_validate_directory, 'directory for logfiles etc', Output_Folder,learning_general,flags:learning_output_dir_handler),
writeln(10),
problog_define_flag(log_frequency, problog_flag_validate_posint, 'log results every nth iteration', 1, learning_general),
problog_define_flag(rebuild_bdds, problog_flag_validate_nonegint, 'rebuild BDDs every nth iteration', 0, learning_general),
problog_define_flag(reuse_initialized_bdds,problog_flag_validate_boolean, 'Reuse BDDs from previous runs',false, learning_general),
@@ -1529,3 +1531,4 @@ init_logger :-
:- initialization(init_flags).
:- initialization(init_logger).