current_prdicate/2

r Please enter the commit message for your changes. Lines starting
This commit is contained in:
Vítor Santos Costa 2019-03-09 06:50:09 +00:00
parent 32a5158c6b
commit 9378622d42
3 changed files with 77 additions and 68 deletions

View File

@ -521,7 +521,12 @@ every 5th iteration only.
atom_concat(PD0, '../../bin', PD),
set_problog_path(PD).
:- PD = '/usr/local/bin',
:- yap_flag(executable, Bin),
file_directory_name(Bin, PD),
set_problog_path(PD).
:- PD = '/usxor/local/bin',
set_problog_path(PD).

View File

@ -507,7 +507,7 @@ init_learning :-
%========================================================================
%= Updates all values of query_probability/2 and query_gradient/4
%= should be called always before these predicates are accessed
%= if the old values are still valid, nothing happens
%= if the old values are still valid, nothing happensv
%========================================================================
update_values :-
@ -518,8 +518,6 @@ update_values :-
retractall(query_gradient_intern(_,_,_,_)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Check, if continuous facts are used.
% if yes, switch to problog_exact
@ -573,7 +571,7 @@ empty_bdd_directory.
init_queries :-
empty_bdd_directory,
format_learning(2,'Build BDDs for examples~n',[]),
forall(user:test_example(ID,Query,_Prob,_),init_one_query(ID,Query,test)),
forall(user:test_example(ID,Query,_Prob,_),init_one_query(ID,Query,test)),
forall(user:example(ID,Query,_Prob,_),init_one_query(ID,Query,training)).
bdd_input_file(Filename) :-
@ -581,63 +579,70 @@ bdd_input_file(Filename) :-
concat_path_with_filename(Dir,'input.txt',Filename).
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
(
recorded(QueryID, _, _)
->
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,graph2bdd(X,Y,N,Bdd))),
Query =.. [_,X,Y]
->
Bdd = bdd(Dir, Tree, MapList),
(
graph2bdd(X,Y,N,Bdd)
->
Query =.. [_|Args],
% problog_flag(init_method,(Query,N,Bdd,M:graph2bdd(Args,N,Bdd))),
Bdd = bdd(Dir, Tree,
u3777777777/....777;;;;;;;;;;;;;;;;;;;666666666MapList),
user:graph2bdd(Args,N,Bdd),
rb_new(H0),
maplist_to_hash(MapList, H0, Hash),
tree_to_grad(Tree, Hash, [], Grad)
tree_to_grad(Tree, Hash, [], Grad),
% ;
% Bdd = bdd(-1,[],[]),
% Grad=[]
),
write('.'),
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),
strip_module(Call,_,Goal),
!,
Bdd = bdd(Dir, Tree, MapList),
% trace,
problog:problog_kbest_as_bdd(Goal,NOf,Bdd),
maplist_to_hash(MapList, H0, Hash),
Tree \= [],
%put_code(0'.),
tree_to_grad(Tree, Hash, [], Grad),
recordz(QueryID,bdd(Dir, Grad, MapList),_)
;
problog_flag(init_method,(Query,NOf,Bdd,Call)) ->
b_setval(problog_required_keep_ground_ids,false),
rb_new(H0),
Bdd = bdd(Dir, Tree, MapList),
% 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),_).
%========================================================================
@ -1010,7 +1015,7 @@ user:progress(FX,X,_G,X_Norm,G_Norm,Step,_N,_Iteration,Ls,0) :-
%========================================================================
init_flags :-
prolog_file_name(queries,Queries_Folder), % get absolute file name for './queries'
% 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),

View File

@ -473,27 +473,26 @@ predicate_erased_statistics(P0,NCls,Sz,ISz) :-
Defines the relation: _P_ is a currently defined predicate whose name is the atom _A_.
*/
current_predicate(A,T0) :-
'$yap_strip_module'(T0, M, T),
( var(M)
->
'$all_current_modules'(M)
;
true
),
(nonvar(T) -> functor(T, A, _) ; true ),
current_predicate(A0,T0) :-
( nonvar(T0) -> '$yap_strip_module'(T0, M, T) ; T0 = T ),
( nonvar(A0) -> '$yap_strip_module'(A0, MA0, A) ; A0 = A ),
M = MA0,
(
'$current_predicate'(A,M, T, user)
;
(nonvar(T)
var(M)
->
'$imported_predicate'(M:T, M1:T1)
true
;
'$imported_predicate'(M:T, M1:T1)
'$all_current_modules'(M)
),
functor(T1, A, _),
\+ '$is_system_predicate'(T1,M1)
).
% M is bound
(
'$current_predicate'(A,M,T,user)
;
'$imported_predicate'(M:T, M1T1), M1T1 \= M:T
),
functor(T, A, _).
/** @pred system_predicate( ?_P_ )