## 2 Materials and Methods
### Model Building
#### 2.4.2 Construction of a Water Quality Prediction Model Based on the LSTM Model  
The fundamental RNN has a hidden-layer structure that is self-connected, distinguishing it from conventional neural networks. The RNN updates the hidden layer state at the current time step by incorporating the hidden layer state from the previous time step. This property makes the RNN well suited for handling time-series data. As the length of the time series increases, training the RNN becomes challenging due to the problem of 'forgetting' early time-series information. This phenomenon can result in either the disappearance of gradients or their explosion, which makes the training process challenging. The introduction of LSTM addresses the limitation of the RNN in retaining early time-series information to some extent [31]. The hidden layer of LSTM maintains a self-connection structure. However, LSTM is capable of capturing two types of information, namely the cell state and hidden layer state, from the previous time step. It achieves this through the utilization of a threshold structure consisting of the 'forgetting gate', 'input gate', and 'output gate'. These gates control the transmission and updating of both the cell state information and the hidden layer state information. The LSTM hidden-layer structure is shown in Figure 2, where \(C_{t-1}\) and \(C_{t}\) are the cell state information at time \(t-1\) and time \(t\), respectively; \(\widetilde{C}_{t}\) is the candidate update information at time \(t\); \(h_{t-1}\) and \(h_{t}\) are the hidden layer state information at time \(t-1\) and time \(t\), respectively; \(X_{t}\) is the input value at time \(t\); \(\sigma\) is the Sigmoid function; and \(f_{t},i_{t}\), and \(o_{t}\) are the control coefficients of the 'forgetting gate', 'input gate', and 'output gate', respectively.  
The 'forgetting gate' is based on \(f_{t}\) determining how much of the cell state information \(C_{t-1}\) can be retained at time \(t-1\). \(f_{t}\) is a value between 0 and 1, calculated by \(X_{t}\) and \(h_{t-1}\) as an input. The closer \(f_{t}\) is to 0, the more information is removed in \(C_{t-1}\), and the closer \(f_{t}\) is to 1, the more information is retained in \(C_{t-1}\); the effect of control coefficients \(i_{t}\) and \(o_{t}\) is similar to that of \(f_{t}\). The role of the 'input gate' is to determine which information will be added to the \(C_{t}\) and to work together with the 'forgetting gate' to determine the update of the \(C_{t}\). The 'output gate' is used to control the output \(h_{t}\) of the hidden layer state information at time \(t\). The formula of the LSTM network is as follows:  
\[f_{t}=\sigma(W_{f},[h_{t-1},X_{t}],b_{f}) \tag{9}\]  
\[i_{t}=\sigma(W_{i},[h_{t-1},X_{t}],b_{i}) \tag{10}\]  
\[\widetilde{C}_{t}=\tanh\sigma(W_{C},[h_{t-1},X_{t}],b_{C}) \tag{11}\]  
\[C_{t}=f_{t}\cdot C_{t-1}+i_{t}\widetilde{C}_{t} \tag{12}\]  
\[o_{t}=\sigma(W_{o},[h_{t-1},X_{t}],b_{o}) \tag{13}\]  
\[h_{t}=o_{t}\cdot\tanh(C_{t}) \tag{14}\]  
In the given formula, the variables \(W_{f}\), \(W_{i}\), \(W_{C}\), \(W_{o}\) represent weights, while \(b_{f}\), \(b_{i}\), \(b_{C}\), \(b_{o}\) represent biases.  
In this paper, the optimal parameters were determined after numerous experiments. The parameter settings in this model are as follows: the number of selected generations is 500, batch size is 64, the initial learning rate is set to 0.001, the RMSProp attenuation coefficient is 0.8, and the error function used is the mean square error.