Energy-aware KNN for EEG Classification: A Case Study in Heterogeneous Platforms
Abstract
Spanish Ministry of Science, Innovation, and Universities under grants PGC2018-098813-B-C31 and PID2022-137461NB-C32
Full text
Energy-aware KNN for EEG Classification: A Case Study in Heterogeneous Platforms Juan Jos´e Escobar1[0000−0002−4258−0264], Francisco Rodr´ıguez2, Rukiye Savran Kızıltepe3[0000−0002−3862−7621], Beatriz Prieto2[0000−0003−0187−6533], Dragi Kimovski4[0000−0001−5933−3246], Andr´es Ortiz5[0000−0003−2690−1926], and Miguel Damas2[0000−0003−2599−8076] 1Department of Software Engineering, CITIC, University of Granada, Spain [email protected] 2Department of Computer Engineering, Automation, and Robotics, CITIC, University of Granada, Spain [email protected] {beap,mdamas}@ugr.es 3Sofware Engineering, Karadeniz Technical University, Turkey [email protected] 4Institute of Information Technology, University of Klagenfurt, Austria [email protected] 5Department of Communications Engineering, University of M´alaga, Spain [email protected] Abstract. The growing energy consumption caused by IT is forcing application developers to consider energy efficiency as one of the fundamental design parameters. This parameter acquires great relevance in HPC systems when running artificial neural networks and Machine Learning applications. Thus, this article shows an example of how to estimate and consider energy consumption in a real case of EEG classification. An efficient and distributed implementation of the KNN algorithm that uses mRMR as a feature selection technique to reduce the dimensionality of the dataset is proposed. The performance of three different workload distributions is analyzed to identify which one is more suitable according to the experimental conditions. The proposed approach outperforms the classification results obtained by previous works. It achieves an accuracy rate of 88.8% and a speedup of 74.53 when running on a multi-node heterogeneous cluster, consuming only 13.38% of the energy of the sequential version. Keywords: Parallel and distributed programming ·Heterogeneous clusters ·Energy-aware computing ·EEG classification ·KNN ·mRMR. 1 Introduction Greenhouse gas emissions caused by energy consumption associated with the proliferation of equipment, applications, and computer programs is growing worryingly. There are estimates that determine that ICT could contribute up to
2 J.J. Escobar et al. 23% of global greenhouse gas emissions in 2030 [8]. To reduce consumption, it is necessary to address the problem simultaneously from different approaches. One of them is to analyze the energy consumption of programs and try to run them in the most energy-efficient configuration. The other one, to exploit the qualities of distributed and heterogeneous parallel platforms. Currently, when designing applications, it is not enough to consider only the precision of the results and execution time, but energy efficiency must also be considered as a fundamental parameter. Among the most complex applications in terms of execution time and energy consumption are those related to Machine Learning. These High-Performance Computing (HPC) applications often have to process large amounts of data (Big Data) and are characterized by high algorithmic complexity. Therefore, this work shows the results of an investigation on the energy efficiency of a bioengineering application, based on the KNN (K-Nearest Neighbors) algorithm, capable of exploiting the qualities of a distributed and heterogeneous parallel platform, which also takes into account performance in terms of accuracy of results and execution time. After this introduction, the rest of the article is structured as follows: Section 2 refers to different works in the literature related to the topic addressed. Section 3 details the proposed KNN implementation for EEG classification. Then, Section 4 analyzes the experimental results and discusses the importance of energy awareness in HPC systems. Finally, Section 5 provides the conclusions. 2 Background The use of artificial neural networks and Machine Learning techniques in bioinformatics has experienced exponential growth in recent years. Among other causes is the considerable growth in the size of biological datasets, as in the case of Electroencephalography. Bioinformatics, among other topics, deals with EEG signals, which represent the electrical activity of different parts of the brain. EEG signals are used to aid in the diagnosis of disorders such as schizophrenia [1], epilepsy [4], dyslexia [19], depression [17], autism [11], or sleep problems [18]. They are also used to classify motor functions of the nervous system, such as movement of limbs or eyes [16], and for the classification of human emotions [14]. However, the main problem of working with EEG signals is their high dimensionality, which makes their correct classification difficult since most of them do not contain relevant information. Therefore, it is important to apply feature selection techniques to obtain the most relevant ones. One of the fundamental objectives of the artificial neural networks and Machine Learning is to recognize patterns in these signals for their subsequent classification. Indeed, the EEG classification problem is usually addressed through various Machine Learning methods, such as regression or clustering algorithms. In this work, a KNN algorithm for instance-based supervised classification has been considered due to its good performance in this type of applications. The KNN algorithm generally tries to classify the instances (patterns) by assigning
Energy-aware KNN for EEG Classification in Heterogeneous Platforms 3 them to the predominant class among their Knearest neighbors. The steps required to classify each new instance are: 1. Calculate the distance between the instance to classify and the rest of training samples. In this work, the Euclidean distance has been used. 2. Sort the distances in increasing order. 3. Identify the predominant class among the nearest Kdistances (neighbors). 4. Assign the new instance to the predominant class. 3 The Proposed KNN for EEG Classification EEG classification has been approached using the KNN algorithm together with the minimum Redundancy Maximum Relevance (mRMR) technique [12], which sorts the NFfeatures of the dataset from least to most relevant. This approach helps to deal with the dimensionality problem [15] and to reduce computation time by avoiding the evaluation of all 2NFpossible subsets of features. Instead, Algorithm 1: Pseudocode of the approach used by the workers to evaluate all possible values of Kfor a feature subset. 1Function evaluateFeatureSubset(T r, T e, Idx) Input : Training dataset, T r Input : Test dataset, T e Input : Index of the last column of the feature subset to evaluate, Idx Output: Accuracy of the best value of K,acc 2NI←getNumberInstances(T e) // Vector with the correct predictions for each value of K 3CP← {0} // Set as many OpenMP threads as logical CPU cores 4#pragma omp parallel for 5for i←1to NItest rows do // Distance between instance te[i]and all training instances 6D←calculateDistances(T e[i], T r, Idx) 7for k←1to NIdo 8PC←predominantClass(k, D) 9if prediction PCis correct then 10 CP[k]++ 11 end 12 end 13 end 14 CP←sort(CP,“Descending”) 15 acc ←CP[1] NI 16 return acc 17 End
4 J.J. Escobar et al. the proposed algorithm only evaluates NFof them, where in each one, the next feature from the list provided by mRMR is added. However, for each subset, all possible values of the Kparameter are also evaluated to get the best classification accuracy. The mRMR implementation is based on the one proposed in [5] and takes the F-test Correlation Quotient (FCQ) criteria to select the next feature. KNN algorithm has been parallelized by distributing feature subsets among worker nodes with MPI library and distributing the test instances to classify among CPU threads with OpenMP. The latter can be seen in the #pragma omp parallel for directive of Algorithm 1 (Line 4). The evaluation of all values of Kfor a test instance has been optimized by calculating its distance from all training instances (Line 6). In this way, the array Dis reused in the loop of Line 7 to obtain the predominant class according to the value of K(Line 8). If the prediction is correct, the value of the k-th position of the prediction vector, CP, is incremented by one. Once all instances have been classified, the prediction vector is sorted and the first position is used to calculate the classification accuracy of the best K(Lines 14 and 15). 3.1 A Distributed Master-worker Scheme for Node-level Parallelism The proposed implementation, whose pseudocode can be found in Algorithm 2, follows a master-worker scheme where the master tells each worker which feature subset must use to evaluate a KNN. The execution ends when there is no more work to process and the function returns the best accuracy found (Line 36). The operation is as follows: the master waits in Line 8 for some worker to request its first job or to return the result of one of them, which is also implicitly associated with the assignment of a new job. The message type is identified by the MPI tags described in Table 1. When the master receives a result, it checks if the accuracy of that job (feature subset) is better than the current one. If so, update its value (Lines 9 to 11) and send a new chunk with the JOB DATA tag (Line 14). Before sending work to a worker, the master checks for unprocessed chunks. If there is no availability, the worker will receive the STOP tag and stop its execution since there is no more work to do (Line 16). Regarding the workers (Lines 20 to 35), they apply the mRMR algorithm on the training dataset to obtain the ranked list of features. A worker requests jobs by sending a message with the FIRST JOB tag (Line 23). For each chunk of Table 1. MPI tags used during communications between master and workers. MPI tag Description Sender Receiver FIRST JOB Request for the first job Worker Master JOB DATA There is work to do Master Worker RESULT Return the result of the job Worker Master STOP No more work to be done Master Worker
Energy-aware KNN for EEG Classification in Heterogeneous Platforms 5 Algorithm 2: Pseudocode of the master-worker approach. 1Function Main(T r, T e, CS, NW k) Input : Training and test datasets, T r and T e Input : Maximum number of features to send to workers (chunk size), CS Input : Number of workers nodes, NW k Output: Accuracy of the best feature subset, bestAcc 2bestAcc ← −1 3if Master then 4NF←getNumberFeatures(T r) 5indexList ← {1,...,NF} 6stops ←0 7while stops =NW k do 8MPI::Recv(acc, tag) 9if tag is RESULT and acc > bestAcc then 10 bestAcc ←acc 11 end // Next chunk to send, e.g. indices 10,11,12 when CS= 3 12 chunk ←getNextFeatureChunk(indexList, CS) 13 if size(chunk)>0then 14 MPI::Send(chunk, JOB DATA) 15 else 16 MPI::Send(NULL,STOP) 17 stops ←stops + 1 18 end 19 end 20 else // mRMR. Reordering of datasets for coalesced memory access 21 rankedF eatures ←mRMR(T r) 22 T r, T e ←sortDatasets(T r, T e, rankedF eatures) // Start asking the master for workloads 23 MPI::Send(NULL,FIRST JOB) 24 MPI::Recv(chunk, tag) 25 while tag is JOB DATA do 26 for i←1to size(chunk)do 27 acc ←evaluateFeatureSubset(T r, T e, chunk[i]) 28 if acc > bestAcc then 29 bestAcc ←acc 30 end 31 end 32 MPI::Send(bestAcc, RESULT) 33 MPI::Recv(chunk, tag) 34 end 35 end 36 return bestAcc 37 End
6 J.J. Escobar et al. 123 56789 Wk1Wk2Wk3 4 (a) Contiguous blocks 1 2 3 Wk1Wk2Wk3Wk1Wk2Wk3Wk1Wk2Wk3 456789 (b) Strided blocks Fig. 1. The two different static workload distributions used by the master node. features received (Lines 26 to 31), the worker obtains the accuracy of the corresponding feature subset by calling in Line 27 to the evaluateFeatureSubset function of Algorithm 1. If the accuracy of the processed feature subset is greater than the existing one, it will be update. Once all the possible subsets of the received chunk have been processed, the worker returns the best accuracy obtained to the master by sending a message with the RESULT tag, and waits for the assignment of a new job (Lines 32 and 33). This process is repeated until the STOP tag is received, indicating that the worker can end its execution. 3.2 Ways of Distributing the Workload As previously seen in Section 3.1, feature chunks are sent to workers via the message-passing interface provided by the MPI library. This allows the application to distribute the workload among the different nodes of the cluster. However, in the algorithm proposed here, the workload of each feature subset is asymmetric since the number of features in each one is variable. For example, suppose a dataset with ten features, two worker nodes, and a chunk size of 2. In this scenario, the first chunk that the master will send contains the indices 1 and 2, corresponding to the subsets {1}and {1,2}. The second worker will receive indices 3 and 4 to compute the subsets {1,2,3}and {1,2,3,4}. In other words, a higher index implies computing more features within the KNN and, consequently, a longer execution time. To deal with workload imbalance, by default, the procedure distributes chunks dynamically according to the specified chunk size. Although this has the disadvantage of increasing communications, it is essential in heterogeneous systems to avoid performance drops. If the user wants, the master can also give each worker a chunk of features at the start of the algorithm by dividing the number of total chunks by the number of workers. This can be done in two ways: contiguous or striding features (see Figure 1). The strided assignment could reduce the workload imbalance [6] present in the contiguous blocks alternative since each node would compute similar subsets. 4 Experimental Results and Discussion All experiments are repeated ten times to obtain more reliable measurements of the application’s behavior. The application has been executed in an HPC cluster composed of eight heterogeneous NUMA nodes whose CPU devices are
Energy-aware KNN for EEG Classification in Heterogeneous Platforms 7 Table 2. Characteristics of the cluster used in the experiments. Node CPU RAM Model Total cores/threads TDP (W) Frequency (MHz) Frequency (MHz) Size (GB) Master 2x Intel Xeon E5-2620 v2 12/24 160 1,600 11x Intel Xeon E5-2620 v4 8/16 85 2,100 2,133 32 22x Intel Xeon E5-2620 v4 16/32 170 3 to 7 2x Intel Xeon Silver 4214 24/48 170 2,200 2,933 64 detailed in Table 2. The cluster runs the Rocky Linux distribution (v8.5) and schedules the jobs using the SLURM task manager (v20.11.7) [10]. The C++ source codes have been compiled with the GNU compiler (GCC v8.5.0), the OpenMPI library (v4.0.5), and optimization flags -O2 -funroll-loops. The energy measurements of each node have been obtained from a custom wattmeter, called Vampire, capable of capturing in real-time information of instantaneous power (W) and accumulated energy consumed (W ·h) for each computing node. The EEG dataset belongs to the BCI laboratory of the University of Essex and corresponds to a human subject coded as #104 [3]. The dataset includes 178 signals for training and another 178 for testing, each with 3,600 features. As the signals can belong to three different motor imagery movements (left hand, right hand, and feet), the KNN algorithm deals with a 3-class classification problem. 4.1 Classification Analysis The proposed algorithm achieves a Kappa index of 0.83 using the first 62 features of mRMR and K= 18. This solution widely outperforms a run without mRMR (0.34), and other approaches in the literature that use the same dataset: [2] (0.63), [9] (0.70), and [13] (0.76). The result has been validated by replicating its value when executing the KNN with the Python and Matlab languages and the same input parameters. Figure 2(a) shows the corresponding confusion matrix, which reveals an overall accuracy rate of 88.8%. The evolution of the accuracy rate and the Kappa index depending on the number of selected features can be observed in Figure 2(b). The general trend is that both metrics increase as new features are added until reaching the peak (62), and then progressively fall. It seems that the algorithm’s convergence is penalized with the selection of many features, which are also irrelevant. It is also observed that the values of accuracy and Kappa distance themselves for extreme values of the graph.
8 J.J. Escobar et al. Hand (R) Hand (L) Feet True class Hand (R) Hand (L) Feet Predicted class 46 25.8% 9 5.1% 0 0.0% 83.6% 16.4% 5 2.8% 60 33.7% 0 0.0% 92.3% 7.7% 4 2.2% 2 1.1% 52 29.2% 89.7% 10.3% 83.6% 16.4% 84.5% 15.5% 100% 0.0% 88.8% 11.2% (a) Confusion matrix of the best case (62 features) 10 30 62 180 450 900 1800 3600 Number of features 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Value Accuracy rate Kappa index (b) Accuracy rate and Kappa index when adding features Fig. 2. Classification results of the proposed approach when using mRMR and K= 18. 0 2 4 6 8 10 12 14 16 Speedup 1 2 4 8 16 32 48 Number of threads 0 20 40 60 80 100 120 140 160 180 200 Energy consumption (W · h) Energy consumption Speedup (a) Speedup and energy consumption 0 1000 2000 3000 4000 Execution time (s) 90 120 150 180 210 240 270 300 Instantaneous power (W) 48 threads 32 threads 16 threads 8 threads 4 threads 2 threads 1 thread (b) Instantaneous power Fig. 3. Performance of the proposed approach in a single-node configuration when varying the number of OpenMP threads. 4.2 Energy-time Performance Figure 3 shows the application’s performance after running on Node 3. The goal is to depict the speedup scalability of the first parallelism level, which occurs within each computing node when the number of logical CPU cores is increased. From Figure 3(a), it can be seen that the maximum speedup of 12.67 is obtained using the 48 threads available in the node. Its behavior is approximately linear, up to four threads, and logarithmic for higher values. The main reason is that the motherboard supports quad-channel memory. Increasing the number of threads above four causes competition for memory accesses since not all of them can do so simultaneously. It is also due, although to a lesser extent, because the workload for each thread decreases and the cost of managing threads becomes important. This means that the speed gain could increase with larger datasets that allow threads to compute for longer periods. It has also been found that distributing the instances to be classified among the threads statically provides the best performance (Line 4 of Algorithm 1). This is expected, as indicated
Energy-aware KNN for EEG Classification in Heterogeneous Platforms 9 0 20 40 60 80 100 120 Execution time (s) 1 2 4 8 16 32 64 128 256 512 Chunk size 0 10 20 30 40 50 60 Energy consumption (W · h) Energy consumption Execution time (a) Execution time and energy consumption when the chunk size is increased 0 10 20 30 40 50 60 70 Execution time (s) 90 120 150 180 210 240 270 300 Instantaneous power (W) Node 1 Node 2 Node 3 Node 4 Node 5 Node 6 Node 7 (b) Instantaneous power of the best chunk size found (4) Fig. 4. Performance of the dynamic workload distribution when using all nodes. in [7], because the computational workload is the same for each thread, so a dynamic distribution has been discarded. Regarding energy consumption, also for the case of using 48 threads, it provides the lowest total energy consumption. This may seem contradictory since the use of more resources is associated with a higher instantaneous power (see Figure 3(b)). However, energy consumption also depends linearly on execution time, and since speedup increases at a greater rate than energy, total energy consumption is less. The performance of the hybrid MPI-OpenMP approach that corresponds to the second level of parallelism is shown in Figures 4 and 5. On the one hand, Figure 4 exposes the behavior of the application when all nodes are used, and the workload distribution is dynamic. Figure 4(a) reveals that a very large chunk size leads to worse execution time and energy consumption mainly due to workload imbalance. The instantaneous power of each node for a chunk size of 4 is plotted in Figure 4(b). Despite the fact that the optimal size ranges from 1 to 64, the value 4 has been set as definitive since it works well with few nodes and should do so with more than 7. What is observed in the figure is that most nodes end up simultaneously, which is expected in dynamic workload distributions. On the other hand, Figure 5 compares the different workload distributions. The number of computation nodes indicated in Figure 5(a) does not correspond to the order shown in Table 2. Instead, the nodes in the graph correspond to homogeneous and heterogeneous ones in that order. That is, first Nodes 3 to 7, and later Nodes 1 and 2. In this way, the scalability of the program can be analyzed according to the type of node added. As expected, for all distributions, the observed speedup grows linearly as more nodes are used, but up to 5 and in different magnitudes. From this point on, only dynamic distribution continues to scale its performance, although to a lesser extent since heterogeneous nodes begin to be used. In fact, it can be seen that the increase in speedup is in line with the added heterogeneous node: adding Node 2 boosts speed up more than adding Node 1 (the slowest one), until reaching a maximum speedup of 5.88. With respect to a sequential execution (1 thread), the application achieves a