From 611af95e43fcc3a919157daf2333dfa63cb0b3bd Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Tue, 30 Nov 2010 19:17:25 +0100 Subject: [PATCH 1/8] added anottated disjunctions --- packages/ProbLog/problog/ad_converter.yap | 394 ++++++++++++++++++++++ 1 file changed, 394 insertions(+) create mode 100644 packages/ProbLog/problog/ad_converter.yap diff --git a/packages/ProbLog/problog/ad_converter.yap b/packages/ProbLog/problog/ad_converter.yap new file mode 100644 index 000000000..bb8fe601b --- /dev/null +++ b/packages/ProbLog/problog/ad_converter.yap @@ -0,0 +1,394 @@ +%%% -*- Mode: Prolog; -*- + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% $Date: 2010-10-13 17:09:47 +0200 (Wed, 13 Oct 2010) $ +% $Revision: 4915 $ +% +% This file is part of ProbLog +% http://dtai.cs.kuleuven.be/problog +% +% ProbLog was developed at Katholieke Universiteit Leuven +% +% Copyright 2009 +% Angelika Kimmig, Vitor Santos Costa, Bernd Gutmann +% +% Main authors of this file: +% Bernd Gutmann +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Artistic License 2.0 +% +% Copyright (c) 2000-2006, The Perl Foundation. +% +% Everyone is permitted to copy and distribute verbatim copies of this +% license document, but changing it is not allowed. Preamble +% +% This license establishes the terms under which a given free software +% Package may be copied, modified, distributed, and/or +% redistributed. The intent is that the Copyright Holder maintains some +% artistic control over the development of that Package while still +% keeping the Package available as open source and free software. +% +% You are always permitted to make arrangements wholly outside of this +% license directly with the Copyright Holder of a given Package. If the +% terms of this license do not permit the full use that you propose to +% make of the Package, you should contact the Copyright Holder and seek +% a different licensing arrangement. Definitions +% +% "Copyright Holder" means the individual(s) or organization(s) named in +% the copyright notice for the entire Package. +% +% "Contributor" means any party that has contributed code or other +% material to the Package, in accordance with the Copyright Holder's +% procedures. +% +% "You" and "your" means any person who would like to copy, distribute, +% or modify the Package. +% +% "Package" means the collection of files distributed by the Copyright +% Holder, and derivatives of that collection and/or of those files. A +% given Package may consist of either the Standard Version, or a +% Modified Version. +% +% "Distribute" means providing a copy of the Package or making it +% accessible to anyone else, or in the case of a company or +% organization, to others outside of your company or organization. +% +% "Distributor Fee" means any fee that you charge for Distributing this +% Package or providing support for this Package to another party. It +% does not mean licensing fees. +% +% "Standard Version" refers to the Package if it has not been modified, +% or has been modified only in ways explicitly requested by the +% Copyright Holder. +% +% "Modified Version" means the Package, if it has been changed, and such +% changes were not explicitly requested by the Copyright Holder. +% +% "Original License" means this Artistic License as Distributed with the +% Standard Version of the Package, in its current version or as it may +% be modified by The Perl Foundation in the future. +% +% "Source" form means the source code, documentation source, and +% configuration files for the Package. +% +% "Compiled" form means the compiled bytecode, object code, binary, or +% any other form resulting from mechanical transformation or translation +% of the Source form. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Permission for Use and Modification Without Distribution +% +% (1) You are permitted to use the Standard Version and create and use +% Modified Versions for any purpose without restriction, provided that +% you do not Distribute the Modified Version. +% +% Permissions for Redistribution of the Standard Version +% +% (2) You may Distribute verbatim copies of the Source form of the +% Standard Version of this Package in any medium without restriction, +% either gratis or for a Distributor Fee, provided that you duplicate +% all of the original copyright notices and associated disclaimers. At +% your discretion, such verbatim copies may or may not include a +% Compiled form of the Package. +% +% (3) You may apply any bug fixes, portability changes, and other +% modifications made available from the Copyright Holder. The resulting +% Package will still be considered the Standard Version, and as such +% will be subject to the Original License. +% +% Distribution of Modified Versions of the Package as Source +% +% (4) You may Distribute your Modified Version as Source (either gratis +% or for a Distributor Fee, and with or without a Compiled form of the +% Modified Version) provided that you clearly document how it differs +% from the Standard Version, including, but not limited to, documenting +% any non-standard features, executables, or modules, and provided that +% you do at least ONE of the following: +% +% (a) make the Modified Version available to the Copyright Holder of the +% Standard Version, under the Original License, so that the Copyright +% Holder may include your modifications in the Standard Version. (b) +% ensure that installation of your Modified Version does not prevent the +% user installing or running the Standard Version. In addition, the +% modified Version must bear a name that is different from the name of +% the Standard Version. (c) allow anyone who receives a copy of the +% Modified Version to make the Source form of the Modified Version +% available to others under (i) the Original License or (ii) a license +% that permits the licensee to freely copy, modify and redistribute the +% Modified Version using the same licensing terms that apply to the copy +% that the licensee received, and requires that the Source form of the +% Modified Version, and of any works derived from it, be made freely +% available in that license fees are prohibited but Distributor Fees are +% allowed. +% +% Distribution of Compiled Forms of the Standard Version or +% Modified Versions without the Source +% +% (5) You may Distribute Compiled forms of the Standard Version without +% the Source, provided that you include complete instructions on how to +% get the Source of the Standard Version. Such instructions must be +% valid at the time of your distribution. If these instructions, at any +% time while you are carrying out such distribution, become invalid, you +% must provide new instructions on demand or cease further +% distribution. If you provide valid instructions or cease distribution +% within thirty days after you become aware that the instructions are +% invalid, then you do not forfeit any of your rights under this +% license. +% +% (6) You may Distribute a Modified Version in Compiled form without the +% Source, provided that you comply with Section 4 with respect to the +% Source of the Modified Version. +% +% Aggregating or Linking the Package +% +% (7) You may aggregate the Package (either the Standard Version or +% Modified Version) with other packages and Distribute the resulting +% aggregation provided that you do not charge a licensing fee for the +% Package. Distributor Fees are permitted, and licensing fees for other +% components in the aggregation are permitted. The terms of this license +% apply to the use and Distribution of the Standard or Modified Versions +% as included in the aggregation. +% +% (8) You are permitted to link Modified and Standard Versions with +% other works, to embed the Package in a larger work of your own, or to +% build stand-alone binary or bytecode versions of applications that +% include the Package, and Distribute the result without restriction, +% provided the result does not expose a direct interface to the Package. +% +% Items That are Not Considered Part of a Modified Version +% +% (9) Works (including, but not limited to, modules and scripts) that +% merely extend or make use of the Package, do not, by themselves, cause +% the Package to be a Modified Version. In addition, such works are not +% considered parts of the Package itself, and are not subject to the +% terms of this license. +% +% General Provisions +% +% (10) Any use, modification, and distribution of the Standard or +% Modified Versions is governed by this Artistic License. By using, +% modifying or distributing the Package, you accept this license. Do not +% use, modify, or distribute the Package, if you do not accept this +% license. +% +% (11) If your Modified Version has been derived from a Modified Version +% made by someone other than you, you are nevertheless required to +% ensure that your Modified Version complies with the requirements of +% this license. +% +% (12) This license does not grant you the right to use any trademark, +% service mark, tradename, or logo of the Copyright Holder. +% +% (13) This license includes the non-exclusive, worldwide, +% free-of-charge patent license to make, have made, use, offer to sell, +% sell, import and otherwise transfer the Package with respect to any +% patent claims licensable by the Copyright Holder that are necessarily +% infringed by the Package. If you institute patent litigation +% (including a cross-claim or counterclaim) against any party alleging +% that the Package constitutes direct or contributory patent +% infringement, then this Artistic License to you shall terminate on the +% date that such litigation is filed. +% +% (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT +% HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED +% WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +% PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT +% PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT +% HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, +% INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE +% OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +:- module(ad_converter,[compile_annotated_disjunction/5, + compile_tunable_annotated_disjunction/5, + proper_annotated_disjunction/1, + proper_tunable_annotated_disjunction/1, + term_expansion_intern_ad/3, + op(1149, yfx, <-- ), + op( 550, yfx, :: ) + ]). + +% general yap modules +:- use_module(library(lists),[reverse/2]). + +:- style_check(all). +:- yap_flag(unknown,error). + +:- op( 550, yfx, :: ). + +% for annotated disjunctions +:- op(1149, yfx, <-- ). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +term_expansion_intern_ad( (Head<--Body),Module,ad_intern((Head<--Body),ID)) :- + proper_tunable_annotated_disjunction(Head), + !, + compile_tunable_annotated_disjunction(Head,Body,Facts,Bodies,ID), + assert_all_ad_facts(Facts,Module), + assert_all_ad_bodies(Bodies,Module). +term_expansion_intern_ad( (Head<--Body),Module,ad_intern((Head<--Body),ID)) :- + proper_annotated_disjunction(Head), + !, + compile_annotated_disjunction(Head,Body,Facts,Bodies,ID), + assert_all_ad_facts(Facts,Module), + assert_all_ad_bodies(Bodies,Module). +term_expansion_intern_ad( (Head<--Body),_,_) :- + format_to_chars('Error at compiling the annotated disjunction ~q<--Body.',[Head,Body],Error), + print_message(error,Error), + fail. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +assert_all_ad_facts([],_). +assert_all_ad_facts([F|T],Module) :- + once(problog:term_expansion_intern(F,Module,Atom)), + assertz(problog:Atom), + assert_all_ad_facts(T,Module). + +assert_all_ad_bodies([],_). +assert_all_ad_bodies([B|T],Module) :- + assertz(Module:B), + assert_all_ad_bodies(T,Module). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +get_next_unique_id(ID) :- + ( + bb_get(mvs_unique_id,ID) + -> + true; + ID=1 + ), + ID2 is ID+1, + bb_put(mvs_unique_id,ID2). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +proper_annotated_disjunction(AD) :- + proper_annotated_disjunction(AD,0.0,Sum), + Sum=<1. + +proper_annotated_disjunction( P :: _, OldSum,NewSum) :- + % evaluate P + P2 is P, + P2>=0, + P2=<1, + NewSum is OldSum+P. +proper_annotated_disjunction((X;Y),OldSum,Sum) :- + proper_annotated_disjunction(X,OldSum,NewSum), + proper_annotated_disjunction(Y,NewSum,Sum). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +proper_tunable_annotated_disjunction( t(_) :: _). +proper_tunable_annotated_disjunction((X;Y)) :- + proper_tunable_annotated_disjunction(X), + proper_tunable_annotated_disjunction(Y). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +compile_tunable_annotated_disjunction(Head,Body,Facts2,Bodies2,Extra_ID) :- + get_next_unique_id(Extra_ID), + + convert_a_tunable(Head,Extra_ID,[],Facts), + convert_b(Head,Body,_NewBody,Extra_ID,[],Bodies), + + reverse(Facts,Facts2), + reverse(Bodies,Bodies2). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +compile_annotated_disjunction(Head,Body,Facts2,Bodies2,Extra_ID) :- + get_next_unique_id(Extra_ID), + + convert_a(Head,0.0,_Acc,Extra_ID,[],Facts), + convert_b(Head,Body,_NewBody,Extra_ID,[],Bodies), + + reverse(Facts,Facts2), + reverse(Bodies,Bodies2). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +convert_a((X;Y),OldAcc,Acc,Extra_ID,OldFacts,Facts) :- + convert_a(X,OldAcc,NewAcc,Extra_ID,OldFacts,NewFacts), + convert_a(Y,NewAcc,Acc,Extra_ID,NewFacts,Facts). +convert_a(P::Atom,OldAcc,NewAcc,Extra_ID,OldFacts,[P1::ProbFact|OldFacts]) :- + Atom =.. [Functor|AllArguments], + length(AllArguments,Arity), + + atomic_concat([mvs_fact_,Functor,'_',Arity,'_',Extra_ID],NewAtom), + + ProbFact =.. [NewAtom|AllArguments], + ( + P=:=0 + -> + P1 is 0.0 ; + ( + OldAcc=:=0 + -> + P1 is P; + P1 is P/(1-OldAcc) + ) + ), + NewAcc is OldAcc+P. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +convert_a_tunable((X;Y),Extra_ID,OldFacts,Facts) :- + convert_a_tunable(X,Extra_ID,OldFacts,NewFacts), + convert_a_tunable(Y,Extra_ID,NewFacts,Facts). +convert_a_tunable(P::Atom,Extra_ID,OldFacts,[P::ProbFact|OldFacts]) :- + Atom =.. [Functor|AllArguments], + length(AllArguments,Arity), + + atomic_concat([mvs_fact_,Functor,'_',Arity,'_',Extra_ID],NewAtom), + + ProbFact =.. [NewAtom|AllArguments]. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +convert_b((X;Y),OldBody,Body,ExtraID,OldBodies,Bodies) :- + convert_b(X,OldBody,NewBody,ExtraID,OldBodies,NewBodies), + convert_b(Y,NewBody,Body,ExtraID,NewBodies,Bodies). +convert_b(_::Atom,OldBody,NewBody,Extra_ID,OldBodies,[(Atom:-ThisBody)|OldBodies]) :- + Atom =.. [Functor|AllArguments], + + length(AllArguments,Arity), + atomic_concat([mvs_fact_,Functor,'_',Arity,'_',Extra_ID],NewFunctor), + + ProbFact =.. [NewFunctor|AllArguments], + tuple_append(OldBody,ProbFact,ThisBody), + tuple_append(OldBody,problog_not(ProbFact),NewBody). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +tuple_append(true,X,X) :- + !. +tuple_append(X,true,X) :- + !. +tuple_append((A,B),X,(A,B2)) :- + X \= true, + !, + tuple_append(B,X,B2). +tuple_append(X,Y,(X,Y)) :- + X \= true, + Y \= true, + X \= (_,_). From b02507ed22c0865e370e7eb7ec0a71bd42086378 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 2 Dec 2010 11:49:58 +0000 Subject: [PATCH 2/8] fix 32 bit atoms to ensure alignment at 8 bytes (broken with blobs). --- H/Atoms.h | 10 ++++++---- H/Yatom.h | 1 + library/dialect/swi/fli/blobs.c | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/H/Atoms.h b/H/Atoms.h index 86fbc0bc5..d5a0f8316 100644 --- a/H/Atoms.h +++ b/H/Atoms.h @@ -27,6 +27,11 @@ #include +typedef struct atom_blob { + size_t length; + char data[MIN_ARRAY]; +} atom_blob_t; + /********* operations for atoms ****************************************/ /* Atoms are assumed to be uniquely represented by an OFFSET and to have @@ -55,10 +60,7 @@ typedef struct AtomEntryStruct union { char uStrOfAE[MIN_ARRAY]; /* representation of atom as a string */ wchar_t uWStrOfAE[MIN_ARRAY]; /* representation of atom as a string */ - struct { - size_t length; /* size of blob */ - char data[MIN_ARRAY]; /* data */ - } blob; + struct atom_blob blob[MIN_ARRAY]; } rep; } AtomEntry; diff --git a/H/Yatom.h b/H/Yatom.h index ecaf3052b..1d4fbe0b0 100755 --- a/H/Yatom.h +++ b/H/Yatom.h @@ -1604,3 +1604,4 @@ PredPropByAtom (Atom at, Term cur_mod) #endif #endif + diff --git a/library/dialect/swi/fli/blobs.c b/library/dialect/swi/fli/blobs.c index efc080245..156607a3b 100644 --- a/library/dialect/swi/fli/blobs.c +++ b/library/dialect/swi/fli/blobs.c @@ -85,11 +85,11 @@ PL_blob_data(atom_t a, size_t *len, struct PL_blob_t **type) return x->StrOfAE; } if ( len ) - *len = x->rep.blob.length; + *len = x->rep.blob[0].length; if ( type ) *type = RepBlobProp(x->PropsOfAE)->blob_t; - return x->rep.blob.data; + return x->rep.blob[0].data; } PL_EXPORT(void) From 7e59179622232bf0bccf075b77e58c69206ac68f Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 2 Dec 2010 12:10:03 +0000 Subject: [PATCH 3/8] fix bad SWI functor :( --- library/dialect/swi/fli/swi.c | 14 +++++++------- library/dialect/swi/fli/swi.h | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/library/dialect/swi/fli/swi.c b/library/dialect/swi/fli/swi.c index 5946702b4..c7266cefe 100755 --- a/library/dialect/swi/fli/swi.c +++ b/library/dialect/swi/fli/swi.c @@ -50,12 +50,12 @@ extern X_API Int YAP_PLArityOfSWIFunctor(functor_t at); X_API Int -YAP_PLArityOfSWIFunctor(functor_t at) { - if (IsAtomTerm(at)) +YAP_PLArityOfSWIFunctor(functor_t f) { + if (IsAtomTerm(f)) return 0; - if ((CELL)(at) & 2) - return ArityOfFunctor(SWI_Functors[((CELL)at)/4]); - return ArityOfFunctor((Functor)at); + if ((CELL)f < N_SWI_FUNCTORS*(LowTagBits+1)) + return ArityOfFunctor(SWI_Functors[(CELL)f/(LowTagBits+1)]); + return ArityOfFunctor((Functor)f); } void @@ -64,10 +64,10 @@ Yap_InitSWIHash(void) int i, j; memset(SWI_ReverseHash, 0, N_SWI_HASH*sizeof(swi_rev_hash)); for (i=0; i < N_SWI_ATOMS; i++) { - add_to_hash(i*2+1, (ADDR)SWI_Atoms[i]); + add_to_hash(i, (ADDR)SWI_Atoms[i]); } for (j=0; j < N_SWI_FUNCTORS; j++) { - add_to_hash((((CELL)(j))*4+2), (ADDR)SWI_Functors[j]); + add_to_hash(j, (ADDR)SWI_Functors[j]); } } diff --git a/library/dialect/swi/fli/swi.h b/library/dialect/swi/fli/swi.h index 3032aece8..9fd1a3c4c 100644 --- a/library/dialect/swi/fli/swi.h +++ b/library/dialect/swi/fli/swi.h @@ -83,15 +83,15 @@ AtomToSWIAtom(Atom at) { atom_t ats; if ((ats = in_hash((ADDR)at))) - return ats; + return (atom_t)((CELL)at*(LowTagBits+1)); return (atom_t)at; } static inline Atom SWIAtomToAtom(atom_t at) { - if ((CELL)at & 1) - return SWI_Atoms[at>>1]; + if ((CELL)at < N_SWI_ATOMS*(LowTagBits+1)) + return SWI_Atoms[((CELL)at)/(LowTagBits+1)]; return (Atom)at; } @@ -110,17 +110,17 @@ FunctorToSWIFunctor(Functor at) { atom_t ats; if ((ats = in_hash((ADDR)at))) - return (functor_t)ats; + return (functor_t)((CELL)at*(LowTagBits+1)); return (functor_t)at; } static inline Functor -SWIFunctorToFunctor(functor_t at) +SWIFunctorToFunctor(functor_t f) { - if (IsAtomTerm(at)) - return (Functor)at; - if ((CELL)(at) & 2) - return SWI_Functors[((CELL)at)/4]; - return (Functor)at; + if (IsAtomTerm(f)) + return (Functor)f; + if ((CELL)f < N_SWI_FUNCTORS*(LowTagBits+1)) + return SWI_Functors[(CELL)f/(LowTagBits+1)]; + return (Functor)f; } From 6ffa3eb06b0fa8e032587e0a111db69ef9b0ede1 Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Thu, 2 Dec 2010 14:48:28 +0100 Subject: [PATCH 4/8] ... --- packages/ProbLog/Makefile.in | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ProbLog/Makefile.in b/packages/ProbLog/Makefile.in index e32e752ec..fb3db27c6 100644 --- a/packages/ProbLog/Makefile.in +++ b/packages/ProbLog/Makefile.in @@ -53,6 +53,7 @@ PROBLOG_PROGRAMS= \ $(srcdir)/problog/version_control.yap \ $(srcdir)/problog/nestedtries.yap \ $(srcdir)/problog/utils.yap \ + $(srcdir)/problog/ad_converter.yap \ $(srcdir)/problog/variables.yap PROBLOG_EXAMPLES = \ From b54517d41922c4a08c7fa43c3c73a8b55b6f8864 Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Thu, 2 Dec 2010 14:54:47 +0100 Subject: [PATCH 5/8] Updating ProbLog and adding ADs --- packages/ProbLog/dtproblog.yap | 2 +- packages/ProbLog/problog.yap | 37 +++++- packages/ProbLog/problog/os.yap | 108 ++++++++++++----- .../ProbLog/problog/{tptree.yap => ptree.yap} | 41 ++----- packages/ProbLog/problog/utils.yap | 113 ++++++++++++++++-- packages/ProbLog/problog/utils_learning.yap | 97 +++++++++------ packages/ProbLog/problog_learning.yap | 6 +- 7 files changed, 287 insertions(+), 117 deletions(-) rename packages/ProbLog/problog/{tptree.yap => ptree.yap} (98%) diff --git a/packages/ProbLog/dtproblog.yap b/packages/ProbLog/dtproblog.yap index f368e019c..0fca0f292 100644 --- a/packages/ProbLog/dtproblog.yap +++ b/packages/ProbLog/dtproblog.yap @@ -304,7 +304,7 @@ :- use_module('problog/os', [convert_filename_to_working_path/2, convert_filename_to_problog_path/2]). -:- use_module('problog/tptree', [delete_ptree/1]). +:- use_module('problog/ptree', [delete_ptree/1]). :- use_module('problog/tabling', [clear_tabling/0]). diff --git a/packages/ProbLog/problog.yap b/packages/ProbLog/problog.yap index f7be7462e..0f729fc5c 100644 --- a/packages/ProbLog/problog.yap +++ b/packages/ProbLog/problog.yap @@ -2,8 +2,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% $Date: 2010-11-09 02:47:35 +0100 (Tue, 09 Nov 2010) $ -% $Revision: 4991 $ +% $Date: 2010-11-23 11:47:48 +0100 (Tue, 23 Nov 2010) $ +% $Revision: 5027 $ % % This file is part of ProbLog % http://dtai.cs.kuleuven.be/problog @@ -314,7 +314,36 @@ :- use_module('problog/flags'). :- use_module('problog/print'). :- use_module('problog/os'). -:- use_module('problog/tptree'). +:- use_module('problog/ptree', [init_ptree/1, + delete_ptree/1, + member_ptree/2, + enum_member_ptree/2, + insert_ptree/2, + delete_ptree/2, + edges_ptree/2, + count_ptree/2, + prune_check_ptree/2, + empty_ptree/1, + merge_ptree/2, + merge_ptree/3, + bdd_ptree/3, + bdd_struct_ptree/3, + bdd_ptree_map/4, + bdd_struct_ptree_map/4, + traverse_ptree/2, %theo + print_ptree/1, %theo + statistics_ptree/0, %theo + print_nested_ptree/1, %theo + trie_to_bdd_trie/5, %theo + trie_to_bdd_struct_trie/5, + nested_trie_to_bdd_trie/5, %theo + nested_trie_to_bdd_struct_trie/5, + ptree_decomposition/3, + ptree_decomposition_struct/3, + nested_ptree_to_BDD_script/3, %theo + nested_ptree_to_BDD_struct_script/3, + ptree_db_trie_opt_performed/3, + bdd_vars_script/1]). :- use_module('problog/tabling'). :- use_module('problog/sampling'). :- use_module('problog/intervals'). @@ -393,7 +422,7 @@ :- initialization(( problog_define_flag(first_threshold, problog_flag_validate_indomain_0_1_open, 'starting threshold iterative deepening', 0.1, inference), - problog_define_flag(last_threshold, problog_flag_validate_indomain_0_1_open, 'stopping threshold iterative deepening', 1e-30, inference, flags:last_threshold_handler), + problog_define_flag(last_threshold, problog_flag_validate_indomain_0_1_open, 'stopping threshold iterative deepening', 1.0E-30, inference, flags:last_threshold_handler), problog_define_flag(id_stepsize, problog_flag_validate_indomain_0_1_close, 'threshold shrinking factor iterative deepening', 0.5, inference, flags:id_stepsize_handler) )). diff --git a/packages/ProbLog/problog/os.yap b/packages/ProbLog/problog/os.yap index 42bcea592..670a9a28b 100644 --- a/packages/ProbLog/problog/os.yap +++ b/packages/ProbLog/problog/os.yap @@ -2,8 +2,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% $Date: 2010-10-06 12:56:13 +0200 (Wed, 06 Oct 2010) $ -% $Revision: 4877 $ +% $Date: 2010-11-29 10:58:04 +0100 (Mon, 29 Nov 2010) $ +% $Revision: 5029 $ % % This file is part of ProbLog % http://dtai.cs.kuleuven.be/problog @@ -208,18 +208,18 @@ % Collected OS depended instructions %%%%%%%% :- module(os, [set_problog_path/1, - problog_path/1, - convert_filename_to_working_path/2, - convert_filename_to_problog_path/2, - concat_path_with_filename/3, - concat_path_with_filename2/3, - split_path_file/3, - check_existance/1, - calc_md5/2]). + problog_path/1, + convert_filename_to_working_path/2, + convert_filename_to_problog_path/2, + concat_path_with_filename/3, + concat_path_with_filename2/3, + split_path_file/3, + check_existance/1, + calc_md5/2]). % load library modules -:- use_module(library(system), [exec/3, file_exists/1]). +:- use_module(library(system), [exec/3, file_exists/1,wait/2]). :- use_module(library(lists), [memberchk/2]). % load our own modules @@ -228,10 +228,23 @@ :- dynamic(problog_path/1). :- dynamic(problog_working_path/1). + +%======================================================================== +%= +%= +%= +%======================================================================== + set_problog_path(Path):- retractall(problog_path(_)), assertz(problog_path(Path)). +%======================================================================== +%= +%= +%= +%======================================================================== + convert_filename_to_working_path(File_Name, Path):- flag_get(dir, Dir), concat_path_with_filename(Dir, File_Name, Path). @@ -240,22 +253,30 @@ convert_filename_to_problog_path(File_Name, Path):- problog_path(Dir), concat_path_with_filename(Dir, File_Name, Path). + +%======================================================================== +%= +%= +%= +%======================================================================== + concat_path_with_filename(Path, File_Name, Result):- - nonvar(File_Name), - nonvar(Path), + nonvar(File_Name), + nonvar(Path), + + % make sure, that there is no path delimiter at the end + prolog_file_name(Path,Path_Absolute), - % make sure, that there is no path delimiter at the end - prolog_file_name(Path,Path_Absolute), - - path_seperator(Path_Seperator), - atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result). + path_seperator(Path_Seperator), + atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result). concat_path_with_filename2(Path, File_Name, Result):- - nonvar(File_Name), - nonvar(Path), - path_seperator(Path_Seperator), - (atomic_concat(Path_Absolute, Path_Seperator, Path) ; Path_Absolute = Path), - atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result). + nonvar(File_Name), + nonvar(Path), + path_seperator(Path_Seperator), + (atomic_concat(Path_Absolute, Path_Seperator, Path) ; Path_Absolute = Path), + atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result). + %======================================================================== %= Calculate the MD5 checksum of +Filename by calling md5sum @@ -275,10 +296,10 @@ calc_md5(Filename,MD5):- calc_md5_intern(Filename,Command,MD5) :- ( file_exists(Filename) -> true ; throw(md5_file(Filename)) ), - atomic_concat([Command,' "',Filename,'"'],Call), + atomic_concat([Command,' "',Filename,'"'],Call), % execute the md5 command - exec(Call,[null,pipe(S),null],_PID), + exec(Call,[null,pipe(S),null],PID), bb_put(calc_md5_temp,End-End), % use difference list bb_put(calc_md5_temp2,0), @@ -308,28 +329,49 @@ calc_md5_intern(Filename,Command,MD5) :- !, close(S), + wait(PID,_Status), bb_delete(calc_md5_temp, FinalList-[]), bb_delete(calc_md5_temp2,_), atom_codes(MD5,FinalList). - + + +%======================================================================== +%= +%= +%= +%======================================================================== path_seperator('\\'):- yap_flag(windows, true), !. path_seperator('/'). + +%======================================================================== +%= +%= +%= +%======================================================================== + split_path_file(PathFile, Path, File):- path_seperator(PathSeperator), - atomic_concat(Path, File, PathFile), name(PathSeperator, [PathSeperatorName]), + + atomic_concat(Path, File, PathFile), name(File, FileName), \+ memberchk(PathSeperatorName, FileName), !. -% (Path = '' ; atomic_concat(_, PathSeperator, Path)). + +%======================================================================== +%= +%= +%= +%======================================================================== + check_existance(FileName):- - convert_filename_to_problog_path(FileName, Path), - catch(file_exists(Path), _, fail). + convert_filename_to_problog_path(FileName, Path), + catch(file_exists(Path), _, fail). check_existance(FileName):- - problog_path(PD), - write(user_error, 'WARNING: Can not find file: '), write(user_error, FileName), - write(user_error, ', please place file in problog path: '), write(user_error, PD), nl(user_error). + problog_path(PD), + write(user_error, 'WARNING: Can not find file: '), write(user_error, FileName), + write(user_error, ', please place file in problog path: '), write(user_error, PD), nl(user_error). diff --git a/packages/ProbLog/problog/tptree.yap b/packages/ProbLog/problog/ptree.yap similarity index 98% rename from packages/ProbLog/problog/tptree.yap rename to packages/ProbLog/problog/ptree.yap index 9ff552589..2450f27b0 100644 --- a/packages/ProbLog/problog/tptree.yap +++ b/packages/ProbLog/problog/ptree.yap @@ -2,8 +2,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% $Date: 2010-11-03 19:08:13 +0100 (Wed, 03 Nov 2010) $ -% $Revision: 4984 $ +% $Date: 2010-12-02 14:35:05 +0100 (Thu, 02 Dec 2010) $ +% $Revision: 5041 $ % % This file is part of ProbLog % http://dtai.cs.kuleuven.be/problog @@ -483,12 +483,11 @@ nested_ptree_to_BDD_struct_script(Trie, BDDFileName, Variables):- true; VarCNT = 0 ), - create_bdd_file_with_header(BDDFileName,VarCNT,InterCNT,TmpFile1), - delete_file_silent(TmpFile1), + prefix_bdd_file_with_header(BDDFileName,VarCNT,InterCNT,TmpFile1), cleanup_BDD_generation );( close(BDDS), - delete_file_silent(TmpFile1), + delete_file_silently(TmpFile1), cleanup_BDD_generation, fail ) @@ -610,8 +609,7 @@ ptree_decomposition_struct(Trie, BDDFileName, Variables) :- write('L1'), nl ), told, - create_bdd_file_with_header(BDDFileName,VarCnt,LCnt,TmpFile1), - delete_file_silent(TmpFile1). + prefix_bdd_file_with_header(BDDFileName,VarCnt,LCnt,TmpFile1). %%%%%%%%%%%%%%%%%%%%%%%% % write BDD info for given ptree to file @@ -1113,15 +1111,14 @@ nested_ptree_to_BDD_script(Trie, BDDFileName, VarFileName):- true; VarCNT = 0 ), - create_bdd_file_with_header(BDDFileName,VarCNT,InterCNT,TmpFile1), - delete_file_silent(TmpFile1), + prefix_bdd_file_with_header(BDDFileName,VarCNT,InterCNT,TmpFile1), open(VarFileName, 'write', VarStream), bddvars_to_script(Vars, VarStream), close(VarStream), cleanup_BDD_generation ; close(BDDS), - delete_file_silent(TmpFile1), + delete_file_silently(TmpFile1), cleanup_BDD_generation, fail ). @@ -1853,8 +1850,7 @@ ptree_decomposition(Trie, BDDFileName, VarFileName) :- write('L1'), nl ), told, - create_bdd_file_with_header(BDDFileName,VarCnt,LCnt,TmpFile1), - delete_file_silent(TmpFile1). + prefix_bdd_file_with_header(BDDFileName,VarCnt,LCnt,TmpFile1). get_next_inter_step(I):- nb_getval(next_inter_step, I), @@ -2040,24 +2036,3 @@ mark_deref(DB_Trie):- ), fail. mark_deref(_). - -% end of Theo - -create_bdd_file_with_header(BDD_File_Name,VarCount,IntermediateSteps,TmpFile) :- - open(BDD_File_Name,write,H), - % this is the header of the BDD script for problogbdd - format(H, '@BDD1~n~q~n0~n~q~n',[VarCount,IntermediateSteps]), - - % append the content of the file TmpFile - open(TmpFile,read,H2), - - ( - repeat, - get_byte(H2,C), - put_byte(H,C), - at_end_of_stream(H2), - ! - ), - close(H2), - - close(H). \ No newline at end of file diff --git a/packages/ProbLog/problog/utils.yap b/packages/ProbLog/problog/utils.yap index ca395066d..92291640c 100644 --- a/packages/ProbLog/problog/utils.yap +++ b/packages/ProbLog/problog/utils.yap @@ -2,8 +2,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% $Date: 2010-10-20 18:06:47 +0200 (Wed, 20 Oct 2010) $ -% $Revision: 4969 $ +% $Date: 2010-12-02 14:35:05 +0100 (Thu, 02 Dec 2010) $ +% $Revision: -1 $ % % This file is part of ProbLog % http://dtai.cs.kuleuven.be/problog @@ -204,22 +204,54 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- module(utils, [delete_file_silent/1, +:- module(utils, [delete_file_silently/1, + delete_files_silently/1, + delete_file_pattern_silently/2, variable_in_term_exactly_once/2, - slice_n/4]). + slice_n/4, + sorted_overlap_test/2, + prefix_bdd_file_with_header/4, + split_list/3]). + +:- use_module(library(system), [delete_file/1]). + +% load swi library, at some point vitor will make swi_expand_file_name/2 a built-in +:- load_foreign_files([libplstream], [], initIO). + +% load our own modules +:- use_module(os). -:- use_module(library(system), [delete_file/1, file_exists/1]). %======================================================================== %= %= %======================================================================== -delete_file_silent(File) :- - file_exists(File), +delete_file_silently(File) :- delete_file(File), !. -delete_file_silent(_). +delete_file_silently(_). + +%======================================================================== +%= +%= +%======================================================================== + +delete_files_silently([]). +delete_files_silently([H|T]) :- + delete_file_silently(H), + delete_files_silently(T). + +%======================================================================== +%= +%= +%======================================================================== + +delete_file_pattern_silently(Path,Pattern) :- + concat_path_with_filename(Path,Pattern,AbsolutePattern), + swi_expand_file_name(AbsolutePattern,Files), + + delete_files_silently(Files). %======================================================================== %= Split a list into the first n elements and the tail @@ -234,7 +266,7 @@ slice_n([H|T],N,[H|T2],T3) :- !, N2 is N-1, slice_n(T,N2,T2,T3). -slice_n(L,_,[],L). +slice_n(L,0,[],L). %======================================================================== %= succeeds if the variable V appears exactly once in the term T @@ -255,3 +287,66 @@ var_memberchk_none([H|T],V) :- var_memberchk_none(T,V). var_memberchk_none([],_). +%======================================================================== +%= sorted_overlap_test(+L1,+L2) +%= L1 and L2 are ground sorted lists +%= the predicate is true if there is an element X both appearing in L1 and L2 +%======================================================================== + +sorted_overlap_test([H|_],[H|_]) :- + !. +sorted_overlap_test([H1|T1],[H2|T2]) :- + H1 @> H2, + !, + sorted_overlap_test([H1|T1],T2). +sorted_overlap_test([_|T1],[H2|T2]) :- + sorted_overlap_test(T1,[H2|T2]). + +%======================================================================== +%= TmpFile is the file name that contains the "body" of a SimpleCUDD +%= script file. This predicate creates a new file BDD_File_Name that +%= starts with the right header and contains the body. The body file +%= is deleted afterwards. +%= +%= prefix_bdd_file_with_header(+BDD_File_Name,+VarCount,+IntermediateSteps,+TmpFile) +%======================================================================== + +prefix_bdd_file_with_header(BDD_File_Name,VarCount,IntermediateSteps,TmpFile) :- + open(BDD_File_Name,write,H), + % this is the header of the BDD script for problogbdd + format(H, '@BDD1~n~q~n0~n~q~n',[VarCount,IntermediateSteps]), + + % append the content of the file TmpFile + open(TmpFile,read,H2), + + ( + repeat, + get_byte(H2,C), + put_byte(H,C), + at_end_of_stream(H2), + ! + ), + close(H2), + + close(H), + delete_file_silently(TmpFile). + + +%======================================================================== +%= +%= +%= +%======================================================================== + + +split_list([],[],[]). +split_list([H|T],L1,L2) :- + length([H|T],Len), + Len1 is integer(Len/2+0.5), + split_list_intern(Len1,[H|T],L1,L2). + +split_list_intern(0,L,[],L). +split_list_intern(N,[H|T],[H|T1],L) :- + N>0, + N2 is N-1, + split_list_intern(N2,T,T1,L). \ No newline at end of file diff --git a/packages/ProbLog/problog/utils_learning.yap b/packages/ProbLog/problog/utils_learning.yap index 85402a6b2..64551487f 100644 --- a/packages/ProbLog/problog/utils_learning.yap +++ b/packages/ProbLog/problog/utils_learning.yap @@ -2,8 +2,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% $Date: 2010-10-20 18:06:47 +0200 (Wed, 20 Oct 2010) $ -% $Revision: 4969 $ +% $Date: 2010-12-02 14:35:05 +0100 (Thu, 02 Dec 2010) $ +% $Revision: 5041 $ % % This file is part of ProbLog % http://dtai.cs.kuleuven.be/problog @@ -205,12 +205,13 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% :- module(utils_learning, [empty_bdd_directory/0, - empty_output_directory/0]). + empty_output_directory/0, + create_known_values_file_name/2, + create_bdd_file_name/3, + create_bdd_input_file_name/2, + create_bdd_output_file_name/4]). -% load library modules -:- use_module(library(lists), [append/3, member/2]). -:- use_module(library(system), [delete_file/1, directory_files/2, file_exists/1]). % load our own modules :- use_module(os). @@ -225,14 +226,11 @@ 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]). + delete_file_pattern_silently(Path,'query*'). empty_bdd_directory :- throw(error(problog_flag_does_not_exist(bdd_directory))). + %======================================================================== %= %= @@ -245,41 +243,72 @@ empty_output_directory :- concat_path_with_filename(Path,'log.dat',F1), concat_path_with_filename(Path,'out.dat',F2), - delete_file_silent(F1), - delete_file_silent(F2), + delete_file_silently(F1), + delete_file_silently(F2), - atom_codes('values_', PF1), % 'values_*_q_*.dat' - atom_codes('factprobs_', PF2), % 'factprobs_*.pl' - atom_codes('input_', PF3), % 'input_*.pl' - atom_codes('trainpredictions_',PF4), % 'trainpredictions_*.pl' - atom_codes('testpredictions_',PF5), % 'testpredictions_*.pl' - atom_codes('predictions_',PF6), % 'predictions_*.pl' - directory_files(Path,List), - delete_files_with_matching_prefix(List,Path,[PF1,PF2,PF3,PF4,PF5,PF6]). + delete_file_pattern_silently(Path,'values_*'), + delete_file_pattern_silently(Path,'factprobs_*'), + delete_file_pattern_silently(Path,'input_*'), + delete_file_pattern_silently(Path,'trainpredictions_*'), + delete_file_pattern_silently(Path,'testpredictions_*'), + delete_file_pattern_silently(Path,'predictions_*'). empty_output_directory :- throw(error(problog_flag_does_not_exist(output_directory))). +%======================================================================== +%= +%= +%======================================================================== + +create_known_values_file_name(QueryID,Absolute_File_Name) :- + problog_flag(bdd_directory,Path), + !, + + atomic_concat(['query_',QueryID,'_known_values'],File_Name), + concat_path_with_filename(Path,File_Name,Absolute_File_Name). +create_known_values_file_name(_,_) :- + throw(error(problog_flag_does_not_exist(bdd_directory))). + %======================================================================== %= %= %======================================================================== -delete_files_with_matching_prefix([],_,_). -delete_files_with_matching_prefix([Name|T],Path,Prefixes) :- - atom_codes(Name,NameCode), +create_bdd_file_name(QueryID,ClusterID,Absolute_File_Name) :- + problog_flag(bdd_directory,Path), + !, - ( - (member(Prefix,Prefixes), append(Prefix,_Suffix,NameCode)) - -> - ( - concat_path_with_filename(Path,Name,F), - delete_file_silent(F) - ); - true - ), + 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))). - delete_files_with_matching_prefix(T,Path,Prefixes). +%======================================================================== +%= +%= +%======================================================================== +create_bdd_output_file_name(QueryID,ClusterID,Iteration,Absolute_File_Name) :- + problog_flag(output_directory,Path), + !, + + atomic_concat(['values_',Iteration,'_query_',QueryID,'_cluster_',ClusterID],File_Name), + concat_path_with_filename(Path,File_Name,Absolute_File_Name). +create_bdd_output_file_name(_,_,_,_) :- + throw(error(problog_flag_does_not_exist(output_directory))). +%======================================================================== +%= +%= +%======================================================================== + +create_bdd_input_file_name(Iteration,Absolute_File_Name) :- + problog_flag(output_directory,Path), + !, + + atomic_concat(['input_',Iteration,'.txt'],File_Name), + concat_path_with_filename(Path,File_Name,Absolute_File_Name). +create_bdd_input_file_name(_,_) :- + throw(error(problog_flag_does_not_exist(output_directory))). \ No newline at end of file diff --git a/packages/ProbLog/problog_learning.yap b/packages/ProbLog/problog_learning.yap index 82a350075..407e4f4c5 100644 --- a/packages/ProbLog/problog_learning.yap +++ b/packages/ProbLog/problog_learning.yap @@ -2,8 +2,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% $Date: 2010-10-20 18:06:47 +0200 (Wed, 20 Oct 2010) $ -% $Revision: 4969 $ +% $Date: 2010-12-02 14:35:05 +0100 (Thu, 02 Dec 2010) $ +% $Revision: 5041 $ % % This file is part of ProbLog % http://dtai.cs.kuleuven.be/problog @@ -770,7 +770,7 @@ update_values :- % start write current probabilities to file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% bdd_input_file(Probabilities_File), - delete_file_silent(Probabilities_File), + delete_file_silently(Probabilities_File), open(Probabilities_File,'write',Handle), From df162a0ae6196bc10c965f503f76f6d33a90b06d Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Thu, 2 Dec 2010 14:55:15 +0100 Subject: [PATCH 6/8] Updating ProbLog and adding ADs --- packages/ProbLog/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ProbLog/Makefile.in b/packages/ProbLog/Makefile.in index fb3db27c6..009e0ea99 100644 --- a/packages/ProbLog/Makefile.in +++ b/packages/ProbLog/Makefile.in @@ -46,7 +46,7 @@ PROBLOG_PROGRAMS= \ $(srcdir)/problog/sampling.yap \ $(srcdir)/problog/tabling.yap \ $(srcdir)/problog/timer.yap \ - $(srcdir)/problog/tptree.yap \ + $(srcdir)/problog/ptree.yap \ $(srcdir)/problog/variable_elimination.yap \ $(srcdir)/problog/print_learning.yap \ $(srcdir)/problog/utils_learning.yap \ From f46000cd1171ada2b12c1dcabc074983a09f5865 Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Thu, 2 Dec 2010 15:02:49 +0100 Subject: [PATCH 7/8] office fix --- packages/ProbLog/problog_examples/office.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ProbLog/problog_examples/office.pl b/packages/ProbLog/problog_examples/office.pl index 115a22d4a..cc3fdd08d 100644 --- a/packages/ProbLog/problog_examples/office.pl +++ b/packages/ProbLog/problog_examples/office.pl @@ -3,13 +3,13 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % ProbLog program describing an office window % example for using hybrid ProbLog -% $Id: office.pl 4876 2010-10-05 16:15:57Z theo $ +% $Id: office.pl 4970 2010-10-21 08:47:36Z bernd $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% :- use_module('../problog'). -width(gaussian(2,1)). -length(gaussian(9,3)). +(W,gaussian(2,1)) :: width(W). +(L,gaussian(9,3)) :: length(L). 0.8 :: office_has_window. 0.001 :: corridor_has_window. From 9ee83ddf6c4b3727d1438448209f48f705b0a437 Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Thu, 2 Dec 2010 15:04:42 +0100 Subject: [PATCH 8/8] problog examples fix --- packages/ProbLog/problog_examples/graph.pl | 2 +- packages/ProbLog/problog_examples/graph_tabled.pl | 2 +- packages/ProbLog/problog_examples/learn_graph.pl | 4 ++-- packages/ProbLog/problog_examples/office.pl | 2 +- packages/ProbLog/problog_examples/viralmarketing.pl | 2 +- packages/ProbLog/problog_examples/viralmarketing_tabled.pl | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/ProbLog/problog_examples/graph.pl b/packages/ProbLog/problog_examples/graph.pl index aedbc9f4c..8a1e84047 100644 --- a/packages/ProbLog/problog_examples/graph.pl +++ b/packages/ProbLog/problog_examples/graph.pl @@ -6,7 +6,7 @@ % $Id: graph.pl 4875 2010-10-05 15:28:35Z theo $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- use_module('../problog'). +:- use_module(library(problog)). %%%% % background knowledge diff --git a/packages/ProbLog/problog_examples/graph_tabled.pl b/packages/ProbLog/problog_examples/graph_tabled.pl index 10e2b3465..4656d2077 100644 --- a/packages/ProbLog/problog_examples/graph_tabled.pl +++ b/packages/ProbLog/problog_examples/graph_tabled.pl @@ -6,7 +6,7 @@ % $Id: graph_tabled.pl 4875 2010-10-05 15:28:35Z theo $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- use_module('../problog'). +:- use_module(library(problog)). % New trie method ensures Probibilistic Cycle Handling needed for tabling that handles loops :- set_problog_flag(use_db_trie, true). diff --git a/packages/ProbLog/problog_examples/learn_graph.pl b/packages/ProbLog/problog_examples/learn_graph.pl index ff75fe1b4..65ccb0b12 100644 --- a/packages/ProbLog/problog_examples/learn_graph.pl +++ b/packages/ProbLog/problog_examples/learn_graph.pl @@ -14,8 +14,8 @@ % will run 20 iterations of learning with default settings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- use_module('../problog'). -:- use_module('../problog_learning'). +:- use_module(library(problog)). +:- use_module(library(problog_learning)). %%%% % background knowledge diff --git a/packages/ProbLog/problog_examples/office.pl b/packages/ProbLog/problog_examples/office.pl index cc3fdd08d..37faee83a 100644 --- a/packages/ProbLog/problog_examples/office.pl +++ b/packages/ProbLog/problog_examples/office.pl @@ -6,7 +6,7 @@ % $Id: office.pl 4970 2010-10-21 08:47:36Z bernd $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- use_module('../problog'). +:- use_module(library(problog)). (W,gaussian(2,1)) :: width(W). (L,gaussian(9,3)) :: length(L). diff --git a/packages/ProbLog/problog_examples/viralmarketing.pl b/packages/ProbLog/problog_examples/viralmarketing.pl index 1cdf3d2a7..f19ae39ee 100644 --- a/packages/ProbLog/problog_examples/viralmarketing.pl +++ b/packages/ProbLog/problog_examples/viralmarketing.pl @@ -8,7 +8,7 @@ % The viral marketing example consists of a social network of friend relations. You have to decide which persons to market. Sending marketing has a cost of 2, but might cause people to buy your product, giving you a profit of 5. When someone buys the product, it becomes more likely that his friends also buy the product. -:- use_module('../dtproblog'). +:- use_module(library(dtproblog)). % Decisions ? :: marketed(P) :- person(P). diff --git a/packages/ProbLog/problog_examples/viralmarketing_tabled.pl b/packages/ProbLog/problog_examples/viralmarketing_tabled.pl index a4bc1e687..db50589a6 100644 --- a/packages/ProbLog/problog_examples/viralmarketing_tabled.pl +++ b/packages/ProbLog/problog_examples/viralmarketing_tabled.pl @@ -8,7 +8,7 @@ % The viral marketing example consists of a social network of friend relations. You have to decido which persons to market. Sending marketing has a cost of 2, but might cause people to buy your product, giving you a profit of 5. When someone buys the product, it becomes more likely that his friends also buy the product. -:- use_module('../dtproblog'). +:- use_module(library(dtproblog)). % Decisions ? :: marketed(P) :- person(P).