## 3 Methodological Approach
### Ship Fuel Consumption Prediction Model Based on SA-LSTM  
Due to the successful application of the SA-LSTM model in previous studies across various fields, this paper considers applying it to predict ship fuel consumption. This model can concurrently consider information from each time step within a sequence and dynamically adjust based on the significance of elements in the sequence, effectively capturing patterns and trends in the time series data. The self-attention mechanism, originating from the Transformer model, weighs elements at different positions in a sequence to determine their importance. The structure of the SA-LSTM model used in this study is depicted in Figure 3.  
In the SA-LSTM model, the self-attention mechanism is integrated into the LSTM model to enhance the model's ability to focus on information at various positions in the sequence, thereby better capturing long-distance dependencies within the sequence. The introduction of the self-attention mechanism involves the following steps:  
(1) Input Sequence Representation: The sequence signifying the ship's operating parameters is presented as \(X=x_{1},x_{2}\ldots,x_{t}\), where \(t\) is the sequence length. (2) Setting queries, keys, and values: For any given input, first set the weights \(W^{q}\), \(W^{k}\), \(W^{c}\) of the query, key, and value, respectively, and transform the input linearly to obtain the corresponding results \(Q\), \(K\), and \(V\), and the expression is:  
\[ \begin{cases}Q=W^{q}X\\ K=W^{k}X\\ V=W^{v}X\end{cases}  \tag{1}\]  
Embedding the input sequence, mapping each parameter, \(x_{i}\), to a vector in a high-dimensional space, \(E(X)=e_{1},e_{2},\ldots e_{t}\). According to the high-dimensional mapping, it can assist the model in better comprehending the relationships among different parameters. (3) Self-attention calculation: Evaluates the correlation, \(S\), between the \(Q\) and \(K\), and then performs a softmax operation on each row of the attention score matrix, \(S\), to obtain the attention weight matrix, \(A\). The specific calculation formula is as follows:  
\[ \begin{cases}S(q,k)=v*\tanh(W_{q}Q+W_{k}K)\\ A=\text{softmax}(S(q,k))\end{cases}  \tag{2}\]  
Figure 3: General structure of the SA\(-\)LSTM model. where \(v\) is the learnable vector, tanh is the activation function, and \(W_{q}\) and \(W_{k}\) are the learnable parameters. (4) Attention-weighted representation: Use the attention weights to perform a weighted sum of the embedded vectors to obtain the attention-weighted representation vector, \(C\), at each position. \[C=A(Q,K,V)=\text{softmax}(S(q,k))V \tag{3}\]  
where \(C\) is the attention-weighted representation vector. (5) Combination with the LSTM model: Input the obtained attention-weighted representation vector, \(C\), into the LSTM model as its input sequence. SA-LSTM can capture the long-term dependency relationships in the sequence through the recursive operation of the time step, \(t\), and the recursive formula is as follows:  
\[ \begin{cases}i_{t}=\sigma(W_{ii}\cdot x_{t}+b_{ii}+W_{hi}\cdot h_{t-1}+b_{hi}),\\ f_{t}=\sigma\left(W_{if}\cdot x_{t}+b_{if}+W_{hf}\cdot h_{t-1}+b_{hf}\right), \\ g_{t}=\tanh(W_{ig}\cdot x_{t}+b_{ig}+W_{hg}\cdot h_{t-1}+b_{hg}),\\ o_{t}=\sigma(W_{io}\cdot x_{t}+b_{io}+W_{ho}\cdot h_{t-1}+b_{ho}),\\ c_{t}=f_{t}+c_{t-1}+i_{t}\cdot g_{t},\\ h_{t}=o_{t}\text{-tanh}(c_{t}),\end{cases}  \tag{4}\]  
where the parameters in Equation (4) are described as follows in the Table 1.  
Most previous literature has adopted traditional machine learning methods for relevant research, lacking the application of deep learning models, and the SA-LSTM model has shown excellent performance in studies related to temporal sequence prediction.