{'fraction_non_alphanumeric': 0.033131124591693886, 'fraction_numerical': 0.018237673044019288, 'mean_word_length': 4.813065099457504, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Deep learning approach to detect seizure using reconstructed phase space images

Epilepsy is a chronic neurological disorder that affects the function of the brain in people of all ages. It manifests in the electroencephalogram (EEG) signal which records the electrical activity of the brain. Various image processing, signal processing, and machine-learning based techniques are employed to analyze epilepsy, using spatial and temporal features. The nervous system that generates the EEG signal is considered nonlinear and the EEG signals exhibit chaotic behavior. In order to capture these nonlinear dynamics, we use reconstructed phase space (RPS) representation of the signal. Earlier studies have primarily addressed seizure detection as a binary classification (normal vs. ictal) problem and rarely as a ternary class (normal vs. interictal vs. ictal) problem. We employ transfer learning on a pre-trained deep neural network model and retrain it using RPS images of the EEG signal. The classification accuracy of the model for the binary classes is (98.5±1.5)% and (95±2)% for the ternary classes. The performance of the convolution neural network (CNN) model is better than the other existing statistical approach for all performance indicators such as accuracy, sensitivity, and specificity. The result of the proposed approach shows the prospect of employing RPS images with CNN for predicting epileptic seizures.


Introduction
Epilepsy is a common neurological condition that causes recurrent and unprovoked seizures. Epilepsy is a central nervous system disease that causes abnormal behavior and sometimes even loss of awareness in a patient. About seventy million people in the world are affected by epilepsy. The epileptic seizure may be related to brain damage or hereditary, in which the cause is often completely unknown. Electroencephalogram (EEG) signals which monitor brain activity are generally analyzed by neurologists and specialists to detect and categorize various types of disease and to identify regions indicative of pre-ictal spikes and seizures. The presence of numerous spikes in the EEG signals is an indication of epileptic seizure activity in the brain.
Normally in clinical environments, diagnosis of seizure in patients involves continuous monitoring using video and EEG signals recorded over long periods. Human experts are then required to manually review the data based on the visual inspection to arrive at a clinical interpretation. This is timeconsuming and there is a lack of sufficient expertise. Hence automation of seizure detection is essential.
Automation systems require features extracted from the signal. Several techniques exist for extracting the feature either in the time, frequency, or timefrequency domains. Due to the nonlinear and nonstationary nature of the EEG signals, features based on the time-frequency domain are used for detecting epileptic signals [1][2][3] . Empirical mode decomposition technique and Fourier-Bessel expansion are used for computing the mean frequency of intrinsic mode functions (IMFs) to discriminate ictal from interictal EEG signals [4] . Recurrence quantification analysis (RQA) [5] , wavelet transform and multi-wavelet transform are used for classification of the EEG signal into three classes such as normal, interictal and ictal in [6] . Alternatively, a pattern recognition approach that recognizes the recorded EEG signals on cognitive conditions focusing more on improving classification accuracy is proposed [7] . Numerous machine learning algorithms like k-nearest neighbor (k-NN), naive Bayes (NB), random forest, artificial neural networks (ANN), support vector machine (SVM), decision trees, least square-support vector machine (LS-SVM), general regression neural network (GRNN) and mixture of expert model have been proposed to classify the abnormality from the EEG data. Based on information from magnetoencephalogram, electromyogram, electrooculogram, electrocardiogram and EEG, nonlinear dynamic techniques are effectively used in biomedical applications [2][3][4][5][6][7][8] . This study focuses on modeling the nonlinear dynamics of the brain. As universally accepted, the brain is regarded as a chaotic dynamic system, and it produces EEG signals that are usually chaotic [9] . In another sense, an EEG signal is chaotic, as its amplitude changes randomly over time. These chaotic signals are characterized by long-term unpredictability, which makes classical signal processing techniques less helpful. Modeling the dynamics is a challenge when using conventional features/models. We use reconstructed phase space (RPS) techniques developed for chaotic signal analysis on the epilepsy dataset from the University of Bonn (UoB) and show improved classification accuracy for 22 different class combinations.
The use of RPS trajectory images as input to a convolution neural network helps to model the dynamics. Further, the deep neural network results in an end-to-end system, eliminating the need to handcraft features for modeling. The end-to-end system proposed performs at par or better than other state-of-the-art systems reported in literature. A pretrained convolutional neural network of the AlexNet architecture is retrained with RPS images extracted from the dataset to classify the data into different classes. Representative RPS images for each of the five classes of UoB dataset are shown in Fig. 1.
Due to the tedious nature of observing EEG signals in clinical settings, researchers have employed machine learning approaches for automating the detection of seizure classification of EEG signals with promising results. In 1979, Gotman et al [10] is one of the pioneers who helped open up the research in seizure detection, used sharp and spike waves for an automatic recognition system that used prolonged EEG recordings to detect interictal epileptic activity. Later on, he focused on using functional magnetic resonance imaging to examine automatic seizure detection with high-frequency activities in the wavelet domain [11] .
Using UoB dataset, researchers have examined several techniques for the automatic detection of Deep learning approach to detect seizure using RPS images 241 epilepsy [12] . SVMs have commonly been used as a classifier to distinguish seizure vs. non-seizure [13] using features based on discrete wavelet transform (DWT) [14] , tunable Q-wavelet transform [15] and recurrence quantification analysis [16] with an accuracy of 96.3%, 98.6%, and 94.4%, respectively. Shoeb [17] used SVM for patient-specific prediction which resulted in 96% accuracy. Gandhi et al [18] utilized a probabilistic neural network (PNN) in combination with SVM which resulted in an accuracy of 95.44% for classifying class combination ABCD-E. Sharmila et al [7] studied fourteen different combinations of classes using statistical features extracted from DWT coefficients and applied naive Bayes and k-NN classifiers. A GRNN was employed for the classification of ictal and non-ictal states in [19] . Both the studies [7,19] achieved maximum accuracy of 100% for A-E (normal vs. seizure) cases. In a study by Nicolaou et al [20] , where entropy-based features were employed an accuracy of 93.55% was attained for A-E cases and 86.1% for ABCD-E. A probabilistic approach to modeling the distribution of the classes using Gaussian mixture model (GMM) by Chua et al [21] resulted in an accuracy of 93.11% for three classes (normal, interictal and ictal) when using higher order spectra (HOS) features [22] and 93.1% classification accuracy when using power spectral density features [23] .
Deep learning approaches in machine learning are currently outperforming the state-of-art performance of conventional machine learning algorithms in numerous domains. Employing deep learning methods, Ishan Ullah et al [24] used pyramidal onedimensional convolution neural network (P-1D-CNN) and achieved the maximum accuracy of 100% for A-E class combination. In the P-1D-CNN, novel data augmentation schemes and an effective deep CNN model were used for the classification of UoB dataset. Rajendra Acharya et al [25] reported accuracy of 88.67% using a CNN with thirteen deep convolution layers. Table 1 reviews selected studies on EEG classification using the UoB dataset with the features, classifiers used and their accuracies.
The PSR signal provides a visualization of the signal's dynamic behavior over time which is useful to guide model specification. In some studies, two dimensional (2D) and three-dimensional (3D) PSRs of the IMFs are used for the classification of EEG signals [30] . Using dataset of Graz University of Technology, the PSR technique has been used for the three-class combination of motor imagery classification [35] . Based on 2D RPS plot, from Physionet CHB MIT database, central tendency measure (CTM) was used to compute the region of 2D RPS plots to differentiate between seizure and seizurefree EEG signals [36] .
The rest of the paper describes in detail the process involved and discusses the basic details about RPS, convolution neural network, its layers and transfer learning. Next, it describes the Bonn Dataset, the design of the proposed system to classify EEG signals based on RPS images, and finally deals with the experimental results and performance of the system.

Reconstructed phase space (RPS)
RPS is a method used to construct the phase space of a dynamical system which is a space where various possible states of a system are represented. At any given time, the state of the system is represented. The state of the system changes with time. Thus the dynamics of the system are captured by the vector describing the state change over time in the phase space. The shape of the trajectories gives insights about the periodic/chaotic nature of the system. From Takens embedding theorem [37] , the phase space can be reconstructed using a single observation and employing a small time delay embedding. For a time series S[t i ], i=1, 2,...N, the phase space can be denoted at time t i as: Here time delay is denoted by τ and m is the phase space dimension.
Time delay embedding is the most frequently used method of RPS. It is essential to determine the optimal values of time delay τ and the embedding dimension m. The choice of both parameters τ and m are key factors in nonlinear analysis. Using average mutual information we can select a suitable time delay and by applying false nearest neighbor (FNN) method one can identify the dimension of RPS. In this study we use a time delay of τ=6 and embedding dimension of m=2 explained under proposed model, to construct the RPS portraits for the given EEG time series data.

Convolution neural network (CNN)
CNN is a deep neural network architecture conventionally employed to analyze images. CNN is composed of multiple convolution layers and each layer generates a feature map to preserve unique information about the input images [38] . Convolution operations are applied by the convolution layer to the input image and transfer the result to the succeeding layer. Next, the pooling layer is used in the middle of the convolution layer for reducing the dimensionality of the feature map while preserving the relevant features. It limits the number of trainable parameters by reducing the size. The max pool operation selects 242 Ilakiyaselvan N et al. J Biomed Res, 2020, 34 (3) the most dominant features in the map. Fully connected (FC) layers are typically applied after the convolution layers for classification purposes. The last fully connected layer is a softmax layer used to normalize the output and predict the class of the input image. In this study, we use the AlexNet model and experiment with different class combinations, achieving the best results using RPS portraits.

Transfer learning
The problem of classifying the signal as being from an epileptic source is mapped to classifying RPS images of epileptic/non-epileptic subjects using deep learning. Training deep learning models requires a large dataset of images and numerous iterations for convergence [39] . As acquiring a large dataset is challenging we adopt transfer learning for the task [40] . Transfer learning aims to use the knowledge learned from the source domain to the target domains. It enables us to create accurate models without training an entire network from scratch even with an insufficient dataset. In place of learning from scratch, we begin with patterns learned when solving a different problem. Thus we gain knowledge (features and weights) from previously learned models to train new models and avoid proceeding from scratch [41] . Pre-trained CNN models like LeNet, AlexNet, VGGNet, GoogLeNet, ResNet, etc., can be used for the task.
Choosing a pre-trained model in transfer learning indicates the specific categorization of the domain and its essential features are shaped by (i) the input quantity of the images and (ii) the similitude of the model's domain to the task employed, for it has a bearing on the performance of the system. Epileptic/ non-epileptic is the domain specific class label.

Dataset description
The University of Bonn, Department of Epileptology, Germany, provides an open-source epileptic EEG dataset [42] . Bonn database is a widely used benchmarking dataset for validating seizure detection models. The dataset uses the 10-20 international electrode placement system for acquiring the data. This experimental dataset includes five sets of EEG data A, B, C, D, and E as shown in Table 2. Sets A and B contain normal EEG signals recorded from five healthy subjects. The remaining sets of C, D, and E were recorded from epilepsy patients. The sets A and B of normal subjects were relaxed in an awaken state and represent EEG recordings with their eyes in open and closed states respectively. Before an epileptic attack, set C was recorded opposite to the epileptogenic zone, while set D was recorded in the Sharmila et al [7] Conventional features from DWT 95.10-100.00 NB + k-NN Guo et al [26] Genetic programming 93.50 k-NN Tzallas et al [27] Time-frequency features 97.70-100.00 ANN Guo et al [28] Line length features on wavelet transform 97.77-99.60 Kumar et al [29] DWT based approximate entropy 92.50-100.00 ANN + SVM Sharma et al [30] 2D and 3D phase space representation of intrinsic mode functions 98.60 LS-SVM Manish et al [31] Analytic time frequency -flexible wavelet transform 92.50-100.00 Bhattacharyya et al [15] Tunable Q-wavelet transform 98.60 SVM Acharya et al [16] Recurrence quantification analysis 94. 40 Nicolaou et al [20] Permutation entropy 79.94-93.55 Acharya et al [32] DWT 96.30 Subashi et al [33] DWT 98.75-100 Swami et al [19] Dual tree complex wavelet transform 93.30-100.00 GRNN Chua et al [22] Higher order spectra features 93.10 GMM Acharya et al [34] Nonlinear parameters: approximate entropy, correlation dimension, Hurst exponent, fractal dimension 95.00 Ullah et al [24] Data augmentation schemes 99.10-100.00 P-1D-CNN Acharya et al [25] 13 epileptogenic zone. These two sets C, D represent the interictal state. Set E was recorded during an occurrence of epileptic seizure (ictal) signal in an epileptogenic zone. Each set of data recorded with a 128-channel amplifier system comprises 100 files corresponding to single-channel EEG segments and the duration of each sample recording is 23.6 seconds with a sampling rate of 173.61 Hz. A band-pass filter with a passband of 0.53 Hz -40 Hz (12 dB/oct) was used to select the EEG signal of the required band. As a result of visual inspection of artifacts (e.g., owing to a pathological activity or eye movement), these artifacts were removed from the continuous multi-channel EEG recordings. From all recording locations with ictal activity, the EEG segments were selected for set E [12] .
Thus each recording data contains 4 097 samples which have been split into segments of 510 samples each to generate many instances from one record. These segments form the basis for all further processing.

Proposed model
The proposed system uses RPS images that are extracted from segments of the EEG signal in the UoB dataset. The RPS image is used to test a CNN of the AlexNet [43] architecture, so as to classify the RPS image into epileptic and non-epileptic classes. The functional flow diagram is shown in Fig. 2.

RPS image dataset
The observational dataset includes five sets of EEG data A, B, C, D, and E. These sets pertain to normal, seizure-free (interictal) and epileptic seizure (ictal) signals. The choice of segmenting each recording into 510 samples is because RPS portraits are too dense for larger samples and CNN cannot capture the intrinsic feature the phase space depicts. Therefore, by trial and error, 510 samples are found to be the most suitable segment size to represent RPS portraits as well as to generate sufficient images to retrain the CNN model. Fig. 3 shows the process flow diagram for the dataset creation.
Embedding dimension 'm' and time delay 'τ' are the critical parameters of the RPS portraits [44] . FNN is chosen for finding embedding dimension, while mutual information is used for finding the time delay [45] . The embedding dimension is based on the FNN percentage where it effectively drops to zero as depicted in Fig. 4A and the time delay is based on mutual information at which the first minimum occurs as depicted in Fig. 4B (3) experiments we arrived at an appropriate delay of τ=6 as seen from Fig. 4B. Likewise Fig. 4A, it can be seen that the ideal embedding dimension would be m=3, but since we are working on two dimensional (2D) CNN we restrict our dimension to m=2. Every segment is transformed into a RPS image and these images are extracted for the non-overlapping segments with the dimension m=2 and time delay τ=6.

Pre-trained model: AlexNet
In this study, a pre-trained AlexNet model is used as it shows better performance in classifying epileptic seizure sets as compared to another state of the art of CNN models namely LeNet and GoogLeNet as shown in Table 3. AlexNet changed all the records of preexisting non-deep learning-based techniques. AlexNet contains five convolution (Conv) layers and three fully connected (FC) layers. Each convolution layer consists of 96 to 384 filters and the size of the filters ranges from 3×3 to 11×11 with the feature map of 3 to 256 channels each. In each layer, a non-linear ReLU (Rectified Linear Unit) activation function is used. ReLU is an important feature of AlexNet instead of the tanh or sigmoid activation function used to train a model for a neural network. The primary reasons for using ReLU in Convolution layers are faster convergence owing to the lack of vanishing gradient problem and inducing sparsity in the features. 3×3 Max pooling is applied to the outputs of layer 1, 2 and 5. In the first layer, a stride of 4 is used to reduce the computation.
Local Response Normalization (LRN) is used in the first and second layers before max pooling. When compared to LeNet, AlexNet applies larger weights and the shape varies from layer to layer [43] . To handle overfitting, dropout is used instead of regularization. The training time, however, is doubled by a 0.5 dropout rate. AlexNet model's tensor sizes (images) and number of parameters of convolution layers are shown in Fig. 5.

Training AlexNet
For training the proposed model, 90% of epileptic and non-epileptic RPS images of the dataset (section 5.1) are utilized (75% training and 15% validation). 10% of the data is reserved for testing. To optimize the performance stratified 10-fold cross validation (CV) is performed. The 10-fold CV splits the data at random into 10-disjoint sub-sets called folds. The stratified folds maintain the mean response value in all folds, which is approximately equal. Each fold holds the same proportions of the two types of class labels, namely epileptic (Set E) and non-epileptic (Sets A, B, C, and D) classes.
Training of AlexNet model requires the weight (Kernels) to be learned from the data. We use backpropagation with cross entropy as the loss function along with the stochastic gradient descent for optimization to learn these parameters. The model is trained for image classification using the Caffe framework. This model is trained for 200 epochs with learning rate (0.01), batch size (128), weight decay (0.0001), gamma (0.1), and momentum (0.9) as hyperparameters. The outcome is that the model's depth is significant for its high efficiency, which is computationally expensive but made possible using graphics processing units (GPUs). Several other complicated CNNs can perform very effectively on faster GPUs, even on large datasets. Using K80 GPU machine, this step takes around 45 minutes for one run of training for computation on UoB datasets. As the model complexity increases, the computational complexity during training and testing also increases. The retrained AlexNet model in Fig. 6 shows the visualization of convolution filters of the CNN model trained on RPS images of the UoB dataset.

Results
In this work, twenty-two different combinations of classes were considered for classifying the segments into being epileptic/non-epileptic conditions. To evaluate the performance of the proposed RPS based deep learning approach, the performance was evaluated based on standard metrics like classification accuracy, sensitivity, specificity, precision and F-score for all the binary and ternary classes as described below.
Sensitivity (S ens) or Recall = T P T P + FN (3)  Fig. 6 Trained AlexNet with a representative feature map learned from RPS images. Here, TP refers to the number of images that are actually epileptic and predicted as epileptic class, FP indicates actually non-epileptic class predicted as epileptic. TN refers to actually non-epileptic class predicted as non-epileptic class, while FN indicates actually epileptic and predicted as non-epileptic class. Table 4 shows the classification accuracy, sensitivity, and specificity for 15 different binary class combinations. The corresponding confusion matrices for a few binary classes are shown in Table 5. Likewise, the performance of the system for ternary class combinations is given in Table 6.
The corresponding confusion matrices for selected ternary class combinations are given in Table 7. The results indicate that the proposed system performs best for the case A-E with 100% accuracy. The system performed better than or at par with other results reported in the literature ( Table 1).
The performance of our approach was compared with the state-of-the-art methods of earlier investigations for all twenty-two class combinations. Sensitivity scores of the proposed approach indicate that the percentage of correctly identified epileptic patients for all class combinations is always high and for nine of the classes 100% is achieved. For specificity, the proposed approach achieves 100% for case A-E and very high percentages for the rest of the class combinations. Table 8 reports the sensitivity and specificity for various class combinations in comparison with results in the literature. To the best of the authors' knowledge, the performance of our sensitivity is better than existing approaches. We see that the proposed approach of using RPS based CNN models perform better than existing approaches for all binary classes with an accuracy of (98.5±1.5)%. For ternary class combinations, the proposed system has an accuracy of (95±2)% except for the C-D-E case where the accuracy is 84.44%.

Discussion
Chaotic dynamical systems like EEG may evolve asymptotically towards lower dimensional attractors. These attractors can be indirectly visualized using the phase space reconstruction. We see from Fig. 1, more so for the ictal case (class E), that such lower dimensional attractors exist for EEG signals. This was reflected in earlier studies too [30,[35][36] , where the RPS was used as a basis to manually extract features and then classify.
To reconstruct phase space and its chaotic features, the choice of time delay and embedding dimension are the critical factors [46] . If the range of τ is too low, the attractor will be compressed into the area of the diagonal line of the coordinate system; on the other hand, if the range of τ is too high, the data point trajectory will wrinkle and fold, making it hard to achieve clear projection relationships. This study to the best of our understanding is the first approach to use the RPS images as the basis to develop an end-toend CNN based system that performs at par or better than other approaches in the literature. It can automatically extract features and detect the ictal case with close to 100% accuracy.
In conclusion, the brain is a nonlinear dynamic system and the EEG signal is modeled as a chaotic system using RPS portraits. The novelty of this study is the use of these RPS images as input to the CNN model. We further employ transfer learning on the standard AlexNet model to learn the RPS images for the seizure detection problem. We report an accuracy of (98.5±1.5)% (epileptic vs. non-epileptic) and (95±2)% (normal vs. interictal vs. ictal) which is higher than most existing results in the literature. We thus see that the proposed approach can model the dynamic nature of the EEG signal. The RPS images are seen to be valid input representations, and the CNN model can accurately capture the features in the RPS image and perform with high accuracy for 22 different class combinations. The outcome of the proposed system using RPS images could be used in supporting physicians to detect epilepsy and may serve as a precursor to assist the neurologist in classifying the epileptic states of the patients.