Latest ProbLog
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-08-19 13:13:56 +0200 (Fri, 19 Aug 2011) $
|
||||
% $Revision: 6471 $
|
||||
% $Date: 2011-11-28 16:17:25 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6765 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
@@ -267,7 +267,7 @@ term_expansion_intern_ad((Head<--Body), Module, Mode, [user:ad_intern((Head<--Bo
|
||||
),
|
||||
|
||||
% call term_expansion for the aux facts, this has the same effect
|
||||
% as if the use had defined the facts in the original file
|
||||
% as if the user had defined the facts in the original file
|
||||
findall(problog:Atom,(
|
||||
member(F,Aux_Facts),
|
||||
once(problog:term_expansion_intern(F,Module,Atom))
|
||||
@@ -278,7 +278,8 @@ term_expansion_intern_ad((Head<--Body), Module, Mode, [user:ad_intern((Head<--Bo
|
||||
create_aux_bodies(Head,Body_Vars,Body,ID,1,Aux_Facts,Mode,Aux_Clauses),
|
||||
|
||||
(
|
||||
Mode==lfi_learning ->
|
||||
Mode==lfi_learning
|
||||
->
|
||||
findall(Module:myclause(H,B),member((H:-B),Aux_Clauses),Result,Result_Atoms)
|
||||
;
|
||||
findall(Module:B,member(B,Aux_Clauses),Result,Result_Atoms)
|
||||
@@ -295,7 +296,8 @@ term_expansion_intern_ad((Head<--Body), Module, Mode, [user:ad_intern((Head<--Bo
|
||||
format(' - - - - - - - - - - - - - - - - - - - - - - ~n',[]),
|
||||
forall(member(B,Aux_Clauses),format(' ~q.~n',[B])),
|
||||
format('================================================~2n',[])
|
||||
);
|
||||
)
|
||||
;
|
||||
true
|
||||
).
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
%%% -*- Mode: Prolog; -*-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-07-27 17:38:26 +0200 (Wed, 27 Jul 2011) $
|
||||
% $Revision: 6461 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-04-21 14:18:59 +0200 (Thu, 21 Apr 2011) $
|
||||
% $Revision: 6364 $
|
||||
% $Date: 2011-12-05 14:07:19 +0100 (Mon, 05 Dec 2011) $
|
||||
% $Revision: 6766 $
|
||||
%
|
||||
% Main authors of this file:
|
||||
% Bernd Gutmann
|
||||
@@ -211,6 +211,7 @@
|
||||
|
||||
% load our own modules
|
||||
:- use_module('../problog').
|
||||
:- use_module(grounder).
|
||||
:- use_module(logger).
|
||||
:- use_module(termhandling).
|
||||
:- use_module(flags).
|
||||
@@ -226,13 +227,6 @@
|
||||
:- initialization(problog_define_flag(output_dot_files,problog_flag_validate_boolean,'Output .dot files for BDD scripts',true,learning_bdd_generation)).
|
||||
:- initialization(problog_define_flag(split_bdds,problog_flag_validate_boolean,'Split BDD scripts when possible',true,learning_bdd_generation)).
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
user:myclause(_InterpretationID,Head,Body) :-
|
||||
current_predicate(user:myclause/2),
|
||||
user:myclause(Head,Body).
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
@@ -261,7 +255,7 @@ propagate_evidence(InterpretationID,Query_Type) :-
|
||||
eraseall(rules),
|
||||
eraseall(unpropagated_rules),
|
||||
eraseall(known_atoms),
|
||||
eraseall(reachable),
|
||||
grounder_reset,
|
||||
|
||||
(
|
||||
Query_Type==test
|
||||
@@ -297,10 +291,14 @@ propagate_evidence(InterpretationID,Query_Type) :-
|
||||
% iterate over all evidence atoms
|
||||
forall(user:known(InterpretationID,Atom,Value),
|
||||
(
|
||||
(calculate_dep_atom_outer(Atom,InterpretationID);Value==false)
|
||||
->
|
||||
true;
|
||||
throw(unprovable_evidence(Atom))
|
||||
grounder_compute_reachable_atoms(Atom,InterpretationID,Success),
|
||||
(
|
||||
(Success==true; Value==false)
|
||||
->
|
||||
true
|
||||
;
|
||||
throw(unprovable_evidence(Atom))
|
||||
)
|
||||
)
|
||||
),
|
||||
logger_stop_timer(Key_BDD_script_generation_grounding),
|
||||
@@ -315,8 +313,8 @@ propagate_evidence(InterpretationID,Query_Type) :-
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Bring out intermediate garbage %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
eraseall(reachable),
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
grounder_reset,
|
||||
!,
|
||||
garbage_collect_atoms,
|
||||
|
||||
@@ -376,7 +374,7 @@ propagate_evidence(InterpretationID,Query_Type) :-
|
||||
eraseall(rules),
|
||||
eraseall(unpropagated_rules),
|
||||
eraseall(known_atoms),
|
||||
eraseall(reachable),
|
||||
grounder_reset,
|
||||
logger_stop_timer(Key_BDD_script_generation).
|
||||
|
||||
|
||||
@@ -402,8 +400,8 @@ completion(InterpretationID) :-
|
||||
% iterate over all reachable atoms where the completion
|
||||
% can be computed. This will skip reachable probabilistic facts.
|
||||
forall((
|
||||
recorded(reachable,Head,_),
|
||||
completion_for_atom(Head,Rule,InterpretationID)
|
||||
grounder_reachable_atom(Head),
|
||||
grounder_completion_for_atom(Head,InterpretationID,Rule)
|
||||
),
|
||||
(
|
||||
once(propagate_interpretation(Rule,InterpretationID,Rule2)),
|
||||
@@ -426,7 +424,7 @@ completion(InterpretationID) :-
|
||||
)
|
||||
),
|
||||
|
||||
print_theory,
|
||||
% print_theory,
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Store known Atoms %%
|
||||
@@ -436,15 +434,6 @@ completion(InterpretationID) :-
|
||||
).
|
||||
|
||||
|
||||
completion_for_atom(Head,'$atom'(Head)<=>Disjunction,InterpretationID) :-
|
||||
% find all clauses
|
||||
findall(Body2,(
|
||||
user:myclause(InterpretationID,Head,Body),
|
||||
ground_term_with_known_atoms(Body,Body2)
|
||||
),Bodies),
|
||||
Bodies\==[],
|
||||
list_to_disjunction(Bodies,Disjunction).
|
||||
|
||||
|
||||
%========================================================================
|
||||
%= find rule which makes sense to propagate
|
||||
@@ -474,7 +463,7 @@ propagate_intern_known(true) :-
|
||||
forall(
|
||||
(
|
||||
recorded(rules,Rule,Key2),
|
||||
once(propagate(Rule,'$atom'(Atom),AtomValue,NewRule,true)) % will succeed only when Atom appears in Rule
|
||||
once(propagate(Rule,Atom,AtomValue,NewRule,true)) % will succeed only when Atom appears in Rule
|
||||
),
|
||||
(
|
||||
erase(Key2),
|
||||
@@ -620,26 +609,21 @@ know_atom_expected_count(false,0).
|
||||
%========================================================================
|
||||
|
||||
print_theory :-
|
||||
format_learning(5,'== Unpropagated Rules ==~n',[]),
|
||||
format_learning(5,'~n Current Theory~n == Unpropagated Rules ==~n',[]),
|
||||
forall(recorded(unpropagated_rules,Rule,Key),
|
||||
format_learning(6,'~q. (~q)~n',[Rule,Key])
|
||||
),
|
||||
forall(recorded(unpropagated_rules,Rule,Key),
|
||||
format_learning_rule(5,Rule,Key)
|
||||
format_learning(5,' ~q. (~q)~n',[Rule,Key])
|
||||
),
|
||||
|
||||
format_learning(6,'== Rules ==~n',[]),
|
||||
format_learning(5,' == Rules ==~n',[]),
|
||||
forall(recorded(rules,Rule,Key),
|
||||
format_learning(6,'~q. (~q)~n',[Rule,Key])),
|
||||
format_learning(5,'== Prettyprint Rules ==~n',[]),
|
||||
forall(recorded(rules,Rule,Key),
|
||||
(format_learning_rule(5,Rule,Key))
|
||||
format_learning(5,' ~q. (~q)~n',[Rule,Key])),
|
||||
|
||||
format_learning(5,' == Known and Propagated Atoms ==~n',[]),
|
||||
forall(recorded(known_atoms,Head <=> Bodies,Key),
|
||||
format_learning(5,' ~q <=> ~q. (~q)~n',[Head,Bodies,Key])
|
||||
),
|
||||
|
||||
format_learning(5,'== Known and Propagated Atoms ==~n',[]),
|
||||
forall(recorded(known_atoms,Head <=> Bodies,Key),
|
||||
format('~q <=> ~q. (~q)~n',[Head,Bodies,Key])
|
||||
).
|
||||
format_learning(5,'~3n',[]).
|
||||
|
||||
|
||||
%========================================================================
|
||||
@@ -968,155 +952,4 @@ next_counter(ID) :-
|
||||
atomic_concat(['L',N2],ID),
|
||||
bb_put(counter,N2).
|
||||
|
||||
%========================================================================
|
||||
%= calculate_dep_atom(+Atom)
|
||||
%========================================================================
|
||||
|
||||
|
||||
calculate_dep_atom_outer(Atom,InterpretationID) :-
|
||||
bb_put(dep_proven,false),
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
( % go over all proofs for atom
|
||||
calculate_dep_atom(Atom,InterpretationID),
|
||||
bb_put(dep_proven,true),
|
||||
|
||||
fail; % go to next proof
|
||||
true
|
||||
),
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
bb_delete(dep_proven,Result),
|
||||
Result==true.
|
||||
|
||||
|
||||
calculate_dep_atom(true,_) :-
|
||||
!.
|
||||
calculate_dep_atom(false,_) :-
|
||||
!.
|
||||
calculate_dep_atom( (X is Y),_ ) :-
|
||||
!,
|
||||
call(X is Y).
|
||||
calculate_dep_atom( (X > Y),_ ) :-
|
||||
!,
|
||||
call(X > Y).
|
||||
calculate_dep_atom( (X < Y),_ ) :-
|
||||
!,
|
||||
call(X < Y).
|
||||
calculate_dep_atom( (X == Y),_ ) :-
|
||||
!,
|
||||
call(X == Y).
|
||||
calculate_dep_atom( (X = Y),_ ) :-
|
||||
!,
|
||||
call(X = Y).
|
||||
calculate_dep_atom( (X > Y),_ ) :-
|
||||
!,
|
||||
call(X > Y).
|
||||
calculate_dep_atom( (X < Y),_ ) :-
|
||||
!,
|
||||
call(X < Y).
|
||||
calculate_dep_atom( (X =< Y),_ ) :-
|
||||
!,
|
||||
call(X =< Y).
|
||||
calculate_dep_atom( (X >= Y),_ ) :-
|
||||
!,
|
||||
call(X >= Y).
|
||||
calculate_dep_atom(call(X),_) :-
|
||||
!,
|
||||
call(X).
|
||||
calculate_dep_atom( Atom,_ ) :-
|
||||
recorded(reachable,Atom,_),
|
||||
% FIXME, could this cut prune away too much? what if Atom is non-ground?
|
||||
!.
|
||||
calculate_dep_atom( Atom,InterpretationID ) :-
|
||||
ground(Atom),
|
||||
!,
|
||||
recorda(reachable,Atom,_),
|
||||
if(user:myclause(InterpretationID,Atom,Body),(calculate_dep_atom_intern(Body,InterpretationID)),probabilistic_fact(_,Atom,_)).
|
||||
calculate_dep_atom( Atom,InterpretationID ) :-
|
||||
if(user:myclause(InterpretationID,Atom,Body),(calculate_dep_atom_intern(Body,InterpretationID)),probabilistic_fact(_,Atom,_)),
|
||||
(
|
||||
ground(Atom)
|
||||
->
|
||||
(
|
||||
recorded(reachable,Atom,_)
|
||||
->
|
||||
true;
|
||||
recorda(reachable,Atom,_)
|
||||
);
|
||||
(
|
||||
format(user_error,'Error at running the meta interpreter.~n',[]),
|
||||
format(user_error,'The clauses defined by myclause/2 have to be written in a way such that~n',[]),
|
||||
format(user_error,'each atom in the body of a clause gets fully grounded when it is called.~n',[]),
|
||||
format(user_error,' This is not the case for the atom ~w~3n',[Atom]),
|
||||
throw(meta_interpreter_error(Atom))
|
||||
)
|
||||
).
|
||||
|
||||
|
||||
calculate_dep_atom_intern((X,Y),InterpretationID) :-
|
||||
!,
|
||||
calculate_dep_atom_intern(X,InterpretationID),
|
||||
calculate_dep_atom_intern(Y,InterpretationID).
|
||||
calculate_dep_atom_intern((X;Y),InterpretationID) :-
|
||||
!,
|
||||
(
|
||||
calculate_dep_atom_intern(X,InterpretationID);
|
||||
calculate_dep_atom_intern(Y,InterpretationID)
|
||||
).
|
||||
calculate_dep_atom_intern(\+X,InterpretationID) :-
|
||||
!,
|
||||
calculate_dep_atom_intern(X,InterpretationID).
|
||||
calculate_dep_atom_intern(X,InterpretationID) :-
|
||||
calculate_dep_atom(X,InterpretationID).
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
|
||||
|
||||
ground_term_with_known_atoms( (X,Y), (X2,Y2)) :-
|
||||
!,
|
||||
ground_term_with_known_atoms(X,X2),
|
||||
ground_term_with_known_atoms(Y,Y2).
|
||||
ground_term_with_known_atoms( (X;Y), (X2;Y2)) :-
|
||||
!,
|
||||
ground_term_with_known_atoms(X,X2),
|
||||
ground_term_with_known_atoms(Y,Y2).
|
||||
|
||||
ground_term_with_known_atoms( \+ X, \+ X2) :-
|
||||
!,
|
||||
ground_term_with_known_atoms(X,X2).
|
||||
ground_term_with_known_atoms( true, true) :-
|
||||
!.
|
||||
ground_term_with_known_atoms( false, false) :-
|
||||
!.
|
||||
ground_term_with_known_atoms( (X is Y), true) :-
|
||||
!,
|
||||
call(X is Y).
|
||||
ground_term_with_known_atoms( (X < Y), true) :-
|
||||
!,
|
||||
call(X < Y).
|
||||
ground_term_with_known_atoms( (X > Y), true) :-
|
||||
!,
|
||||
call(X > Y).
|
||||
ground_term_with_known_atoms( (X >= Y), true) :-
|
||||
!,
|
||||
call(X >= Y).
|
||||
ground_term_with_known_atoms( (X =< Y), true) :-
|
||||
!,
|
||||
call(X =< Y).
|
||||
ground_term_with_known_atoms( (X = Y), true) :-
|
||||
!,
|
||||
call(X = Y).
|
||||
ground_term_with_known_atoms( (X == Y), true) :-
|
||||
!,
|
||||
call(X == Y).
|
||||
ground_term_with_known_atoms( call(X), '$atom'(X)) :-
|
||||
!,
|
||||
call(X).
|
||||
ground_term_with_known_atoms( X, '$atom'(X)) :-
|
||||
!,
|
||||
recorded(reachable,X,_).
|
||||
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-02-08 16:00:57 +0100 (Tue, 08 Feb 2011) $
|
||||
% $Revision: 5614 $
|
||||
% $Date: 2011-12-08 16:20:16 +0100 (Thu, 08 Dec 2011) $
|
||||
% $Revision: 6775 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
@@ -297,8 +297,8 @@ bdd_file_handler(validate, Value):-
|
||||
bdd_file_handler(validate, Value):-
|
||||
convert_filename_to_working_path(Value, Path),
|
||||
catch((\+ file_exists(Path), tell(Path)), _, fail),
|
||||
told,
|
||||
delete_file(Path).
|
||||
told,
|
||||
catch(delete_file(Path),_, fail).
|
||||
bdd_file_handler(validated, _Value).
|
||||
bdd_file_handler(stored, Value):-
|
||||
atomic_concat(Value, '_probs', ParValue),
|
||||
@@ -314,8 +314,8 @@ working_file_handler(validate, Value):-
|
||||
working_file_handler(validate, Value):-
|
||||
convert_filename_to_working_path(Value, Path),
|
||||
catch((\+ file_exists(Path), tell(Path)), _, fail),
|
||||
told,
|
||||
delete_file(Path).
|
||||
told,
|
||||
catch(delete_file(Path),_, fail).
|
||||
working_file_handler(validated, _Value).
|
||||
working_file_handler(stored, _Value).
|
||||
|
||||
@@ -354,6 +354,8 @@ learning_prob_init_handler(validating, N) :-
|
||||
number(N),
|
||||
N>0,
|
||||
N =< 1.
|
||||
learning_prob_init_handler(validating, A) :-
|
||||
atom(A), !.
|
||||
%learning_prob_init_handler(validate, V_).
|
||||
learning_prob_init_handler(validated, _Value).
|
||||
learning_prob_init_handler(stored, _Value).
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
@@ -444,7 +444,8 @@ flag_validate_file(Value):-
|
||||
atomic(Value),
|
||||
catch((\+ file_exists(Value), tell(Value)), _, fail),
|
||||
told,
|
||||
delete_file(Value).
|
||||
catch(delete_file(Value),_, fail).
|
||||
|
||||
|
||||
|
||||
flag_validate_in_list(Domain):-
|
||||
|
252
packages/ProbLog/problog/grounder.yap
Normal file
252
packages/ProbLog/problog/grounder.yap
Normal file
@@ -0,0 +1,252 @@
|
||||
%%% -*- Mode: Prolog; -*-
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% Main author of this file:
|
||||
% Bernd Gutmann
|
||||
%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
:- module(grounder, [grounder_reset/0,
|
||||
grounder_compute_reachable_atoms/3,
|
||||
grounder_reachable_atom/1,
|
||||
grounder_ground_term_with_reachable_atoms/2,
|
||||
grounder_completion_for_atom/3
|
||||
]).
|
||||
|
||||
|
||||
:- style_check(all).
|
||||
:- yap_flag(unknown,error).
|
||||
|
||||
:- use_module('../problog',[probabilistic_fact/3]).
|
||||
:- use_module(termhandling).
|
||||
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
:- multifile user:myclause/3.
|
||||
|
||||
user:myclause(_InterpretationID,Head,Body) :-
|
||||
current_predicate(user:myclause/2),
|
||||
user:myclause(Head,Body).
|
||||
|
||||
|
||||
%========================================================================
|
||||
%= reset the internal state, that is, forget all reachable atoms
|
||||
%========================================================================
|
||||
|
||||
grounder_reset :-
|
||||
eraseall(reachable).
|
||||
|
||||
|
||||
%========================================================================
|
||||
%= grounder_reachable_atom(-Atom)
|
||||
%========================================================================
|
||||
|
||||
grounder_reachable_atom(Atom) :-
|
||||
recorded(reachable,Atom,_Key).
|
||||
|
||||
|
||||
%========================================================================
|
||||
%= grounder_compute_reachable_atoms(+A,+ID,-Success)
|
||||
%= A is a ground atom
|
||||
%= ID is an interpretation ID
|
||||
%= Success is "true" if there is a proof for A, otherwise "false"
|
||||
%=
|
||||
%= The predicate always succeeds exactly once
|
||||
%=
|
||||
%= This is basically a vanilla meta-interpreter, that follows all
|
||||
%= paths in the SLD tree and records which atoms can be reached
|
||||
%= while proving A.
|
||||
%= the only "speciality" is that the negation of a probilistic
|
||||
%= fact always succeeds
|
||||
%=
|
||||
%= the reachable atoms are stored in the internal database
|
||||
%= under the key "reachable"
|
||||
%========================================================================
|
||||
|
||||
grounder_compute_reachable_atoms(A,ID,Success) :-
|
||||
bb_put(dep_proven,false),
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
( % go over all proofs for A in interpretation ID
|
||||
tabled_meta_interpreter(A,ID),
|
||||
bb_put(dep_proven,true),
|
||||
|
||||
fail; % go to next proof
|
||||
true
|
||||
),
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
bb_delete(dep_proven,Success).
|
||||
|
||||
|
||||
%========================================================================
|
||||
%= tabled_meta_interpreter(+E, +ID)
|
||||
%= E is a valid Prolog expression
|
||||
%= ID is an interpretation ID
|
||||
%=
|
||||
%= the predicate succeeds if there is a proof for E
|
||||
%= upon backtracking all possible proofs are generated
|
||||
%= the atoms visited while proving E are added to the internal database
|
||||
%= using the key "reachable"
|
||||
%=
|
||||
%= if a ground atom is revisited, it is not proven again
|
||||
%========================================================================
|
||||
|
||||
|
||||
tabled_meta_interpreter((X,Y),ID) :-
|
||||
!,
|
||||
tabled_meta_interpreter(X,ID),
|
||||
tabled_meta_interpreter(Y,ID).
|
||||
tabled_meta_interpreter((X;Y),ID) :-
|
||||
!,
|
||||
(
|
||||
tabled_meta_interpreter(X,ID);
|
||||
tabled_meta_interpreter(Y,ID)
|
||||
).
|
||||
tabled_meta_interpreter(\+ X,ID) :-
|
||||
!,
|
||||
(
|
||||
probabilistic_fact(_, X, _)
|
||||
->
|
||||
tabled_meta_interpreter(X,ID) % prob. facts can be true/false
|
||||
;
|
||||
\+ tabled_meta_interpreter(X,ID)
|
||||
).
|
||||
tabled_meta_interpreter(X,_) :-
|
||||
predicate_property(X,built_in),
|
||||
!,
|
||||
call(X).
|
||||
tabled_meta_interpreter( Atom,ID ) :-
|
||||
ground(Atom),
|
||||
!,
|
||||
|
||||
(
|
||||
recorded(reachable,Atom,_) % did we see this atom before?
|
||||
->
|
||||
true % nothing to do
|
||||
;
|
||||
% nope, we have to continue proving
|
||||
recorda(reachable,Atom,_),
|
||||
tabled_meta_interpreter_aux_ground_atom(Atom,ID)
|
||||
).
|
||||
tabled_meta_interpreter(Atom,ID) :-
|
||||
% at this point we know, Atom is non-ground
|
||||
% hence we need to be carefull not to ignore any path in the SLD tree
|
||||
%
|
||||
% we can ignore probabilistic facts and only look for myclauses
|
||||
% since in ProbLog the requirement is that non-ground facts have to be
|
||||
% ground at query time
|
||||
|
||||
current_predicate(user:myclause/3),
|
||||
user:myclause(ID,Atom,Body),
|
||||
|
||||
tabled_meta_interpreter(Body,ID),
|
||||
|
||||
% check whether Atom got grounded now,
|
||||
% if not, complain and give up
|
||||
|
||||
(
|
||||
ground(Atom)
|
||||
->
|
||||
recorda(reachable,Atom,_)
|
||||
;
|
||||
|
||||
format(user_error,'Error at running the meta interpreter.~n',[]),
|
||||
format(user_error,'The clauses defined by myclause/2 have to be written in a way such that~n',[]),
|
||||
format(user_error,'each atom in the body of a clause gets fully grounded when it is called.~n',[]),
|
||||
format(user_error,' This is not the case for the atom ~w~3n',[Atom]),
|
||||
throw(meta_interpreter_error(Atom))
|
||||
).
|
||||
% note, that on backtracking all alternative proofs will
|
||||
% be followed as well
|
||||
|
||||
%========================================================================
|
||||
%= tabled_meta_interpreter_aux_ground_atom(+E, +ID)
|
||||
%= E is a valid Prolog expression
|
||||
%= ID is an interpretation ID
|
||||
%=
|
||||
%= the predicate succeeds if there is a proof for E
|
||||
%= upon backtracking all possible proofs are generated
|
||||
%= the atoms visited while proving E are added to the internal database
|
||||
%= using the key "reachable"
|
||||
%=
|
||||
%= if a ground atom is revisited, it is not proven again
|
||||
%=
|
||||
%= DON'T call this predicate directly, it is a helper predicate for
|
||||
%= tabled_meta_interpreter/2
|
||||
%========================================================================
|
||||
|
||||
tabled_meta_interpreter_aux_ground_atom(Atom,_ID) :-
|
||||
probabilistic_fact(_, Atom, _),
|
||||
!.
|
||||
% probabilistic facts and background knowledge must not have
|
||||
% an atom in common. hence we can savely put that cut above.
|
||||
tabled_meta_interpreter_aux_ground_atom(Atom,ID) :-
|
||||
current_predicate(user:myclause/3),
|
||||
user:myclause(ID,Atom,Body),
|
||||
% find a suitable clause and continue proving
|
||||
% on backtracking we will try all suitable clauses
|
||||
tabled_meta_interpreter(Body,ID).
|
||||
|
||||
|
||||
%========================================================================
|
||||
%= grounder_ground_term_with_reachable_atoms(+T1,-T2)
|
||||
%= T1 is a (possible non-ground) term
|
||||
%= T2 is ground term
|
||||
%=
|
||||
%= generates on backtracking all possible ground instances of T1
|
||||
%= where atoms are grounded with reachable atoms that have
|
||||
%= been found before by grounder_compute_reachable_atoms/3
|
||||
%========================================================================
|
||||
|
||||
grounder_ground_term_with_reachable_atoms( (X,Y), (X2,Y2)) :-
|
||||
!,
|
||||
grounder_ground_term_with_reachable_atoms(X,X2),
|
||||
grounder_ground_term_with_reachable_atoms(Y,Y2).
|
||||
grounder_ground_term_with_reachable_atoms( (X;Y), (X2;Y2)) :-
|
||||
!,
|
||||
grounder_ground_term_with_reachable_atoms(X,X2),
|
||||
grounder_ground_term_with_reachable_atoms(Y,Y2).
|
||||
grounder_ground_term_with_reachable_atoms( \+X, \+X2) :-
|
||||
!,
|
||||
grounder_ground_term_with_reachable_atoms(X,X2).
|
||||
grounder_ground_term_with_reachable_atoms( false, false) :-
|
||||
!.
|
||||
grounder_ground_term_with_reachable_atoms(X, true) :-
|
||||
predicate_property(X,built_in),
|
||||
!,
|
||||
call(X).
|
||||
grounder_ground_term_with_reachable_atoms(X,'$atom'(X)) :-
|
||||
!,
|
||||
recorded(reachable,X,_).
|
||||
|
||||
%========================================================================
|
||||
%= grounder_completion_for_atom(+A,+ID,-X)
|
||||
%= A is
|
||||
%= X is
|
||||
%= ID is
|
||||
%=
|
||||
%=
|
||||
%=
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
|
||||
grounder_completion_for_atom(Head,InterpretationID,'$atom'(Head)<=>Disjunction) :-
|
||||
% find all clauses
|
||||
findall(Body2,(
|
||||
user:myclause(InterpretationID,Head,Body),
|
||||
grounder_ground_term_with_reachable_atoms(Body,Body2)
|
||||
),Bodies),
|
||||
Bodies\==[],
|
||||
list_to_disjunction(Bodies,Disjunction).
|
||||
|
||||
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-16 13:33:43 +0100 (Thu, 16 Dec 2010) $
|
||||
% $Revision: 5156 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-07-28 15:19:56 +0200 (Thu, 28 Jul 2011) $
|
||||
% $Revision: 6462 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-04-21 14:18:59 +0200 (Thu, 21 Apr 2011) $
|
||||
% $Revision: 6364 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-04-11 17:23:11 +0200 (Mon, 11 Apr 2011) $
|
||||
% $Revision: 5920 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
@@ -697,7 +697,8 @@ bdd_vars_script_intern(A, NameA) :-
|
||||
problog:get_fact_probability(A,P),
|
||||
format('@~w~n~12f~n~w~n',[NameA,P,1])
|
||||
;
|
||||
format('@~w~n~12f~n~w~n',[NameA,0,1])
|
||||
dtproblog:initial_probability(P),
|
||||
format('@~w~n~12f~n~w~n',[NameA,P,1])
|
||||
)
|
||||
; % it's a normal ProbLog fact
|
||||
problog:get_fact_probability(A,P),
|
||||
@@ -730,7 +731,8 @@ bdd_vars_script_intern2(A, NameA) :-
|
||||
problog:dynamic_probability_fact_extract(Goal,P),
|
||||
format('@~w~n~12f~n~w~n',[NameA,P,1])
|
||||
;
|
||||
format('@~w~n~12f~n~w~n',[NameA,0,1])
|
||||
dtproblog:initial_probability(P),
|
||||
format('@~w~n~12f~n~w~n',[NameA,P,1])
|
||||
)
|
||||
;
|
||||
(problog:dynamic_probability_fact(ID) ->
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-04-11 17:23:11 +0200 (Mon, 11 Apr 2011) $
|
||||
% $Revision: 5920 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2011-04-09 12:00:00 +0200 (Sat, 09 Apr 2011) $
|
||||
% $Revision: 5890 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% Main authors of this file:
|
||||
% Bernd Gutmann
|
||||
@@ -269,6 +269,8 @@ propagate_interpretation('$atom'(X),ID,Value) :-
|
||||
true;
|
||||
Value='$atom'(X)
|
||||
).
|
||||
propagate_interpretation(true,_,true).
|
||||
propagate_interpretation(false,_,false).
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
@@ -290,18 +292,15 @@ propagate((X <=> Y),A,AValue,(X2 <=> Y2),Result) :-
|
||||
or(Result1,Result2,Result).
|
||||
propagate((\+ X), A, AValue,\+ X2,Result) :-
|
||||
propagate(X,A,AValue,X2,Result).
|
||||
propagate('$atom'(X),'$atom'(A),AValue,X2,Result) :-
|
||||
propagate('$atom'(X),'$atom'(A),AValue,ResultTerm,Propagated) :-
|
||||
(
|
||||
X==A
|
||||
X==A
|
||||
->
|
||||
(
|
||||
X2=AValue,
|
||||
Result=true
|
||||
);
|
||||
(
|
||||
X2=X,
|
||||
Result=false
|
||||
)
|
||||
ResultTerm=AValue,
|
||||
Propagated=true
|
||||
;
|
||||
ResultTerm='$atom'(X),
|
||||
Propagated=false
|
||||
).
|
||||
propagate(true,_,_,true,false).
|
||||
propagate(false,_,_,false,false).
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-15 15:52:58 +0100 (Wed, 15 Dec 2010) $
|
||||
% $Revision: 5144 $
|
||||
% $Date: 2011-12-06 21:50:45 +0100 (Tue, 06 Dec 2011) $
|
||||
% $Revision: 6772 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
@@ -229,7 +229,7 @@
|
||||
%========================================================================
|
||||
|
||||
delete_file_silently(File) :-
|
||||
catch(delete_file(File),_,fail),
|
||||
catch(delete_file(File),_, fail),
|
||||
!.
|
||||
delete_file_silently(_).
|
||||
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-14 20:30:07 +0100 (Tue, 14 Dec 2010) $
|
||||
% $Revision: 5134 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-12-02 15:20:15 +0100 (Thu, 02 Dec 2010) $
|
||||
% $Revision: 5043 $
|
||||
% $Date: 2011-11-28 14:41:26 +0100 (Mon, 28 Nov 2011) $
|
||||
% $Revision: 6764 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
|
Reference in New Issue
Block a user