Agricultural product future price trend prediction method based on image coding and attention
By converting the time series data of agricultural product futures prices into image data, and using convolutional neural networks and long-term memory networks to extract features in combination with attention mechanisms, the problem of insufficient prediction accuracy and robustness of agricultural product futures prices in the existing technology is solved, and higher prediction accuracy and model stability are achieved.
Patent Information
- Application Number
- CN202510083675.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-20
- Publication Date
- 2025-05-13
AI Technical Summary
The prior art is difficult to effectively deal with the nonlinear and non-stationary characteristics of price fluctuations in agricultural product futures price prediction, resulting in insufficient prediction accuracy and robustness.
Deep learning method based on image encoding and attention is adopted to convert the one-dimensional time series data of agricultural product futures prices into two-dimensional image data, and spatial and temporal features are extracted through convolutional neural networks and long and short-term memory networks, combining the channel attention mechanism and time-step attention mechanism to optimize feature representation and model generalization capabilities.
It significantly improves the accuracy and robustness of agricultural product futures price trend forecasts, enhances the model's ability to capture complex features and analyzes price fluctuations laws, and reduces the risk of overfitting.
Smart Images

Figure CN119991192A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of agricultural product price prediction, and in particular relates to an agricultural product futures price trend prediction method based on image coding and attention. Background Art
[0002] In the prior art, the prediction of agricultural futures prices mainly adopts statistical methods and machine learning and deep learning methods based on artificial intelligence. Statistical methods such as the autoregressive integrated moving average model (ARIMA) and the generalized autoregressive conditional heteroskedasticity model (GARCH) are classic methods for time series prediction. They capture the trend of price changes by modeling historical data and perform better when processing linear and stationary data. However, these methods have strong assumptions about the data, such as requiring the stationarity and linearity of the data. When the data has complex dynamic characteristics or large volatility, the prediction accuracy of these methods is often significantly limited.
[0003] With the development of artificial intelligence, data-driven machine learning methods have gradually been applied to agricultural futures price forecasting. Such methods can capture nonlinear relationships in price fluctuations through deep mining and feature extraction of historical data, such as support vector machines and extreme learning machines. However, machine learning methods still have shortcomings in feature extraction efficiency and model stability, and are highly sensitive to parameter settings.
[0004] Deep learning technology has been widely used in the field of time series forecasting due to its excellent feature extraction capabilities and adaptability to complex data. For example, long short-term memory networks and bidirectional long short-term memory networks can effectively capture long-term and short-term dependencies in price time series. However, existing deep learning methods still have problems such as single feature representation and insufficient model generalization ability.
[0005] In order to improve the accuracy and robustness of agricultural futures price forecasting, there is an urgent need for a forecasting method that can effectively deal with the nonlinear and non-stationary characteristics of price fluctuations. Summary of the invention
[0006] The main purpose of the present invention is to overcome the shortcomings and deficiencies of the prior art and to propose a method for predicting agricultural product futures prices based on image coding and attention.
[0007] In order to achieve the above object, the present invention adopts the following technical solutions:
[0008] The agricultural product futures price trend prediction method based on image coding and attention includes the following steps:
[0009] Using Gram's angle field or improved recursive graph method, the one-dimensional time series data of agricultural futures prices are converted into two-dimensional image data, and the two-dimensional image data are organized into input-output mapping pairs, which are subsequently input into the ImgEnc-AttNet model for training;
[0010] A deep learning hybrid network model ImgEnc-AttNet based on image encoding and attention mechanism is constructed. The ImgEnc-AttNet model includes convolution module, embedding layer, LSTM module, fully connected layer and output layer. The channel attention mechanism is introduced in the convolution module. The time step attention mechanism is introduced in the LSTM module. The ImgEnc-AttNet model includes three steps: image feature extraction, time feature extraction and trend prediction. In the image feature extraction step, the convolution module extracts image features from the input image data. In the time feature extraction step, the LSTM module extracts time features from agricultural futures price data.
[0011] Train the ImgEnc-AttNet model and use the trained ImgEnc-AttNet model to predict agricultural futures price trends.
[0012] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0013] 1. The present invention converts time series data into image representation by introducing image coding technology (GASF, GADF and RP), combines convolutional neural network to extract spatial features and long short-term memory network to process temporal features, enhances the model's ability to capture complex features, and significantly improves the accuracy of agricultural product futures price trend forecasting.
[0014] 2. The present invention introduces a channel attention mechanism in the convolution module and a time step attention mechanism in the LSTM module, so that the model can dynamically focus on key feature points and important time nodes, optimize the quality of feature representation, and improve the ability to analyze the dynamic changes of agricultural futures prices.
[0015] 3. By adopting a multi-channel data fusion strategy, the present invention retains the dynamic characteristics of the original data to the maximum extent during the conversion process from time series to images, reduces the risk of information loss, and enhances the model's ability to express complex data.
[0016] 4. By optimizing the model structure and feature representation, the present invention improves the robustness of the model in small sample data and multi-scenario applications, significantly reduces the risk of overfitting, and enhances the adaptability to new data.
[0017] 5. The present invention uses the time-step attention mechanism to dynamically assign the importance weights of each time point in the time series, thereby enhancing the model's ability to analyze price fluctuation patterns and hidden correlations. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is the overall framework diagram of the present invention;
[0019] Figure 2 It is an example of data transformation and mapping;
[0020] Figure 3 It is a feature extraction process through convolution and pooling;
[0021] Figure 4 This is a schematic diagram of the convolutional module architecture that introduces the channel attention mechanism;
[0022] Figure 5 It is a schematic diagram of the time step attention mechanism flow. DETAILED DESCRIPTION
[0023] The present invention is further described in detail below in conjunction with embodiments and drawings, but the embodiments of the present invention are not limited thereto.
[0024] Explanation of related terms:
[0025] Image encoding: A technique for converting one-dimensional time series data into a two-dimensional image representation in order to mine deeper feature information.
[0026] Time step attention: A feature optimization method in deep learning that dynamically assigns weights to each time step in time series data to highlight important time points in the prediction task, thereby improving the model's ability to capture time dependencies and prediction accuracy.
[0027] GASF (Gramian Angular Summation Field): A method for visualizing time series data that maps the time series into a symmetric matrix using a polar coordinate system, representing the cumulative relationship between time points, which is suitable for feature extraction and pattern recognition.
[0028] GADF (Gramian Angular Difference Field): A graphical method related to GASF that maps a time series into a symmetric matrix to represent the difference relationship between time points and is used to analyze the local dynamic characteristics of the series.
[0029] RP (Recurrence Plot): A technique that maps the periodicity, chaotic characteristics, and non-stationarity of a time series through graphical representation, which can visualize the recurring behavior of the time series.
[0030] Accuracy: An indicator for evaluating the overall accuracy of a prediction model, indicating the proportion of correctly predicted samples to the total samples.
[0031] F1 Score: F1 score is an indicator used to evaluate the performance of classification models. It is the harmonic mean of precision and recall, and comprehensively reflects the performance of the model on an imbalanced data set.
[0032] Best-Acc: The best accuracy refers to the highest accuracy achieved by the model in all evaluations, which is used to measure the best performance of the model.
[0033] Best-F1: The best F1 score refers to the highest F1 score achieved by the model in all evaluations, reflecting the best balanced performance of the model in the classification task.
[0034] Top5-Acc: The average of the top five accuracy rates. When the Bayesian optimization method is used to evaluate the model, it indicates the average accuracy rate of the top five best parameter combinations generated during the optimization process.
[0035] Top5-F1: The average of the top five F1 scores. When the Bayesian optimization method is used to evaluate the model, it indicates the average of the F1 scores corresponding to the top five best parameter combinations generated during the optimization process.
[0036] Example
[0037] like Figure 1 As shown, the present invention, a method for predicting agricultural product futures price trends based on image coding and attention, comprises the following steps:
[0038] S1. Using the Gram angular field and recursive graph method, the one-dimensional time series data of agricultural futures prices are converted into two-dimensional image data, and the two-dimensional image data are organized into input-output mapping pairs, which are subsequently input into the ImgEnc-AttNet model for training.
[0039] By converting the one-dimensional time series data of agricultural futures prices into two-dimensional image data, we can fully utilize the powerful capabilities of deep learning in the field of computer vision, so that the convolutional neural network (CNN) commonly used for image recognition can be applied to time series data, thereby enhancing the model's interpretation and analysis capabilities.
[0040] In this embodiment, the Gram angle field is used to convert the one-dimensional time series data into two-dimensional image data. The specific steps are as follows:
[0041] For one-dimensional time series data X = {x1, x2, ..., x N}Normalize and scale it to the interval [0,1];
[0042] The normalized data x ′ n Converted to polar coordinates, where the angle θ n and radius r n The calculation formula is:
[0043]
[0044] In the polar coordinate system, each pair of points (θ n ,r n ) and (θ m ,r m ) is expressed by calculating the cosine or sine value of their angle difference, thereby forming a Gram matrix; the Gram matrix includes the Gram sum angle matrix GASF and the Gram difference angle matrix GADF, and the calculation formula is as follows:
[0045]
[0046] Recurrence plots (RP) are an effective technique for analyzing the periodicity, chaotic properties, and non-stationarity of time series data. By visualizing the periodic characteristics of phase space trajectories, RP is able to reveal the internal structure of time series data, containing key dynamic information. This makes RP particularly suitable for representing the recurrence of previous states in a time series. The application of RP not only preserves the dynamic characteristics of the time series, but also provides important visual data for deep learning models, enabling the models to better understand and predict time series data.
[0047] The recursive graph is used to convert one-dimensional time series data into two-dimensional image data. The specific steps are as follows:
[0048] For one-dimensional time series data X = {x1, x2, ..., x N}Normalize and scale it to the interval [0,1];
[0049] The recursive graph is constructed by calculating the distance between different points in the time series. The element R(i,j) of the RP matrix represents the relationship between the i-th observation and the j-th observation in the time series. The calculation formula is:
[0050] R(i,j)=Θ(∈-∥x i -x j ∥),i,j=1,2,…,N
[0051] Where Θ is the Heaviside step function, ∈ is a predefined threshold; when x i and x j When the distance between them is less than or equal to ∈, R(i,j)=1 is marked in the recursive graph and displayed as a black area in the image; otherwise, R(i,j)=0 is displayed as a blank area in the image.
[0052] The standard RP method generates binary output, which may cause loss of information details. In order to more comprehensively capture the information in the time series, this embodiment improves the recursive graph method. The calculation formula of the element R(i,j) of the improved RP matrix is:
[0053]
[0054] The improved method makes the RP output no longer binary but continuous, thus generating a color RP graph. The color graph can more intuitively display the randomness, periodicity, chaos and trend in the time series. The improved RP method can more clearly show the corresponding relationship in the time series. The improved RP method can more accurately analyze and explain the complex dynamics in the time series, thereby improving the accuracy of complex series prediction.
[0055] S2. Construct a deep learning hybrid network model ImgEnc-AttNet based on image encoding and attention mechanism. The ImgEnc-AttNet model includes a convolution module, an embedding layer, an LSTM module, a fully connected layer and an output layer; the ImgEnc-AttNet model includes three steps: image feature extraction, time feature extraction and trend prediction.
[0056] In order to extract more embedded features from time series data to improve the accuracy of prediction, this embodiment combines multiple related time series in the futures market (including opening price, highest price, lowest price, closing price and trading volume) to predict the trend of closing price. The relationship between the observation windows and prediction points of multiple time series is transformed into a new mapping relationship, such as Figure 2 As shown, the (c) (d) process in the figure includes encoding multiple time series into multi-channel time series images, thereby making full use of the image features of the encoded data to improve the prediction accuracy.
[0057] In analyzing a set of time series {S i (t)}, where i represents different market indicators (such as opening price, highest price, lowest price, closing price and trading volume), t is the time index, and t∈{1,2,…,T}, it is crucial to transform these one-dimensional time series data into structured input-output pairs suitable for deep learning models. To achieve this transformation, the following steps are required:
[0058] Data normalization, before processing the data through window segmentation and image encoding, data normalization is performed to ensure that each feature has a uniform contribution during model training. The normalization formula is as follows:
[0059]
[0060] Among them, Si (t) is the original value, min(S i ) and max(S i ) represent the minimum and maximum values observed in the time series of market indicator i, respectively;
[0061] Window segmentation and image encoding, define the window length as W, for each market indicator i and time point t, select the data in the window from t-W+1 to t, and encode it into a W×W image matrix M through a specific image encoding function encode i (t):
[0062]
[0063] The construction of the channel image combines the image matrices from all N market indicators into a multi-channel image I(t) at each time point t, expressed as:
[0064] I(t)=[M1(t),M2(t),…,M N (t)]
[0065] Define serialized multi-channel image and numerical sequence input. The input data set consists of a multi-channel image sequence from I(t) to I(t+k-1) and a numerical sequence of all market indicators in the same time interval. The format is as follows:
[0066] Image input: Each I(t) contains N channels, each channel corresponds to a W×W image matrix:
[0067]
[0068] Numerical sequence input: Each S i (t) represents the value of the i-th market indicator at time t, organized as a k×N matrix:
[0069]
[0070] Define the model output. The output label y(t+k) represents the market trend at time point t+k. c The direction of change is defined as:
[0071]
[0072] This approach combines visual features extracted through image encoding with the temporal dynamics of numerical data to form unambiguous input-output pairs, thereby providing an optimized input format for subsequent training of deep learning models.
[0073] S21, image feature extraction, the convolution module extracts image features from the input image data, specifically:
[0074] The convolution module specifically includes two convolution layers, each of which consists of a 3×3 convolution kernel convolution operation, batch normalization, and maximum pooling. The convolution operation effectively captures local features through sliding window convolution. The number of feature map channels is determined by the number of convolution kernels. As the layers deepen, more complex information is gradually extracted from simple features. Figure 3 As shown, examples of convolution and pooling operations are shown.
[0075] After each convolution operation, batch normalization is performed to standardize the mean and variance of the feature map. This normalization reduces internal variable shift, thereby speeding up training and increasing stability across training batches. Max pooling reduces the dimensionality of feature representation and the number of parameters by selecting the most significant feature responses. This process increases the model's robustness to feature location while improving its ability to interpret visual content.
[0076] The operations in the convolutional layer are mathematically represented as:
[0077] f l+1 =Maxpool(BN(ReLU(W l *f l +b1)))
[0078] Among them, f l and f l+1 Represent the feature maps of the lth layer and the l+1th layer respectively, W l and b l are the weights and biases of the lth convolutional layer, * represents the convolution operation, and ReLU is the activation function.
[0079] The convolutional module is designed to extract high-level features from raw market indicator data, which is critical for accurate predictions. Each layer is designed to capture different characteristics of image data, such as edges, textures, or complex shapes. As data passes through each layer of the module, the extracted features become increasingly abstract and refined, allowing the model to make predictions based on these complex features.
[0080] Introducing a nonlinear activation function (such as ReLU) after the convolution operation can effectively handle nonlinear relationships in the data, thereby enhancing the model's ability to interpret complex features. This structured feature extraction mechanism highlights the excellent adaptability of deep learning models in processing images and visual data. In the agricultural futures price prediction model of this method, this feature is crucial for learning and interpreting complex market dynamics, providing a core information basis for the prediction task.
[0081] Although traditional time series prediction methods can capture inherent temporal dependencies, they often cannot adapt to the variability between different data channels. Therefore, in this embodiment, the convolution module introduces a channel attention mechanism to address this limitation by enhancing the model's adaptability across multiple channels. Figure 4 shown.
[0082] In conventional convolution operations, the local nature of the receptive field limits the model’s ability to capture extensive long-range information. To address this problem, the global feature map Convert it into different channels through global pooling, reduce its dimension to 1×1×C, and quantize the importance of each channel into a scalar;
[0083] The channel-level feature map is further processed by average pooling and maximum pooling, and then passes through a shared multi-layer perceptron MLP. The MLP first compresses the number of channels to C / r (such as r=4, reducing the number of channels from C to C / 4), and then expands it back to C, using the ReLU activation function for nonlinear transformation. The mathematical expression of this process is as follows:
[0084] Z avg =W1·ReLU(W0·AvgPool(F))
[0085] Z max =W1·ReLU(W0·MaxPool(F))
[0086] Weight Matrix and Applied to both pooling operations, ReLU activation function follows W0;
[0087] The output of the channel attention mechanism is merged and activated through the sigmoid function to calculate the final channel attention weight, which is used to adjust the channels of the feature map, effectively adjusting the impact of each channel on the subsequent layers of the network:
[0088] Att c (F) = Sigmoid(Z avg +Z max )
[0089] F ′ =F⊙Att c (F)
[0090] Among them, ⊙ represents the Hadamard product, that is, point-by-point multiplication, applying the attention weight directly to each corresponding channel of F.
[0091] Although the convolutional layers change the direct correspondence between channels and market indicators, the channel attention mechanism compensates for this change through effective feature selection. It adjusts the response to the derived features to focus the model on the most predictive attributes, thereby improving the accuracy and adaptability of the model.
[0092] This approach ensures that global information is fully utilized through multiple pooling strategies, significantly improving the ability to identify key channels, thereby improving the prediction accuracy and adaptability of the model. The integration of the channel attention mechanism enhances the performance and generalization ability of the model when processing complex data sets.
[0093] S22, time feature extraction, including image and numerical feature fusion and LSTM module to extract time features in agricultural futures price series;
[0094] Among them, the fusion of image and numerical features includes:
[0095] In this embodiment, the model integrates two main data types: image data and numerical data. The image data input to the ImgEnc-AttNet model is converted from the time series through image encoding, and then processed by the convolution module and channel attention mechanism to obtain the weighted multi-channel feature map F ′ (t);
[0096] The numerical features S(t) input to the ImgEnc-AttNet model come from the row vectors corresponding to the numerical input matrix and the image input I(t), covering five market indicators: opening price, highest price, lowest price, closing price, and trading volume;
[0097] Fusion of image and numerical features, weighted multi-channel feature map F ′ (t) is expanded into a one-dimensional feature vector and merged with the corresponding numerical feature S(t) through concatenation to form the integrated feature vector x(t). The process is expressed as:
[0098] x(t)=concat(flatten(F ′ (t)),S(t)).
[0099] This approach not only expands the dimension of information processed by the model, but also enables the model to capture local image patterns and global numerical trends simultaneously, thereby improving the ability to predict future market behavior.
[0100] In the agricultural futures price trend prediction model, feature fusion is a key step to improve the model's ability to process different types of data features. Inspired by the embedding layer in the Transformer model in the field of natural language processing (NLP), this embodiment introduces an embedding layer to achieve efficient feature fusion. The role of the embedding layer is to unify the features of image data and original numerical data into a representation space, thereby enhancing the model's understanding and processing capabilities of these fused features.
[0101] The application of the embedding layer in the model for feature fusion is expressed as:
[0102] e(t0=Embedding(x(t))
[0103] Among them, x(t) is the merged vector containing the expanded multi-channel image features and numerical features, and e(t0) represents the feature vector after the embedding layer conversion.
[0104] The embedding layer optimizes the internal structure of the features by learning the intrinsic relationship between different features, so that the fused feature vector not only retains the important information of the original data, but also adds new contextual information. This processing is crucial for capturing and representing complex patterns in data, especially when predicting market fluctuations. The feature fusion results provide more expressive data features for subsequent networks (such as LSTM or other time series processing networks), thereby providing richer information for the dynamic prediction of agricultural futures prices and effectively improving the prediction accuracy.
[0105] The LSTM module extracts the time features in the agricultural futures price series, specifically:
[0106] The input and output of the LSTM module have multiple features, and the output of each time step is a vector containing multiple complex features. In the model, predicting the trend of agricultural futures prices is essentially a sequence classification task, and the importance of information at different time steps varies. In order to enable the model to automatically focus on more important information, a time step attention mechanism is introduced after the LSTM module, thus forming an LSTM-attention module. The process of the time step attention mechanism is as follows Figure 5 As shown, including:
[0107] Calculate the correlation between hidden layer states, the formula is:
[0108] e ij =tanh(W1h i +W2h j +b)
[0109] Among them, e ijrepresents the relationship between the state of the i-th step and the state of the j-th step in the LSTM module output, W1 and W2 are weight vectors of dimension u, b is the scalar bias, and h i and h j Respectively represent the hidden states of the i-th step and the j-th step in the LSTM module output; this formula calculates the raw attention score, which represents the interaction between the two states;
[0110] The raw attention score is normalized using the softmax function, and the formula is:
[0111]
[0112] Among them, a ij is the normalized attention weight, which represents the weight of state i on state j, ensuring that the sum of all weights is equal to 1, that is,
[0113] Calculate the output, the formula is:
[0114]
[0115] Among them, H i represents the final output state after processing by the attention mechanism, reflecting the contributions of all hidden states to position i, which are weighted by their respective attention weights.
[0116] S23. Trend forecasting, including:
[0117] After the initial processing by the time-step attention mechanism, the enhanced feature vector is assigned to its individual elements, and the expanded vector is processed by two sequential fully connected layers; the first fully connected layer further optimizes the features, and the second fully connected layer is connected to the output layer;
[0118] The output layer uses the sigmoid activation function to compress the output into the range of [0,1]. The output value directly represents the probability of an event occurring. Based on this probability, the binary classification task of price increase and decrease is completed by setting a threshold (such as 0.5) to obtain the price trend prediction result.
[0119] S3. Train the ImgEnc-AttNet model and use the trained ImgEnc-AttNet model to predict the price trend of agricultural futures.
[0120] In this embodiment, the prediction performance of the trained ImgEnc-AttNet model is also evaluated; since agricultural futures prices have financial characteristics, the rise and fall prediction of their time series is equally important. Therefore, accuracy and weighted F1 score are used as performance evaluation indicators, and the calculation formula is as follows:
[0121]
[0122] Among them, TP (True Positives) and TN (True Negatives) represent the number of samples correctly classified as positive and negative classes, respectively; FP (False Positives) and FN (False Negatives) represent the number of samples misclassified as positive and negative classes, respectively; TP i , FP i and FN i They represent the number of samples correctly classified as positive, misclassified as positive, and misclassified as negative in the i-th class respectively; w i represents the weight assigned to the i-th class, usually calculated as the ratio of the number of samples in this class to the total number of samples; n i represents the number of samples in the i-th category, and N represents the total number of samples.
[0123] By using these weights, the evaluation metrics can accurately reflect the prediction quality on different categories, especially in the case of imbalanced class distribution, ensuring that the evaluation is more comprehensive and fair.
[0124] Finally, the effectiveness of the model proposed in the present invention is verified by taking the trend prediction (rise and fall prediction) of wheat futures prices and lean pork futures prices as examples. The experiment compares the prediction performance of seven models including support vector machine (SVM), random forest (RandomForest), long short-term memory network (LSTM), multi-layer perceptron (MLP), Transformer, convolutional neural network (CNN) and the model of the present invention (ImgEnc-AttNet). As shown in Table 1 below, the performance comparison of each model in wheat futures price prediction is shown; as shown in Table 2 below, the performance comparison of each model in lean pork futures price prediction is shown.
[0125]
[0126] Table 1
[0127]
[0128] Table 2
[0129] It should also be noted that in this specification, terms such as "comprises", "includes" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0130] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for predicting agricultural product futures prices based on image coding and attention, characterized in that: The following steps are involved: Using Gram's angle field or improved recursive graph method, the one-dimensional time series data of agricultural futures prices are converted into two-dimensional image data, and the two-dimensional image data are organized into input-output mapping pairs, which are subsequently input into the ImgEnc-AttNet model for training; A deep learning hybrid network model ImgEnc-AttNet based on image encoding and attention mechanism is constructed. The ImgEnc-AttNet model includes convolution module, embedding layer, LSTM module, fully connected layer and output layer. The channel attention mechanism is introduced in the convolution module. The time step attention mechanism is introduced in the LSTM module. The ImgEnc-AttNet model includes three steps: image feature extraction, time feature extraction and trend prediction. In the image feature extraction step, the convolution module extracts image features from the input image data. In the time feature extraction step, the LSTM module extracts the time features in the agricultural futures price data; Train the ImgEnc-AttNet model and use the trained ImgEnc-AttNet model to predict agricultural futures price trends.
2. The agricultural product futures price trend prediction method based on image coding and attention according to claim 1 is characterized in that: The Gram angle field is used to convert one-dimensional time series data into two-dimensional image data. The specific steps are as follows: For one-dimensional time series data X = {x1, x2, ..., x N }Normalize and scale it to the interval [0,1]; The normalized data x ′ n Converted to polar coordinates, where the angle θ n and radius r n The calculation formula is: In the polar coordinate system, each pair of points (θ n ,r n ) and (θ m ,r m ) is expressed by calculating the cosine or sine value of their angle difference, thereby forming a Gram matrix; the Gram matrix includes the Gram sum angle matrix GASF and the Gram difference angle matrix GADF, and the calculation formula is as follows:
3. The agricultural product futures price trend prediction method based on image coding and attention according to claim 2 is characterized in that: The improved recursive graph method is used to convert one-dimensional time series data into two-dimensional image data. The specific steps are as follows: For one-dimensional time series data X = {x1, x2, ..., x N }Normalize and scale it to the interval [0,1]; The recurrence graph is constructed by calculating the distance between different points in the time series. The element R(i,j) of the RP matrix represents the i-th observation x in the time series. i and the jth observation x j The relationship between them is calculated as follows: Here, ∈ is a predefined threshold.
4. The agricultural product futures price trend prediction method based on image coding and attention according to claim 3 is characterized in that: It also includes converting one-dimensional time series data into structured input and output suitable for the ImgEnc-AttNet model, which specifically includes the following steps: Data normalization, before processing the data through window segmentation and image encoding, data normalization is performed. The normalization formula is as follows: Among them, S i (t) is the original value, min(S i ) and max(S i ) represent the minimum and maximum values observed in the time series of market indicator i, respectively; Window segmentation and image encoding, define the window length as W, for each market indicator i and time point t, select the data in the window from t-W+1 to t, and encode it into a W×W image matrix M through a specific image encoding function encode i (t): The construction of the channel image combines the image matrices from N market indicators into a multi-channel image I(t) at each time point t, expressed as: I(t)=[M1(t),M2(t),…,M N (t)] Define serialized multi-channel image and numerical sequence input. The input data set consists of a multi-channel image sequence from I(t) to I(t+k-1) and a numerical sequence of all market indicators in the same time interval. The format is as follows: Image input, each I(t) contains N channels, each channel corresponds to a W×W image matrix: Numeric sequence input, each S i (t) represents the value of the i-th market indicator at time t, organized as a k×N matrix: Define the ImgEnc-AttNet model output, the output label y(t+k) represents the market trend at time point t+k, according to the closing price S c The direction of change is defined as:
5. The agricultural product futures price trend prediction method based on image coding and attention according to claim 4 is characterized in that: The convolution module specifically includes two convolution layers, each of which consists of a convolution operation with a 3×3 convolution kernel, batch normalization, and maximum pooling. The convolution operation captures local features through sliding window convolution, and the number of feature map channels is determined by the number of convolution kernels. After each convolution operation, batch normalization is performed to standardize the mean and variance of the feature map; maximum pooling reduces the dimension of feature representation and the number of parameters by selecting the most significant feature responses; The operations in the convolutional layer are mathematically represented as: f l+1 =Maxpool(BN(ReLU(W l *f l +b1))) Among them, f l and f l+1 Represent the feature maps of the lth layer and the l+1th layer respectively, W l and b l are the weights and biases of the lth convolutional layer, * represents the convolution operation, and ReLU is the activation function.
6. The agricultural product futures price trend prediction method based on image coding and attention according to claim 5 is characterized in that: The channel attention mechanism is introduced in the convolution module, specifically: The global feature map Convert it into different channels through global pooling, reduce its dimension to 1×1×C, and quantize the importance of each channel into a scalar; The channel-level feature map is further processed by average pooling and maximum pooling, and then passes through a shared multi-layer perceptron MLP; MLP first compresses the number of channels to C / r, and then expands it back to C, using the ReLU activation function for nonlinear transformation. The mathematical expression of this process is: Z avg =W1·ReLU(W0·AvgPool(F)) WITH max =W1 ReLU(W0 MaxPool(F)) Weight Matrix and Applied to both pooling operations, ReLU activation function follows W0; The output of the channel attention mechanism is merged and activated through the sigmoid function to calculate the final channel attention weight, which is used to adjust the channels of the feature map to adjust the impact of each channel on the subsequent layers: To c (F)=Sigmoid(Z avg +Z max ) F ′ =F⊙Att c (F) Among them, ⊙ represents the Hadamard product, that is, point-by-point multiplication, applying the attention weight directly to each corresponding channel of F.
7. The agricultural product futures price trend prediction method based on image coding and attention according to claim 6 is characterized in that: The temporal feature extraction step includes image and numerical feature fusion and LSTM module to extract temporal features in agricultural futures price series; Among them, the fusion of image and numerical features includes: The image data input to the ImgEnc-AttNet model is converted from the time series through image encoding, and then processed by the convolution module and channel attention mechanism to obtain the weighted multi-channel feature map F ′ (t); The numerical features S(t) input to the ImgEnc-AttNet model come from the row vectors corresponding to the numerical input matrix and the image input I(t), including five market indicators: opening price, highest price, lowest price, closing price, and trading volume. Fusion of image and numerical features, weighted multi-channel feature map F ′ (t) is expanded into a one-dimensional feature vector and merged with the corresponding numerical feature S(t) through concatenation to form the integrated feature vector x(t). The process is expressed as: x(t)=concat(flatten(F ′ (t)),S(t))。 8. The agricultural product futures price trend prediction method based on image coding and attention according to claim 7 is characterized in that: The embedding layer is used to achieve efficient feature fusion. The application of the embedding layer in the feature fusion of the model is expressed as: e(t)=Embedding(x(t)) Among them, x(t) is the merged vector containing the expanded multi-channel image features and numerical features, and e(t) represents the feature vector after the embedding layer conversion.
9. The agricultural product futures price trend prediction method based on image coding and attention according to claim 7 is characterized in that: The LSTM module extracts the time features in the agricultural futures price series, specifically: The input and output of the LSTM module have multiple features, and the output of each time step contains a vector of multiple complex features. The time step attention mechanism is introduced to form the LSTM-attention module. The attention mechanism includes the following processes: Calculate the correlation between hidden layer states, the formula is: e ij =tanh(W1h i +W2h j +b) Among them, e ij represents the relationship between the state of the i-th step and the state of the j-th step in the LSTM module output, W1 and W2 are weight vectors of dimension u, b is the scalar bias, and h i and h j Respectively represent the hidden states of the i-th step and the j-th step in the LSTM module output; this formula calculates the raw attention score, which represents the interaction between the two states; The raw attention score is normalized using the softmax function, and the formula is: Among them, a ij is the normalized attention weight, which represents the weight of state i on state j, ensuring that the sum of all weights is equal to 1, that is, Calculate the output, the formula is: Among them, H i represents the final output state after processing by the attention mechanism, reflecting the contributions of all hidden states to position i, which are weighted by their respective attention weights.
10. The agricultural product futures price trend prediction method based on image coding and attention according to claim 9 is characterized in that: There are two fully connected layers; the first fully connected layer further optimizes the features, and the second fully connected layer connects to the output layer; After being processed by the time-step attention mechanism, the enhanced feature vector is assigned to its elements, and the expanded vector is processed through two sequential fully connected layers; The output layer uses the sigmoid activation function to compress the output into the range of [0,1]. The output value directly represents the probability of an event occurring. Based on this probability, the binary classification task of price increase and decrease is completed by setting the threshold to obtain the price trend prediction result.
Citation Information
Cited By
Mine safety detection method and system based on Internet of Things
CN120744466A