55c85014de1de3ac72459bddd32f80c5d98e9b69
[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 for 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 \section{Implementation}
101 This distribution results in the \textit{AILog} code in Listing~\ref{alarm.ail}
102
103 \begin{listing}[H]
104 \label{alarm.ail}
105 \caption{alarm.ail}
106 \inputminted[linenos,fontsize=\footnotesize]{prolog}{./src/alarm.ail}
107 \end{listing}
108
109 \section{Queries}
110 Using the following queries the probabilities or as follows:\\
111 \begin{enumerate}[a)]
112 \item $P(\text{Burglary})=
113 0.002737757092501968$
114 \item $P(\text{Burglary}|\text{Watson called})=
115 0.005321803679438259$
116 \item $P(\text{Burglary}|\text{Watson called}\wedge\text{Gibbons called})=
117 0.11180941544755249$
118 \item $P(\text{Burglary}|\text{Watson called}\wedge\text{Gibbons called}
119 \wedge\text{Radio})=0.01179672476662423$
120 \end{enumerate}
121
122 \begin{listing}[H]
123 \begin{minted}[fontsize=\footnotesize]{prolog}
124 ailog: predict burglar.
125 Answer: P(burglar|Obs)=0.002737757092501968.
126 [ok,more,explanations,worlds,help]: ok.
127
128 ailog: observe watson.
129 Answer: P(watson|Obs)=0.4012587986186947.
130 [ok,more,explanations,worlds,help]: ok.
131
132 ailog: predict burglar.
133 Answer: P(burglar|Obs)=[0.005321803679438259,0.005321953115441623].
134 [ok,more,explanations,worlds,help]: ok.
135
136 ailog: observe gibbons.
137 Answer: P(gibbons|Obs)=[0.04596053565368094,0.045962328885721306].
138 [ok,more,explanations,worlds,help]: ok.
139
140 ailog: predict burglar.
141 Answer: P(burglar|Obs)=[0.11180941544755249,0.1118516494624678].
142 [ok,more,explanations,worlds,help]: ok.
143
144 ailog: observe radio.
145 Answer: P(radio|Obs)=[0.02582105837443645,0.025915745316785182].
146 [ok,more,explanations,worlds,help]: ok.
147
148 ailog: predict burglar.
149 Answer: P(burglar|Obs)=[0.01179672476662423,0.015584580594335082].
150 [ok,more,explanations,worlds,help]: ok.
151 \end{minted}
152 \end{listing}
153
154 \section{Comparison with manual calculation}
155 Querying the \textit{Alarm} variable gives the following answer
156 \begin{minted}{prolog}
157 ailog: predict alarm.
158 Answer: P(alarm|Obs)=0.0031469965467367292.
159
160 [ok,more,explanations,worlds,help]: ok.
161 \end{minted}
162
163 Using formula: $P(i_1|C_1)+P(i_2|C_2)(1-P(i_1|C_1))$ we can calculate the
164 probability of the \textit{Alarm} variable using variable elimination. This
165 results in the following answer:
166 $$0.2*0.0027+0.95*0.0027*(1-0.2*0.0027)=0.00314699654673673$$
167 TODOOOOOOOOOOO
168
169 \newpage
170 \section{Burglary problem with extended information}
171 $P(burglary)\cdot\left(
172 P(\text{first house is holmes'})+
173 P(\text{second house is holmes'})+
174 P(\text{third house is holmes'})\right)=\\
175 0.5102041\cdot\left(
176 \frac{1}{10000}+
177 \frac{9999}{10000}\cdot\frac{1}{9999}+
178 \frac{9999}{10000}\cdot\frac{9998}{9999}\cdot\frac{1}{9998}\right)=
179 \frac{3}{19600}\approx0.000153$
180
181 \section{Bayesian networks}
182 A bayesian network representation of the burglary problem with a multitude of
183 houses and burglars is possible but would be very big and tedious because all
184 the constraints about the burglars must be incorporated in the network.
185 The network would look something like in figere~\ref{bnnetworkhouses}
186
187 \begin{tabular}{|l|l|}
188 \hline
189 Joe &\\
190 \hline
191 T & $\nicefrac{5}{7}$\\
192 F & $\nicefrac{2}{7}$\\
193 \hline
194 \end{tabular}
195 \begin{tabular}{|l|l|}
196 \hline
197 William &\\
198 \hline
199 T & $\nicefrac{5}{7}$\\
200 F & $\nicefrac{2}{7}$\\
201 \hline
202 \end{tabular}
203 \begin{tabular}{|l|l|}
204 \hline
205 Jack & \\
206 \hline
207 T & $\nicefrac{5}{7}$\\
208 F & $\nicefrac{2}{7}$\\
209 \hline
210 \end{tabular}
211 \begin{tabular}{|l|l|}
212 \hline
213 Averall & \\
214 \hline
215 T & $\nicefrac{5}{7}$\\
216 F & $\nicefrac{2}{7}$\\
217 \hline
218 \end{tabular}
219
220 \begin{tabular}{|llll|ll|}
221 \hline
222 & & & & Burglary &\\
223 Joe & William & Jack & Averall & T & F\\
224 \hline
225 F& F& F& F & $0$ & $1$\\
226 F& F& F& T & $0$ & $1$\\
227 F& F& T& F & $0$ & $1$\\
228 F& F& T& T & $0$ & $1$\\
229 F& T& F& F & $0$ & $1$\\
230 F& T& F& T & $0$ & $1$\\
231 F& T& T& F & $0$ & $1$\\
232 F& T& T& T & $0$ & $1$\\
233 T& F& F& F & $0$ & $1$\\
234 T& F& F& T & $0$ & $1$\\
235 T& F& T& F & $1$ & $0$\\
236 T& F& T& T & $0$ & $1$\\
237 T& T& F& F & $1$ & $0$\\
238 T& T& F& T & $0$ & $1$\\
239 T& T& T& F & $1$ & $0$\\
240 T& T& T& T & $1$ & $0$\\
241 \hline
242 \end{tabular}
243 \begin{tabular}{|lll|}
244 \hline
245 & Holmes &\\
246 Burglary & T & F\\
247 \hline
248 T & $0.000153$ & $0.999847$\\
249 F & $0$ & $1$\\
250 \hline
251 \end{tabular}
252
253
254 \begin{figure}[H]
255 \caption{Bayesian network of burglars and houses}
256 \label{bnnetworkhouses}
257 \centering
258 %\includegraphics[scale=0.5]{d2.eps}
259 \end{figure}