# A Heart Rate Variability-Based Paroxysmal Atrial Fibrillation Prediction System
## 2 Materials and Methods
### Parameter Determinations  
As mentioned previously, a GA was employed to determine the parameters in feature conversion and in CNN structure optimization. A GA is a stochastic search algorithm for function optimization inspired by natural genetics. It begins with the random generation of an initial population of many individuals. An individual can be represented by either a binary or a real vector, depending on the applied problem. Each of the individuals in the population is then evaluated by a fitness function (the minimum of training accuracy and validation accuracy in this work). Individuals with better fitness values are more likely to be selected for mating. Each pair of selected individuals produces a pair of new individuals through crossover and mutation under some predetermined probabilities. The same population size is produced in each generation and some of the new individuals may exhibit better fitness values than those in the previous generation. The evolutionary process is continued until the maximum number of generations is reached. In real practice, the related settings are as follows: population size = 500, cross over rate = 0.85, mutation rate = 0.1, and the tournament method was used for individual selection.  
In feature conversion, the time lags \(\tau\) of the extended Poincare plots and the usage of the four resultant feature matrices were determined by GA. Four time lags were correspondingly calculated by \(\mathbf{v}\mathbf{t}_{i}+1\), where \(\mathbf{v}\mathbf{t}_{i}\), \(i=1\), 2, 3, 4, were binary vectors of length 5, making each time lag drawn from integers in the range of [1, 32]. The first two time lags were for the two inter-person feature matrices, whereas the latter two were for the two intra-person feature matrices. An additional binary vector, \(\mathbf{v}\mathbf{m}\), of length 4 were used to control the usage (1 for use and 0 for not use) of the four feature matrices, resulting in a total of 24 binary numbers for feature conversion.  
In CNN structure optimization, the layer usage in each layer set and the filter size and filter numbers in each convolution layer were determined by GA. Firstly, we assigned the maximum number of layer sets as 5, according to our preliminary studies. Then, five length-4 binary vectors, \(\mathbf{v}\mathbf{l}_{i}\), \(i=1\), 2, 3, 4, 5, were employed to regulate the usage of the convolution layer, batch normalization layer, ReLU layer, and max-pooling layer sequentially in each of the layer sets. Finally, the number of filters and the size of the filters in the convolution layer of each layer set were determined accordingly via \(\mathbf{v}\mathbf{f}_{i}+1\) and \(\mathbf{v}\mathbf{s}_{i}+1\), where \(\mathbf{v}\mathbf{f}_{i}\) and \(\mathbf{v}\mathbf{s}_{i}\), \(i=1\), 2, 3, 4, 5, were binary vectors of length 4, making the number of filters and the size of filters all drawn from integers in the range of [1, 16].  
In summary, a length-84 binary vector \(\mathbf{v}=[\mathbf{v}\mathbf{t}_{i}\), \(\mathbf{v}\mathbf{m}\), \(\mathbf{v}\mathbf{l}_{i}\), \(\mathbf{v}\mathbf{f}_{j}\), \(\mathbf{v}\mathbf{s}_{j}]\), \(i=1\), 2, 3, 4 and \(j=1\), 2, 3, 4, 5, selected by GA determined the parameters and the architecture of our PAF prediction system. Figure 2 shows the flowchart for the construction of the system. Let \(E_{t}(\mathbf{v})\) and \(E_{v}(\mathbf{v})\) denote accordingly the training error and the validation error of the system determined by a binary vector \(\mathbf{v}\), then the design of our PAF prediction system can be formulated as the following optimization problem.  
\[\min_{\mathbf{v}}(\max(E_{t}(\mathbf{v}),E_{v}(\mathbf{v}))) \tag{3}\]  
Figure 2: Flowchart of the construction of the proposed PAF prediction system.