From bd84949f099e471992e391e80981954d550130a8 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 10 Jan 2013 17:23:09 +0000 Subject: [PATCH 01/14] Trivial --- packages/CLPBN/clpbn/horus_lifted.yap | 4 ++-- packages/CLPBN/pfl.yap | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/CLPBN/clpbn/horus_lifted.yap b/packages/CLPBN/clpbn/horus_lifted.yap index 533d6fa92..846e15848 100644 --- a/packages/CLPBN/clpbn/horus_lifted.yap +++ b/packages/CLPBN/clpbn/horus_lifted.yap @@ -44,7 +44,7 @@ call_horus_lifted_solver(QueryVars, AllVars, Output) :- init_horus_lifted_solver(_, AllVars, _, state(Network, DistIds)) :- get_parfactors(Parfactors), get_observed_keys(AllVars, ObservedKeys), - % writeln(network:(parfactors=Parfactors, evidence=ObservedKeys)), nl, + %writeln(network:(parfactors=Parfactors, evidence=ObservedKeys)), nl, cpp_create_lifted_network(Parfactors, ObservedKeys, Network), maplist(get_dist_id, Parfactors, DistIds0), sort(DistIds0, DistIds). @@ -74,7 +74,7 @@ is_factor(pf(Id, Ks, Rs, Phi, Tuples)) :- maplist(get_range, Ks, Rs), Table \= avg, gen_table(Table, Phi), - all_tuples(Constraints, Vs, Tuples). + all_tuples(Constraints, Vs, Tuples). get_range(K, Range) :- diff --git a/packages/CLPBN/pfl.yap b/packages/CLPBN/pfl.yap index ba39dcf81..29403108b 100644 --- a/packages/CLPBN/pfl.yap +++ b/packages/CLPBN/pfl.yap @@ -150,16 +150,16 @@ process_arg(Sk, Id, _I) --> }, [Sk]. -new_skolem(Sk,D) :- +new_skolem(Sk, D) :- copy_term(Sk, Sk1), skolem(Sk1, D1), - functor(Sk1,N,A), - functor(Sk ,N,A), + functor(Sk1, N, A), + functor(Sk , N, A), !, ( D1 = D -> true ; throw(pfl(permission_error(redefining_domain(Sk),D:D1)))). -new_skolem(Sk,D) :- - functor(Sk ,N,A), - functor(NSk ,N,A), +new_skolem(Sk, D) :- + functor(Sk, N, A), + functor(NSk, N, A), interface_predicate(NSk), assert(skolem(NSk, D)). From e5e224d89b69e189b9c938bc929c7191866d0dfa Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 10 Jan 2013 21:51:45 +0000 Subject: [PATCH 02/14] Fix typo --- packages/CLPBN/clpbn.yap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/CLPBN/clpbn.yap b/packages/CLPBN/clpbn.yap index 995f38e07..6ade48da4 100644 --- a/packages/CLPBN/clpbn.yap +++ b/packages/CLPBN/clpbn.yap @@ -361,7 +361,7 @@ call_ground_solver(ve, GVars, GoalKeys, Keys, Factors, Evidence) :- !, call_ve_ground_solver(GVars, GoalKeys, Keys, Factors, Evidence, _Answ). call_ground_solver(hve, GVars, GoalKeys, Keys, Factors, Evidence) :- !, - clpbn_horus:set_horus_flag(ground_solver, ve), + clpbn_horus:set_horus_flag(ground_solver, hve), call_horus_ground_solver(GVars, GoalKeys, Keys, Factors, Evidence, _Answ). call_ground_solver(bdd, GVars, GoalKeys, Keys, Factors, Evidence) :- !, @@ -699,7 +699,7 @@ pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, ve) :- !, init_ve_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State). pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, hve) :- !, - clpbn_horus:set_horus_flag(ground_solver, ve), + clpbn_horus:set_horus_flag(ground_solver, hve), init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State). pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, bdd) :- !, From fdeca2852ad59b2f8d1ad706dc847fba5e9ab1c9 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 10 Jan 2013 22:10:22 +0000 Subject: [PATCH 03/14] Use only one interface for options. set_pfl_flag/2 now can be called for setting options for solvers written in Prolog and for solvers in Horus. --- packages/CLPBN/clpbn.yap | 6 ++++++ packages/CLPBN/pfl.tex | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/CLPBN/clpbn.yap b/packages/CLPBN/clpbn.yap index 6ade48da4..c5b74709e 100644 --- a/packages/CLPBN/clpbn.yap +++ b/packages/CLPBN/clpbn.yap @@ -69,6 +69,9 @@ run_pcg_solver/3 ]). +:- use_module('clpbn/horus', + [set_horus_flag/2]). + :- use_module('clpbn/horus_ground', [call_horus_ground_solver/6, check_if_horus_ground_solver_done/1, @@ -201,6 +204,9 @@ clpbn_flag(output,Before,After) :- retract(output(Before)), assert(output(After)). +clpbn_flag(HorusKey,_Before,After) :- + set_horus_flag(HorusKey,After). + set_solver(Solver) :- set_clpbn_flag(solver,Solver). diff --git a/packages/CLPBN/pfl.tex b/packages/CLPBN/pfl.tex index b0e102990..0e3463d9d 100644 --- a/packages/CLPBN/pfl.tex +++ b/packages/CLPBN/pfl.tex @@ -292,11 +292,11 @@ For instance, if we want to use belief propagation to solve some probabilistic q \texttt{?- set\_solver(bp).} -It is possible to tweak some parameters of PFL through \texttt{set\_horus\_flag/2} predicate. The first argument is a key that identifies the parameter that we want to tweak. The second argument is some possible value for this key. +It is possible to tweak some parameters of PFL through \texttt{set\_pfl\_flag/2} predicate. The first argument is a key that identifies the parameter that we want to tweak. The second argument is some possible value for this key. The \texttt{verbosity} key controls the level of debugging information that will be printed. Its possible values are positive integers. The higher the number, the more information that will be shown. For instance, we can view some basic debugging information by calling the following goal. -\texttt{?- set\_horus\_flag(verbosity, 1).} +\texttt{?- set\_pfl\_flag(verbosity, 1).} This key defaults to 0 (no debugging) and only \texttt{hve}, \texttt{bp}, \texttt{cbp}, \texttt{lve}, \texttt{lkc} and \texttt{lbp} solvers have support for this key. @@ -382,7 +382,7 @@ By default, all probability tasks are resolved using the \texttt{hve} solver. It Notice that only the \texttt{hve}, \texttt{bp} and \texttt{cbp} solvers can be used with \texttt{hcli}. -The options that are available with the \texttt{set\_horus\_flag/2} predicate can be used in \texttt{hcli} too. The syntax is a pair \texttt{=} before the model's file name. +The options that are available with the \texttt{set\_pfl\_flag/2} predicate can be used in \texttt{hcli} too. The syntax is a pair \texttt{=} before the model's file name. From d3e2abd6771e89caf3cca108e42614ee4680264e Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 10 Jan 2013 22:39:46 +0000 Subject: [PATCH 04/14] Don't use the name horus in documentation. It is just an internal code name. --- packages/CLPBN/horus/HorusCli.cpp | 2 +- packages/CLPBN/pfl.tex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/CLPBN/horus/HorusCli.cpp b/packages/CLPBN/horus/HorusCli.cpp index 82e995921..dda8767e9 100644 --- a/packages/CLPBN/horus/HorusCli.cpp +++ b/packages/CLPBN/horus/HorusCli.cpp @@ -17,7 +17,7 @@ VarIds readQueryAndEvidence (FactorGraph&, int, const char* [], int); void runSolver (const FactorGraph&, const VarIds&); const string USAGE = "usage: ./hcli [solver=hve|bp|cbp] \ -[=]... [|=]... " ; +[=]... [|=]... " ; int diff --git a/packages/CLPBN/pfl.tex b/packages/CLPBN/pfl.tex index 0e3463d9d..1a84ccf2c 100644 --- a/packages/CLPBN/pfl.tex +++ b/packages/CLPBN/pfl.tex @@ -352,13 +352,13 @@ It is possible to choose the solver that will be used for the inference part dur %------------------------------------------------------------------------------ %------------------------------------------------------------------------------ %------------------------------------------------------------------------------ -\section{Horus Command Line} +\section{External Interface} This package also includes an external command for perform inference over probabilistic graphical models described in formats other than PFL. Currently two are support, the \href{http://cs.ru.nl/~jorism/libDAI/doc/fileformats.html}{libDAI file format}, and the \href{http://graphmod.ics.uci.edu/uai08/FileFormat}{UAI08 file format}. This utility is called \texttt{hcli} and its usage is as follows. \begin{verbatim} - $ ./hcli [solver=hve|bp|cbp] [=]... + $ ./hcli [solver=hve|bp|cbp] [=]... [|=]... \end{verbatim} From f7fcfec8ce8943e38fe12f56c65c83b5a1c2d5ab Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 10 Jan 2013 22:42:23 +0000 Subject: [PATCH 05/14] PFL manual: some rewording --- packages/CLPBN/pfl.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/CLPBN/pfl.tex b/packages/CLPBN/pfl.tex index 1a84ccf2c..5c2de1414 100644 --- a/packages/CLPBN/pfl.tex +++ b/packages/CLPBN/pfl.tex @@ -355,14 +355,14 @@ It is possible to choose the solver that will be used for the inference part dur \section{External Interface} This package also includes an external command for perform inference over probabilistic graphical models described in formats other than PFL. Currently two are support, the \href{http://cs.ru.nl/~jorism/libDAI/doc/fileformats.html}{libDAI file format}, and the \href{http://graphmod.ics.uci.edu/uai08/FileFormat}{UAI08 file format}. -This utility is called \texttt{hcli} and its usage is as follows. +This command's name is \texttt{hcli} and its usage is as follows. \begin{verbatim} $ ./hcli [solver=hve|bp|cbp] [=]... [|=]... \end{verbatim} -Let's assume that the current directory is the one where the examples are located. We can perform inference in any supported model by passing the file name where the model is defined as argument. Next, we show how to load a model using the \texttt{hcli} utility. +Let's assume that the current directory is the one where the examples are located. We can perform inference in any supported model by passing the file name where the model is defined as argument. Next, we show how to load a model with \texttt{hcli}. \texttt{\$ ./hcli burglary-alarm.uai} From f3bd8ad414426f2b5663469273d37fed3f16abaf Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 10 Jan 2013 22:59:12 +0000 Subject: [PATCH 06/14] Use the word option instead of key. Key reminds me of hashes --- packages/CLPBN/clpbn.yap | 4 +-- packages/CLPBN/horus/HorusCli.cpp | 2 +- packages/CLPBN/horus/HorusYap.cpp | 10 +++---- packages/CLPBN/horus/Util.cpp | 50 +++++++++++++++---------------- packages/CLPBN/horus/Util.h | 2 +- packages/CLPBN/pfl.tex | 26 ++++++++-------- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/packages/CLPBN/clpbn.yap b/packages/CLPBN/clpbn.yap index c5b74709e..86df4178c 100644 --- a/packages/CLPBN/clpbn.yap +++ b/packages/CLPBN/clpbn.yap @@ -204,8 +204,8 @@ clpbn_flag(output,Before,After) :- retract(output(Before)), assert(output(After)). -clpbn_flag(HorusKey,_Before,After) :- - set_horus_flag(HorusKey,After). +clpbn_flag(HorusOption,_Before,After) :- + set_horus_flag(HorusOption,After). set_solver(Solver) :- set_clpbn_flag(solver,Solver). diff --git a/packages/CLPBN/horus/HorusCli.cpp b/packages/CLPBN/horus/HorusCli.cpp index dda8767e9..7fadd3d1a 100644 --- a/packages/CLPBN/horus/HorusCli.cpp +++ b/packages/CLPBN/horus/HorusCli.cpp @@ -17,7 +17,7 @@ VarIds readQueryAndEvidence (FactorGraph&, int, const char* [], int); void runSolver (const FactorGraph&, const VarIds&); const string USAGE = "usage: ./hcli [solver=hve|bp|cbp] \ -[=]... [|=]... " ; +[