Tekst toegevoegd deel 1, nog niet klaar
[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 a\textit{Burglar} event happening at some day is then (assuming a Gregorian
16 calendar and leap days):
17 $$\frac{1}{365 + 0.25 - 0.01 - 0.0025}=\frac{1}{365.2425}$$
18
19 The resultant probability distributions can be found in table ~\ref{probdist}, in order to avoid a unclear graph.
20
21 \begin{table}[H]
22 \label{probdist}
23 \begin{tabular}{|l|l|}
24 \hline
25 & Earthquake\\
26 \hline
27 T & $0.0027$\\
28 F & $0.9973$\\
29 \hline
30 \end{tabular}
31 %
32 \begin{tabular}{|l|l|}
33 \hline
34 & Burglar\\
35 \hline
36 T & $0.0027$\\
37 F & $0.9973$\\
38 \hline
39 \end{tabular}
40
41 \begin{tabular}{|l|ll|}
42 \hline
43 & \multicolumn{2}{c|}{$I_1$}\\
44 Earthquake & T & F\\
45 \hline
46 T & $0.2$ & $0.8$\\
47 F & $0$ & $1$\\
48 \hline
49 \end{tabular}
50 \begin{tabular}{|l|ll|}
51 \hline
52 & \multicolumn{2}{c|}{$I_2$}\\
53 Burglar & T & F\\
54 \hline
55 T & $0.95$ & $0.05$\\
56 F & $0$ & $1$\\
57 \hline
58 \end{tabular}
59 \begin{tabular}{|ll|ll|}
60 \hline
61 && \multicolumn{2}{c|}{Alarm}\\
62 $I_1$ & $I_2$ & T & F\\
63 \hline
64 T & T & $1$ & $0$\\
65 T & F & $1$ & $0$\\
66 F & T & $1$ & $0$\\
67 F & F & $0$ & $1$\\
68 \hline
69 \end{tabular}
70
71 \begin{tabular}{|l|ll|}
72 \hline
73 & \multicolumn{2}{c|}{Watson}\\
74 Alarm & T & F\\
75 \hline
76 T & $0.8$ & $0.2$\\
77 F & $0.4$ & $0.6$\\
78 \hline
79 \end{tabular}
80 \begin{tabular}{|l|ll|}
81 \hline
82 & \multicolumn{2}{c|}{Gibbons}\\
83 Alarm & T & F\\
84 \hline
85 T & $0.99$ & $0.01$\\
86 F & $0.04$ & $0.96$\\
87 \hline
88 \end{tabular}
89 \begin{tabular}{|l|ll|}
90 \hline
91 & \multicolumn{2}{c|}{Radio}\\
92 Earthquake & T & F\\
93 \hline
94 T & $0.9998$ & $0.0002$\\
95 F & $0.0002$ & $0.9998$\\
96 \hline
97 \end{tabular}
98 \end{table}
99
100 \textit{If there is a burglar present (which could happen once every ten years), the alarm is known to go off 95\% of the time.} We modelled this by setting the value for Burglar True and $I_2$ True on 0,95. \\
101 \textit{There’s a 40\% chance that Watson is joking and the alarm is in fact off.} This is modelled by putting the value for Watson True and Alarm F on 0,4. As Holmes expects Watson to call in 80\% of the time, the value for alarm True and Watson True is set 0,2. Because the rows have to sum to 1, the other values are easily calculated. \\
102 \textit{She may not have heard the alarm in 1\% of the cases and is thought to erroneously report an alarm when it is in fact off in 4\% of the cases.} We modelled this by assuming that when Mrs. Gibbons hears the alarm, she calls Holmes. Meaning that the value for Gibbons False and Alarm true is 0,01. As she reports when the alarm is in fact off in 4\% of the cases, the value for Gibbons True and alarm False is 0,04. \\
103
104
105
106 \section{Implementation}
107 We implemented the distributions in \textit{AILog}, see Listing~\ref{alarm.ail}
108
109 \begin{listing}[H]
110 \label{alarm.ail}
111 \caption{Alarm.ail}
112 \inputminted[linenos,fontsize=\footnotesize]{prolog}{./src/alarm.ail}
113 \end{listing}
114
115 \section{Queries}
116 Now that we have modelled the story with the corresponding probabilities, we can have ailog calculate some other probabilities given a some observations. Down below we wrote down some probabilties and the associated ailog output. \\
117 The chance that a burglary happens given that Watson calls is greater than the chance that a burglary happens without this observations, as is observerd by the difference between a and b. This makes sense as Watson calls rightly in 80\% of the time. So when Holmes receives a call by Watson, the chance that the alarm goes of increases. \\
118 When we compare b to c, the same mechanisme holds. There are more observations that give evidence for a burglary as both Watson and Gibbons have called in the case of c. \\
119 When you take a look at the last case, d, you see that the probability has decreased compared to c. This can be explained by an observation that is added on top of the observations of b; the radio. The variable Radio means that the newcast tells that there was an earhquake. As that is also a reason why the alarm could go of, but has nothing to do with a burglary, it decreases the probability of a burglary.
120 %We kunnen misschien de kans uitrekenen dat Watson en Gibbons allebei foutief bellen? Daar mis je denk ik info over of niet?
121 \begin{enumerate}[a)]
122 \item $P(\text{Burglary})=
123 0.002737757092501968$
124 \item $P(\text{Burglary}|\text{Watson called})=
125 0.005321803679438259$
126 \item $P(\text{Burglary}|\text{Watson called},\text{Gibbons called})=
127 0.11180941544755249$
128 \item $P(\text{Burglary}|\text{Watson called},\text{Gibbons called}
129 , \text{Radio})=0.01179672476662423$
130 \end{enumerate}
131
132 \begin{listing}[H]
133 \begin{minted}[fontsize=\footnotesize]{prolog}
134 ailog: predict burglar.
135 Answer: P(burglar|Obs)=0.002737757092501968.
136 [ok,more,explanations,worlds,help]: ok.
137
138 ailog: observe watson.
139 Answer: P(watson|Obs)=0.4012587986186947.
140 [ok,more,explanations,worlds,help]: ok.
141
142 ailog: predict burglar.
143 Answer: P(burglar|Obs)=[0.005321803679438259,0.005321953115441623].
144 [ok,more,explanations,worlds,help]: ok.
145
146 ailog: observe gibbons.
147 Answer: P(gibbons|Obs)=[0.04596053565368094,0.045962328885721306].
148 [ok,more,explanations,worlds,help]: ok.
149
150 ailog: predict burglar.
151 Answer: P(burglar|Obs)=[0.11180941544755249,0.1118516494624678].
152 [ok,more,explanations,worlds,help]: ok.
153
154 ailog: observe radio.
155 Answer: P(radio|Obs)=[0.02582105837443645,0.025915745316785182].
156 [ok,more,explanations,worlds,help]: ok.
157
158 ailog: predict burglar.
159 Answer: P(burglar|Obs)=[0.01179672476662423,0.015584580594335082].
160 [ok,more,explanations,worlds,help]: ok.
161 \end{minted}
162 \end{listing}
163
164 ToDO write down the most probable explanation for the observed evidence
165
166 \section{Comparison with manual calculation}
167 ToDO: english.
168 When we let ailog calculate the probability of alarm. %Wat is Obs hier??
169 Querying the \textit{Alarm} variable gives the following answer:
170 \begin{minted}{prolog}
171 ailog: predict alarm.
172 Answer: P(alarm|Obs)=0.0031469965467367292.
173
174 [ok,more,explanations,worlds,help]: ok.
175 \end{minted}
176
177 Using the formula for causal independence with a logical OR: \\ $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 probability of the \textit{Alarm} variable using variable elimination. This results in the following answer: \\
178 $P(Alarm|burglar, earthquake) = P(i_1|burglar)+P(i_2|earthquake)(1-P(i_1|burglar)) = 0.2*0.0027+0.95*0.0027*(1-0.2*0.0027)=0.00314699654673673$ \\
179 TODOOOOOOOOOOO %Ik weet niet of we i_1 en i_2 nog door iets anders vervangen moeten worden.
180 When you compare the output of ailog and of the variable elimination, you see that they are similar.
181
182 \newpage
183 \section{Burglary problem with extended information}
184 $P(burglary)\cdot\left(
185 P(\text{first house is holmes'})+
186 P(\text{second house is holmes'})+
187 P(\text{third house is holmes'})\right)=\\
188 0.5102041\cdot\left(
189 \frac{1}{10000}+
190 \frac{9999}{10000}\cdot\frac{1}{9999}+
191 \frac{9999}{10000}\cdot\frac{9998}{9999}\cdot\frac{1}{9998}\right)=
192 \frac{3}{19600}\approx0.000153$
193
194 \section{Bayesian networks}
195 A bayesian network representation of the burglary problem with a multitude of
196 houses and burglars is possible but would be very big and tedious because all
197 the constraints about the burglars must be incorporated in the network.
198 The network would look something like in figure~\ref{bnnetworkhouses}
199
200
201 \begin{tabular}{|l|l|}
202 \hline
203 Joe &\\
204 \hline
205 T & $\nicefrac{5}{7}$\\
206 F & $\nicefrac{2}{7}$\\
207 \hline
208 \end{tabular}
209 \begin{tabular}{|l|l|}
210 \hline
211 William &\\
212 \hline
213 T & $\nicefrac{5}{7}$\\
214 F & $\nicefrac{2}{7}$\\
215 \hline
216 \end{tabular}
217 \begin{tabular}{|l|l|}
218 \hline
219 Jack & \\
220 \hline
221 T & $\nicefrac{5}{7}$\\
222 F & $\nicefrac{2}{7}$\\
223 \hline
224 \end{tabular}
225 \begin{tabular}{|l|l|}
226 \hline
227 Averall & \\
228 \hline
229 T & $\nicefrac{5}{7}$\\
230 F & $\nicefrac{2}{7}$\\
231 \hline
232 \end{tabular}
233
234 \begin{tabular}{|llll|ll|}
235 \hline
236 & & & & Burglary &\\
237 Joe & William & Jack & Averall & T & F\\
238 \hline
239 F& F& F& F & $0$ & $1$\\
240 F& F& F& T & $0$ & $1$\\
241 F& F& T& F & $0$ & $1$\\
242 F& F& T& T & $0$ & $1$\\
243 F& T& F& F & $0$ & $1$\\
244 F& T& F& T & $0$ & $1$\\
245 F& T& T& F & $0$ & $1$\\
246 F& T& T& T & $0$ & $1$\\
247 T& F& F& F & $0$ & $1$\\
248 T& F& F& T & $0$ & $1$\\
249 T& F& T& F & $1$ & $0$\\
250 T& F& T& T & $0$ & $1$\\
251 T& T& F& F & $1$ & $0$\\
252 T& T& F& T & $0$ & $1$\\
253 T& T& T& F & $1$ & $0$\\
254 T& T& T& T & $1$ & $0$\\
255 \hline
256 \end{tabular}
257 \begin{tabular}{|lll|}
258 \hline
259 & Holmes &\\
260 Burglary & T & F\\
261 \hline
262 T & $0.000153$ & $0.999847$\\
263 F & $0$ & $1$\\
264 \hline
265 \end{tabular}
266
267 \begin{figure}[H]
268 \caption{Bayesian network of burglars and houses}
269 \label{bnnetworkhouses}
270 \centering
271 %\includegraphics[scale=0.5]{d2.eps}
272 \end{figure}