The Prolog Factor Language (PFL) is a language that extends Prolog for providing a syntax to describe first-order probabilistic graphical models. These models can be either directed (bayesian networks) or undirected (markov networks). This language replaces the old one known as CLP(BN).
<p>The package also includes implementations for a set of well-known inference algorithms for solving probabilistic queries on these models. Both ground and lifted inference methods are support.</p>
<p><ahref="#top"style="font-size:15px">Back to the top</a></p>
PFL is included with the <ahref="http://www.dcc.fc.up.pt/~vsc/Yap/">YAP</a> Prolog system. However, there isn't yet a stable release of YAP that includes PFL and you will need to install a development version. To do so, you must have installed the <ahref="http://git-scm.com/">Git</a> version control system. The commands to perform a default installation of YAP in your home directory in a Unix-based environment are shown next.
<p>In case you want to install YAP somewhere else or with different settings, please consult the YAP documentation. From now on, we will assume that the directory <spanclass=texttt>$HOME ▷ bin</span> (where the binary is) is in your <spanclass=texttt>$PATH</span> environment variable.</p>
<p>Once in a while, we will refer to the PFL examples directory. In a default installation, this directory will be located at <spanclass=texttt> $HOME ▷ share ▷ doc ▷ Yap ▷ packages ▷ examples ▷ CLPBN</span>.</p>
<p><ahref="#top"style="font-size:15px">Back to the top</a></p>
<em>Type</em> refers the type of network over which the parfactor is defined. It can be <spanclass=texttt>bayes</span> for directed networks, or <spanclass=texttt>markov</span> for undirected ones.
<p>
</li>
<li>
<em>F</em> is a comma-separated sequence of Prolog terms that will define sets of random variables under the constraint <em>C</em>. If <em>Type</em> is <spanclass=texttt>bayes</span>, the first term defines the node while the remaining terms define its parents.
<p>
</li>
<li>
<em>Phi</em> is either a Prolog list of potential values or a Prolog goal that unifies with one. Notice that if <em>Type</em> is <spanclass=texttt>bayes</span>, this will correspond to the conditional probability table. Domain combinations are implicitly assumed in ascending order, with the first term being the 'most significant' (e.g.
<em>C</em> is a (possibly empty) list of Prolog goals that will instantiate the logical variables that appear in <em>F</em>, that is, the successful substitutions for the goals in <em>C</em> will be the valid values for the logical variables. This allows the constraint to be defined as any relation (set of tuples) over the logical variables.
<p>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.</p>
<p>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.</p>
<divclass="pflcode">
<pre>
1.5 : Smokes(x) => Cancer(x)
1.1 : Smokes(x) ^ Friends(x,y) => Smokes(y)
</pre>
</div>
<p>Next, we show the PFL representation for this model.</p>
<p>Notice that we have defined the world to be consisted of only two persons, <spanclass=texttt>anna</span> and <spanclass=texttt>bob</span>. We can easily add as many persons as we want by inserting in the program a fact like <spanclass=texttt>person @ 10.</span> . This would automatically create ten persons named <spanclass=texttt>p1</span>, <spanclass=texttt>p2</span>, ..., <spanclass=texttt>p10</span>.</p>
<p>Unlike other fist-order probabilistic languages, in PFL the logical variables that appear in the terms are not directly typed, and they will be only constrained by the goals that appears in the constraint of the parfactor. This allows the logical variables to be constrained to any relation (set of tuples), and not only pairwise (in)equalities. For instance, the next example defines a network with three ground factors, each defined respectively over the random variables <spanclass=texttt>p(a,b)</span>, <spanclass=texttt>p(b,d)</span> and <spanclass=texttt>p(d,e)</span>.</p>
<divclass="pflcode">
<pre>
constraint(a,b).
constraint(b,d).
constraint(d,e).
markov p(A,B); some_table; [constraint(A,B)].
</pre>
</div>
<p>We can easily add static evidence to PFL programs by inserting a fact with the same functor and arguments as the random variable, plus one extra argument with the observed state or value. For instance, suppose that we know that <spanclass=texttt>anna</span> and <spanclass=texttt>bob</span> are friends. We can add this knowledge to the program with the following fact: <spanclass=texttt>friends(anna,bob,t).</span> .</p>
<p>One last note for the domain of the random variables. By default, all terms instantiate boolean (<spanclass=texttt>t</span>/<spanclass=texttt>f</span>) random variables. It is possible to choose a different domain for a term by appending a list of its possible values or states. Next we present a self-explanatory example of how this can be done.</p>
In this section we demonstrate how to use PFL to solve probabilistic queries. We will use the sprinkler network as example.
<p>Assuming that the current directory is the one where the examples are located, first we load the model with the following command.</p>
<pclass=console>$ yap -l sprinkler.pfl</p>
<p>Let's suppose that we want to estimate the marginal probability for the <em>WetGrass</em> random variable. To do so, we call the following goal.</p>
<pclass=console>?- wet_grass(X).</p>
<p>The output of this goal will show the marginal probability for each <em>WetGrass</em> possible state or value, that is, <spanclass=texttt>t</span> and <spanclass=texttt>f</span>. Notice that in PFL a random variable is identified by a term with the same functor and arguments plus one extra argument.</p>
<p>Now let's suppose that we want to estimate the probability for the same random variable, but this time we have evidence that it had rained in the day before. We can estimate this probability without resorting to static evidence with:</p>
<pclass=console>?- wet_grass(X), rain(t).</p>
<p>PFL also supports calculating joint probability distributions. For instance, we can obtain the joint probability for <em>Sprinkler</em> and <em>Rain</em> with:</p>
<pclass=console>?- sprinkler(X), rain(Y).</p>
<p><ahref="#top"style="font-size:15px">Back to the top</a></p>
PFL supports both ground and lifted inference methods. The inference algorithm can be chosen by calling <spanclass=texttt>set_solver/1</span>. The following are supported:
<ul>
<li><spanclass=texttt>ve</span>, variable elimination (written in Prolog)</li>
<li><spanclass=texttt>hve</span>, variable elimination (written in C++)</li>
<p>For instance, if we want to use belief propagation to solve some probabilistic query, we need to call first:</p>
<pclass=console>?- set_solver(bp).</p>
<p>It is possible to tweak some parameters of PFL through <spanclass=texttt>set_pfl_flag/2</span> 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.</p>
<h3><spanclass=texttt>verbosity</span></h3>
This option controls the level of debugging information that will be shown.
<ul>
<li>Values: a positive integer (default is 0 - no debugging). The higher the number, the more information that will be shown.</li>
<li>Affects: <spanclass=texttt>hve</span>, <spanclass=texttt>bp</span>, <spanclass=texttt>cbp</span>, <spanclass=texttt>lve</span>, <spanclass=texttt>lkc</span> and <spanclass=texttt>lbp</span>.</li>
</ul>
<p>
For instance, we can view some basic debugging information by calling the following goal.
<p>An explanation for each of these heuristics can be found in Daphne Koller's book <em>Probabilistic Graphical Models</em>.</p>
<h3><spanclass=texttt>bp_max_iter</span></h3>
This option establishes a maximum number of iterations. One iteration consists in sending all possible messages.
<ul>
<li>Values: a positive integer (default is <spanclass=texttt>1000</span>).</li>
<li>Affects: <spanclass=texttt>bp</span>, <spanclass=texttt>cbp</span> and <spanclass=texttt>lbp</span>.</li>
</ul>
<h3><spanclass=texttt>bp_accuracy</span></h3>
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.
<ul>
<li>Values: a float-point number (default is <spanclass=texttt>0.0001</span>).</li>
<li>Affects: <spanclass=texttt>bp</span>, <spanclass=texttt>cbp</span> and <spanclass=texttt>lbp</span>.</li>
</ul>
<h3><spanclass=texttt>bp_msg_schedule</span></h3>
This option allows to control the message sending order.
<ul>
<li>Values:
<ul>
<li><spanclass=texttt>seq_fixed</span> (default), at each iteration, all messages are sent with the same order.<p></li>
<li><spanclass=texttt>seq_random</span>, at each iteration, all messages are sent with a random order.<p></li>
<li><spanclass=texttt>parallel</span>, at each iteration, all messages are calculated using only the values of the previous iteration.<p></li>
<li><spanclass=texttt>max_residual</span>, the next message to be sent is the one with maximum residual (as explained in the paper <em>Residual Belief Propagation: Informed Scheduling for Asynchronous Message Passing</em>).</li>
</ul>
</li>
<li>Affects: <spanclass=texttt>bp</span>, <spanclass=texttt>cbp</span> and <spanclass=texttt>lbp</span>.
<li><spanclass=texttt>Data</span> 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 or value is not instantiated).</li>
<li><spanclass=texttt>MaxError</span> is the maximum error allowed before stopping the EM loop.</li>
<li><spanclass=texttt>MaxIters</span> is the maximum number of iterations for the EM loop.</li>
<li><spanclass=texttt>CPTs</span> is a list with the estimated conditional probability tables.</li>
<li><spanclass=texttt>LogLik</span> is the log-likelihood.</li>
</ul>
<p>It is possible to choose the solver that will be used for the inference part during parameter learning with the <spanclass=texttt>set_em_solver/1</span> predicate (defaults to <spanclass=texttt>hve</span>). At the moment, only the following solvers support parameter learning: <spanclass=texttt>ve</span>, <spanclass=texttt>hve</span>, <spanclass=texttt>bdd</span>, <spanclass=texttt>bp</span> and <spanclass=texttt>cbp</span>.</p>
<p>Inside the <spanclass=texttt>learning</span> directory from the examples directory, one can find more examples of parameter learning.</p>
<p><ahref="#top"style="font-size:15px">Back to the top</a></p>
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 http://cs.ru.nl/ jorism/libDAI/doc/fileformats.htmllibDAI file format, and the http://graphmod.ics.uci.edu/uai08/FileFormatUAI08 file format.
<p>This command's name is <spanclass=texttt>hcli</span> and its usage is as follows.</p>
<p>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 <spanclass=texttt>hcli</span>.</p>
<pclass=console>$ ./hcli burglary-alarm.uai</p>
<p>With the above command, the program will load the model and print the marginal probabilities for all defined random variables. We can view only the marginal probability for some variable with a identifier <em>X</em>, if we pass <em>X</em> as an extra argument following the file name. For instance, the following command will output only the marginal probability for the variable with identifier <em>0</em>.</p>
<pclass=console>$ ./hcli burglary-alarm.uai 0</p>
<p>If we give more than one variable identifier as argument, the program will output the joint probability for all the passed variables.</p>
<p>Evidence can be given as a pair containing a variable identifier and its observed state (index), separated by a '=`. For instance, we can introduce knowledge that some variable with identifier <em>0</em> has evidence on its second state as follows.</p>
<p>By default, all probability tasks are resolved using the <spanclass=texttt>hve</span> solver. It is possible to choose another solver using the <spanclass=texttt>solver</span> option as follows.</p>
<p>Notice that only the <spanclass=texttt>hve</span>, <spanclass=texttt>bp</span> and <spanclass=texttt>cbp</span> solvers can be used with <spanclass=texttt>hcli</span>.</p>
<p>The options that are available with the <spanclass=texttt>set_pfl_flag/2</span> predicate can be used in <spanclass=texttt>hcli</span> too. The syntax is a pair <spanclass=texttt><Option>=<Value></span> before the model's file name.</p>
<p><ahref="#top"style="font-size:15px">Back to the top</a></p>