Advertisement
Guest User

Exercise 3

a guest
Nov 23rd, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 7.29 KB | None | 0 0
  1. %Author of paper:
  2. % Jonathan Borgviken
  3.  
  4. \documentclass{article}
  5. \usepackage[utf8]{inputenc}
  6.  
  7. \usepackage{authblk}
  8. \usepackage{listings}
  9. \lstset{showstringspaces=false, language=Matlab, frame=shadowbox, frameround=tftf}
  10.  
  11. \usepackage{graphicx} % Used to handle graphics
  12. \graphicspath{}
  13.  
  14. \title{Perspective Course [Exercise 3]}
  15. \author{Jonathan Borgviken}
  16. \author{Christoffer Brun}
  17. \author{Pajtim Cerimi}
  18. \author{Niklas Ling}
  19. \author{Lolita Mageramova}
  20. \affil{School of Information Science, Computer and Electrical Engineering, Halmstad University}
  21.  
  22. \begin{document}
  23.  
  24. \maketitle
  25.  
  26. \section*{Task 1}
  27. In this task we were supposed to explain how a given \textit{heuristic}\footnote{A \textit{heuristic} is in this context a function which evaluates a given board position.} works. We were also supposed to work out \textbf{why} it works better than letting a computer do random moves to try and solve the puzzle. In addition to this we were also supposed to provide examples of boards with higher, and lower \textit{heuristic score}\footnote{\textit{Heuristic score} is the function value of a \textit{heuristic} function.}.
  28. \par
  29. For our purposes, let us define the two artificial intelligences discussed in this section. If we let our first \textit{AI}\footnote{\textit{AI} is an abbreviation for artificial intelligence} in \textbf{MATLAB} be defined as
  30. \begin{lstlisting}
  31.  function direction = myAI(~)
  32.  
  33.  d = {'up', 'down', 'right', 'left'};
  34.  direction = d{randi(4)};
  35.  
  36.  end
  37. \end{lstlisting}
  38. then what we have is an \textit{AI} which does not use any information available. It is, most would say, dumb in that sense.
  39. \par
  40. Our second \textit{AI}, let us refer to it as the smarter \textit{AI}, will be using a \textit{heuristic}, $h$, to its advantage. Without providing source code to the \textit{AI}, let us describe the \textit{AI} to base its decisions solely on our heuristic function $h$. In short, the \textit{AI} will let $h$ evaluate the board when asked to, hypothetically, make a move \textbf{up}, \textbf{down}, \textbf{left}, and \textbf{right} respectively. The move with the highest \textit{heuristic score} will be the move our \textit{AI} decide to do.
  41. \newpage
  42. \noindent If we let \textbf{B} be a matrix representing our board, in \textit{logarithmic scale}\footnote{In practice, we have converted our board from squares with values $2^k$ to squares with values of $k$ using the logarithmic function with base 2.}, our heuristic score is calculated according to $h$ as
  43. \begin{lstlisting}
  44.  function u = heuristic1(B)
  45.  u  =  - sum(B(:));  
  46.  end
  47. \end{lstlisting}
  48. And as such, one could draw a parallel explanation from the perspective of a matrix \textbf{A} representing the board in its true form, in a more mathematical approach. Let \textbf{A} be an \textbf{r} (rows) times \textbf{c} (columns) matrix.
  49. \[h(A) = -\sum^r_{i=1} \sum^c_{j=1}\log_2 A_{i,j} = -\left(\log_2 A_{1,1} + \log_2 A_{1,2} + \ldots + \log_2 A_{r,c}\right)\]
  50. \par
  51. Let us now provide some examples to show you what a board with higher, and lower heuristic score looks like. For simplicity, we will provide examples for our logarithmic matrix, i.e. just like our matrix \textbf{B}. Study the following matrices.
  52. \begin{center}
  53. $X_1 =$
  54.  \begin{tabular}{c|c|c}
  55.    1 & 2 & 2  \\
  56.    \hline
  57.    3 & 0 & 0  \\
  58.    \hline
  59.    2 & 0 & 0
  60.  \end{tabular}
  61.  $X_2 =$
  62.  \begin{tabular}{c|c|c}
  63.    2 & 1 & 2  \\
  64.    \hline
  65.    3 & 0 & 0  \\
  66.    \hline
  67.    2 & 0 & 2
  68.  \end{tabular}
  69. \end{center}
  70. \begin{center}
  71.  $X_3 =$
  72.  \begin{tabular}{c|c|c}
  73.    5 & 3 & 2  \\
  74.    \hline
  75.    2 & 6 & 3  \\
  76.    \hline
  77.    2 & 3 & 1
  78.  \end{tabular}
  79.  $X_4 =$
  80.  \begin{tabular}{c|c|c}
  81.    4 & 5 & 5  \\
  82.    \hline
  83.    3 & 6 & 2  \\
  84.    \hline
  85.    2 & 1 & 3
  86.  \end{tabular}
  87. \end{center}
  88. The portrayed matrices' heuristic scores are evaluated as
  89. $$h(X_1) = -10,\qquad h(X_2) = -12$$
  90. $$h(X_3) = -27,\qquad h(X_4) = -31$$
  91. With this said, matrices $X_1$, and $X_2$ are the preferred boards for our smarter \textit{AI}. Their heuristic score is higher, and are therefore more sought-after. Matrices $X_3$, and $X_4$ on the other hand have, relatively, low heuristic score compared to our first two matrices, and as such are not preferred boards for our smarter \textit{AI}.
  92. \newpage
  93. \section*{Task 2}
  94. \begin{figure}[h]
  95.  \centering
  96.  \includegraphics[scale=0.7]{hist_AI4.png}
  97.  \caption{Histogram for $h_0$}
  98.  \label{h0}
  99. \end{figure}
  100. \begin{figure}[h!]
  101.  \centering
  102.  \includegraphics[scale=0.7]{hist_AI5.png}
  103.  \caption{Histogram for $h_1$}
  104.  \label{h1}
  105. \end{figure}
  106. \newpage
  107. \noindent In this task we were asked to first compare two heuristics, see fig.~\ref{h0} and fig.~\ref{h1}. The first heuristic $h_0$ is the heuristic used in our smart \textit{AI} in the last section of this report. Our second heuristic $h_1$ is a heuristic which evaluates a board with high amounts of empty squares to have a high heuristic score.
  108. \par
  109. The two histograms portrayed are created from data running both $h_0$, and $h_1$ three hundred times, respectively. Let us compare the two simulations.
  110. \begin{center}
  111.  \begin{tabular}{|c| c c c|}
  112.    \hline
  113.    & Mean score & Max score & Highest block\\
  114.    \hline
  115.    $h_0$ & 4996 & 9170 & 512  \\
  116.    \hline
  117.    $h_1$ & 3848 & 7107 & 512  \\
  118.    \hline
  119.  \end{tabular}
  120. \end{center}
  121. From this we see that $h_0$ outperformed $h_1$ by far. Its mean score is 1148 points above, and its max score, whilst not too much of a difference, outperformed $h_1$ by 2063 points. However, we see that they both achieved 512 as their highest block.
  122. \par
  123. Further we were asked to create a new heuristic, using both $h_0$, and $h_1$. In the simplest way, we were to create a heuristic $h_{\alpha} = (1-\alpha)h_0+\alpha h_1$, where $\alpha\in[0,1]$. We went ahead and tried three values for $\alpha$, namely $\alpha = 0.25, 0.5, 0.75$. To test these three new heuristics, we tried simulating them three hundred time each.
  124. \par
  125. Take a look at each histogram on the following two pages, and then let us compare the results. We will, just as before, base our results on three parameters. First of all, how the mean score compares to the other $\alpha$ values, our other two parameters are the max score and their highest block.
  126. \begin{center}
  127.  \begin{tabular}{|c| c c c|}
  128.    \hline
  129.    $\alpha$& Mean score & Max score & Highest block\\
  130.    \hline
  131.    .25 & 5636 & 10400 & 1024  \\
  132.    \hline
  133.    .50 & 6160 & 11380 & 1024  \\
  134.    \hline
  135.    .75 & 4222 & 7644 & 512 \\
  136.    \hline
  137.  \end{tabular}
  138. \end{center}
  139. From this we see that $\alpha = 0.5$ gave us the best results. Comparing with the aforementioned heuristics ($h_0$ and $h_1$) one sees that using both heuristics yields better outcomes in all three categories. Experimenting more, one would most indubitably find a better value for $\alpha$, a quick glance gives the impression it may exist such a value $\beta \in\,].25,.50[$.
  140. \newpage
  141. \begin{figure}
  142.  \centering
  143.  \includegraphics[scale=0.7]{hist_025.png}
  144.  \caption{Histogram for $\alpha = 0.25$}
  145.  \label{h025}
  146. \end{figure}
  147. \begin{figure}
  148.  \centering
  149.  \includegraphics[scale=0.7]{hist_05.png}
  150.  \caption{Histogram for $\alpha = 0.5$}
  151.  \label{h05}
  152. \end{figure}
  153. \begin{figure}
  154.  \centering
  155.  \includegraphics[scale=0.7]{hist_075.png}
  156.  \caption{Histogram for $\alpha = 0.75$}
  157.  \label{h075}
  158. \end{figure}
  159.  
  160. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement