Merge branch 'master' of yap.dcc.fc.up.pt:yap-6

This commit is contained in:
Vítor Santos Costa 2010-09-30 20:09:58 +01:00
commit d912527de0
22 changed files with 202 additions and 182 deletions

View File

@ -3922,8 +3922,8 @@ Arc cosine.
@item atan(@var{X}) [ISO]
Arc tangent.
@item atan2(@var{X},@var{Y})
Four-quadrant arc tangent.
@item atan(@var{X},@var{Y})
Four-quadrant arc tangent. Also available as @code{atan2/2}.
@item sinh(@var{X})
Hyperbolic sine.

View File

@ -2,7 +2,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:14:21 +0200 (Tue, 24 Aug 2010) $
% $Date: 2010-08-24 15:14:21 +0200 (Di, 24. Aug 2010) $
% $Revision: 4671 $
%
% This file is part of ProbLog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-30 18:09:17 +0200 (Mon, 30 Aug 2010) $
% $Revision: 4728 $
% $Date: 2010-09-29 13:03:26 +0200 (Wed, 29 Sep 2010) $
% $Revision: 4843 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -290,6 +290,7 @@
problog_real_kbest/4,
op( 550, yfx, :: ),
op( 550, fx, ?:: ),
op(1149, yfx, <-- ),
op( 1150, fx, problog_table ),
in_interval/3,
below/2,
@ -320,12 +321,15 @@
:- use_module('problog/sampling').
:- use_module('problog/intervals').
:- use_module('problog/mc_DNF_sampling').
:- use_module('problog/variable_elimination').
:- catch(use_module('problog/ad_converter'),_,true).
:- catch(use_module('problog/variable_elimination'),_,true).
% op attaching probabilities to facts
:- op( 550, yfx, :: ).
:- op( 550, fx, ?:: ).
% for annotated disjunctions
% :- op(1149, yfx, <-- ).
%%%%%%%%%%%%%%%%%%%%%%%%
% control predicates on various levels
@ -371,21 +375,16 @@
:- dynamic(dynamic_probability_fact_extract/2).
% for storing continuous parts of proofs (Hybrid ProbLog)
:- dynamic(hybrid_proof/3, hybrid_proof/4).
:- dynamic([hybrid_proof/3, hybrid_proof/4]).
:- dynamic(hybrid_proof_disjoint/4).
% ProbLog files declare prob. facts as P::G
% and this module provides the predicate X::Y to iterate over them
:- multifile('::'/2).
% directory where problogbdd executable is located
% automatically set during loading -- assumes it is in same place as this file (problog.yap)
:- initialization((getcwd(PD), set_problog_path(PD))).
:- getcwd(PD), set_problog_path(PD).
%%%%%%%%%%%%
% iterative deepening on minimal probabilities (delta, max, kbest):
@ -466,9 +465,15 @@
% Default inference method
%%%%%%%%%%%%
:- initialization(
problog_define_flag(inference, problog_flag_validate_dummy, 'default inference method', exact, inference)
).
:- initialization(problog_define_flag(inference, problog_flag_validate_dummy, 'default inference method', exact, inference)).
%%%%%%%%%%%%
% Tunable Facts
%%%%%%%%%%%%
:- initialization(problog_define_flag(tunable_fact_start_value,problog_flag_validate_dummy,'How to initialize tunable probabilities',uniform(0.1,0.9),learning_general,flags:learning_prob_init_handler)).
problog_dir(PD):- problog_path(PD).
@ -567,6 +572,9 @@ generate_atoms(N, A):-
% dynamic predicate problog_predicate(Name,Arity) keeps track of predicates that already have wrapper clause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
term_expansion_intern(A, B, C):-
catch(term_expansion_intern_ad(A, B, C), _, false).
% converts ?:: prefix to ? :: infix, as handled by other clause
term_expansion_intern((Annotation::Fact), Module, ExpandedClause) :-
Annotation == '?',
@ -580,7 +588,7 @@ term_expansion_intern((Annotation :: Head :- Body), Module, problog:ExpandedClau
% It's a decision with a body
copy_term((Head,Body),(HeadCopy,_BodyCopy)),
functor(Head, Functor, Arity),
atom_concat(problog_, Functor, LongFunctor),
atomic_concat([problog_,Functor],LongFunctor),
Head =.. [Functor|Args],
append(Args,[LProb],LongArgs),
probclause_id(ID),
@ -626,7 +634,7 @@ user:term_expansion(P::Goal,Goal) :-
term_expansion_intern(P :: Goal,Module,problog:ProbFact) :-
copy_term((P,Goal),(P_Copy,Goal_Copy)),
functor(Goal, Name, Arity),
atom_concat(problog_, Name, ProblogName),
atomic_concat([problog_,Name],ProblogName),
Goal =.. [Name|Args],
append(Args,[LProb],L1),
probclause_id(ID),
@ -636,7 +644,7 @@ term_expansion_intern(P :: Goal,Module,problog:ProbFact) :-
->
(
assertz(tunable_fact(ID,TrueProb)),
LProb is log(random*0.9+0.05) % set unknown probability randomly in [0.05, 0.95]
sample_initial_value_for_tunable_fact(LProb)
);
(
ground(P)
@ -671,7 +679,34 @@ term_expansion_intern(P :: Goal,Module,problog:ProbFact) :-
problog_predicate(Name, Arity, ProblogName,Module).
sample_initial_value_for_tunable_fact(LogP) :-
problog_flag(tunable_fact_start_value,Initializer),
(
Initializer=uniform(Low,High)
->
(
Spread is High-Low,
random(Rand),
P1 is Rand*Spread+Low,
% security check, to avoid log(0)
(
P1>0
->
P=P1;
P=0.5
)
);
(
number(Initializer)
->
P=Initializer;
throw(unkown_probability_initializer(Initializer))
)
),
LogP is log(P).
@ -708,7 +743,7 @@ user:term_expansion(Goal, problog:ProbFact) :-
),
functor(Goal, Name, Arity),
atom_concat(problogcontinuous_, Name, ProblogName),
atomic_concat([problogcontinuous_,Name],ProblogName),
probclause_id(ID),
GaussianArg=gaussian(Mu_Arg,Sigma_Arg),
@ -807,16 +842,16 @@ interval_merge((_ID,GroundID,_Type),Interval) :-
problog_assertz(P::Goal) :-
problog_assertz(user,P::Goal).
problog_assertz(Module, P::Goal) :-
problog_assert(P::Goal) :-
problog_assert(user,P::Goal).
problog_assert(Module, P::Goal) :-
term_expansion_intern(P::Goal,Module,problog:ProbFact),
assertz(problog:ProbFact).
problog_retractall(Goal) :-
Goal =.. [F|Args],
append([_ID|Args],[_Prob],Args2),
atom_concat('problog_', F, F2),
atomic_concat(['problog_',F],F2),
ProbLogGoal=..[F2|Args2],
retractall(problog:ProbLogGoal).
@ -964,7 +999,7 @@ probabilistic_fact(P2,Goal,ID) :-
->
(
Goal =.. [F|Args],
atom_concat('problog_', F, F2),
atomic_concat('problog_',F,F2),
append([ID|Args],[P],Args2),
Goal2 =..[F2|Args2],
length(Args2,N),
@ -977,8 +1012,8 @@ probabilistic_fact(P2,Goal,ID) :-
get_internal_fact(ID,ProblogTerm,_ProblogName,_ProblogArity),
ProblogTerm =.. [F,_ID|Args],
append(Args2,[P],Args),
atom_codes(F,[_p,_r,_o,_b,_l,_o,_g,_|F2Chars]),
atom_codes(F2,F2Chars),
name(F,[_p,_r,_o,_b,_l,_o,_g,_|F2Chars]),
name(F2,F2Chars),
Goal =.. [F2|Args2],
(
dynamic_probability_fact(ID)
@ -1011,7 +1046,7 @@ prob_for_id(dummy,dummy,dummy).
get_fact_probability(A, Prob) :-
ground(A),
\+ number(A),
atom_codes(A, A_Codes),
name(A, A_Codes),
once(append(Part1, [95|Part2], A_Codes)), % 95 = '_'
number_codes(ID, Part1), !,
% let's check whether Part2 contains an 'l' (l=low)
@ -1072,7 +1107,7 @@ set_fact_probability(ID,Prob) :-
get_internal_fact(ID,ProblogTerm,ProblogName,ProblogArity) :-
problog_predicate(Name,Arity),
atom_concat(problog_, Name, ProblogName),
atomic_concat([problog_,Name],ProblogName),
ProblogArity is Arity+2,
functor(ProblogTerm,ProblogName,ProblogArity),
arg(1,ProblogTerm,ID),
@ -1090,7 +1125,7 @@ get_continuous_fact_parameters(ID,Parameters) :-
get_internal_continuous_fact(ID,ProblogTerm,ProblogName,ProblogArity,ContinuousPos) :-
problog_continuous_predicate(Name,Arity,ContinuousPos),
atom_concat(problogcontinuous_, Name, ProblogName),
atomic_concat([problogcontinuous_,Name],ProblogName),
ProblogArity is Arity+1,
functor(ProblogTerm,ProblogName,ProblogArity),
arg(1,ProblogTerm,ID),
@ -1147,7 +1182,7 @@ get_fact(ID,OutsideTerm) :-
ProblogTerm =.. [_Functor,ID|Args],
atomic_concat('problog_',OutsideFunctor,ProblogName),
Last is ProblogArity-1,
nth(Last,Args,_LogProb,OutsideArgs), % PM avoid nth/3; use nth0/3 or nth1/3 instead
nth(Last,Args,_LogProb,OutsideArgs),
OutsideTerm =.. [OutsideFunctor|OutsideArgs].
% ID of instance of non-ground fact: get fact from grounding table
get_fact(ID,OutsideTerm) :-
@ -1155,12 +1190,12 @@ get_fact(ID,OutsideTerm) :-
grounding_is_known(OutsideTerm,GID).
recover_grounding_id(Atom,ID) :-
atom_codes(Atom,List),
name(Atom,List),
reverse(List,Rev),
recover_number(Rev,NumRev),
reverse(NumRev,Num),
atom_codes(ID,Num).
recover_number([95|_],[]) :- !. % atom_codes('_',[95])
name(ID,Num).
recover_number([95|_],[]) :- !. % name('_',[95])
recover_number([A|B],[A|C]) :-
recover_number(B,C).
@ -1294,9 +1329,9 @@ montecarlo_check(ComposedID) :-
fail.
% (c) for unknown groundings of non-ground facts: generate a new sample (decompose the ID first)
montecarlo_check(ID) :-
atom_codes(ID,IDN),
name(ID,IDN),
recover_number(IDN,FactIDName),
atom_codes(FactID,FactIDName),
name(FactID,FactIDName),
new_sample_nonground(ID,FactID).
% sampling from ground fact: set array value to 1 (in) or 2 (out)
@ -1332,10 +1367,10 @@ new_sample_nonground(ComposedID,ID) :-
% fail.
split_grounding_id(Composed,Fact,Grounding) :-
atom_codes(Composed,C),
name(Composed,C),
split_g_id(C,F,G),
atom_codes(Fact,F),
atom_codes(Grounding,G).
name(Fact,F),
name(Grounding,G).
split_g_id([95|Grounding],[],Grounding) :- !.
split_g_id([A|B],[A|FactID],GroundingID) :-
split_g_id(B,FactID,GroundingID).
@ -2698,7 +2733,7 @@ build_trie(Goal, Trie) :-
throw(error('Flag settings not supported by build_trie/2.'))
).
build_trie_supported :- problog_flag(inference,exact). % PM this can easily be written to avoid creating choice-points
build_trie_supported :- problog_flag(inference,exact).
build_trie_supported :- problog_flag(inference,low(_)).
build_trie_supported :- problog_flag(inference,atleast-_-best).
build_trie_supported :- problog_flag(inference,_-best).
@ -2991,7 +3026,7 @@ write_global_bdd_file_line(I,Max) :-
).
write_global_bdd_file_query(I,Max) :-
(I=Max -> % PM shouldn't this be instead I =:= Max ?
(I=Max ->
format("L~q~n",[I])
;
format("L~q,",[I]),
@ -3026,8 +3061,8 @@ bdd_par_file(BDDParFile) :-
require(Feature) :-
atom(Feature),
atom_concat('problog_required_', Feature, Feature_Required),
atom_concat(Feature_Required, '_depth', Feature_Depth),
atomic_concat(['problog_required_',Feature],Feature_Required),
atomic_concat([Feature_Required,'_',depth],Feature_Depth),
(required(Feature) ->
b_getval(Feature_Depth,Depth),
Depth1 is Depth+1,
@ -3040,8 +3075,8 @@ require(Feature) :-
unrequire(Feature) :-
atom(Feature),
atom_concat('problog_required_', Feature, Feature_Required),
atom_concat(Feature_Required, '_depth', Feature_Depth),
atomic_concat(['problog_required_',Feature],Feature_Required),
atomic_concat([Feature_Required,'_',depth],Feature_Depth),
b_getval(Feature_Depth,Depth),
(Depth=1 ->
nb_delete(Feature_Required),
@ -3054,7 +3089,7 @@ unrequire(Feature) :-
required(Feature) :-
atom(Feature),
atom_concat('problog_required_', Feature, Feature_Required),
atomic_concat(['problog_required_',Feature],Feature_Required),
catch(b_getval(Feature_Required,Val),error(existence_error(variable,Feature_Required),_),fail),
Val == required.

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -204,15 +204,14 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:-module(flags, [
problog_define_flag/4,
problog_define_flag/5,
problog_define_flag/6,
problog_defined_flag/5,
problog_defined_flag_group/1,
set_problog_flag/2,
reset_problog_flags/0,
problog_flag/2]).
:-module(flags, [problog_define_flag/4,
problog_define_flag/5,
problog_define_flag/6,
problog_defined_flag/5,
problog_defined_flag_group/1,
set_problog_flag/2,
reset_problog_flags/0,
problog_flag/2]).
:- use_module(gflags).
@ -344,8 +343,17 @@ learning_init_handler(validating, (_,_,_,_,_)).
learning_init_handler(validated, _Value).
learning_init_handler(stored, _Value).
learning_prob_init_handler(message, '(Q,P,Query)').
learning_prob_init_handler(validating, (_,_,_)).
learning_prob_init_handler(message, '(0,1] or uniform(l,h) ').
learning_prob_init_handler(validating, uniform(Low,High)) :-
number(Low),
number(High),
Low<High,
Low>0,
High =< 1.
learning_prob_init_handler(validating, N) :-
number(N),
N>0,
N =< 1.
%learning_prob_init_handler(validate, V_).
learning_prob_init_handler(validated, _Value).
learning_prob_init_handler(stored, _Value).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -515,16 +515,15 @@ logger_write_header :-
bb_get(logger_filename,FName),
bb_get(logger_variables,Variables),
open(FName,'append',Handle),
write(Handle,'# '),
logger_write_header_intern(Variables,Handle),
write(Handle,'\n'),
format(Handle,'#####################################################################~n',[]),
format(Handle,'# ~w~6+~w~7+~w~n',['Pos','Type','Name']),
format(Handle,'#####################################################################~n',[]),
logger_write_header_intern(Variables,1,Handle),
format(Handle,'#####################################################################~n',[]),
close(Handle).
logger_write_header_intern([],_).
logger_write_header_intern([(Name,_Type)],Handle) :-
write(Handle,Name).
logger_write_header_intern([(Name,_Type),Next|T],Handle) :-
bb_get(logger_delimiter,D),
write(Handle,Name),
write(Handle,D),
logger_write_header_intern([Next|T],Handle).
logger_write_header_intern([],_,_).
logger_write_header_intern([(Name,Type)|T],Position,Handle) :-
format(Handle,'# ~q~6+~q~7+~q~n',[Position,Type,Name]),
Position2 is Position+1,
logger_write_header_intern(T,Position2,Handle).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-24 15:54:45 +0200 (Fri, 24 Sep 2010) $
% $Revision: 4822 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-23 11:13:10 +0200 (Thu, 23 Sep 2010) $
% $Revision: 4804 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-07 23:20:03 +0200 (Tue, 07 Sep 2010) $
% $Revision: 4765 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -246,7 +246,7 @@
% load library modules
:- use_module(library(tries)).
:- use_module(library(lists), [append/3, member/2, memberchk/2]).
:- use_module(library(lists), [append/3, member/2, memberchk/2, delete/3]).
:- use_module(library(system), [delete_file/1, shell/1]).
:- use_module(library(ordsets), [ord_intersection/3, ord_union/3]).
@ -260,10 +260,10 @@
% this is a test to determine whether YAP provides the needed trie library
:- initialization(
( predicate_property(trie_disable_hash, imported_from(tries)) ->
trie_disable_hash
; print_message(warning,'The predicate tries:trie_disable_hash/0 does not exist. Please update trie library.')
)
( predicate_property(trie_disable_hash, imported_from(tries)) ->
trie_disable_hash
; print_message(warning,'The predicate tries:trie_disable_hash/0 does not exist. Please update trie library.')
)
).
%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-24 15:54:45 +0200 (Fri, 24 Sep 2010) $
% $Revision: 4822 $
% $Date: 2010-09-29 13:24:43 +0200 (Wed, 29 Sep 2010) $
% $Revision: 4845 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -204,17 +204,11 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%
% Collected OS depended instructions
%%%%%%%%
:- module(utils_learning, [empty_bdd_directory/1,
empty_output_directory/1,
delete_file_silent/1
]).
:- module(utils_learning, [empty_bdd_directory/0,
empty_output_directory/0,
delete_file_silent/1,
slice_n/4]).
% switch on all tests to reduce bug searching time
:- style_check(all).
:- yap_flag(unknown,error).
% load library modules
:- use_module(library(lists), [append/3, member/2]).
@ -222,28 +216,33 @@
% load our own modules
:- use_module(os).
:- use_module(flags).
%========================================================================
%=
%=
%========================================================================
empty_bdd_directory(Path) :-
ground(Path),
empty_bdd_directory :-
problog_flag(bdd_directory,Path),
!,
atom_codes('query_', PF1), % 'query_*'
directory_files(Path,List),
delete_files_with_matching_prefix(List,Path,[PF1]).
empty_bdd_directory :-
throw(error(problog_flag_does_not_exist(bdd_directory))).
%========================================================================
%=
%=
%========================================================================
empty_output_directory(Path) :-
ground(Path),
empty_output_directory :-
problog_flag(output_directory,Path),
!,
concat_path_with_filename(Path,'log.dat',F1),
concat_path_with_filename(Path,'out.dat',F2),
@ -270,12 +269,16 @@ empty_output_directory(Path) :-
directory_files(Path,List),
delete_files_with_matching_prefix(List,Path,[PF1,PF2,PF3,PF4,PF5,PF6]).
empty_output_directory :-
throw(error(problog_flag_does_not_exist(output_directory))).
%========================================================================
%=
%=
%========================================================================
delete_file_silent(File) :-
file_exists(File),
delete_file(File),
!.
delete_file_silent(_).
@ -300,3 +303,18 @@ delete_files_with_matching_prefix([Name|T],Path,Prefixes) :-
),
delete_files_with_matching_prefix(T,Path,Prefixes).
%========================================================================
%= Split a list into the first n elements and the tail
%= +List +Integer -Prefix -Residuum
%========================================================================
slice_n([],_,[],[]) :-
!.
slice_n([H|T],N,[H|T2],T3) :-
N>0,
!,
N2 is N-1,
slice_n(T,N2,T2,T3).
slice_n(L,_,[],L).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -204,12 +204,7 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(variable_elimination, [
trie_check_for_and_cluster/1,
trie_replace_and_cluster/2,
clean_up/0,
variable_elimination_stats/3
]).
:- module(variable_elimination, [trie_check_for_and_cluster/1, trie_replace_and_cluster/2, clean_up/0, variable_elimination_stats/3]).
:- use_module(library(lists), [append/3, delete/3, memberchk/2, reverse/2]).
:- use_module(library(tries)).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
% $Revision: 4672 $
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog

View File

@ -12,6 +12,7 @@
% will run 20 iterations of learning with default settings
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog').
:- use_module('../problog_learning').
%%%%

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-24 15:54:45 +0200 (Fri, 24 Sep 2010) $
% $Revision: 4822 $
% $Date: 2010-09-29 18:43:14 +0200 (Wed, 29 Sep 2010) $
% $Revision: 4854 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -205,18 +205,9 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(learning,[
do_learning/1,
do_learning/2,
set_learning_flag/2,
learning_flag/2,
learning_flags/0,
problog_help/0,
set_problog_flag/2,
problog_flag/2,
problog_flags/0,
auto_alpha/0
]).
:- module(learning,[do_learning/1,
do_learning/2
]).
% switch on all the checks to reduce bug searching time
:- style_check(all).
@ -224,7 +215,6 @@
% load modules from the YAP library
:- use_module(library(lists), [max_list/2, min_list/2, sum_list/2]).
:- use_module(library(random)). % PM doesn't seem to be used!
:- use_module(library(system), [delete_file/1, file_exists/1, shell/2]).
% load our own modules
@ -439,7 +429,7 @@ do_learning(Iterations,Epsilon) :-
Iterations>0,
do_learning_intern(Iterations,Epsilon).
do_learning(_,_) :-
format(user_error,'~n~nWarning: No training examples specified !!!~n~n',[]).
format(user_error,'~n~Error: No training examples specified.~n~n',[]).
do_learning_intern(0,_) :-
@ -449,9 +439,7 @@ do_learning_intern(Iterations,Epsilon) :-
init_learning,
current_iteration(CurrentIteration),
!,
retractall(current_iteration(_)),
!,
NextIteration is CurrentIteration+1,
assertz(current_iteration(NextIteration)),
EndIteration is CurrentIteration+Iterations-1,
@ -462,7 +450,7 @@ do_learning_intern(Iterations,Epsilon) :-
logger_start_timer(duration),
mse_testset,
once(ground_truth_difference),
ground_truth_difference,
gradient_descent,
problog_flag(log_frequency,Log_Frequency),
@ -500,8 +488,10 @@ do_learning_intern(Iterations,Epsilon) :-
->
(
retractall(values_correct),
once(delete_all_queries),
once(init_queries)
retractall(query_is_similar(_,_)),
retractall(query_md5(_,_,_)),
empty_bdd_directory,
init_queries
); true
),
@ -551,7 +541,7 @@ init_learning :-
)
->
true;
delete_all_queries
empty_bdd_directory
),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -648,23 +638,6 @@ init_learning :-
format_learning(1,'~n',[]).
%========================================================================
%=
%=
%=
%========================================================================
delete_all_queries :-
problog_flag(bdd_directory,BDD_Directory),
empty_bdd_directory(BDD_Directory),
retractall(query_is_similar(_,_)),
retractall(query_md5(_,_,_)).
empty_output_directory :-
problog_flag(output_directory,Directory),
empty_output_directory(Directory).
%========================================================================
%= This predicate goes over all training and test examples,
@ -770,13 +743,8 @@ update_values :-
% start write current probabilities to file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bdd_input_file(Probabilities_File),
(
file_exists(Probabilities_File)
->
delete_file(Probabilities_File);
true
),
delete_file_silent(Probabilities_File),
open(Probabilities_File,'write',Handle),
( % go over all probabilistic facts
@ -845,7 +813,7 @@ update_query(QueryID,Symbol,What_To_Update) :-
problog_dir(PD),
((What_To_Update=all;query_is_similar(_,QueryID)) -> Method='g' ; Method='l'),
atomic_concat([PD,
'/ProblogBDD',
'/problogbdd',
' -i "', Probabilities_File, '"',
' -l "', Query_Directory,'/query_',QueryID, '"',
' -m ', Method,
@ -1639,7 +1607,7 @@ auto_alpha :-
%========================================================================
%= initialize the logger module and set the flags for learning
%= don't change anything here! use set_learning_flag/2 instead
%= don't change anything here! use set_problog_flag/2 instead
%========================================================================
init_flags :-
@ -1681,10 +1649,6 @@ init_logger :-
logger_define_variable(learning_rate,float),
logger_define_variable(alpha,float).
%========================================================================
%=
%=
%========================================================================
:- initialization(init_flags).
:- initialization(init_logger).
:- initialization((init_flags,init_logger)).