Multi-head attention mechanism-based ship control motion extremely-short-term forecasting method
By using a neural network based on a multi-head attention mechanism, the separation and processing of ship motion state and control variables and the capture of long-range temporal dependencies were achieved, solving the problems of low forecast efficiency and insufficient accuracy in existing technologies and improving the accuracy and efficiency of ship motion prediction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI JIAOTONG UNIV
- Filing Date
- 2025-12-25
- Publication Date
- 2026-04-28
AI Technical Summary
Existing ship motion prediction methods based on recurrent neural networks suffer from poor training parallelism due to the recurrent computation mechanism, resulting in low efficiency when processing long sequences. Furthermore, they fail to effectively distinguish between motion state variables and control variables, leading to low prediction accuracy.
A ship motion timing prediction neural network based on a multi-head attention mechanism is adopted. Through feature mapping module, position encoding module, attention calculation module, masking module and output mapping module, the motion state and control quantity are separated and processed. The multi-head attention allocation strategy and sine-cosine position encoding are used to capture long-term temporal dependencies and avoid future information leakage.
It improves the accuracy and efficiency of ship motion state prediction, can accurately capture the coupling relationship of ship motion, adapts to the needs of different prediction scenarios, and reduces prediction errors.
Smart Images

Figure CN121935518A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of ship motion prediction technology, and in particular to a method for predicting ship maneuvering motion response based on a multi-head attention mechanism. Background Technology
[0002] Accurate ship motion prediction is a core technology for advanced navigation aid systems, dynamic positioning, and autonomous navigation vessels. A ship's pitch speed, sway speed, and yaw rate are jointly determined by propulsion equipment such as propellers and rudders, as well as environmental disturbances. This dynamic process exhibits strong nonlinearity, coupling, and time delay. Existing time-series ship motion prediction methods based on recurrent neural networks and their variants suffer from poor training parallelism due to their recurrent computation mechanism, resulting in low efficiency when processing long sequences. Furthermore, they fail to distinguish the inherent physical differences between motion state variables and control variables.
[0003] Therefore, there is an urgent need in this field for a new forecasting method that can accurately model the physical mechanisms of ship motion, perform efficient reasoning, and provide high forecast accuracy. Summary of the Invention
[0004] The purpose of this invention is to provide a ship motion timing prediction neural network based on a multi-head attention mechanism, which solves the problems of insufficient long-range dependency capture, poor coupling processing of motion and control quantities, and low multi-step prediction accuracy in the prior art, and achieves accurate timing prediction of ship motion state.
[0005] To solve the above-mentioned technical problems, the present invention adopts the following technical solution: A method for predicting ship maneuvering motions based on a multi-head attention mechanism, characterized by the following steps: Step 1: Collect the ship's motion data and propeller control information, preprocess the data, and construct a training dataset. The preprocessing includes: The data is standardized to obtain sequence data containing standardized motion state characteristics and control characteristics. The input sequence-output sequence pair is obtained using the sequence data; Step 2: Construct a manipulation motion prediction model. The model consists of a feature mapping module, a position encoding module, an attention calculation module, a mask processing module, and an output mapping module. Step 3: Input sequence-output sequence pairs from the training set are fed into the model from Step 2 for processing and the parameters of the model from Step 2 are adjusted, thereby training the manipulation motion prediction model. Step 4: Use the trained maneuver motion prediction model to predict motion. Input the historical motion state feature sequence, the historical control quantity feature sequence, and the future control quantity feature sequence, and output the future motion state feature sequence.
[0006] Preferably, the feature mapping module decomposes the input sequence data into a motion state feature set. S =[ u , v , r and control quantity feature set C =[s, The motion state feature set passes through the first linear layer. Mapped to a high-dimensional feature space, the control quantity feature set passes through a second linear layer. Mapped to the same dimension, u represents sway velocity, v represents roll velocity, r represents bow roll rate, and s represents engine speed. As the rudder angle, The mapped high-dimensional features are then fed into two sets of FeedForward layers with identical structures. The motion state features and control quantity features output from the feedforward layer are respectively used as two sub-matrices of the value matrix. , Together they form a complete value matrix , Position encoding module: Employs sine-cosine position encoding, generating two sets of position codes based on the historical sequence length m and the target sequence length n. , , In the formula, The time step number. Let 'i' be the positional encoding dimension, and 'i' be the index of the encoding dimension. The input sequence corresponds to the positional encoding sequence. The target sequence is a sequence of length m, and the corresponding position encoding sequence is... A complete positional encoding sequence of length m+n is obtained by concatenating the two sequences, with the starting index continuing from the ending index of the input sequence. ,Will , The bond matrix is obtained by mapping through two linear layers respectively. and query matrix ,
[0007]
[0008] In the formula, , For trainable weight matrix, , For bias terms, The attention calculation module includes six attention heads, divided into three groups, each group corresponding to a predictor variable. ), groups with the same Q, K, and , Each attention calculation module independently calculates the attention weight, using the following formula:
[0009]
[0010] The mask processing module performs a Hadamard product operation on the mask matrix and the attention weight matrix, and then processes the attention weight matrix... and The time-weighted results are concatenated and mapped through a linear layer to obtain the attention fusion feature. , , , The output mapping module will fuse features. , , After processing by this feedforward layer, enhanced high-dimensional features are obtained. , , ;
[0011]
[0012]
[0013] In the formula, , , , , , For trainable weight matrix, , , , , , For bias terms; Enhanced high-dimensional features , , The formula for mapping to the target dimension via a linear layer is:
[0014] In the formula, For trainable weight matrix, For output bias terms; The output matrix is an n-row, 3-column matrix, with each row corresponding to the [u, v, r] three-dimensional motion state of a prediction time step, ultimately forming a prediction sequence of length n.
[0015] Preferably, the specific process of constructing the dataset in step 1 includes: Step 1.1: Select feature variables, using the ship's pitch speed u, yaw speed v, and yaw rate r as motion state features, and the main engine speed s and rudder angle as features. As a characteristic of control quantity; Step 1.2: Standardize the data according to the following formula to obtain standardized ship motion state and control quantity sequence data;
[0016] In the formula, Representation of features x (u, v, r, s, The original data at time i, Representation of features Standardized data, express x The minimum value of the sequence. express x The maximum value in the sequence; Step 1.3: Construct input sequence-output sequence pairs, where the input sequence includes the historical sequence and the target sequence; Step 1.4: For the continuously collected ship time-series data, a sliding window method is used for sampling. The sampling process includes: from the i-th data point to the... Given a set of data, extract a historical sequence of length m from it. From the first data point to the... Given a set of data, extract an output sequence and a target sequence of length n to form a set of training data. Start sliding from the i-th data point... The data, from the first Starting with the first data point, continue building input-output sequence pairs, repeating the sliding operation until all data has been traversed. The preset sliding window interval; Step 1.5: Shuffle the order of all input-output pairs obtained by the sliding window sampling and divide them into training set, validation set and test set according to a predetermined ratio.
[0017] Preferably, the input sequence-output sequence pair includes an input sequence and an output sequence. The input sequence is a complete feature sequence of length m, containing motion state features and control quantity features. Motion state refers to velocity variables u, v, and r, and control quantity refers to rotational speed and rudder angle. The output sequence is a motion state feature sequence of length n.
[0018] Preferably, the method includes: Two target sequence construction methods are employed, adapted to both direct multi-step prediction mode and iterative multi-step prediction mode, respectively: Method 1, adapted to direct multi-step prediction mode, the target sequence includes a motion state feature sequence of length n and a control quantity feature sequence of length n, where the values of the motion state feature sequence are assigned to 0. Method 2, adapted to iterative multi-step prediction mode, the target sequence includes a motion state feature sequence of length n and a control quantity feature sequence of length n.
[0019] Preferably, a mask matrix is constructed. Satisfy: For the i-th row, the first... The column element is 1, and the remainder is... The column element is 0, that is:
[0020] The Hadamard product of the mask matrix and the attention weight matrix is performed to shield against future information interference. The formula is as follows:
[0021] After masking within each attention module, the attention weight matrix will be... and The time-weighted results are concatenated and mapped through a linear layer to obtain the attention fusion feature. , , :
[0022]
[0023]
[0024] Preferably, the process of maneuver motion prediction model prediction in step 4 includes: (1) Prediction Mode 1, Direct Multi-Step Prediction Mode: Input a preprocessed historical motion state feature sequence and a historical control quantity feature sequence of length m, input a preprocessed target control quantity feature sequence of length n and a target motion feature sequence of length n with a value of 0, and output a motion state prediction sequence of length n in one go by manipulating the motion prediction model; (2) Prediction Mode 2, Iterative Multi-Step Prediction Mode: Input the preprocessed historical motion state feature sequence and historical control quantity feature sequence of length m, input the preprocessed target control quantity feature of step m+1 and the target motion feature with a value of 0 at step m+1, and output the motion state prediction sequence of step m+1 by manipulating the motion prediction model. Construct the target control variable feature and the target motion feature with a value of 0 in the (m+2)th step, and concatenate them to the end of the target control variable feature and the predicted motion feature in the (m+1)th step to form a new target sequence of length 2. Repeat the above steps until a predicted motion feature sequence of length n is generated.
[0025] On the other hand, the present invention provides a ship maneuvering prediction model based on a multi-head attention mechanism, characterized in that the prediction model includes: a feature mapping module, a position encoding module, an attention calculation module, a mask processing module, and an output mapping module. The feature mapping module is used to decompose the input sequence data into a motion state feature set. and control quantity feature set The motion state feature set passes through the first linear layer Mapped to a high-dimensional feature space, the control quantity feature set passes through a second linear layer. Mapped to the same dimension, where u is the sway velocity, v is the roll velocity, r is the bow roll rate, and s is the engine rotation speed. As the rudder angle, The mapped high-dimensional features are then fed into two sets of FeedForward layers with identical structures. The features output from the feedforward layer for the motion state and control quantity are respectively used as two sub-matrices of the value matrix. , Together they form a complete value matrix , The position encoding module is used to generate two sets of position codes based on the length m of the historical sequence and the length n of the target sequence, using sine-cosine position encoding: , , In the formula, pos is the time step number. Let 'i' be the positional encoding dimension, and 'i' be the index of the encoding dimension. The input sequence corresponds to the positional encoding sequence. The target sequence is a sequence of length m, and the corresponding position encoding sequence is... A complete positional encoding sequence of length m+n is obtained by concatenating the two sequences, with the starting index continuing from the ending index of the input sequence. ,Will , The bond matrix is obtained by mapping through two linear layers respectively. K and query matrix Q ,
[0026]
[0027] In the formula, , For trainable weight matrix, , For bias terms, The attention calculation module includes six attention heads, divided into three groups. Each group corresponds to a prediction variable (u, v, r), and each group has the same Q, K, ... and ,
[0028]
[0029] The mask processing module is used to perform a Hadamard product operation between the mask matrix and the attention weight matrix, and to process the attention weight matrix... and The time-weighted results are concatenated and mapped through a linear layer to obtain the attention fusion feature. , , , The output mapping module is used to fuse features. , , After processing by this feedforward layer, the features are obtained. , , ;
[0030]
[0031]
[0032] In the formula, , , , , , For trainable weight matrix, , , , , , For bias terms; Enhanced high-dimensional features , , The formula for mapping to the target dimension via a linear layer is:
[0033] In the formula, For trainable weight matrix, For output bias terms; The output matrix O is an n-row, 3-column matrix, with each row corresponding to the [u, v, r] three-dimensional motion state of a prediction time step, ultimately forming a prediction sequence of length n.
[0034] The beneficial effects of this invention are as follows: 1. A feature processing mechanism that separates motion state from control variables is adopted. The expression of different types of features is enhanced through independent linear layers and feedforward layers, thereby improving the model's ability to capture the coupling relationship of ship motion. 2. Design a targeted multi-head attention allocation strategy, with two attention heads corresponding to each prediction target, focusing on the influence of motion state and control quantity respectively, to solve the problem of multivariate collaborative prediction; 3. By adopting sine-cosine positional encoding and concatenated K-matrix design, combined with lower triangular mask processing, long-term temporal dependencies are effectively captured, future information leakage is avoided, and the reliability of modeling is improved. 4. Attention weights are calculated using only the Q and K matrices after position encoding mapping, without introducing high-dimensional feature encodings into the weight calculation. This effectively avoids interference from irrelevant "semantic relevance" in ship motion scenarios, allowing the model to focus on capturing the temporal dependencies of motion parameters, which is consistent with the essential characteristics of ship motion time series data. 5. Offers two prediction modes to suit different scenario requirements; Attached Figure Description
[0035] Figure 1 Flowchart for building a ship maneuvering motion prediction model.
[0036] Figure 2 A schematic diagram is constructed for the two target sequences.
[0037] Figure 3 This is a diagram of the architecture of a ship maneuvering motion prediction model.
[0038] Figure 4 Loss function variation curve.
[0039] Figure 5 This is a distribution diagram of attention weights for the two forecasting models.
[0040] Figure 6 The flowcharts are for two forecasting modes.
[0041] Figure 7 This is a diagram showing the speed prediction results. Detailed Implementation
[0042] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0043] The ship maneuvering motion prediction method based on a multi-head attention mechanism in this embodiment is based on an innovative model architecture that combines separate modeling of motion state and control variables, six-head attention allocation, and dual-mode prediction (direct multi-step / iterative multi-step). A feature preprocessing module independently maps ship motion state features and control variable features to a high-dimensional space. Then, a multi-head attention calculation module based solely on position encoding captures the temporal dependencies of the motion sequence. A masking module prevents future information leakage. Finally, a feedforward network strengthens feature representation, and the output mapping module generates the prediction result. Compared to traditional multi-head attention mechanisms, this invention, through its design of "using only position encoding to calculate weights + dedicated allocation to six attention heads," gives each attention head a clear functional positioning, enhancing the accurate modeling of ship maneuvering motion temporal sequences.
[0044] The specific solution of the present invention is as follows: 1. Data Acquisition and Preprocessing: Collect ship motion data (pitch speed u, sway speed v, yaw rate r) and propeller control information (main engine speed s, rudder angle). That is, selecting characteristic variables, using the ship's pitch speed u, sway speed v, and bow roll rate r as motion state characteristics, and the main engine speed s and rudder angle as characteristics. As a control variable feature, the data is standardized according to the following formula to obtain standardized ship motion state and control variable sequence data;
[0045] In the formula, Representation of features x (u, v, r, s, The original data at time i, Representation of features Standardized data, express x The minimum value of the sequence. express x The maximum value of the sequence.
[0046] To eliminate the phenomenon of repeated data in multiple frames caused by insufficient accuracy of inertial navigation velocity measurement, the data is downsampled to 0.5Hz.
[0047] Construct input sequence-output sequence pairs, where the input sequence includes the historical sequence and the target sequence. The input sequence is a complete feature sequence of length m, containing motion state features and control variable features. The motion state refers to the velocity variables u, v, and r, and the control variable refers to the rotational speed and rudder angle. The output sequence is a motion state feature sequence of length n.
[0048] For continuously collected ship time-series data, a sliding window method is used for sampling. The specific process is as follows: from the i-th data point to the... Given a set of data, extract a historical sequence of length m, starting from the (i+m)th data point and continuing to the (i+m)th data point. Given a set of data, extract an output sequence and a target sequence of length n to form a training set (a training set includes input and output quantities, both of which are continuous sequences, meaning a sequence consists of several consecutive time points sampled, each data point including (u, v, r, s, ...). These variables. The input and output sequences are also continuous; that is, the first m data points are used to predict the next n data points. The complete dataset can be viewed as a very long sequence. When truncating, the required length is truncated starting from the i-th data point. After taking a set of "training samples", the sequence is truncated again starting from the i-th index and moving forward. (A data point, from which the sequence is further truncated). Slide forward from the i-th data point. For each data point, starting from the (i+s1)th data point, continue constructing input-output sequence pairs; repeat the sliding window operation until all data points have been traversed. Shuffle the order of all input-output pairs obtained from the sliding window sampling and divide them into training, validation, and test sets in a 7:2:1 ratio.
[0049] In this embodiment: the length of the historical sequence is set to m=10, the length of the target and output sequences is n=30, the sliding step is 1, and finally 7865 effective input-output pairs are generated, which are divided into training set, validation set and test set in a ratio of 7:2:1 for model training, hyperparameter adjustment and performance evaluation.
[0050] Two target sequence construction methods are used, each adapted to different prediction modes: Method 1, adapted to iterative multi-step prediction mode, the target sequence contains a motion state feature sequence of length n and a control quantity feature sequence of length n; Method 2, adapted to the direct multi-step prediction mode, the target sequence includes a motion state feature sequence of length n and a control quantity feature sequence of length n, where the value of the motion state feature sequence is assigned to 0.
[0051] The two modes are as follows: Figure 2 (a) Figure 2As shown in (b), the iterative multi-step prediction mode does not set the target motion sequence to 0, while the direct multi-step prediction mode does set the target motion sequence to 0.
[0052] 2. Model Building: A ship maneuvering motion prediction model based on a multi-head attention mechanism is constructed, the specific architecture of which is as follows: Figure 3 As shown, it includes: feature mapping module, position encoding module, attention calculation module, mask processing module and output mapping module. The following sections introduce each module and the methods it executes.
[0053] The feature mapping module, serving as the input to the ship maneuvering motion prediction model, decomposes the input sequence into a set of motion state features. and control quantity feature set They are mapped to a high-dimensional feature space through the following linear layers respectively:
[0054]
[0055] In the formula, , For trainable weight matrix, , For bias terms; In this example, the high-dimensional feature dimension The mapped high-dimensional features are then fed into two sets of FeedForward layers with identical structures. Each feedforward layer consists of two linear layers and an intermediate ReLU activation function, as shown in the formula: In the formula , For trainable weight matrix, , This is a bias term.
[0056] The features output from the feedforward layer for the motion state and control quantity are respectively used as two sub-matrices of the value matrix. , Together they form a complete value matrix .
[0057] ,
[0058] , In the formula, , , , For trainable weight matrix, , , , For bias terms; The second module is the position encoding module, which uses sine-cosine position encoding to generate two sets of position codes based on the length m of the historical sequence and the length n of the target sequence:
[0059]
[0060] In the formula, pos is the time step number. Here, i represents the positional encoding dimension, and i is the index of the encoding dimension; the input sequence corresponds to the positional encoding sequence. The target sequence is a sequence of length m, and the corresponding position encoding sequence is... A complete positional encoding sequence of length m+n is obtained by concatenating the two sequences, with the starting index continuing from the ending index of the input sequence. ,Will , The bond matrix is obtained by mapping through two linear layers respectively. K and query matrix Q ;
[0061]
[0062] In the formula, , For trainable weight matrix, , This is a bias term.
[0063] The third module is the multi-head attention calculation module, which uses six attention heads to achieve accurate weight allocation for multiple variables and feature types. The specific allocation mode is as follows: The six attention heads are divided into three groups, each corresponding to a predictor variable (u, v, r), and each group has the same Q, K, ... and Two attention heads within each group are processed separately. and There are a total of six attention heads, and Q and K are the same in each head, with three heads having the same Q and K. The other three heads are .
[0064] The attention mechanism originates from the Transformer model, which consists of a cascaded encoder and decoder. Each encoder and decoder comprises several network layers, each containing a cascaded FeedForward layer and an attention layer. The attention layer is the core component of the Transformer model. It maps input features to queries (Q), keys (K), and values (V) through learnable parameters, calculates and normalizes the association weights between Q and K, and weighted aggregates V to obtain key features. This achieves dynamic focusing on long-range and core information in the input, overcoming the limitations of information transmission in traditional convolutional neural networks and recurrent neural networks. (FeedForward and attention are...) Figure 3 (All of them are included) Within each attention head, Q, K, and V are split according to the number of attention heads, resulting in... , , (i=1,2,…,6); Each attentional point is calculated independently using the following formula:
[0065] .
[0066] The fourth module is the mask processing module, which constructs the mask matrix. Satisfy: For the i-th row, the first... The column element is 1, and the remainder is... The column element is 0, that is:
[0067] The Hadamard product of the mask matrix and the attention weight matrix is performed to shield against future information interference. The formula is as follows:
[0068] After applying a mask within each attention module, the attention weight matrix will be... and The time-weighted results are concatenated and mapped through a linear layer to obtain the attention fusion feature. , , :
[0069]
[0070]
[0071] The fifth module is the output mapping module, which adopts the same FeedForward structure as the feature preprocessing module, and maps the fused features. , , After processing by this feedforward layer, enhanced high-dimensional features are obtained. , , ;
[0072]
[0073]
[0074] In the formula, , , , , , For trainable weight matrix, , , , , , For bias terms; Enhanced high-dimensional features , , The formula for mapping to the target dimension via a linear layer is:
[0075] In the formula, For trainable weight matrix, For output bias terms; Output matrix Each row corresponds to the [u, v, r] three-dimensional motion state of a prediction time step, ultimately forming a prediction sequence of length n; 3. Based on the training dataset, the ship maneuvering motion prediction model is iteratively trained with the goal of minimizing the loss function. The model is then fine-tuned based on the validation set results to determine the final ship maneuvering motion prediction model. The loss function descent process during training is as follows: Figure 3 As shown.
[0076] Example of visualization results of the attention weights of the trained model: Figure 5 (a) Figure 5 As shown in (b).
[0077] 4. Use the trained maneuver motion prediction model to predict motion. Input the historical motion state feature sequence, the historical control quantity feature sequence, and the future control quantity feature sequence, and output the future motion state feature sequence. The prediction modes of the manipulator motion prediction model are divided into two types: Direct multi-step prediction, such as Figure 6As shown in (a), the input is a preprocessed historical motion state feature sequence and a historical control quantity feature sequence of length m, the input is a preprocessed target control quantity feature sequence of length n and a target motion feature sequence of length n with a value of 0, and the motion prediction model is manipulated to output a motion state prediction sequence of length n in one go; Iterative multi-step prediction, such as Figure 6 As shown in (b), the input is a preprocessed historical motion state feature sequence and a historical control quantity feature sequence of length m, the input is a preprocessed target control quantity feature of step m+1 and a target motion feature with a value of 0 at step m+1, and the output is a motion state prediction sequence of step m+1 by manipulating the motion prediction model. Construct the target control variable feature and the target motion feature with a value of 0 at step m+2, and concatenate them to the end of the target control variable feature and the predicted motion feature at step m+1 to form a new target sequence of length 2. Repeat the above steps until a predicted motion feature sequence of length n is generated.
[0078] The text mentions three sequences: historical sequence, target sequence, and output sequence. The historical and target sequences serve as input sequences for the model, while the output sequence represents the actual, future motion state (excluding control variables), which the model learns from. The target sequence is special; it corresponds to the same time period as the output sequence and includes both motion state and control variables. Predicting future motion requires knowing how to control the ship in the future, so both methods of constructing the target sequence include the control variable sequence. The difference between the two sequences lies in the handling of the future motion state sequence. The "future motion state sequence" mentioned here is the same as the output sequence, which the model outputs. Therefore, method one retains this sequence and uses it only during training iterations. Method two, however, appends the motion state, ensuring that information is not leaked. Experimental testing: The object of this embodiment is a trimaran with a length of 12m, a full load displacement of 9t, and a maximum speed of 12kn. The model history sequence length is 5s, the prediction sequence length is 15s, that is, motion prediction is performed every 15s, the data sampling interval is 0.5s, the maneuvering motion is mainly turning motion and zigzag motion, and the total prediction time is 1 hour. Figure 7 The results shown are the predictions over 150 seconds, with the model making 10 consecutive predictions.
[0079] The speed prediction results of the ship maneuvering motion prediction model based on the multi-head attention mechanism in this embodiment are as follows: Figure 7 As shown, compared to the LSTM model, the average velocity prediction error of the model is reduced by 27%.
Claims
1. A method for predicting ship maneuvering motions based on a multi-head attention mechanism, characterized in that, Includes the following steps: Step 1: Collect the ship's motion data and propeller control information, preprocess the data, and construct a training dataset. The preprocessing includes: The data is standardized to obtain sequence data containing standardized motion state characteristics and control characteristics. The input sequence-output sequence pair is obtained using the sequence data; Step 2: Construct a manipulation motion prediction model. The model consists of a feature mapping module, a position encoding module, an attention calculation module, a mask processing module, and an output mapping module. Step 3: Input sequence-output sequence pairs from the training set are fed into the model from Step 2 for processing and the parameters of the model from Step 2 are adjusted, thereby training the manipulation motion prediction model. Step 4: Use the trained maneuver motion prediction model to predict motion. Input the historical motion state feature sequence, the historical control quantity feature sequence, and the future control quantity feature sequence, and output the future motion state feature sequence.
2. The ship maneuvering motion prediction method based on multi-head attention mechanism according to claim 1, characterized in that, The feature mapping module decomposes the input sequence data into a motion state feature set S=[u,v,r] and a control quantity feature set C=[s, The motion state feature set passes through the first linear layer. Mapped to a high-dimensional feature space, the control quantity feature set passes through a second linear layer. Mapped to the same dimension, u represents sway velocity, v represents roll velocity, r represents bow roll rate, and s represents engine speed. As the rudder angle, The mapped high-dimensional features are then fed into two sets of FeedForward layers with identical structures. The motion state features and control quantity features output from the feedforward layer are respectively used as two sub-matrices of the value matrix. , Together they form a complete value matrix , Position encoding module: Employs sine-cosine position encoding, generating two sets of position codes based on the historical sequence length m and the target sequence length n. , , In the formula, pos is the time step number. Let 'i' be the positional encoding dimension, and 'i' be the index of the encoding dimension. The input sequence corresponds to the positional encoding sequence. The target sequence is a sequence of length m, and the corresponding position encoding sequence is... A complete positional encoding sequence of length m+n is obtained by concatenating the two sequences, with the starting index continuing from the ending index of the input sequence. ,Will , The key matrix K and query matrix Q are obtained through two linear layers of mapping, respectively. , , In the formula, , For trainable weight matrix, , As a bias term, the attention calculation module includes six attention heads, divided into three groups, each corresponding to a predictor variable (u, v, r), with identical Q, K, and ... within each group. and Each attention calculation module independently calculates the attention weights, using the following formula: , , The mask processing module performs a Hadamard product operation on the mask matrix and the attention weight matrix, and then processes the attention weight matrix... and The time-weighted results are concatenated and mapped through a linear layer to obtain the attention fusion feature. , , , The output mapping module will fuse features. , , After processing by this feedforward layer, enhanced high-dimensional features are obtained. , , ; , , , In the formula, , , , , , For trainable weight matrix, , , , , , For bias terms; Enhanced high-dimensional features , , The formula for mapping to the target dimension via a linear layer is: , In the formula, For trainable weight matrix, For output bias terms; The output matrix is an n-row, 3-column matrix, with each row corresponding to the [u, v, r] three-dimensional motion state of a prediction time step, ultimately forming a prediction sequence of length n.
3. The method for predicting ship maneuvering motions according to claim 2, characterized in that, The specific process of constructing the dataset in step 1 includes: Step 1.1: Select feature variables, using the ship's pitch speed u, yaw speed v, and yaw rate r as motion state features, and the main engine speed s and rudder angle as features. As a characteristic of control quantity; Step 1.2: Standardize the data according to the following formula to obtain standardized ship motion state and control quantity sequence data; , In the formula, Representing the feature x(u, v, r, s, The original data at time i, Representation of features Standardized data, Let x represent the minimum value of the sequence. This represents the maximum value of the x sequence; Step 1.3: Construct input sequence-output sequence pairs, where the input sequence includes historical sequences and target sequences; Step 1.4: For continuously collected ship time-series data, use the sliding window method for sampling. The sampling process includes: from the i-th data point to the (i+m-1)-th data point, extract a historical sequence of length m; from the (i+m)-th data point to the (i+m+n-1)-th data point, extract an output sequence and a target sequence of length n to form a set of training data; slide s1 data points backward from the i-th data point; continue constructing input-output sequence pairs from the (i+s1)-th data point, repeating the sliding operation until all data is traversed, where s1 is the preset sliding window interval; Step 1.5: Shuffle the order of all input-output pairs obtained by the sliding window sampling and divide them into training set, validation set, and test set according to a predetermined ratio.
4. The method for predicting ship maneuvering motions according to claim 3, characterized in that, Input sequence-output sequence pairs include an input sequence and an output sequence. The input sequence is a complete feature sequence of length m, containing motion state features and control quantity features. Motion state refers to velocity variables u, v, and r, and control quantity refers to rotational speed and rudder angle. The output sequence is a motion state feature sequence of length n.
5. The method for predicting ship maneuvering motions according to claim 4, characterized in that, The method includes: Two target sequence construction methods are employed, adapted to both direct multi-step prediction mode and iterative multi-step prediction mode, respectively: Method 1, adapted to direct multi-step prediction mode, the target sequence includes a motion state feature sequence of length n and a control quantity feature sequence of length n, where the values of the motion state feature sequence are assigned to 0. Method 2, adapted to iterative multi-step prediction mode, the target sequence includes a motion state feature sequence of length n and a control quantity feature sequence of length n.
6. The method for predicting ship maneuvering motions according to claim 4, characterized in that, Construct a mask matrix Satisfies the following condition: For the i-th row, the first m+i-1 columns are 1s, and the remaining n-i+1 columns are 0s, that is: , The Hadamard product of the mask matrix and the attention weight matrix is performed to shield against future information interference. The formula is as follows: , After masking within each attention module, the attention weight matrix will be... and The time-weighted results are concatenated and mapped through a linear layer to obtain the attention fusion feature. , , : , , 。 7. The method for predicting ship maneuvering motions according to claim 5, characterized in that, Step 4 describes the process of predicting motion using a maneuvering prediction model, which includes: (1) Prediction Mode 1, Direct Multi-Step Prediction Mode: Input a preprocessed historical motion state feature sequence and a historical control quantity feature sequence of length m, input a preprocessed target control quantity feature sequence of length n and a target motion feature sequence of length n with a value of 0, and output a motion state prediction sequence of length n in one go by manipulating the motion prediction model; (2) Prediction Mode 2, Iterative Multi-Step Prediction Mode: Input the preprocessed historical motion state feature sequence and historical control quantity feature sequence of length m, input the preprocessed target control quantity feature of step m+1 and the target motion feature with a value of 0 at step m+1, and output the motion state prediction sequence of step m+1 by manipulating the motion prediction model. Construct the target control variable feature and the target motion feature with a value of 0 in the (m+2)th step, and concatenate them to the end of the target control variable feature and the predicted motion feature in the (m+1)th step to form a new target sequence of length 2. Repeat the above steps until a predicted motion feature sequence of length n is generated.
8. A ship maneuvering prediction model based on a multi-head attention mechanism, characterized in that, The prediction model includes: a feature mapping module, a position encoding module, an attention calculation module, a mask processing module, and an output mapping module. The feature mapping module is used to decompose the input sequence data into a motion state feature set S=[u,v,r] and a control quantity feature set C=[s,δ]. The motion state feature set is then processed by a first linear layer. Mapped to a high-dimensional feature space, the control quantity feature set passes through a second linear layer. Mapped to the same dimension, where u is the sway velocity, v is the roll velocity, r is the bow roll rate, and s is the engine rotation speed. As the rudder angle, the mapped high-dimensional features are fed into two sets of FeedForward layers with identical structures. The features output by the motion state and control quantity through the feedforward layers are used as two sub-matrices of the value matrix. , Together they form a complete value matrix The position encoding module is used to generate two sets of position codes based on the length m of the historical sequence and the length n of the target sequence, using sine-cosine position encoding: , , In the formula, pos is the time step number. Let 'i' be the positional encoding dimension, and 'i' be the index of the encoding dimension. The input sequence corresponds to the positional encoding sequence. The target sequence is a sequence of length m, and the corresponding position encoding sequence is... A complete positional encoding sequence of length m+n is obtained by concatenating the two sequences, with the starting index continuing from the ending index of the input sequence. ,Will , The key matrix K and query matrix Q are obtained through two linear layers of mapping, respectively. , , In the formula, , For trainable weight matrix, , As a bias term, the attention calculation module includes six attention heads, divided into three groups, each corresponding to a predictor variable (u, v, r), with identical Q, K, and ... within each group. and Each attention calculation module independently calculates the attention weights, using the following formula: , , The mask processing module is used to perform a Hadamard product operation between the mask matrix and the attention weight matrix, and to process the attention weight matrix... and The time-weighted results are concatenated and mapped through a linear layer to obtain the attention fusion feature. , , , The output mapping module is used to fuse features. , , After processing by this feedforward layer, the features are obtained. , , ; , , , In the formula, , , , , , For trainable weight matrix, , , , , , For bias terms; Enhanced high-dimensional features , , The formula for mapping to the target dimension via a linear layer is: , In the formula, For trainable weight matrix, For output bias terms; The output matrix O is an n-row, 3-column matrix, with each row corresponding to the [u, v, r] three-dimensional motion state of a prediction time step, ultimately forming a prediction sequence of length n.