# Time Series Clustering of Online Gambling Activities for Addicted Users' Detection
## 3 Experimental Phase
### Experimental Settings  
The clustering allows performing time series K-means on the data sets obtained from the data preparation phase. The optimal value of \(k\), the number of clusters to form, can be obtained using the elbow method. The silhouette score is also used to assess the consistency of the results given by the elbow method. The strategy used to obtain the results was the following: the elbow method was used, with \(k\) ranging from two to eight, to obtain an indication regarding the optimal number of clusters to create; subsequently, the silhouette score was calculated using the possible optimal values of \(k\) indicated by the previous method, aiming at assessing the consistency of the previous results and providing a further indication about the ideal value of \(k\). After that, the clustering algorithm was performed with the chosen \(k\). The experimental phase was performed on the Galileo supercomputer. Galileo has currently 102,236 core compute nodes. Each one contains 218 core Intel Xeon E5-2697 v4 (Broadwell) at 2.30 GHz. All the compute nodes have 128 GB of memory. In more detail, this supercomputer has the following technical specifications:  
* Model: Lenovo NeXtScale
* Architecture: Linux Infiniband Cluster
* Nodes: 1022
* Processors: 2 \(\times\) 18-cores Intel Xeon E5-2697 v4 (Broadwell) at 2.30 GHz
* Cores: 36 cores/node
* RAM: 128 GB/node, 3.5 GB/core
* Internal Network: Intel OmniPath, 100 Gb/s
* Peak performance single node: 1.3 TFlop/s
* Peak Performance: 1.5 PFlop/s
* Accelerators: 60 nodes equipped with 1 Nvidia K80 GPU and 2 nodes equipped with 1 Nvidia V100 GPU  
We relied on the implementation of time series k-means available in the tslearn Python package. However, we had to modify some parts of the library source code due to the following two reasons:  
* multiple calls to a data preparation function. * part of the computation of the algorithm does not take place in parallel. The first problem was encountered during the first application of the algorithm: the calculation of the distance matrices was interrupted after a few minutes of computation \begin{table}
\begin{tabular}{c c c c c} \hline \hline  & \multicolumn{4}{c}{**Data Preparation**} \\ \hline
**Type of Game** & **\# of Raw Datasets** & **Total Size Raw Datasets** & **Size Final Dataset** & **\# of Time Series** \\ \hline Sports & 7 & 5.40 GB & 101 MB & 15,081 \\ Black Jack & 5 & 481 MB & 72.6 MB & 5177 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Raw data set and processed data set. due to a memory error. We found that this type of error was caused by multiple calls to the function to_time_series_data set(\(\cdot\)) that transforms a time series data set so that it fits the format used in tslearn models. This function was called at each iteration of the k-means algorithm and also at each iteration of the barycenter computation process, causing memory and performance problems. This issue was addressed by eliminating redundant calls to this function and keeping only the first. After solving this problem, we realized that the algorithm continued to have a very high execution time, and we discovered that only the computation of the distance matrices (DTW) actually took place in parallel, while the DTW Barycenter Averaging (DBA) part took place in serial. To solve this problem, it was decided to completely rewrite the code related to the DBA part, with the aim of making it efficient, in terms of memory and computational time. The dynamic barycenter averaging procedure is mainly composed of three different functions:  
* _mm_assignment: computes item assignment based on DTW alignments and returns cost as a bonus. * _mm_valence_warping: computes valence and warping matrices from paths, returning the sum of diagonals and a list of matrices. * _mm_update_barycenter: updates the barycenters.