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