From fc9d1cf4ee511f5015abc3fed9a80a2d76afbcd6 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 6 Jan 2015 12:21:51 +0100 Subject: [PATCH] goede berekening --- report/ass2-1.tex | 84 +++++++++++++++++++++++++++++++++++++++++------ report/report.tex | 3 ++ 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/report/ass2-1.tex b/report/ass2-1.tex index 7f2b15f..2c7e5ce 100644 --- a/report/ass2-1.tex +++ b/report/ass2-1.tex @@ -23,21 +23,21 @@ Table~\ref{probdist} \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} @@ -103,8 +103,72 @@ Table~\ref{probdist} \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. diff --git a/report/report.tex b/report/report.tex index aa9ef93..d74001b 100644 --- a/report/report.tex +++ b/report/report.tex @@ -3,6 +3,9 @@ \usepackage{graphicx} \usepackage{minted} \usepackage{float} +\usepackage{enumerate} +\usepackage{amsmath} +\usepackage{amssymb} \usepackage[hidelinks]{hyperref} \author{ -- 2.20.1