Merge branch 'master' of ssh://yap.git.sourceforge.net/gitroot/yap/yap-6.3

This commit is contained in:
Vitor Santos Costa 2013-01-14 23:10:56 +00:00
commit a0cd8070c9
19 changed files with 231 additions and 139 deletions

View File

@ -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,
@ -165,42 +168,45 @@ clpbn_flag(Flag, Option) :-
set_clpbn_flag(Flag,Option) :-
clpbn_flag(Flag, _, Option).
clpbn_flag(solver,Before,After) :-
clpbn_flag(solver,Before,After) :- !,
retract(solver(Before)),
assert(solver(After)).
clpbn_flag(em_solver,Before,After) :-
clpbn_flag(em_solver,Before,After) :- !,
retract(em_solver(Before)),
assert(em_solver(After)).
clpbn_flag(bnt_solver,Before,After) :-
clpbn_flag(bnt_solver,Before,After) :- !,
retract(bnt:bnt_solver(Before)),
assert(bnt:bnt_solver(After)).
clpbn_flag(bnt_path,Before,After) :-
clpbn_flag(bnt_path,Before,After) :- !,
retract(bnt:bnt_path(Before)),
assert(bnt:bnt_path(After)).
clpbn_flag(bnt_model,Before,After) :-
clpbn_flag(bnt_model,Before,After) :- !,
retract(bnt:bnt_model(Before)),
assert(bnt:bnt_model(After)).
clpbn_flag(suppress_attribute_display,Before,After) :-
clpbn_flag(suppress_attribute_display,Before,After) :- !,
retract(suppress_attribute_display(Before)),
assert(suppress_attribute_display(After)).
clpbn_flag(parameter_softening,Before,After) :-
clpbn_flag(parameter_softening,Before,After) :- !,
retract(parameter_softening(Before)),
assert(parameter_softening(After)).
clpbn_flag(use_factors,Before,After) :-
clpbn_flag(use_factors,Before,After) :- !,
retract(use_parfactors(Before)),
assert(use_parfactors(After)).
clpbn_flag(output,Before,After) :-
clpbn_flag(output,Before,After) :- !,
retract(output(Before)),
assert(output(After)).
clpbn_flag(HorusOption, _Before, After) :-
set_horus_flag(HorusOption, After).
set_solver(Solver) :-
set_clpbn_flag(solver,Solver).
@ -361,7 +367,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 +705,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) :- !,

View File

@ -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) :-

View File

@ -1,7 +1,7 @@
:- use_module(library(pfl)).
:- set_solver(hve).
%:- set_solver(ve).
%:- set_solver(hve).
%:- set_solver(jt).
%:- set_solver(bdd).
%:- set_solver(bp).

View File

@ -5,8 +5,8 @@
:- use_module(library(pfl)).
:- set_solver(hve).
%:- set_solver(ve).
%:- set_solver(hve).
%:- set_solver(jt).
%:- set_solver(bdd).
%:- set_solver(bp).

View File

@ -5,9 +5,10 @@
:- use_module(library(pfl)).
:- set_solver(hve).
%:- set_solver(ve).
%:- set_solver(hve).
%:- set_solver(jt).
%:- set_solver(bdd).
%:- set_solver(bp).
%:- set_solver(cbp).
%:- set_solver(gibbs).

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
:- use_module(library(clpbn/learning/em)).
:- set_em_solver(ve).
%:- set_em_solver(ve).
%:- set_em_solver(hve).
%:- set_em_solver(bdd).
%:- set_em_solver(bp).
@ -29,25 +29,19 @@ abi_table([0.3, 0.3, 0.4]).
pop_table([0.3, 0.3, 0.4, 0.3, 0.3, 0.4, 0.3, 0.3, 0.4]).
goal_list([
/*
abi(p0,h),
abi(p1,m),
abi(p2,m),
abi(p3,m),
*/
abi(p4,l),
pop(p5,h),
abi(p5,_),
abi(p6,_),
pop(p7,_)]).
pop(p7,_)
]).
timed_main :-
statistics(runtime, _),
main(Lik),
statistics(runtime, [T,_]),
format('Took ~d msec and Lik ~3f~n',[T,Lik]).
main(Lik) :-
main :-
goal_list(L),
em(L,0.01,10,_,Lik).
em(L, 0.01, 10, CPTs, Lik),
writeln(Lik:CPTs).

View File

@ -2,13 +2,13 @@
/* We do not consider aggregates yet. */
:- use_module(library(clpbn/learning/em)).
:- [pos:train].
:- ['../../examples/School/school_32'].
:- set_em_solver(ve).
:- use_module(library(clpbn/learning/em)).
%:- set_em_solver(ve).
%:- set_em_solver(hve).
%:- set_em_solver(bdd).
%:- set_em_solver(bp).
@ -16,14 +16,14 @@
timed_main :-
statistics(runtime, _),
findall(X,goal(X),L),
em(L,0.01,10,_,Lik),
findall(X, goal(X), L),
em(L, 0.01, 10, _, Lik),
statistics(runtime, [T,_]),
format('Took ~d msec and Lik ~3f~n',[T,Lik]).
main :-
findall(X,goal(X),L),
em(L,0.001,10,CPTs,Lik),
em(L, 0.01, 10, CPTs, Lik),
writeln(Lik:CPTs).
%

View File

@ -4,14 +4,12 @@
:- use_module(library(clpbn/learning/em)).
:- set_em_solver(ve).
%:- set_em_solver(ve).
%:- set_em_solver(hve).
%:- set_em_solver(bdd).
%:- set_em_solver(bp).
%:- set_em_solver(cbp).
:- dynamic id/1.
data(t,t,t,t).
data(_,t,_,t).
data(t,t,f,f).
@ -26,17 +24,11 @@ data(t,t,_,f).
data(t,f,f,t).
data(t,f,t,t).
timed_main :-
statistics(runtime, _),
main(Lik),
statistics(runtime, [T,_]),
format('Took ~d msec and Lik ~3f~n',[T,Lik]).
main(Lik) :-
findall(X,scan_data(X),L),
em(L,0.01,10,_,Lik).
scan_data([wet_grass(W),sprinkler(S),rain(R),cloudy(C)]) :-
data(W, S, R, C).
main :-
findall(X, scan_data(X), L),
em(L, 0.01, 10, CPTs, Lik),
writeln(Lik:CPTs).
scan_data([cloudy(C),sprinkler(S),rain(R),wet_grass(W)]) :-
data(C, S, R, W).

View File

@ -5,8 +5,8 @@
:- use_module(library(pfl)).
:- set_solver(hve).
%:- set_solver(ve).
%:- set_solver(hve).
%:- set_solver(jt).
%:- set_solver(bdd).
%:- set_solver(bp).

View File

@ -5,8 +5,8 @@
:- use_module(library(pfl)).
:- set_solver(hve).
%:- set_solver(ve).
%:- set_solver(hve).
%:- set_solver(jt).
%:- set_solver(bdd).
%:- set_solver(bp).

View File

@ -1,7 +1,7 @@
:- ensure_loaded(library(pfl)).
:- set_solver(hve).
%:- set_solver(ve).
%:- set_solver(hve).
%:- set_solver(jt).
%:- set_solver(bdd).
%:- set_solver(bp).

View File

@ -5,8 +5,8 @@
:- use_module(library(pfl)).
:- set_solver(hve).
%:- set_solver(ve).
%:- set_solver(hve).
%:- set_solver(jt).
%:- set_solver(bdd).
%:- set_solver(bp).

View File

@ -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] \
[<HORUS_KEY>=<VALUE>]... <FILE> [<VAR>|<VAR>=<EVIDENCE>]... " ;
[<OPTION>=<VALUE>]... <FILE> [<VAR>|<VAR>=<EVIDENCE>]... " ;
int

View File

@ -325,24 +325,24 @@ setVarsInformation (void)
int
setHorusFlag (void)
{
string key ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG1)));
string option ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG1)));
string value;
if (key == "verbosity") {
if (option == "verbosity") {
stringstream ss;
ss << (int) YAP_IntOfTerm (YAP_ARG2);
ss >> value;
} else if (key == "bp_accuracy") {
} else if (option == "bp_accuracy") {
stringstream ss;
ss << (float) YAP_FloatOfTerm (YAP_ARG2);
ss >> value;
} else if (key == "bp_max_iter") {
} else if (option == "bp_max_iter") {
stringstream ss;
ss << (int) YAP_IntOfTerm (YAP_ARG2);
ss >> value;
} else {
value = ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG2)));
}
return Util::setHorusFlag (key, value);
return Util::setHorusFlag (option, value);
}

View File

@ -188,10 +188,10 @@ getStateLines (const Vars& vars)
bool invalidValue (string key, string value)
bool invalidValue (string option, string value)
{
cerr << "Warning: invalid value `" << value << "' " ;
cerr << "for `" << key << "'" ;
cerr << "for `" << option << "'." ;
cerr << endl;
return false;
}
@ -199,32 +199,32 @@ bool invalidValue (string key, string value)
bool
setHorusFlag (string key, string value)
setHorusFlag (string option, string value)
{
bool returnVal = true;
if (key == "lifted_solver") {
if (option == "lifted_solver") {
if (value == "lve") Globals::liftedSolver = LiftedSolverType::LVE;
else if (value == "lbp") Globals::liftedSolver = LiftedSolverType::LBP;
else if (value == "lkc") Globals::liftedSolver = LiftedSolverType::LKC;
else returnVal = invalidValue (key, value);
else returnVal = invalidValue (option, value);
} else if (key == "ground_solver" || key == "solver") {
} else if (option == "ground_solver" || option == "solver") {
if (value == "hve") Globals::groundSolver = GroundSolverType::VE;
else if (value == "bp") Globals::groundSolver = GroundSolverType::BP;
else if (value == "cbp") Globals::groundSolver = GroundSolverType::CBP;
else returnVal = invalidValue (key, value);
else returnVal = invalidValue (option, value);
} else if (key == "verbosity") {
} else if (option == "verbosity") {
stringstream ss;
ss << value;
ss >> Globals::verbosity;
} else if (key == "use_logarithms") {
} else if (option == "use_logarithms") {
if (value == "true") Globals::logDomain = true;
else if (value == "false") Globals::logDomain = false;
else returnVal = invalidValue (key, value);
else returnVal = invalidValue (option, value);
} else if (key == "hve_elim_heuristic") {
} else if (option == "hve_elim_heuristic") {
if (value == "sequential")
ElimGraph::setElimHeuristic (ElimHeuristic::SEQUENTIAL);
else if (value == "min_neighbors")
@ -236,9 +236,9 @@ setHorusFlag (string key, string value)
else if (value == "weighted_min_fill")
ElimGraph::setElimHeuristic (ElimHeuristic::WEIGHTED_MIN_FILL);
else
returnVal = invalidValue (key, value);
returnVal = invalidValue (option, value);
} else if (key == "bp_msg_schedule") {
} else if (option == "bp_msg_schedule") {
if (value == "seq_fixed")
BeliefProp::setMsgSchedule (MsgSchedule::SEQ_FIXED);
else if (value == "seq_random")
@ -248,44 +248,44 @@ setHorusFlag (string key, string value)
else if (value == "max_residual")
BeliefProp::setMsgSchedule (MsgSchedule::MAX_RESIDUAL);
else
returnVal = invalidValue (key, value);
returnVal = invalidValue (option, value);
} else if (key == "bp_accuracy") {
} else if (option == "bp_accuracy") {
stringstream ss;
double acc;
ss << value;
ss >> acc;
BeliefProp::setAccuracy (acc);
} else if (key == "bp_max_iter") {
} else if (option == "bp_max_iter") {
stringstream ss;
unsigned mi;
ss << value;
ss >> mi;
BeliefProp::setMaxIterations (mi);
} else if (key == "export_libdai") {
} else if (option == "export_libdai") {
if (value == "true") FactorGraph::enableExportToLibDai();
else if (value == "false") FactorGraph::disableExportToLibDai();
else returnVal = invalidValue (key, value);
else returnVal = invalidValue (option, value);
} else if (key == "export_uai") {
} else if (option == "export_uai") {
if (value == "true") FactorGraph::enableExportToUai();
else if (value == "false") FactorGraph::disableExportToUai();
else returnVal = invalidValue (key, value);
else returnVal = invalidValue (option, value);
} else if (key == "export_graphviz") {
} else if (option == "export_graphviz") {
if (value == "true") FactorGraph::enableExportToGraphViz();
else if (value == "false") FactorGraph::disableExportToGraphViz();
else returnVal = invalidValue (key, value);
else returnVal = invalidValue (option, value);
} else if (key == "print_fg") {
} else if (option == "print_fg") {
if (value == "true") FactorGraph::enablePrintFactorGraph();
else if (value == "false") FactorGraph::disablePrintFactorGraph();
else returnVal = invalidValue (key, value);
else returnVal = invalidValue (option, value);
} else {
cerr << "Warning: invalid key `" << key << "'" << endl;
cerr << "Warning: invalid option `" << option << "'" << endl;
returnVal = false;
}
return returnVal;

View File

@ -81,7 +81,7 @@ string parametersToString (const Params&, unsigned = Constants::PRECISION);
vector<string> getStateLines (const Vars&);
bool setHorusFlag (string key, string value);
bool setHorusFlag (string option, string value);
void printHeader (string, std::ostream& os = std::cout);

View File

@ -14,10 +14,11 @@
{\VerbatimEnvironment \setstretch{0.8} \begin{pflcodeve}}
{\end{pflcodeve} }
\newcommand{\true} {\mathtt{t}}
\newcommand{\false} {\mathtt{f}}
\newcommand{\pathsep} { $\triangleright$ }
\newcommand{\tableline} {\noalign{\hrule height 0.8pt}}
\newcommand{\true} {\mathtt{t}}
\newcommand{\false} {\mathtt{f}}
\newcommand{\pathsep} { $\triangleright$ }
\newcommand{\tableline} {\noalign{\hrule height 0.8pt}}
\newcommand{\optionsection}[1] {\subsection*{\texttt{#1}}}
\tikzstyle{nodestyle} = [draw, thick, circle, minimum size=0.9cm]
\tikzstyle{bnedgestyle} = [-triangle 45,thick]
@ -37,7 +38,7 @@ CRACS \& INESC TEC, Faculty of Sciences, University of Porto
\thispagestyle{empty}
\vspace{5cm}
\begin{center}
\large Last revision: January 8, 2013
\large Last revision: January 11, 2013
\end{center}
\newpage
@ -102,14 +103,14 @@ $$Type~~F~~;~~Phi~~;~~C.$$
\begin{center}
\begin{tikzpicture}[>=latex',line join=bevel,transform shape,scale=0.8]
\node (cloudy) at (50bp, 122bp) [nodestyle,ellipse,inner sep=0pt,minimum width=2.7cm] {$Cloudy$};
\node (sprinker) at ( 0bp, 66bp) [nodestyle,ellipse,inner sep=0pt,minimum width=2.7cm] {$Sprinker$};
\node (rain) at (100bp, 66bp) [nodestyle,ellipse,inner sep=0pt,minimum width=2.7cm] {$Rain$};
\node (wetgrass) at (50bp, 10bp) [nodestyle,ellipse,inner sep=0pt,minimum width=2.7cm] {$WetGrass$};
\draw [bnedgestyle] (cloudy) -- (sprinker);
\draw [bnedgestyle] (cloudy) -- (rain);
\draw [bnedgestyle] (sprinker) -- (wetgrass);
\draw [bnedgestyle] (rain) -- (wetgrass);
\node (cloudy) at (50bp, 122bp) [nodestyle,ellipse,inner sep=0pt,minimum width=2.7cm] {$Cloudy$};
\node (sprinkler) at ( 0bp, 66bp) [nodestyle,ellipse,inner sep=0pt,minimum width=2.7cm] {$Sprinkler$};
\node (rain) at (100bp, 66bp) [nodestyle,ellipse,inner sep=0pt,minimum width=2.7cm] {$Rain$};
\node (wetgrass) at (50bp, 10bp) [nodestyle,ellipse,inner sep=0pt,minimum width=2.7cm] {$WetGrass$};
\draw [bnedgestyle] (cloudy) -- (sprinkler);
\draw [bnedgestyle] (cloudy) -- (rain);
\draw [bnedgestyle] (sprinkler) -- (wetgrass);
\draw [bnedgestyle] (rain) -- (wetgrass);
\node [above=0.4cm of cloudy,inner sep=0pt] {
\begin{tabular}[b]{lc}
@ -119,7 +120,7 @@ $$Type~~F~~;~~Phi~~;~~C.$$
\end{tabular}
};
\node [left=0.4cm of sprinker,inner sep=0pt] {
\node [left=0.4cm of sprinkler,inner sep=0pt] {
\begin{tabular}{lcc}
$S$ & $C$ & $P(S|C)$ \\ \tableline
$\true$ & $\true$ & 0.1 \\
@ -189,7 +190,7 @@ wet_grass_table(
0.01, 0.1, 0.1, 1.0 ]).
\end{pflcode}
We started by loading the PFL library, then we have defined one factor for each node, and finally we have specified the probabilities for each conditional probability table.
In the example, we started by loading the PFL library, then we have defined one factor for each node, and finally we have specified the probabilities for each conditional probability table.
Notice that this network is fully grounded, as all constraints are empty. Next we present the PFL representation for a well-known markov logic network - the social network model. For convenience, the two main weighted formulas of this model are shown below.
@ -251,7 +252,7 @@ In this section we demonstrate how to use PFL to solve probabilistic queries. We
Assuming that the current directory is the one where the examples are located, first we load the model with the following command.
\texttt{\$ yap -l sprinker.pfl}
\texttt{\$ yap -l sprinkler.pfl}
Let's suppose that we want to estimate the marginal probability for the $WetGrass$ random variable. To do so, we call the following goal.
@ -292,34 +293,61 @@ 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 option name that identifies the parameter that we want to tweak. The second argument is some possible value for this option. Next we explain the available options in detail.
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.
\optionsection{verbosity}
This option controls the level of debugging information that will be shown.
\texttt{?- set\_horus\_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.
The \texttt{use\_logarithms} key controls whether the calculations performed during inference should be done in a logarithm domain or not. Its values can be \texttt{true} (default) or \texttt{false}. This key only affects \texttt{hve}, \texttt{bp}, \texttt{cbp}, \texttt{lve}, \texttt{lkc} and \texttt{lbp} solvers. The remaining solvers always perform their calculations in a logarithm domain.
There are keys specific to some algorithms. The \texttt{hve\_elim\_heuristic} key allows to choose which elimination heuristic will be used by the \texttt{hve} solver (but not \texttt{ve}). The following are supported:
\begin{itemize}
\item \texttt{sequential}
\item \texttt{min\_neighbors}
\item \texttt{min\_weight}
\item \texttt{min\_fill}
\item \texttt{weighted\_min\_fill} (default)
\item Values: a positive integer (default is 0 - no debugging). The higher the number, the more information that will be shown.
\item Affects: \texttt{hve}, \texttt{bp}, \texttt{cbp}, \texttt{lve}, \texttt{lkc} and \texttt{lbp}.
\end{itemize}
For instance, we can view some basic debugging information by calling the following goal.
\texttt{?- set\_pfl\_flag(verbosity, 1).}
\optionsection{use\_logarithms}
This option controls whether the calculations performed during inference should be done in a logarithm domain or not.
\begin{itemize}
\item Values: \texttt{true} (default) or \texttt{false}.
\item Affects: \texttt{hve}, \texttt{bp}, \texttt{cbp}, \texttt{lve}, \texttt{lkc} and \texttt{lbp}.
\end{itemize}
\optionsection{hve\_elim\_heuristic}
This option allows to choose which elimination heuristic will be used by the \texttt{hve}.
\begin{itemize}
\item Values: \texttt{sequential}, \texttt{min\_neighbors}, \texttt{min\_weight}, \texttt{min\_fill} and\\ \texttt{weighted\_min\_fill} (default).
\item Affects: \texttt{hve}.
\end{itemize}
An explanation for each of these heuristics can be found in Daphne Koller's book \textit{Probabilistic Graphical Models}.
The \texttt{bp\_msg\_schedule}, \texttt{bp\_accuracy} and \texttt{bp\_max\_iter} keys are specific for message passing based algorithms, namely \texttt{bp}, \texttt{cbp} and \texttt{lbp}.
The \texttt{bp\_max\_iter} key establishes a maximum number of iterations. One iteration consists in sending all possible messages. It defaults to \texttt{1000}.
\optionsection{bp\_max\_iter}
This option establishes a maximum number of iterations. One iteration consists in sending all possible messages.
The \texttt{bp\_accuracy} key allows to control when the message passing should cease. Be the residual of one message the difference (according some metric) between the one sent in the current iteration and the one sent in the previous. If the highest residual is lesser than the given value, the message passing is stopped and the probabilities are calculated using the last messages that were sent. This key defaults to \texttt{0.0001}.
\begin{itemize}
\item Values: a positive integer (default is \texttt{1000}).
\item Affects: \texttt{bp}, \texttt{cbp} and \texttt{lbp}.
\end{itemize}
The key \texttt{bp\_msg\_schedule} allows to control the message sending order. Its possible values are:
\optionsection{bp\_accuracy}
This option allows to control when the message passing should cease. Be the residual of one message the difference (according some metric) between the one sent in the current iteration and the one sent in the previous. If the highest residual is lesser than the given value, the message passing is stopped and the probabilities are calculated using the last messages that were sent.
\begin{itemize}
\item Values: a float-point number (default is \texttt{0.0001}).
\item Affects: \texttt{bp}, \texttt{cbp} and \texttt{lbp}.
\end{itemize}
\optionsection{bp\_msg\_schedule}
This option allows to control the message sending order.
\begin{itemize}
\item Values:
\begin{itemize}
\item \texttt{seq\_fixed} (default), at each iteration, all messages are sent with the same order.
@ -329,8 +357,39 @@ The key \texttt{bp\_msg\_schedule} allows to control the message sending order.
\item \texttt{max\_residual}, the next message to be sent is the one with maximum residual (as explained in the paper \textit{Residual Belief Propagation: Informed Scheduling for Asynchronous Message Passing}).
\end{itemize}
\item Affects: \texttt{bp}, \texttt{cbp} and \texttt{lbp}.
\end{itemize}
The \texttt{export\_libdai} and \texttt{export\_uai} keys can be used to export the current model respectively to \href{http://cs.ru.nl/~jorism/libDAI/doc/fileformats.html}{libDAI}, and \href{http://graphmod.ics.uci.edu/uai08/FileFormat}{UAI08} formats. With the \texttt{export\_graphviz} key it is possible to export the factor graph structure into a format that can be parsed by \href{http://www.graphviz.org/}{Graphviz}. The \texttt{print\_fg} key allows to print a textual representation of the factor graph. All these four keys accept \texttt{true} and \texttt{false} as their values and only have effect in \texttt{hve}, \texttt{bp}, and \texttt{cbp} solvers.
\optionsection{export\_libdai}
This option allows exporting the current model to the \href{http://cs.ru.nl/~jorism/libDAI/doc/fileformats.html}{libDAI} file format.
\begin{itemize}
\item Values: \texttt{true} or \texttt{false} (default).
\item Affects: \texttt{hve}, \texttt{bp}, and \texttt{cbp}.
\end{itemize}
\optionsection{export\_uai}
This option allows exporting the current model to the \href{http://graphmod.ics.uci.edu/uai08/FileFormat}{UAI08} file format.
\begin{itemize}
\item Values: \texttt{true} or \texttt{false} (default).
\item Affects: \texttt{hve}, \texttt{bp}, and \texttt{cbp}.
\end{itemize}
\optionsection{export\_graphviz}
This option allows exporting the factor graph's structure into a format that can be parsed by \href{http://www.graphviz.org/}{Graphviz}.
\begin{itemize}
\item Values: \texttt{true} or \texttt{false} (default).
\item Affects: \texttt{hve}, \texttt{bp}, and \texttt{cbp}.
\end{itemize}
\optionsection{print\_fg}
This option allows to print a textual representation of the factor graph.
\begin{itemize}
\item Values: \texttt{true} or \texttt{false} (default).
\item Affects: \texttt{hve}, \texttt{bp}, and \texttt{cbp}.
\end{itemize}
@ -341,10 +400,50 @@ The \texttt{export\_libdai} and \texttt{export\_uai} keys can be used to export
\section{Parameter Learning}
PFL is capable to learn the parameters for bayesian networks, through an implementation of the expectation-maximization algorithm.
Inside the \texttt{learning} directory from the examples directory, one can find some examples of how learning works in PFL.
Next we show an example of parameter learning for the sprinkler network.
\begin{pflcode}
:- [sprinkler.pfl].
:- use_module(library(clpbn/learning/em)).
data(t, t, t, t).
data(_, t, _, t).
data(t, t, f, f).
data(t, t, f, t).
data(t, _, _, t).
data(t, f, t, t).
data(t, t, f, t).
data(t, _, f, f).
data(t, t, f, f).
data(f, f, t, t).
main :-
findall(X, scan_data(X), L),
em(L, 0.01, 10, CPTs, LogLik),
writeln(LogLik:CPTs).
scan_data([cloudy(C), sprinkler(S), rain(R), wet_grass(W)]) :-
data(C, S, R, W).
\end{pflcode}
Parameter learning is done by calling the \texttt{em/5} predicate. Its arguments are the following.
\texttt{em(+Data, +MaxError, +MaxIters, -CPTs, -LogLik)}
Where,
\begin{itemize}
\item \texttt{Data} is a list of samples for the distribution that we want to estimate. Each sample is a list of either observed random variables or unobserved random variables (denoted when its state value is not instantiated).
\item \texttt{MaxError} is the maximum error allowed before stopping the EM loop.
\item \texttt{MaxIters} is the maximum number of iterations for the EM loop.
\item \texttt{CPTs} is a list with the estimated conditional probability tables.
\item \texttt{LogLik} is the log-likelihood.
\end{itemize}
It is possible to choose the solver that will be used for the inference part during parameter learning with the \texttt{set\_em\_solver/1} predicate (defaults to \texttt{hve}). At the moment, only the following solvers support parameter learning: \texttt{ve}, \texttt{hve}, \texttt{bdd}, \texttt{bp} and \texttt{cbp}.
Inside the \texttt{learning} directory from the examples directory, one can find more examples of parameter learning.
@ -352,17 +451,17 @@ 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.
This command's name is \texttt{hcli} and its usage is as follows.
\begin{verbatim}
$ ./hcli [solver=hve|bp|cbp] [<HORUS_KEY>=<VALUE>]...
$ ./hcli [solver=hve|bp|cbp] [<OPTION>=<VALUE>]...
<FILE> [<VAR>|<VAR>=<EVIDENCE>]...
\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}
@ -376,13 +475,13 @@ Evidence can be given as a pair containing a variable identifier and its observe
\texttt{\$ ./hcli burglary-alarm.uai 0=1}
By default, all probability tasks are resolved using the \texttt{hve} solver. It is possible to choose another solver using the \texttt{solver} key as follows.
By default, all probability tasks are resolved using the \texttt{hve} solver. It is possible to choose another solver using the \texttt{solver} option as follows.
\texttt{\$ ./hcli solver=bp burglary-alarm.uai}
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{<Key>=<Value>} 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{<Option>=<Value>} before the model's file name.

View File

@ -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)).