## 4 Materials and Methods
### Introduction to the LSTM Algorithm  
The Long Short-Term Memory Network (LSTM), an improved variant of the Recurrent Neural Network (RNN), is specifically designed to address the gradient vanishing/exploding issues faced by traditional RNNs when processing long-sequence data, enabling effective capture of long-range dependencies. Its core idea lies in introducing a gating mechanism to selectively control information flow, thus achieving storage and management of long-term memory [39; 40; 41]. An LSTM consists of a cell state (\(CellState,~{}(C_{t})\)) and three gating units: the forget gate, input gate, and output gate. Each gating unit uses a sigmoid activation function to output values between 0 and 1, representing the proportion of information allowed to pass through [42]. The LSTM model designed in this paper employs a two-layer network structure with the following specific configurations:  
1. The first layer adopts a unidirectional LSTM structure with 64 memory units, returning full sequence outputs;The second layer contains 32 memory units, returning only the output of the last time step in the sequence;
3. A 30% Dropout layer is set after each LSTM layer to suppress overfitting;
4. The output layer uses a fully connected structure with a Relu activation function for nonlinear transformation; For model training:
1. The Adam optimizer is used to adaptively adjust the learning rate;
2. The Huber loss function is selected (with stronger robustness to outliers);
3. An early stopping mechanism is applied, halting training when validation loss shows no improvement for 10 consecutive epochs;
4. A learning rate adjustment strategy is adopted: if validation loss remains unchanged for 5 consecutive epochs, the learning rate is reduced by 80%. This combination of network structure and training strategies effectively captures dependencies in time series while ensuring the model's generalization ability and training stability [43]. The schematic diagram of LSTM is shown in Figure 7 below [44]. Taking the first layer of the model as an example, the specific calculation process is as follows:  
Forget Gate Stage: The forget gate calculates its output using the formula \(f_{t}=\sigma\Big{(}W_{if}x_{t}+b_{if}+W_{hf}h_{(t-1)}+b_{hf}\Big{)}\) (\(\sigma\) denotes the Sigmoid function), based on the current input \(x_{t}\) and the previous hidden state \(h_{(t-1)}\). This output is element-wise multiplied by the previous cell state \(c_{(t-1)}\) to determine which information to discard from \(c_{(t-1)}\). Memory Update Stage: The Sigmoid component of the input gate computes the proportion of information to update via \(i_{t}=\sigma\Big{(}W_{if}x_{t}+b_{if}+W_{hi}h_{(t-1)}+b_{hi}\Big{)}\). The tanh component generates a candidate vector \(g_{t}=tanh\Big{(}W_{ig}x_{t}+b_{ig}+W_{hg}h_{(t-1)}+b_{hg}\Big{)}\). The cell state is updated as \(c_{t}=f_{t}*c_{(t-1)}+i_{t}*g_{t}\). Output Stage: The output gate first determines the output proportion through \(o_{t}=\sigma\Big{(}W_{io}x_{t}+b_{io}+W_{ho}h_{(t-1)}\Big{)}+b_{ho}\). The final output is then computed as \(h_{t}=o_{t}*tanh(c_{t})\), which serves as the input for the next time step or the model's prediction. For the first LSTM layer in this study:  
Number of memory units: 64;  
Input vector: \(x_{t}\in\mathbb{R}^{1}\);  
Previous hidden state: \(h_{t-1}\in\mathbb{R}^{64}\);  
Figure 7: Schematic diagram of LSTM. Input weight matrix: \(W_{if}\in\mathrm{R}^{64\times 1}\);  
Hidden state weight matrix: \(W_{hf}\in\mathrm{R}^{64\times 64}\);  
Bias vector: \(b_{if}\in\mathrm{R}^{64}\). Thus, the formula for the forget gate \(f_{t}\) in the first LSTM layer is derived as follows:  
\[W_{if}x_{t}= \begin{bmatrix}w_{if,1,1}&w_{if,2,1}\vdots w_{if,64,1}\end{bmatrix}  \cdot x_{t}= \begin{bmatrix}w_{if,1,1}\cdot x_{t}&w_{if,2,1}\cdot x_{t}&\ldots& w_{if,64,1}\cdot x_{t}\end{bmatrix} \in\mathrm{R}^{64} \tag{3}\]  
\[W_{hf}h_{t-1}=