-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.tex
201 lines (182 loc) · 7.79 KB
/
report.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
\documentclass[unicode,11pt,a4paper,oneside,numbers=endperiod,openany]{scrartcl}
\newcommand\tab[1][0.5cm]{\hspace*{#1}}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{seqsplit}
\usepackage{float}
\usepackage{booktabs}
\usepackage{subcaption}
\usepackage{adjustbox}
%New colors defined below
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.98,0.98,0.98}
%Code listing style named "mystyle"
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour}, commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
numbers=none
}
\lstdefinestyle{base}{
language=C,
emptylines=1,
breaklines=true,
basicstyle=\ttfamily\color{black},
moredelim=**[is][\color{red}]{@}{@},
}
\lstset{style=mystyle}
\newcommand\MyBox[2]{
\fbox{\lower0.75cm
\vbox to 1.7cm{\vfil
\hbox to 1.7cm{\hfil\parbox{1.4cm}{#1\\#2}\hfil}
\vfil}%
}%
}
\input{assignment.sty}
\usepackage{subcaption}
\begin{document}
\setassignment
\serieheader{Particle Methods}{2023}{Student: Filippo Casari}{}{Report for Assignment 1}{}
\newline
\section*{Introduction}
My first approach for this assignment was using python.
Although the logic behing the code seemed to work, by using $H>4$ as parameter, I got some
troubles about the performances of the program. Consequently, I switched to Matlab to exploit multithreading and GPU power. \\
The program asks to users to decide whether to save the result image, to apply random search, and to choose the number H as well.
\section*{Implementation}
I used 2 strategies for implementing the algorithm for moving the agents:
\begin{itemize}
\item \textbf{Random search}: The unhappy agents move to a random position in the grid. The direction is chosen randomly.
\item \textbf{NN}: Nearest Neiighbour. The unhappy agents move to the nearest empty position in the grid. The direction goes from the left to the right, and from the top to the bottom.
\end{itemize}
It could happen for large number of H that the algorithm is going to converge very slowly or in the case of NN never converges. For this reason, I implemented a so-called \textbf{early stopping} condition.
It consists of checking if the number of unhappy agents is the same for 1000 consecutive iterations. If this happens, the algorithm stops. \\
Speaking about the best strategy, it turns out that the Random one is the best. Indeed, sometimes the NN does not let the algorithm converge to 100 percent of happiness. \\
In contrast, the Random movement agent strategy for large H takes very long time to converge, and this leads to an early stopping criterion.\\
I show below one picture of the inital conditions (generated randomly).
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{images/Initial_Condition_1.png}
\caption{Initial conditions}
\label{fig:image0}
\end{figure}
\section*{Results}
When the algorithm reaches 100 percent of happiness, the result image shows a really nice patterns which look like a sort of segregation between green and red points.
\begin{figure}[H]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{results/iterations_5_H_1_random_1.png}
\caption{H 1}
\label{fig:image1}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{results/iterations_16_H_2_random_1.png}
\caption{H 2}
\label{fig:image2}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{results/iterations_64_H_3_random_1.png}
\caption{H 3}
\label{fig:image3}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{results/iterations_196_H_4_random_1.png}
\caption{H 4}
\label{fig:image4}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{results/iterations_1888_H_5_random_1.png}
\caption{H 5}
\label{fig:image5}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\adjustbox{max height=\dimexpr\textheight-9\baselineskip}{
\includegraphics[width=\textwidth]{results/iterations_2261_H_6_random_1.png}}
\caption{H 6}
\label{fig:image6}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{results/iterations_1056_H_7_random_1.png}
\caption{H 7}
\label{fig:image7}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{results/iterations_1002_H_8_random_1.png}
\caption{H 8}
\label{fig:image8}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{results/iterations_1002_H_9_random_1.png}
\caption{H 9}
\label{fig:image9}
\end{subfigure}
\end{figure}
I reported above the grids at the end of the algorithm for different values of H and Random=True.
I also saved the grids for Random=False (NN) in "results" directory. \\
It turns out that with $H>5$ (from image 6) the segregation is not so clear or there isn't at all. \\
Below I reported also the level (percentage) of happiness for each case. If the level si not 100 percent is because maybe the algorithm converges to a local "minimum" or because of the early stopping criterion was met. This could happen if the happiness did not improve within a time window of 1000 iterations.
\begin{figure}[H]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{Convergence/ConvergenceH1Random_1.png}
\caption{H 1}
\label{fig:image10}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{Convergence/ConvergenceH2Random_1.png}
\caption{H 2}
\label{fig:image11}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{Convergence/ConvergenceH3Random_1.png}
\caption{H 3}
\label{fig:image12}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{Convergence/ConvergenceH4Random_1.png}
\caption{H 4}
\label{fig:image13}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{Convergence/ConvergenceH5Random_1.png}
\caption{H 5}
\label{fig:image14}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{Convergence/ConvergenceH6Random_1.png}
\caption{H 6}
\label{fig:image15}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{Convergence/ConvergenceH7Random_1.png}
\caption{H 7}
\label{fig:image16}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{Convergence/ConvergenceH8Random_1.png}
\caption{H 8}
\label{fig:image17}
\end{subfigure}
\end{figure}
As one can see the heppiness with $H<6$
converges whereas with H higher level is
going up and down without reaching a good level of happiness. \\
\end{document}