1 Introduction
0.9::flies(X) :- bird(X).
is given by the set of its ground instantiations of the form 0.9::flies(x) :- bird(x).
, which has the just described meaning. In this paper, we aim at adding to PLPDS the possibility of expressing “Type 1” statements, exploiting for this purpose Probabilistic Answer Set Programming.2 Background
2.1 Answer Set Programming
;
and \(\leftarrow \) with :-
when describing actual code. We consider only safe rules, where all variables occur in a positive literal in the body. If \(m = 0\) and \(n > 0\), the rule is an integrity constraint. Facts can also be defined through a range with the notation f(a..b)
, where both a
and b
are integers. A rule is ground when it does not contain variables. A program, also called knowledge base, is a finite set of rules. Given an answer set program \(\mathcal {P}\), we define its Herbrand base (denoted with \(B_\mathcal {\mathcal {P}}\)) as the set of all ground atoms that can be constructed using the symbols in the program. An interpretation I for \(\mathcal {P}\) is a set such that \(I \subset B_\mathcal {P}\). An interpretation I satisfies a ground rule if at least one head atom is true in I when the body is true in I. If an interpretation satisfies all the groundings of all the rules of a program it is called a model. Given a ground program \(\mathcal {P}_g\) and an interpretation I we call reduct [10] of \(\mathcal {P}_g\) with respect to I the program obtained by removing from \(\mathcal {P}_g\) the rules in which a literal in the body is false in I. An interpretation I is an answer set (also called stable model) for \(\mathcal {P}\) if I is a minimal model (under set inclusion) of the reduct of \(\mathcal {P}_g\). We denote with \( AS (\mathcal {P})\) the set of all the answer sets of a program \(\mathcal {P}\). Sometimes, not all the elements of an answer set are needed, so we can project the computed solution into a set of atoms. That is, we would like to compute the projective solutions [12] given a set of ground atoms V, represented by the set \(AS_V(\mathcal {P}) = \{A \cap V \mid A \in AS(\mathcal {P})\}\). An atom a is a brave consequence of a program \(\mathcal {P}\) if \(\exists A \in AS (\mathcal {P})\) such that \(a \in A\). We denote the set containing all the brave consequences with \( BC (\mathcal {P})\). Similarly, a is a cautious consequence if \(\forall A \in AS (\mathcal {P}), \ a \in A\), and we denote the set containing all the cautious consequences with \( CC (\mathcal {P})\).X
can fly or not fly. In the constraint, the first aggregate counts the flying birds and assigns this value to FB
, while the second aggregate counts the birds and assigns the result to B
. Overall, the constraint imposes that at least 60% of the birds fly (we converted the values into integers since ASP cannot easily manage floating point numbers). This program has 5 answer sets, \(BC(\mathcal {P})\) = {b(1) b(2) b(3) b(4) f(1) nf(1) f(2) nf(2) f(3) nf(3) f(4) nf(4)}
, \(CC(\mathcal {P})\) = {b(1) b(2) b(3) b(4)}
, and \(AS_V(\mathcal {P})\) = {{b(1) b(2) b(3) b(4)
}} where b/1
stands for bird/1
, f/1
for fly/1
, nf/1
for not_fly/1
and V = {b(1)
, b(2)
, b(3)
, b(4)
}.
2.2 Probabilistic Logic Programming
0.9::fly(tweety).
we are stating that the probability that tweety
flies is 0.9, i.e., we believe in the truth of fly(tweety)
with probability 0.9. This is a“Type 2” statement.2.3 Credal Semantics
2.4 Probabilistic Conditionals
3 Probabilistic Answer Set Programming for Statistical Probabilities (PASTA)
C;not_C:-A
. We require this rule to be safe. Then, we introduce two integrity constraints that mimic Eq. 7 through aggregates: we count all the ground atoms that satisfy A (call this value ND) and A and C (call this value NN) and we impose that NN must be greater than or equal to \(100\cdot \varPi _l\) percent of ND and smaller than or equal to \(100\cdot \varPi _u\) percent of ND. The constraints are not generated if the bounds are vacuous. The conditional (fly(X) | bird(X))[0.6]
of Example 2 is transformed into the rule and the constraint shown in Example 1. Finally, the probability interval of a query from a PASTA program is the probability interval of the query computed from the transformed probabilistic answer set program.fly(1)
. There are \(2^4 = 16\) possible worlds. The query is false if bird(1)
is false, so we can consider only \(2^3 = 8\) worlds. There is 1 world with 4 birds, and it has 5 models. The query is true only in 4 of them, so we have a contribution of \(0.4^4\) to the upper probability. There are 3 worlds with 3 birds: these have 4 models each and the query is true in only three of them, so we have a contribution of \(3 \cdot (0.4^3\cdot (1-0.4))\) to the upper probability. There are 3 worlds with 2 birds: these have only one model and the query is true in it, so we have a contribution to both lower and upper probabilities of \(3 \cdot (0.4^2\cdot (1-0.4)^2)\). Finally, there is only 1 world with 1 bird, it has only 1 model and the query is true in it, so we have a contribution to both lower and upper probabilities of \(0.4\cdot (1-0.4)^3\). Overall, for the query fly(1)
we get 0.2592 for the lower and 0.4 for the upper probability, so the probability lies in the range [0.2592, 0.4]. Similarly, by applying Formulas 4 and 5, the probability of the same query given evidence \(e = \) fly(2)
is in the range [0.144, 0.44247] since \(\underline{P}(q,e) = 0.0576\), \(\overline{P}(q,e) = 0.16\), \(\underline{P}(\lnot q,e) = 0.2016\), and \(\overline{P}(\lnot q,e) = 0.3424\).4 Inference in PASTA
fly(1)
, the probabilistic fact bird(1)
must be true to get a contribution to the lower or upper probability, and so we can avoid generating the worlds where this fact is not present. Moreover, for both conditional and unconditional queries, we do not need to generate all the possible models for every world, we just need to check whether there is at least one model that satisfies the required constraints. To accommodate these ideas, we propose Algorithm 1, that we call PASTA like the language.P::f
is converted into two rules of the form f(P1):- f. not_f(1-P1):- not f.
where P1
is P
\(\cdot 10^n\) (since ASP cannot manage floating point numbers). The atom f
is then defined by a rule of the form 0{f}1.
Function ConvertProbFactsAndConditionals performs these conversions. Let us call the resulting program \( PASP_p \). We then add to \( PASP_p \) a constraint (line 4) imposing that the query must be true, represented with :- not query.
(for Example 3 it becomes :- not fly(1).
). We are not interested in all possible solutions, but only in the cautious consequences projected over the ground probabilistic facts, since we want to extract the probabilistic facts that are true in every answer set. These will constitute the minimal set of probabilistic facts. Function ComputeMinimalSet computes this set. These facts can be set to true since they are always present in the answer sets when the query is true, and so when there is a contribution to the probabilities. In the worst case, the resulting set will be empty. If we consider Example 3 and query fly(1)
, the only atom (already converted as described before with \(n = 3\)) in this set will be bird(1,400)
, so the corresponding probabilistic fact must be always true. After this step, we add to \( PASP_p \) one integrity constraint for every element in the minimal set of probabilistic facts, to set them to true. Note that now \( PASP_p \) does not contain the constraint imposed on the query in the previous step. For Example 3 and query fly(1)
, we add :- not bird(1,400).
to the program (line 9). Moreover, we add two more rules that indicate whether a model contains or not the query (line 11). For Example 3 and query fly(1)
these are: q:- fly(1). nq:- not fly(1).
Finally, we project the answer sets [12] to the probabilistic facts and atoms q
and nq
, since we need to consider only the truth values of the probabilistic facts to compute the probability of a world (line 13). The probabilistic facts present in the projected answer sets identify a world. Given an answer set, its probability (the probability of the world it represents) is given by the product of the probabilities of the probabilistic facts in it. Function ComputeContribution (line 18) computes the probability of every world and counts the models, the models where the query is true, the models where the query is false, the models where the query and evidence are true, and the models where the query is false and the evidence is true. For a query without evidence, the number of models where the query is true and the number of models where the query is false will only be either 0 or 1. To get the lower and upper probabilities, we apply Formulas 3. If we consider again Example 3 with query fly(1)
, two of the possible projective solutions are: where, for the sake of brevity, b/2
stands for bird/2
. These two solutions show that the world with 4 birds has at least one model where the query is true and at least one model where the query is false, so it only contributes to the upper probability with \(0.4 \cdot 0.4 \cdot 0.4 \cdot 0.4 = 0.0256\). Here, we also see the improvement given by computing the projective solutions: we only need to know whether the query is true or false in some models of a world, and not the exact number of models in which the query is true. For example, as shown in Example 1, the world with 4 birds has 5 models: 4 where the query is true and 1 where the query is false. However, to compute the probability bounds, it is not necessary to know the exact number: at most two stable models (one with the query true and one with the query false) for each world are needed instead of five. A difference with [23] is that PASOCS computes both brave and cautious consequences for every world, while PASTA computes projective solutions only once.
ev
) to true instead of the query (line 6). We then add two more rules of the form e:- ev.
and ne:- not ev.
(line 15) and project the solutions also on the e
and ne
atoms (line 16). Finally, we analyse the resulting answer sets to compute the values that contribute to the lower (lp) and upper (up) probability, as described in Formulas 4 and 5.
5 Experiments
clingo
[11] to compute answer sets.1 We performed a series of experiments to compare PASTA with PASOCS [23]. For PASOCS, we use the single threaded mode and select exact inference. For PASTA, the execution time includes both the computation of the minimal set of probabilistic facts and the computation of the projective solutions. Usually, the time required for the first operation is negligible with respect to the computation of the probability. We selected three different programs described in [25]. The first program, brd
, is {(fly(X) | bird(X))[0.8,1],0.1::fly(1)}
with an increasing number of probabilistic facts bird/1
with an associated probability of 0.5. The goal is to compute the probability of the query fly(1)
. The second program, mky
, represents the pair of conditionals {(f(X) | h(X)) [0.2,1],(f(X,Y) | h(Y),r(X,Y))[0.9,1]
}, with an increasing number of probabilistic facts h/1
and r/2
, both with an associated probability of 0.5. The distribution of the facts r/2
follows a Barabási-Albert model, i.e., a graph, generated with the Python networkx
package with parameter \(m_0\) (representing the number of edges to attach from a new node to existing nodes) set to 3 and an increasing number of nodes. We randomly selected half of the total number of nodes to generate the h/1
facts. The query is f(0),f(0,1)
. The third program, smk
, represents the conditional {(smokes(Y) | smokes(X),friend(X,Y))[0.4,1]}
with an increasing number of probabilistic facts friend/2
with an associated probability of 0.5, following the Barabási-Albert model. The query is smokes(I)
, where I
is a random node. For both mky
and smk
, the results are averaged over 10 different programs, to make them more representative since the graph generation is not deterministic, and thus some instances can be easier to query. For all the three programs, the minimal set of probabilistic facts is empty, so the PASOCS and PASTA work on the same set of worlds. Inference times are shown in Fig. 1a. PASOCS on mky
returned an internal error of the solver while parsing the program. In a second experiment, bird
, we modify the brd
program by removing 0.1::fly(1)
, and we ask two queries: fly(1)
, and fly(1)
given that fly(2)
has been observed. For these two experiments, the minimal set of probabilistic facts contains bird(1)
. Results are shown in Fig. 1b. Overall, with our solution we can manage a larger number of probabilistic facts. Moreover, the introduction of the minimal set of probabilistic facts gives a substantial improvement, as shown in Fig. 1b. However, both PASOCS and PASTA rely on the generation of all the worlds, which increase in an exponential way.