-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathreport.tex
340 lines (308 loc) · 13.2 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage[english]{babel}
\usepackage{listings}
\usepackage{indentfirst}
\usepackage{multirow}
\usepackage{subcaption}
\usepackage[a4paper, left=3cm, right=3cm, top=3cm]{geometry}
\graphicspath{{diagrams/}}
\begin{document}
\begin{center}
\Huge\textbf{Using Self-Organizing Maps to solve Travelling Salesman
Problem}\\
\vspace{1cm}
\large\textsc{Maximilian Leonard Kleinhans \& Diego Vicente Martín}
\end{center}
\section{System Overview}
The goal of this system is to use Self-Organizing Maps to solve the Travelling
Salesman Problem. To achieve that, we will create a population of neurons that
is spatially distributed on a ring structure and as the algorithm progresses,
neurons are pulled towards the cities. By defining a 1D neighborhood in this 2D
space, we will make sure that the population behaves as an elastic ring that
stretches until it occupies all the cities, while it tries to keep the perimeter
as short as possible. Once we achieve it, we only have to traverse the cities
following the ring to obtain a TSP solution.\\
The main component of the system is located in \texttt{som.py}: First we scale
down the data, so that for each city coordinate $ c= (x, y) ~ 0 \le x,y \le 1$
holds true. Further is here the main execution loop located. In each iteration,
we pick a random city. Then we compute the best matching unit, that is closest
neuron to this city. That neuron, and its neighborhood, will be updated
following the formula:
$$
w_v(s+1) \; \leftarrow \;
w_v(s) + \alpha (s) \cdot \eta (u, v, s) \cdot (D(t) - w_v)
$$
Where $s$ is the iteration in which the neuron $w_u$ has been chosen as the
winner of the city $D(t)$, and the formula is used to update all the neurons
$w_v$ located in its neighborhood. The parameters in the formula are the
learning rate $\alpha(s)$, the neighborhood function $\eta(u, v, s)$. We also
have to remark that those last parameters decay over time. These weights
associated to each vector are initialized in our system to random values that
will be easily corrected through the first iterations, there is no point in
wasting time or computations in finding different ways to initialize the
network.\\
To achieve decaying, we will use different types of decay functions, that are
represented in the \texttt{decay.py} file: static decay (that maintains the same
value for that parameter through all the iterations), linear decay (that linearly
decreases the value of the parameter), or exponential decay (that exponentially
decays the value of the parameter). For convenience, these parameters have been
implemented as classes that can be passed to the computation methods.\\
The calculation of a TSP solution from a list of neuron is done as described in
chapter 4 in the compendium. That is, for each city we select the closest neuron
and then define the city order through the order of the selected neurons.\\
Also relevant to the system is to notice that we have implemented two different
neighborhood functions: \texttt{bubble}, constant in the while neighborhood, 0
elsewhere and \text{gaussian}, that creates a Gaussian distribution around the
winner. Both implementations can be find in the file
\texttt{neighborhood.py}.\\
Apart from these computation files, we also have implemented helper methods for
reading data sets from files and managing user input in \texttt{helper.py}.
Furthermore also methods for plotting and saving snapshots of the system at
different moments of the execution, to see how the system gets to a certain
solution.\\
\section{Tuning the System}
Once the system was implemented, we still had to work with it to get good
results. Different combinations of parameters lay different results,
and we had to be comprehensive when testing for parameters.\\
As a general conclusion, static decay is generally not a good decay approach to
use. By keeping the parameters with a static value during all the execution is
much harder to make the system converge into a solution. It is still possible to
get decent results, but overall it is not worth to use static decay. If, in the
other hand, we use linear, we can see the system converging much better to a
certain solution: in the beginning the system tries different strategies to then
focus on fixing the small details of the chosen one. More or less the same
approach can be seen with exponential, but thanks to its nature it is able to
stabilize much faster than linear. That's why, overall, the best decay strategy
to use is exponential although linear can also lay great results (specially when
applied to the learning rate alone). Another conclusion we can make is, that
with increasing number of cities linear performs worse and in case of the
\texttt{uruguay} data set with 734 cities we could not get decent results using
linear decay.\\
Regarding neighborhood functions, the one that lays the best result is the
Gaussian function. Although bubble does not lay bad results, we can see how
Gaussian moves the network in a much softer fashion, due to its gradient to the
edges versus the 1 or 0 values or bubble. Nevertheless bubble is much faster to
compute and for increasing number of cities it might be more suitable in terms
of runtime.\\
Other parameters to be tuned are the initial value of learning rates and
neighbourhood size, although that depends on great part on the data set and the
decay function we are going to use: static will need lower values and we will be
able to use higher values at the beginning if we use a decay strategy. We also
have to think about the size of the population of neurons. As a general rule, we
will need more neurons than cities so we can model the path through all the
cities in the map. As we have been able to test, the optimal size of the
population to get a network with a proper size is about 4-8 times greater than
the city population of the data set.\\
\newpage
By doing this tuning, we came to the conclusion that these were the best parameters for each of the decay strategies:
\begin{table}[ht]
\begin{center}
\begin{tabular}{| p{1.8cm}| c | c | c | c | c | c | c |}
\hline
Map & Decay & Neurons & $N$
& $\alpha_0$ (decay) & $r_0$ (decay)& TSP Dist.\\
\hline
\hline
\multirow{3}{*}{\textbf{\parbox{1.7cm}{Western Sahara}}}
& Static & 174 & 5000 & 0.3 & 5 & 34814.67 \\
& Linear & 232 & 500 & 0.7 (0.001) & 23 (0.04) & 27620.78 \\
& Exponential & 232 & 500 & 0.7 (0.999) & 23 (0.995)& 27601.17 \\
\hline
\multirow{3}{*}{\textbf{Djibouti}}
& Static & 356 & 5000 & 0.2 & 10 & 7692.15\\
& Linear & 712 & 5000 & 0.7 (0.0001)& 71 (0.014)& 6659.91 \\
& Exponential & 712 & 1000 & 0.7 (0.999)& 71 (0.995)& 6659.91 \\
\hline
\multirow{3}{*}{\textbf{Qatar}}
& Static & 1164 & 5000 & 0.4 & 50 & 14678.38 \\
& Linear & 1552 & 10000 & 0.7 (0.000065) & 155 (0.015) &10284.41 \\
& Exponential & 1552 & 5000 & 0.9 (0.9999)& 155 (0.997)& 10195.32 \\
\hline
\multirow{3}{*}{\textbf{Uruguay}}
& Static & 5872 & 10000 & 0.4 & 500 & 357201.05 \\
& Linear & 5872 & 10000 & 0.9 (0.000089)& 587 (0.055)& 141536.50 \\
& Exponential & 5872 & 10000 & 0.7 (0.9999)& 587 (0.999) & 86819.03 \\
\hline
\end{tabular}
\end{center}
\caption{Chosen parameters and results for TSP-SOM - $N$ is the number of iterations, $a_0$ the initial learning rate, $r_0$ the initial radius}
\label{tab:params}
\end{table}
In figures \ref{fig:sahara}, \ref{fig:djibouti}, \ref{fig:qatar} and \ref{fig:uruguay} are the TSP paths with different decay functions shown. The algorithm was executed with parameters shown in table \ref{tab:params}. Red dots illustrate cities and green dots neuron positions. We can see, that we consistently could obtain the best results with exponential decay, followed by linear. Apparently when not using exponential decay the algorithm is not able to refine the path in the end, resulting in inferior solutions. \\
Finally are in figures \ref{fig:bsahara}, \ref{fig:bdjibouti}, \ref{fig:bqatar} and \ref{fig:buruguay} the best runs illustrates, at the beginning in the middle and the final result of each run.
\begin{figure}
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,
width=\linewidth]{w_s.png}
\caption{Static decay}
\label{fig:ws}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,width=\linewidth]{w_l.png}
\caption{Linear decay}
\label{fig:wl}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,width=\linewidth]{w_e.png}
\caption{Exponential decay}
\label{fig:we}
\end{subfigure}
\caption{Results on \texttt{western\_sahara}}
\label{fig:sahara}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,
width=\linewidth]{d_s.png}
\caption{Static decay}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,width=\linewidth]{d_l.png}
\caption{Linear decay}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,width=\linewidth]{d_e.png}
\caption{Exponential decay}
\end{subfigure}
\caption{Results on \texttt{djibouti}}
\label{fig:djibouti}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,
width=\linewidth]{q_s.png}
\caption{Static decay}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,width=\linewidth]{q_l.png}
\caption{Linear decay}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,width=\linewidth]{q_e.png}
\caption{Exponential decay}
\end{subfigure}
\caption{Results on \texttt{qatar}}
\label{fig:qatar}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,
width=\linewidth]{u_s.png}
\caption{Static decay}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,width=\linewidth]{u_l.png}
\caption{Linear decay}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,width=\linewidth]{u_e.png}
\caption{Exponential decay}
\end{subfigure}
\caption{Results on \texttt{uruguay}}
\label{fig:uruguay}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,
width=\linewidth]{w_0.png}
\caption{Initial state}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,width=\linewidth]{w_250.png}
\caption{After 250 iterations}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,width=\linewidth]{w_500.png}
\caption{After 500 iterations}
\end{subfigure}
\caption{Best results on \texttt{western\_sahara} with exponential decay}
\label{fig:bsahara}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 1cm 4cm 1cm}, clip=true,
width=\linewidth]{d_0.png}
\caption{Initial state}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,width=\linewidth]{d_500.png}
\caption{After 500 iterations}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,width=\linewidth]{d_1000.png}
\caption{After 1000 iterations}
\end{subfigure}
\caption{Best results on \texttt{djibouti} with exponential decay}
\label{fig:bdjibouti}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={3cm 1.5cm 3cm 1.5cm}, clip=true,
width=\linewidth]{q_0.png}
\caption{Initial state}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,width=\linewidth]{q_2500.png}
\caption{After 2500 iterations}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={6cm 2cm 6cm 2cm}, clip=true,width=\linewidth]{q_5000.png}
\caption{After 5000 iterations}
\end{subfigure}
\caption{Best results on \texttt{qatar} with exponential decay}
\label{fig:bqatar}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,
width=\linewidth]{u_0.png}
\caption{Initial state}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,width=\linewidth]{u_5000.png}
\caption{After 5000 iterations}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={4cm 2cm 4cm 2cm}, clip=true,width=\linewidth]{u_10000.png}
\caption{After 10000 iterations}
\end{subfigure}
\caption{Best results on \texttt{uruguay} with exponential decay}
\label{fig:buruguay}
\end{figure}
\end{document}