Bernd fixes
This commit is contained in:
parent
c0b1d3d40d
commit
a8dbd74518
@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-08-24 15:23:06 +0200 (Tue, 24 Aug 2010) $
|
||||
% $Revision: 4672 $
|
||||
% $Date: 2010-09-24 15:54:45 +0200 (Fri, 24 Sep 2010) $
|
||||
% $Revision: 4822 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
@ -212,8 +212,6 @@
|
||||
convert_filename_to_working_path/2,
|
||||
convert_filename_to_problog_path/2,
|
||||
concat_path_with_filename/3,
|
||||
empty_bdd_directory/1,
|
||||
empty_output_directory/1,
|
||||
calc_md5/2]).
|
||||
|
||||
|
||||
@ -253,32 +251,6 @@ concat_path_with_filename(Path, File_Name, Result):-
|
||||
|
||||
atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result).
|
||||
|
||||
%========================================================================
|
||||
%= store the current succes probabilities for training and test examples
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
empty_bdd_directory(Path) :-
|
||||
ground(Path),
|
||||
|
||||
concat_path_with_filename(Path,'query_*',Files),
|
||||
atomic_concat(['rm -f "', Files, '"'],Command),
|
||||
(shell(Command) -> true; true).
|
||||
%========================================================================
|
||||
%= store the current succes probabilities for training and test examples
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
empty_output_directory(Path) :-
|
||||
ground(Path),
|
||||
|
||||
concat_path_with_filename(Path,'log.dat',F1),
|
||||
concat_path_with_filename(Path,'factprobs_*.pl',F2),
|
||||
concat_path_with_filename(Path,'predictions_*.pl',F3),
|
||||
|
||||
atomic_concat(['rm -f "', F1, '" "', F2, '" "', F3, '"'],Command),
|
||||
(shell(Command) -> true; true).
|
||||
|
||||
%========================================================================
|
||||
%= Calculate the MD5 checksum of +Filename by calling md5sum
|
||||
%= in case m5sum is not installed, try md5, otherwise fail
|
||||
|
235
packages/ProbLog/problog/print_learning.yap
Normal file
235
packages/ProbLog/problog/print_learning.yap
Normal file
@ -0,0 +1,235 @@
|
||||
%%% -*- Mode: Prolog; -*-
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-09-23 11:13:10 +0200 (Thu, 23 Sep 2010) $
|
||||
% $Revision: 4804 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
%
|
||||
% ProbLog was developed at Katholieke Universiteit Leuven
|
||||
%
|
||||
% Copyright 2008, 2009, 2010
|
||||
% Katholieke Universiteit Leuven
|
||||
%
|
||||
% 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.
|
||||
%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%%%%%%%
|
||||
% Collected OS depended instructions
|
||||
%%%%%%%%
|
||||
:- module(print_learning, [format_learning/3]).
|
||||
|
||||
|
||||
% load library modules
|
||||
:- ensure_loaded(library(system)).
|
||||
|
||||
% load our own modules
|
||||
:- ensure_loaded(flags).
|
||||
|
||||
:- initialization(problog_define_flag(verbosity_learning, problog_flag_validate_0to5,'How much output shall be given (0=nothing,5=all)',5, learning_general)).
|
||||
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
%=
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
format_learning(Level,String,Arguments) :-
|
||||
problog_flag(verbosity_learning,V_Level),
|
||||
V_Level >= Level,
|
||||
!,
|
||||
format(String,Arguments),
|
||||
flush_output(user).
|
||||
format_learning(_,_,_) :-
|
||||
true.
|
299
packages/ProbLog/problog/utils_learning.pl
Normal file
299
packages/ProbLog/problog/utils_learning.pl
Normal file
@ -0,0 +1,299 @@
|
||||
%%% -*- Mode: Prolog; -*-
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-09-24 15:54:45 +0200 (Fri, 24 Sep 2010) $
|
||||
% $Revision: 4822 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
%
|
||||
% ProbLog was developed at Katholieke Universiteit Leuven
|
||||
%
|
||||
% Copyright 2008, 2009, 2010
|
||||
% Katholieke Universiteit Leuven
|
||||
%
|
||||
% 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.
|
||||
%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%%%%%%%
|
||||
% Collected OS depended instructions
|
||||
%%%%%%%%
|
||||
:- module(utils_learning, [empty_bdd_directory/1,
|
||||
empty_output_directory/1,
|
||||
delete_file_silent/1
|
||||
]).
|
||||
|
||||
|
||||
% load library modules
|
||||
:- ensure_loaded(library(lists)).
|
||||
:- ensure_loaded(library(system)).
|
||||
|
||||
% load our own modules
|
||||
:- ensure_loaded(os).
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
empty_bdd_directory(Path) :-
|
||||
ground(Path),
|
||||
|
||||
atom_codes('query_', PF1), % 'query_*'
|
||||
|
||||
directory_files(Path,List),
|
||||
delete_files_with_matching_prefix(List,Path,[PF1]).
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
empty_output_directory(Path) :-
|
||||
ground(Path),
|
||||
|
||||
concat_path_with_filename(Path,'log.dat',F1),
|
||||
concat_path_with_filename(Path,'out.dat',F2),
|
||||
|
||||
(
|
||||
file_exists(F1)
|
||||
->
|
||||
delete_file_silent(F1);
|
||||
true
|
||||
),
|
||||
|
||||
(
|
||||
file_exists(F2)
|
||||
->
|
||||
delete_file_silent(F2);
|
||||
true
|
||||
),
|
||||
|
||||
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_silent(File) :-
|
||||
delete_file(File),
|
||||
!.
|
||||
delete_file_silent(_).
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
delete_files_with_matching_prefix([],_,_).
|
||||
delete_files_with_matching_prefix([Name|T],Path,Prefixes) :-
|
||||
atom_codes(Name,NameCode),
|
||||
|
||||
(
|
||||
(member(Prefix,Prefixes), append(Prefix,_Suffix,NameCode))
|
||||
->
|
||||
(
|
||||
concat_path_with_filename(Path,Name,F),
|
||||
delete_file_silent(F)
|
||||
);
|
||||
true
|
||||
),
|
||||
|
||||
delete_files_with_matching_prefix(T,Path,Prefixes).
|
@ -2,8 +2,8 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% $Date: 2010-08-25 15:45:22 +0200 (Wed, 25 Aug 2010) $
|
||||
% $Revision: 4692 $
|
||||
% $Date: 2010-09-24 15:54:45 +0200 (Fri, 24 Sep 2010) $
|
||||
% $Revision: 4822 $
|
||||
%
|
||||
% This file is part of ProbLog
|
||||
% http://dtai.cs.kuleuven.be/problog
|
||||
@ -231,7 +231,8 @@
|
||||
:- ensure_loaded('problog/logger').
|
||||
:- ensure_loaded('problog/flags').
|
||||
:- ensure_loaded('problog/os').
|
||||
|
||||
:- ensure_loaded('problog/print_learning').
|
||||
:- ensure_loaded('problog/utils_learning').
|
||||
|
||||
% used to indicate the state of the system
|
||||
:- dynamic values_correct/0.
|
||||
@ -246,23 +247,15 @@
|
||||
:- dynamic query_is_similar/2.
|
||||
:- dynamic query_md5/3.
|
||||
|
||||
:- assert_static(user:(example(A,B,C,=) :- current_predicate(example/3), example(A,B,C))).
|
||||
:- assert_static(user:(test_example(A,B,C,=) :- current_predicate(test_example/3), test_example(A,B,C))).
|
||||
:- multifile(user:example/4).
|
||||
user:example(A,B,C,=) :-
|
||||
current_predicate(user:example/3),
|
||||
user:example(A,B,C).
|
||||
|
||||
%========================================================================
|
||||
%=
|
||||
%=
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
my_format(Level,String,Arguments) :-
|
||||
problog_flag(learning_verbosity_level,V_Level),
|
||||
(
|
||||
V_Level >= Level
|
||||
->
|
||||
(format(String,Arguments),flush_output(user));
|
||||
true
|
||||
).
|
||||
:- multifile(user:test_example/4).
|
||||
user:test_example(A,B,C,=) :-
|
||||
current_predicate(user:test_example/3),
|
||||
user:test_example(A,B,C).
|
||||
|
||||
|
||||
%========================================================================
|
||||
@ -462,7 +455,7 @@ do_learning_intern(Iterations,Epsilon) :-
|
||||
assert(current_iteration(NextIteration)),
|
||||
EndIteration is CurrentIteration+Iterations-1,
|
||||
|
||||
my_format(1,'~nIteration ~d of ~d~n',[CurrentIteration,EndIteration]),
|
||||
format_learning(1,'~nIteration ~d of ~d~n',[CurrentIteration,EndIteration]),
|
||||
logger_set_variable(iteration,CurrentIteration),
|
||||
|
||||
logger_start_timer(duration),
|
||||
@ -543,7 +536,7 @@ init_learning :-
|
||||
|
||||
logger_write_header,
|
||||
|
||||
my_format(1,'Initializing everything~n',[]),
|
||||
format_learning(1,'Initializing everything~n',[]),
|
||||
empty_output_directory,
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
@ -594,7 +587,7 @@ init_learning :-
|
||||
true
|
||||
),
|
||||
bb_delete(test_examples,TestExampleCount),
|
||||
my_format(3,'~q test examples~n',[TestExampleCount]),
|
||||
format_learning(3,'~q test examples~n',[TestExampleCount]),
|
||||
!,
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% stop count test examples
|
||||
@ -616,7 +609,7 @@ init_learning :-
|
||||
),
|
||||
bb_delete(training_examples,TrainingExampleCount),
|
||||
assert(example_count(TrainingExampleCount)),
|
||||
my_format(3,'~q training examples~n',[TrainingExampleCount]),
|
||||
format_learning(3,'~q training examples~n',[TrainingExampleCount]),
|
||||
!,
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% stop count training examples
|
||||
@ -643,7 +636,6 @@ init_learning :-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% build BDD script for every example
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
once(initialize_fact_probabilities),
|
||||
once(init_queries),
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
@ -652,7 +644,7 @@ init_learning :-
|
||||
assert(current_iteration(0)),
|
||||
assert(learning_initialized),
|
||||
|
||||
my_format(1,'~n',[]).
|
||||
format_learning(1,'~n',[]).
|
||||
|
||||
|
||||
%========================================================================
|
||||
@ -681,11 +673,11 @@ empty_output_directory :-
|
||||
|
||||
|
||||
init_queries :-
|
||||
my_format(2,'Build BDDs for examples~n',[]),
|
||||
format_learning(2,'Build BDDs for examples~n',[]),
|
||||
( % go over all test examples
|
||||
current_predicate(user:test_example/4),
|
||||
user:test_example(ID,Query,Prob,_),
|
||||
my_format(3,' test example ~q: ~q~n',[ID,Query]),
|
||||
format_learning(3,' test example ~q: ~q~n',[ID,Query]),
|
||||
flush_output(user),
|
||||
init_one_query(ID,Query,test),
|
||||
|
||||
@ -695,7 +687,7 @@ init_queries :-
|
||||
( % go over all training examples
|
||||
current_predicate(user:example/4),
|
||||
user:example(ID,Query,Prob,_),
|
||||
my_format(3,' training example ~q: ~q~n',[ID,Query]),
|
||||
format_learning(3,' training example ~q: ~q~n',[ID,Query]),
|
||||
flush_output(user),
|
||||
init_one_query(ID,Query,training),
|
||||
|
||||
@ -721,10 +713,10 @@ init_one_query(QueryID,Query,Type) :-
|
||||
(
|
||||
file_exists(Filename)
|
||||
->
|
||||
my_format(3,' Reuse existing BDD ~q~n~n',[Filename]);
|
||||
format_learning(3,' Reuse existing BDD ~q~n~n',[Filename]);
|
||||
(
|
||||
problog_flag(init_method,(Query,_Prob,Filename,Probabilities_File,Call)),
|
||||
once(call(Call)),
|
||||
once(Call),
|
||||
delete_file(Probabilities_File)
|
||||
)
|
||||
),
|
||||
@ -742,38 +734,17 @@ init_one_query(QueryID,Query,Type) :-
|
||||
->
|
||||
(
|
||||
assert(query_is_similar(QueryID,OtherQueryID)),
|
||||
my_format(3, '~q is similar to ~q~2n', [QueryID,OtherQueryID])
|
||||
format_learning(3, '~q is similar to ~q~2n', [QueryID,OtherQueryID])
|
||||
);
|
||||
assert(query_md5(QueryID,Query_MD5,Type))
|
||||
)
|
||||
);
|
||||
|
||||
true
|
||||
).
|
||||
),!,
|
||||
garbage_collect.
|
||||
|
||||
|
||||
%========================================================================
|
||||
%= set all unknown fact probabilities to random values
|
||||
%=
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
initialize_fact_probabilities :-
|
||||
( % go over all tunable facts
|
||||
tunable_fact(FactID,_),
|
||||
problog_flag(probability_initializer,(FactID,Probability,Query)),
|
||||
once(call(Query)),
|
||||
set_fact_probability(FactID,Probability),
|
||||
|
||||
fail; % go to next tunable fact
|
||||
true
|
||||
).
|
||||
|
||||
random_probability(_FactID,Probability) :-
|
||||
% use probs around 0.5 to not confuse k-best search
|
||||
random(Random),
|
||||
Probability is 0.5+(Random-0.5)/100.
|
||||
|
||||
|
||||
|
||||
%========================================================================
|
||||
@ -791,8 +762,8 @@ update_values :-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% delete old values
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
once(retractall(query_probability_intern(_,_))),
|
||||
once(retractall(query_gradient_intern(_,_,_,_))),
|
||||
retractall(query_probability_intern(_,_)),
|
||||
retractall(query_gradient_intern(_,_,_,_)),
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% start write current probabilities to file
|
||||
@ -854,7 +825,7 @@ update_query_cleanup(QueryID) :-
|
||||
% either this query is similar to another or vice versa,
|
||||
% therefore we don't delete anything
|
||||
true;
|
||||
once(retractall(query_gradient_intern(QueryID,_,_,_)))
|
||||
retractall(query_gradient_intern(QueryID,_,_,_))
|
||||
).
|
||||
|
||||
|
||||
@ -867,13 +838,13 @@ update_query(QueryID,Symbol,What_To_Update) :-
|
||||
query_is_similar(QueryID,_)
|
||||
->
|
||||
% we don't have to evaluate the BDD
|
||||
my_format(4,'#',[]);
|
||||
format_learning(4,'#',[]);
|
||||
(
|
||||
problog_flag(sigmoid_slope,Slope),
|
||||
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,
|
||||
@ -921,7 +892,7 @@ update_query(QueryID,Symbol,What_To_Update) :-
|
||||
),
|
||||
|
||||
delete_file(Values_Filename),
|
||||
my_format(4,'~w',[Symbol])
|
||||
format_learning(4,'~w',[Symbol])
|
||||
)
|
||||
),
|
||||
flush_output(user).
|
||||
@ -1056,7 +1027,7 @@ mse_trainingset_only_for_linesearch(MSE) :-
|
||||
length(AllSquaredErrors,Length),
|
||||
sum_list(AllSquaredErrors,SumAllSquaredErrors),
|
||||
MSE is SumAllSquaredErrors/Length,
|
||||
my_format(3,' (~8f)~n',[MSE])
|
||||
format_learning(3,' (~8f)~n',[MSE])
|
||||
); true
|
||||
),
|
||||
retractall(values_correct).
|
||||
@ -1066,7 +1037,7 @@ mse_testset :-
|
||||
(current_predicate(user:test_example/4),user:test_example(_,_,_,_))
|
||||
->
|
||||
(
|
||||
my_format(2,'MSE_Test ',[]),
|
||||
format_learning(2,'MSE_Test ',[]),
|
||||
update_values,
|
||||
findall(SquaredError,
|
||||
(user:test_example(QueryID,_Query,QueryProb,Type),
|
||||
@ -1091,7 +1062,7 @@ mse_testset :-
|
||||
logger_set_variable(mse_testset,MSE),
|
||||
logger_set_variable(mse_min_testset,MinError),
|
||||
logger_set_variable(mse_max_testset,MaxError),
|
||||
my_format(2,' (~8f)~n',[MSE])
|
||||
format_learning(2,' (~8f)~n',[MSE])
|
||||
); true
|
||||
).
|
||||
|
||||
@ -1227,7 +1198,7 @@ add_gradient(Learning_Rate) :-
|
||||
|
||||
|
||||
gradient_descent :-
|
||||
my_format(2,'Gradient ',[]),
|
||||
format_learning(2,'Gradient ',[]),
|
||||
|
||||
save_old_probabilities,
|
||||
update_values,
|
||||
@ -1411,7 +1382,7 @@ gradient_descent :-
|
||||
logger_set_variable(mse_min_trainingset,MSE_Train_Min),
|
||||
logger_set_variable(mse_max_trainingset,MSE_Train_Max),
|
||||
|
||||
my_format(2,'~n',[]),
|
||||
format_learning(2,'~n',[]),
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% start add gradient to current probabilities
|
||||
@ -1422,7 +1393,7 @@ gradient_descent :-
|
||||
problog_flag(learning_rate,LearningRate);
|
||||
lineSearch(LearningRate,_)
|
||||
),
|
||||
my_format(3,'learning rate:~8f~n',[LearningRate]),
|
||||
format_learning(3,'learning rate:~8f~n',[LearningRate]),
|
||||
add_gradient(LearningRate),
|
||||
logger_set_variable(learning_rate,LearningRate),
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
@ -1438,7 +1409,7 @@ gradient_descent :-
|
||||
|
||||
line_search_evaluate_point(Learning_Rate,MSE) :-
|
||||
add_gradient(Learning_Rate),
|
||||
my_format(2,'Line search (h=~8f) ',[Learning_Rate]),
|
||||
format_learning(2,'Line search (h=~8f) ',[Learning_Rate]),
|
||||
mse_trainingset_only_for_linesearch(MSE).
|
||||
|
||||
|
||||
@ -1449,7 +1420,7 @@ lineSearch(Final_X,Final_Value) :-
|
||||
problog_flag(line_search_tau,Tau),
|
||||
problog_flag(line_search_interval,(A,B)),
|
||||
|
||||
my_format(3,'Line search in interval (~4f,~4f)~n',[A,B]),
|
||||
format_learning(3,'Line search in interval (~4f,~4f)~n',[A,B]),
|
||||
|
||||
% init values
|
||||
Acc is Tol * (B-A),
|
||||
@ -1677,11 +1648,9 @@ init_flags :-
|
||||
problog_define_flag(output_directory, problog_flag_validate_directory, 'directory for logfiles etc', Output_Folder,learning_general,flags:learning_output_dir_handler),
|
||||
problog_define_flag(log_frequency, problog_flag_validate_posint, 'log results every nth iteration', 1, learning_general),
|
||||
problog_define_flag(rebuild_bdds, problog_flag_validate_nonegint, 'rebuild BDDs every nth iteration', 0, learning_general),
|
||||
problog_define_flag(learning_verbosity_level, problog_flag_validate_0to5,'How much output shall be given (0=nothing,5=all)',5, learning_general),
|
||||
problog_define_flag(reuse_initialized_bdds,problog_flag_validate_boolean, 'Reuse BDDs from previous runs',false, learning_general),
|
||||
problog_define_flag(check_duplicate_bdds,problog_flag_validate_boolean,'Store intermediate results in hash table',true,learning_general),
|
||||
problog_define_flag(init_method,problog_flag_validate_dummy,'ProbLog predicate to search proofs',(Query,Probability,BDDFile,ProbFile,problog_kbest_save(Query,100,Probability,_Status,BDDFile,ProbFile)),learning_general,flags:learning_init_handler),
|
||||
problog_define_flag(probability_initializer,problog_flag_validate_dummy,'Predicate to initialize probabilities',(FactID,P,random_probability(FactID,P)),learning_general,flags:learning_prob_init_handler),
|
||||
problog_define_flag(alpha,problog_flag_validate_number,'weight of negative examples (auto=n_p/n_n)',auto,learning_general,flags:auto_handler),
|
||||
problog_define_flag(sigmoid_slope,problog_flag_validate_posnumber,'slope of sigmoid function',1.0,learning_general),
|
||||
|
||||
|
Reference in New Issue
Block a user