\begin{table}[H]
\label{probdist}
- \begin{tabular}{|l|ll|}
+ \begin{tabular}{|l|l|}
\hline
- & \multicolumn{2}{c|}{Earthquake}\\
+ & Earthquake\\
\hline
- T & $0.0027$ & $0.9972$ \\
- F & $0.9973$ & $0.0027$\\
+ T & $0.0027$\\
+ F & $0.9973$\\
\hline
\end{tabular}
%
- \begin{tabular}{|l|ll|}
+ \begin{tabular}{|l|l|}
\hline
- & \multicolumn{2}{c|}{Burglar}\\
+ & Burglar\\
\hline
- T & $0.0027$ & $0.9973$ \\
- F & $0.9973$ & $0.0027$\\
+ T & $0.0027$\\
+ F & $0.9973$\\
\hline
\end{tabular}
\section{Implementation}
This distribution results in the \textit{AILog} code in Listing~\ref{alarm.ail}
-\begin{listing}
+\begin{listing}[H]
\label{alarm.ail}
- \caption{Alarm.ail}
+ \caption{alarm.ail}
\inputminted[linenos,fontsize=\footnotesize]{prolog}{./src/alarm.ail}
\end{listing}
+
+\section{Queries}
+Using the following queries the probabilities or as follows:\\
+\begin{enumerate}[a)]
+ \item $P(\text{Burglary})=
+ 0.002737757092501968$
+ \item $P(\text{Burglary}|\text{Watson called})=
+ 0.005321803679438259$
+ \item $P(\text{Burglary}|\text{Watson called}\wedge\text{Gibbons called})=
+ 0.11180941544755249$
+ \item $P(\text{Burglary}|\text{Watson called}\wedge\text{Gibbons called}
+ \wedge\text{Radio})=0.01179672476662423$
+\end{enumerate}
+
+\begin{listing}[H]
+ \begin{minted}[fontsize=\footnotesize]{prolog}
+ailog: predict burglar.
+Answer: P(burglar|Obs)=0.002737757092501968.
+ [ok,more,explanations,worlds,help]: ok.
+
+ailog: observe watson.
+Answer: P(watson|Obs)=0.4012587986186947.
+ [ok,more,explanations,worlds,help]: ok.
+
+ailog: predict burglar.
+Answer: P(burglar|Obs)=[0.005321803679438259,0.005321953115441623].
+ [ok,more,explanations,worlds,help]: ok.
+
+ailog: observe gibbons.
+Answer: P(gibbons|Obs)=[0.04596053565368094,0.045962328885721306].
+ [ok,more,explanations,worlds,help]: ok.
+
+ailog: predict burglar.
+Answer: P(burglar|Obs)=[0.11180941544755249,0.1118516494624678].
+ [ok,more,explanations,worlds,help]: ok.
+
+ailog: observe radio.
+Answer: P(radio|Obs)=[0.02582105837443645,0.025915745316785182].
+ [ok,more,explanations,worlds,help]: ok.
+
+ailog: predict burglar.
+Answer: P(burglar|Obs)=[0.01179672476662423,0.015584580594335082].
+ [ok,more,explanations,worlds,help]: ok.
+ \end{minted}
+\end{listing}
+
+\section{Comparison with manual calculation}
+Querying the \textit{Alarm} variable gives the following answer
+\begin{minted}{prolog}
+ ailog: predict alarm.
+ Answer: P(alarm|Obs)=0.0031469965467367292.
+ [ok,more,explanations,worlds,help]: ok.
+\end{minted}
+
+Using formula: $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:
+$$0.2*0.0027+0.95*0.0027*(1-0.2*0.0027)=0.00314699654673672941001347$$
+
+There is a slight difference in probability. This is probably due to the
+precision of the \textit{AILog} module. The manual calculation was done with
+arbitrary precision. Manual calculation takes a lot longer and therefore one
+can prefer the \textit{AILog} method when speed is of an essence. When
+precision is necessary manual calculation is preferred.