## 3 Networks and Methods
### Genetic Algorithm Time-Serialization Convolutional Neural Network (GATSCNN)
#### 3.3.3 GA-Optimized TSCNN  
To achieve the optimal TSCNN network model, GA was used for the global optimization of TSCNN to determine the parameters to be optimized, including the CNN layer number, fully connected layer number, batch size, times, number of features, convolution kernel size, and number of neurons. Figure 10 shows the GATSCNN flowchart. Figure 10: GATSCNN model flow chart. Figure 9: The excess limit exception. Step 1: Initialize the population. First, the network structure is randomly selected and constructed based on the boundaries of the CNN layers and fully connected layer parameters. Subsequently, the hyperparameters are randomly defined according to the boundaries of the number of layers and other hyperparameters. Figure 11 shows the structure of an individual within a population. The left side of Figure 11 shows the binary encoding of the individual, and the right side shows the parameters. The header of the individual consists of CNN layers and fully connected layers, representing the neural network structure, followed by \"batch size,\" which represents the number of samples in a batch of the neural network. \"Time serialization\" and \"feature\" represent the length of the time series. \"Feature,\" \"kernel,\" and \"neurons\" represent the hyperparameters in the neural network model, as indicated by the feature size (number of nodes) of the convolutional neural network, the length of the convolutional kernel, and the number of neurons in the fully connected layers, respectively. Finally, the optimal parameters are obtained via GA optimization. Step 2: Calculate the fitness function. First, the population is decoded to generate real-valued individuals that can be recognized by the network structure, and then the original data are divided into time-series data based on the individual's time serialization. Subsequently, a neural network model is constructed based on the network structure and the hyperparameters of the individual, and the network model is fully trained for 200 epochs. Finally, the MSE of the model on the test set is used as a measure of fitness. MSE is calculated according to the following equation:  
\[\text{MSE}=\frac{1}{\text{m}}\sum\
olimits_{i=1}^{\text{m}}\left(\text{yi}- \text{yi}^{t}\right)^{2} \tag{3}\]  
where m represents the length of the data, yi denotes the true value of the data, and \(\text{yi}^{t}\) is the value predicted by the neural network model. Step 3: Determine whether the expected result or the maximum number of iterations is reached. If the expected result is achieved, proceed to Step 7; otherwise, continue. Step 4: Perform GA optimization. Based on the fitness obtained in Step 2, perform selection, crossover, and mutation operations on the population. The population does not need to be decoded at this stage and binary encoding can be used. Step 5: Check the data. During GA optimization, it is possible to exceed the limit or obtain a binary matrix of all zeros, which can cause errors in the model beyond the expected results and reduce effectiveness. Therefore, a check function is designed to determine and transform the optimized parameters. First, the population optimized by GA is decoded into a real-numbered population, thereby verifying the real-numbered population based on the  
Figure 11: Individual structure. check function. If abnormal individual data are found, Algorithm 1 is used to transform the data. After completing the check, the population is encoded back into a binary population. Step 6: Return to Step 2. ```
1:pop_GA = {pop1, pop2,..., popn}
2:output output after examining population, pop
3:for n = 1 \(\rightarrow\) N do
4:for k = 1 \(\rightarrow\) K do
5:if popn[k] < min_k or popn[k] > max_k then
6: popn[k] \(\Leftarrow\) (popn[k] % (max_k - min_k) + min_k)
7:endif
8:if popn[k] = 0 then
9: popn[k] \(\Leftarrow\) random(min_k, max_k)
10:endif
11:endfor
12:endfor
13:return pop
```  
**Algorithm 1** check function  
Step 7: Determine the optimal individual and decode the output.