update
[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 chose to introduce a \textit{Noisy OR} to
4 represent the causal independence of \textit{Burglar} and \textit{Earthquake}
5 on \textit{Alarm}. The visual representation of the network is visible in
6 Figure~\ref{bnetwork21}
7
8 \begin{figure}[H]
9 \caption{Bayesian network, visual representation}
10 \label{bnetwork21}
11 \centering
12 \includegraphics[scale=0.5]{d1.eps}
13 \end{figure}
14
15 As for the probabilities for \textit{Burglar} and \textit{Earthquake} we chose
16 to calculate them using days the unit. Calculation for the probability of a
17 \textit{Burglar} event happening at some day is then this(assuming a gregorian
18 calendar and leap days).
19 $$\frac{1}{365 + 0.25 - 0.01 - 0.0025}=\frac{1}{365.2425}$$
20
21 This gives the following probability distributions visible in
22 Table~\ref{probdist}
23
24 \begin{table}[H]
25 \label{probdist}
26 \begin{tabular}{|l|l|}
27 \hline
28 & Earthquake\\
29 \hline
30 T & $0.0027$\\
31 F & $0.9973$\\
32 \hline
33 \end{tabular}
34 %
35 \begin{tabular}{|l|l|}
36 \hline
37 & Burglar\\
38 \hline
39 T & $0.0027$\\
40 F & $0.9973$\\
41 \hline
42 \end{tabular}
43
44 \begin{tabular}{|l|ll|}
45 \hline
46 & \multicolumn{2}{c|}{$I_1$}\\
47 Earthquake & T & F\\
48 \hline
49 T & $0.2$ & $0.8$\\
50 F & $0$ & $1$\\
51 \hline
52 \end{tabular}
53 \begin{tabular}{|l|ll|}
54 \hline
55 & \multicolumn{2}{c|}{$I_2$}\\
56 Burglar & T & F\\
57 \hline
58 T & $0.95$ & $0.05$\\
59 F & $0$ & $1$\\
60 \hline
61 \end{tabular}
62 \begin{tabular}{|ll|ll|}
63 \hline
64 && \multicolumn{2}{c|}{Alarm}\\
65 $I_1$ & $I_2$ & T & F\\
66 \hline
67 T & T & $1$ & $0$\\
68 T & F & $1$ & $0$\\
69 F & T & $1$ & $0$\\
70 F & F & $0$ & $1$\\
71 \hline
72 \end{tabular}
73
74 \begin{tabular}{|l|ll|}
75 \hline
76 & \multicolumn{2}{c|}{Watson}\\
77 Alarm & T & F\\
78 \hline
79 T & $0.8$ & $0.2$\\
80 F & $0.4$ & $0.6$\\
81 \hline
82 \end{tabular}
83 \begin{tabular}{|l|ll|}
84 \hline
85 & \multicolumn{2}{c|}{Gibbons}\\
86 Alarm & T & F\\
87 \hline
88 T & $0.99$ & $0.01$\\
89 F & $0.04$ & $0.96$\\
90 \hline
91 \end{tabular}
92 \begin{tabular}{|l|ll|}
93 \hline
94 & \multicolumn{2}{c|}{Radio}\\
95 Earthquake & T & F\\
96 \hline
97 T & $0.9998$ & $0.0002$\\
98 F & $0.0002$ & $0.9998$\\
99 \hline
100 \end{tabular}
101 \end{table}
102
103 \section{Implementation}
104 This distribution results in the \textit{AILog} code in Listing~\ref{alarm.ail}
105
106 \begin{listing}[H]
107 \label{alarm.ail}
108 \caption{alarm.ail}
109 \inputminted[linenos,fontsize=\footnotesize]{prolog}{./src/alarm.ail}
110 \end{listing}
111
112 \section{Queries}
113 Using the following queries the probabilities or as follows:\\
114 \begin{enumerate}[a)]
115 \item $P(\text{Burglary})=
116 0.002737757092501968$
117 \item $P(\text{Burglary}|\text{Watson called})=
118 0.005321803679438259$
119 \item $P(\text{Burglary}|\text{Watson called}\wedge\text{Gibbons called})=
120 0.11180941544755249$
121 \item $P(\text{Burglary}|\text{Watson called}\wedge\text{Gibbons called}
122 \wedge\text{Radio})=0.01179672476662423$
123 \end{enumerate}
124
125 \begin{listing}[H]
126 \begin{minted}[fontsize=\footnotesize]{prolog}
127 ailog: predict burglar.
128 Answer: P(burglar|Obs)=0.002737757092501968.
129 [ok,more,explanations,worlds,help]: ok.
130
131 ailog: observe watson.
132 Answer: P(watson|Obs)=0.4012587986186947.
133 [ok,more,explanations,worlds,help]: ok.
134
135 ailog: predict burglar.
136 Answer: P(burglar|Obs)=[0.005321803679438259,0.005321953115441623].
137 [ok,more,explanations,worlds,help]: ok.
138
139 ailog: observe gibbons.
140 Answer: P(gibbons|Obs)=[0.04596053565368094,0.045962328885721306].
141 [ok,more,explanations,worlds,help]: ok.
142
143 ailog: predict burglar.
144 Answer: P(burglar|Obs)=[0.11180941544755249,0.1118516494624678].
145 [ok,more,explanations,worlds,help]: ok.
146
147 ailog: observe radio.
148 Answer: P(radio|Obs)=[0.02582105837443645,0.025915745316785182].
149 [ok,more,explanations,worlds,help]: ok.
150
151 ailog: predict burglar.
152 Answer: P(burglar|Obs)=[0.01179672476662423,0.015584580594335082].
153 [ok,more,explanations,worlds,help]: ok.
154 \end{minted}
155 \end{listing}
156
157 \section{Comparison with manual calculation}
158 Querying the \textit{Alarm} variable gives the following answer
159 \begin{minted}{prolog}
160 ailog: predict alarm.
161 Answer: P(alarm|Obs)=0.0031469965467367292.
162
163 [ok,more,explanations,worlds,help]: ok.
164 \end{minted}
165
166 Using formula: $P(i_1|C_1)+P(i_2|C_2)(1-P(i_1|C_1))$ we can calculate the
167 probability of the \textit{Alarm} variable using variable elimination. This
168 results in the following answer:
169 $$0.2*0.0027+0.95*0.0027*(1-0.2*0.0027)=0.00314699654673673$$
170 TODOOOOOOOOOOO
171
172 \newpage
173 \section{Burglary problem with extended information}
174 $P(burglary)\cdot\left(
175 P(\text{first house is holmes'})+
176 P(\text{second house is holmes'})+
177 P(\text{third house is holmes'})\right)=\\
178 0.5102041\cdot\left(
179 \frac{1}{10000}+
180 \frac{9999}{10000}\cdot\frac{1}{9999}+
181 \frac{9999}{10000}\cdot\frac{9998}{9999}\cdot\frac{1}{9998}\right)=
182 \frac{3}{19600}\approx0.000153$
183
184 \section{Bayesian networks}
185 A bayesian network representation of the burglary problem with a multitude of
186 houses and burglars is possible but would be very big and tedious because all
187 the constraints about the burglars must be incorporated in the network.
188 The network would look something like in figere~\ref{bnnetworkhouses}
189 accompanied with the probability distributions below.
190
191 \begin{tabular}{|l|l|}
192 \hline
193 Joe &\\
194 \hline
195 T & $\nicefrac{5}{7}$\\
196 F & $\nicefrac{2}{7}$\\
197 \hline
198 \end{tabular}
199 \begin{tabular}{|l|l|}
200 \hline
201 William &\\
202 \hline
203 T & $\nicefrac{5}{7}$\\
204 F & $\nicefrac{2}{7}$\\
205 \hline
206 \end{tabular}
207 \begin{tabular}{|l|l|}
208 \hline
209 Jack & \\
210 \hline
211 T & $\nicefrac{5}{7}$\\
212 F & $\nicefrac{2}{7}$\\
213 \hline
214 \end{tabular}
215 \begin{tabular}{|l|l|}
216 \hline
217 Averall & \\
218 \hline
219 T & $\nicefrac{5}{7}$\\
220 F & $\nicefrac{2}{7}$\\
221 \hline
222 \end{tabular}
223
224 \begin{tabular}{|llll|ll|}
225 \hline
226 & & & & Burglary &\\
227 Joe & William & Jack & Averall & T & F\\
228 \hline
229 F& F& F& F & $0$ & $1$\\
230 F& F& F& T & $0$ & $1$\\
231 F& F& T& F & $0$ & $1$\\
232 F& F& T& T & $0$ & $1$\\
233 F& T& F& F & $0$ & $1$\\
234 F& T& F& T & $0$ & $1$\\
235 F& T& T& F & $0$ & $1$\\
236 F& T& T& T & $0$ & $1$\\
237 T& F& F& F & $0$ & $1$\\
238 T& F& F& T & $0$ & $1$\\
239 T& F& T& F & $1$ & $0$\\
240 T& F& T& T & $0$ & $1$\\
241 T& T& F& F & $1$ & $0$\\
242 T& T& F& T & $0$ & $1$\\
243 T& T& T& F & $1$ & $0$\\
244 T& T& T& T & $1$ & $0$\\
245 \hline
246 \end{tabular}
247 \begin{tabular}{|lll|}
248 \hline
249 & Holmes &\\
250 Burglary & T & F\\
251 \hline
252 T & $0.000153$ & $0.999847$\\
253 F & $0$ & $1$\\
254 \hline
255 \end{tabular}
256
257 \begin{figure}[H]
258 \caption{Bayesian network of burglars and houses}
259 \label{bnnetworkhouses}
260 \centering
261 \includegraphics[scale=0.5]{d2.eps}
262 \end{figure}