final version
[ker2014-2.git] / report / ass2-1.tex
1 \chapter{Probabilistic representation and reasoning (and burglars)}
2 \section{Formal description}
3 In our representation of the model we introduced a \textit{Noisy OR} to
4 represent the causal independence of \textit{Burglar} and \textit{Earthquake}
5 on \textit{Alarm}. The representation of the network is displayed in
6 Figure~\ref{bnetwork21}
7
8 \begin{figure}[H]
9 \caption{Bayesian network alarmsystem}
10 \label{bnetwork21}
11 \centering
12 \includegraphics[scale=0.5]{d1.eps}
13 \end{figure}
14
15 Days were chosen as unit to model the story. Calculation of the probability of
16 a\textit{Burglar} event happening at some day is then (assuming a gregorian
17 calendar and leap days):
18 $$\frac{1}{365 + 0.25 - 0.01 - 0.0025}=\frac{1}{365.2425}$$
19
20 The resultant probability distributions can be found in Table~\ref{probdist},
21 in order to avoid an unclear graph.
22
23 \begin{table}[H]
24 \label{probdist}
25 \begin{tabular}{|l|l|}
26 \hline
27 & Earthquake\\
28 \hline
29 T & $0.0027$\\
30 F & $0.9973$\\
31 \hline
32 \end{tabular}
33 %
34 \begin{tabular}{|l|l|}
35 \hline
36 & Burglar\\
37 \hline
38 T & $0.0027$\\
39 F & $0.9973$\\
40 \hline
41 \end{tabular}
42
43 \begin{tabular}{|l|ll|}
44 \hline
45 & \multicolumn{2}{c|}{$I_1$}\\
46 Earthquake & T & F\\
47 \hline
48 T & $0.2$ & $0.8$\\
49 F & $0$ & $1$\\
50 \hline
51 \end{tabular}
52 \begin{tabular}{|l|ll|}
53 \hline
54 & \multicolumn{2}{c|}{$I_2$}\\
55 Burglar & T & F\\
56 \hline
57 T & $0.95$ & $0.05$\\
58 F & $0$ & $1$\\
59 \hline
60 \end{tabular}
61 \begin{tabular}{|ll|ll|}
62 \hline
63 && \multicolumn{2}{c|}{Alarm}\\
64 $I_1$ & $I_2$ & T & F\\
65 \hline
66 T & T & $1$ & $0$\\
67 T & F & $1$ & $0$\\
68 F & T & $1$ & $0$\\
69 F & F & $0$ & $1$\\
70 \hline
71 \end{tabular}
72
73 \begin{tabular}{|l|ll|}
74 \hline
75 & \multicolumn{2}{c|}{Watson}\\
76 Alarm & T & F\\
77 \hline
78 T & $0.8$ & $0.2$\\
79 F & $0.4$ & $0.6$\\
80 \hline
81 \end{tabular}
82 \begin{tabular}{|l|ll|}
83 \hline
84 & \multicolumn{2}{c|}{Gibbons}\\
85 Alarm & T & F\\
86 \hline
87 T & $0.99$ & $0.01$\\
88 F & $0.04$ & $0.96$\\
89 \hline
90 \end{tabular}
91 \begin{tabular}{|l|ll|}
92 \hline
93 & \multicolumn{2}{c|}{Radio}\\
94 Earthquake & T & F\\
95 \hline
96 T & $0.9998$ & $0.0002$\\
97 F & $0.0002$ & $0.9998$\\
98 \hline
99 \end{tabular}
100 \end{table}
101
102 \textit{If there is a burglar present (which could happen once every ten
103 years), the alarm is known to go off 95\% of the time.} We modelled this by
104 setting the value for Burglar True and $I_2$ True on 0,95.\\
105 \textit{There’s a 40\% chance that Watson is joking and the alarm is in fact
106 off.} This is modelled by putting the value for Watson True and Alarm F on 0,4.
107 As Holmes expects Watson to call in 80\% of the time, the value for alarm True
108 and Watson True is set 0,2. Because the rows have to sum to 1, the other values
109 are easily calculated.\\
110 \textit{She may not have heard the alarm in 1\% of the cases and is thought to
111 erroneously report an alarm when it is in fact off in 4\% of the cases.} We
112 modelled this by assuming that when Mrs. Gibbons hears the alarm, she calls
113 Holmes. Meaning that the value for Gibbons False and Alarm true is 0,01. As
114 she reports when the alarm is in fact off in 4\% of the cases, the value for
115 Gibbons True and alarm False is 0,04.\\
116
117
118 \section{Implementation}
119 We implemented the distributions in \textit{AILog}, see Listing~\ref{alarm.ail}
120
121 \begin{listing}[H]
122 \label{alarm.ail}
123 \caption{Alarm.ail}
124 \inputminted[linenos,fontsize=\footnotesize]{prolog}{./src/alarm.ail}
125 \end{listing}
126
127 \section{Queries}
128 Now that we have modelled the story with the corresponding probabilities, we
129 can have AILog calculate some other probabilities given by some observations.
130 Down below we wrote down some probabilties and the associated AILog output.\\
131 The chance that a burglary happens given that Watson calls is greater than the
132 chance that a burglary happens without this observations, as is observerd by
133 the difference between a and b. This makes sense as Watson calls rightly in
134 80\% of the time. So when Holmes receives a call by Watson, the chance that the
135 alarm goes of increases.\\
136 When we compare b to c, the same mechanisme holds. There are more observations
137 that give evidence for a burglary as both Watson and Gibbons have called in the
138 case of c.\\
139 When you take a look at the last case, d, you see that the probability has
140 decreased compared to c. This can be explained by an observation that is added
141 on top of the observations of b; the radio. The variable Radio means that the
142 newcast tells that there was an earhquake. As that is also a reason why the
143 alarm could go of, but has nothing to do with a burglary, it decreases the
144 probability of a burglary.
145 %We kunnen misschien de kans uitrekenen dat Watson en Gibbons allebei foutief bellen? Daar mis je denk ik info over of niet?
146 \begin{enumerate}[a)]
147 \item $P(\text{Burglary})=
148 0.002737757092501968$
149 \item $P(\text{Burglary}|\text{Watson called})=
150 0.005321803679438259$
151 \item $P(\text{Burglary}|\text{Watson called},\text{Gibbons called})=
152 0.11180941544755249$
153 \item $P(\text{Burglary}|\text{Watson called},\text{Gibbons called}
154 , \text{Radio})=0.01179672476662423$
155 \end{enumerate}
156
157 \begin{listing}[H]
158 \begin{minted}[fontsize=\footnotesize]{prolog}
159 AILog: predict burglar.
160 Answer: P(burglar|Obs)=0.002737757092501968.
161 [ok,more,explanations,worlds,help]: ok.
162
163 AILog: observe watson.
164 Answer: P(watson|Obs)=0.4012587986186947.
165 [ok,more,explanations,worlds,help]: ok.
166
167 AILog: predict burglar.
168 Answer: P(burglar|Obs)=[0.005321803679438259,0.005321953115441623].
169 [ok,more,explanations,worlds,help]: ok.
170
171 AILog: observe gibbons.
172 Answer: P(gibbons|Obs)=[0.04596053565368094,0.045962328885721306].
173 [ok,more,explanations,worlds,help]: ok.
174
175 AILog: predict burglar.
176 Answer: P(burglar|Obs)=[0.11180941544755249,0.1118516494624678].
177 [ok,more,explanations,worlds,help]: ok.
178
179 AILog: observe radio.
180 Answer: P(radio|Obs)=[0.02582105837443645,0.025915745316785182].
181 [ok,more,explanations,worlds,help]: ok.
182
183 AILog: predict burglar.
184 Answer: P(burglar|Obs)=[0.01179672476662423,0.015584580594335082].
185 [ok,more,explanations,worlds,help]: ok.
186 \end{minted}
187 \end{listing}
188
189 \section{Comparison with manual calculation}
190 Querying the \textit{Alarm} variable gives the following answer:
191 \begin{minted}{prolog}
192 AILog: predict alarm.
193 Answer: P(alarm|Obs)=0.0031469965467367292.
194
195 [ok,more,explanations,worlds,help]: ok.
196 \end{minted}
197
198 Using the formula for causal independence with a logical OR:\\
199 $P(Alarm|C_1, C_2) = P(i_1|C_1)+P(i_2|C_2)(1-P(i_1|C_1))$ we can calculate the
200 probability of the \textit{Alarm} variable using variable elimination. This
201 results in the following answer:\\
202 $P(Alarm|burglar, earthquake) =
203 P(i_1|burglar)+P(i_2|earthquake)(1-P(i_1|burglar)) =
204 0.2*0.0027+0.95*0.0027*(1-0.2*0.0027)=0.00314699654673673$ \\
205
206 When you compare the output of AILog and of the variable elimination, you see
207 that they are exactly the same. The method with which AILog calculates the
208 probability is almost the same but that is mainly because we did not use any
209 techniques that are not available in AILog. When we would have done the same
210 task with a Bayesian network and the use of Bayes' rule we would have had a
211 different method.
212
213 \newpage
214 \section{Burglary problem with extended information}
215 Extending the story with multiple houses and constraints about who wants to work
216 with who the following AILog representation:
217 \inputminted[linenos,fontsize=\footnotesize]{prolog}{./src/burglary.ail}
218
219 The following demandings on the sets of colleagues, limited the number of
220 possible groups to four:
221
222 \begin{itemize}
223 \item needs(joe, [])
224 \item needs(william, [])
225 \item needs(jack, [joe])
226 \item needs(averall, [jack, william])
227 \end{itemize}
228
229 The only way that those people will burgler, is when those constraints are satisfied and when there are at least two people working. So the only combinations possible are then:
230 \begin{enumerate}
231 \item Joe and Jack
232 \item Joe and William
233 \item Joe, William and Jack
234 \item Joe, William, Jack and Averall.
235 \end{enumerate}
236
237 We implemented the extended story using a three layered model.\\
238 \textit{Each day a burglar decides whether he wants to work or not, and on
239 average this happens only 5 days a week}
240 Meaning that every burglar has the same initial working probability: 5/7 (see the first 5 lines of code).\\
241 Then we implemented the constraints on the colleagues by telling AILog that a burglary can happen when at least one of our combinations is working (see line 8 to 11).\\
242 \textit{Finally, if they decide to burgle, then they will burgle 3 houses a night.} The third layer consists of implementing the change that out of the 10,000 houses in which Joe, William, Jack and Averall are the only burglars, Holmes' house is burgled as one of the three (see line 14 to 19). This results in the following probability for a burglary at a Holmes' house.
243
244 $P(burglary)\cdot(
245 P(\text{first house Holmes'})+
246 P(\text{second house Holmes'})+
247 P(\text{third house Holmes'}))=\\
248 0.655976676\cdot\left(
249 \frac{1}{10000}+
250 \frac{9999}{10000}\cdot\frac{1}{9999}+
251 \frac{9999}{10000}\cdot\frac{9998}{9999}\cdot\frac{1}{9998}\right)
252 \approx 0.000196773$
253
254 \section{Bayesian networks}
255 A Bayesian network representation of the extended story is possible, but could
256 become very large because of the great number of houses and burglars. However
257 we found a way to create a network that is very compact, see
258 figure~\ref{bnnetworkhouses} and the corresponding probability tables. The
259 network is created in the same way as our implementation of the extended
260 story. Every burglar has the same starting probabilities that are merged
261 together in whether a burglary happens. Then the probability of a burglary
262 at Holmes' house when there will be burgled is calculated.
263
264 \begin{figure}[H]
265 \caption{Bayesian network of burglars and houses}
266 \label{bnnetworkhouses}
267 \centering
268 \includegraphics[scale=0.5]{d2.eps}
269 \end{figure}
270
271 \begin{tabular}{|l|l|}
272 \hline
273 Joe &\\
274 \hline
275 T & $\nicefrac{5}{7}$\\
276 F & $\nicefrac{2}{7}$\\
277 \hline
278 \end{tabular}
279 \begin{tabular}{|l|l|}
280 \hline
281 William &\\
282 \hline
283 T & $\nicefrac{5}{7}$\\
284 F & $\nicefrac{2}{7}$\\
285 \hline
286 \end{tabular}
287 \begin{tabular}{|l|l|}
288 \hline
289 Jack & \\
290 \hline
291 T & $\nicefrac{5}{7}$\\
292 F & $\nicefrac{2}{7}$\\
293 \hline
294 \end{tabular}
295 \begin{tabular}{|l|l|}
296 \hline
297 Averall & \\
298 \hline
299 T & $\nicefrac{5}{7}$\\
300 F & $\nicefrac{2}{7}$\\
301 \hline
302 \end{tabular}
303
304 \begin{tabular}{|llll|ll|}
305 \hline
306 & & & & Burglary &\\
307 Joe & William & Jack & Averall & T & F\\
308 \hline
309 F& F& F& F & $0$ & $1$\\
310 F& F& F& T & $0$ & $1$\\
311 F& F& T& F & $0$ & $1$\\
312 F& F& T& T & $0$ & $1$\\
313 F& T& F& F & $0$ & $1$\\
314 F& T& F& T & $0$ & $1$\\
315 F& T& T& F & $0$ & $1$\\
316 F& T& T& T & $0$ & $1$\\
317 T& F& F& F & $0$ & $1$\\
318 T& F& F& T & $0$ & $1$\\
319 T& F& T& F & $1$ & $0$\\
320 T& F& T& T & $0$ & $1$\\
321 T& T& F& F & $1$ & $0$\\
322 T& T& F& T & $0$ & $1$\\
323 T& T& T& F & $1$ & $0$\\
324 T& T& T& T & $1$ & $0$\\
325 \hline
326 \end{tabular}
327 \begin{tabular}{|lll|}
328 \hline
329 & Holmes &\\
330 Burglary & T & F\\
331 \hline
332 T & $0.000153$ & $0.999847$\\
333 F & $0$ & $1$\\
334 \hline
335 \end{tabular}
336
337 \section{Additional Questions}
338 We wouldn't change any aspect of the assignment. It is nice that the assignment is slowly increasing in difficulty because of the extention of the story. We estimate that we spent about 20 hours each on the assignment.
339