# Session 1 - Warming Up¶

In this first session, we look at some basic examples to get to know ProbLog’s semantics and basic modelling.

## Exercise 1: the Game¶

Below you can find the example used in the slides.

% We have a biased coin. 0.4 :: heads. % We have two bins containing colored balls. 0.3 :: col(1,red); 0.7 :: col(1,blue). 0.2 :: col(2,red); 0.3 :: col(2,green); 0.5 :: col(2,blue). % These are the rules of the game: % If the coin shows heads and we have a red ball, we win. win :- heads, col(_,red). % If we have two balls of the same color, we win. win :- col(1,C), col(2,C). %

This model is incomplete because it doesn’t specify any queries. By adding the right queries and evidence, you can answer all of the questions below. First, try to answer these questions by computing the solutions manually. After that, verify your answers by editing the model and evaluating it with ProbLog.

1. Compute the probability of winning the game. (Hint: you can specify a query with a fact query(...)).
2. Compute the probability of having a red ball. (Hint: you may need to define an auxiliary predicate for this exercise.)
3. Compute the probability of winning the game if the coin shows heads. (Hint: you can specify an observation with a fact evidence(...))
4. Compute the probability that the first ball is blue, given that you win the game.
5. Compute the probability that the first ball is blue, given that you lose the game. (Hint: you can specify negation as not ...)
6. Compute the probability that any ball is blue, given that you win the game.

## Exercise 2: Bayesian networks¶

We illustrate the use of Bayesian networks in ProbLog using the famous Earthquake example.

Suppose there is a burglary in our house with probability 0.7 and an earthquake with probability 0.2. Whether our alarm will ring depends on both burglary and earthquake:

• if there is a burglary and an earthquake, the alarm rings with probability 0.9;
• if there is only a burglary, it rings with probability 0.8;
• if there is only an earthquake, it rings with probability 0.1;
• if there is neither a burglary nor an earthquake, the alarm doesn’t ring.

Model this problem in ProbLog and answer the following questions:

1. What is the probability that the alarm goes off?
2. When the alarm is going off, what is the probability that a burglary occurred?
3. When the alarm is going off, what is the probability that an earthquake occurred?

## Exercise 3: Tossing coins¶

ProbLog is all about modelling probabilistic choices. The typical example of a probabilistic choice is a coin.

One coin toss can be represented using a probabilistic fact.

We want to determine the probability of getting heads twice if we toss a coin twice by using the following model.

0.5::heads. two_heads :- heads, heads. query(two_heads). %

Is this model correct? If not, what is wrong and can you fix it?