## 2 Methods
### Long Short-Term Memory Networks Couple with Attention  
Long short-term memory (LSTM) networks can effectively capture the nonlinear characteristics of time series through storing historical data streams. However, due to the diversified complexity of dam deformation monitoring, the time lag of influencing factors is particularly prominent. For example, an increase in temperature or water level does not immediately lead to dam deformation, but a gradual process, which manifests as a delayed deformation response. This factor increases the complexity of dam deformation prediction in the time dimension, so this paper develops a dam deformation prediction method based on the attention mechanism coupled with LSTM model. LSTM model is essentially a device that superimposes and stores information. It adjusts the destination of information in the model unit through the special structure called gate. LSTM model has three gate structures: the forget gate determines the information that needs to be removed in the current cell unit; the input gate determines which information in the newly input information fragment is updated to the current cell unit and the output gate collects the information memorized by the cell unit to obtain the final output result. The calculation process expression of each LSTM cell unit is as follows:  
\[f_{t}=\sigma(W_{f}\cdot[h_{t-1},x_{t}]+b_{f}) \tag{13}\]  
\[i_{t}=\sigma(W_{i}\cdot[h_{t-1},x_{t}]+b_{i}) \tag{14}\]  
\[\widetilde{c}_{t}=\tanh(W_{c}\cdot[h_{t-1},x_{t}]+b_{c}) \tag{15}\]  
\[c_{t}=f_{t}*c_{t-1}+i_{t}*\widetilde{c}_{t} \tag{16}\]  
\[o_{t}=\sigma(W_{o}\cdot[h_{t-1},x_{t}]+b_{o}) \tag{17}\]  
\[h_{t}=o_{t}*\tanh(c_{t}) \tag{18}\]  
where \(f_{t}\) is the operating threshold of the forget gate at time \(t\); \(h_{t}\) is the output value of the network at time \(t\); \(h_{t-1}\) is the output value of the network at time \(t-1\); \(i_{t}\) is the operating threshold of the input gate at time \(t\); \(\widetilde{c}_{t}\) is the candidate value that needs to be updated at time \(t\); \(c_{t}\) is the new cell unit state at time \(t\); \(o_{t}\) is the operating threshold of the output gate at time \(t\); \(W_{f}\), \(W_{i}\), \(W_{c}\), and \(W_{o}\) are the weight matrix of the forget gate, input gate, cell state, and output gate, respectively; \(b_{f}\), \(b_{i}\), \(b_{c}\), and \(b_{o}\) are the bias of the forget gate, input gate, cell state, and output gate, respectively; and \(\sigma\) and _tanh_ are the activation functions. However, the conventional LSTM networks are unable to perform quantitative impact analysis on the input data. Thanks to the concept of attention mechanism, it can achieve the focus on key information. It imitates the way humans process information and enable the algorithm to focus on core variables by means of activation functions. Therefore, a novel LSTM algorithm structure is proposed, coupled with an attention mechanism to predict dam deformation. The attention mechanism adds a matrix with the same dimension as the input tensor, weights the hidden state in the time dimension, and then outputs the attention vector value of each time step. The attention mechanism can be added in two positions, in front of the LSTM layer and behind the LSTM layer, as shown in Figure 2. Inactual application, the target series has a complex amount of information, so the position added by the attention mechanism should be selected according to the actual effect. The attention mechanism calculates the weight \(e_{t}^{i}\) in each time dimension, and outputs the attention weight \(a_{t}^{i}\) between zero and one through the activation function, as shown below:  
\[e_{t}^{i}=V^{T}\text{tanh}(W_{s}S_{t-1}+W_{h}h_{t}) \tag{19}\]  
\[a_{t}^{i}=\text{softmax}(e_{t}^{i})=\exp(e_{t}^{i})/\sum_{k=1}^{T}\exp(e_{t}^{ k})(t=1,2,\dots,T) \tag{20}\]  
where \(S_{t-1}\) is the attention layer input at the time \(t-1\), and \(V^{T}\) and \(W_{s}\) are the weight matrices that can be trained.