An optimized method for predicting agricultural pests and diseases
The agricultural pest and disease prediction model constructed through multivariable time series methods and deep learning technology solves the problem that traditional methods are difficult to deal with complex data, achieves higher prediction accuracy and timeliness, and helps agricultural managers optimize their prevention and control strategies.
Patent Information
- Application Number
- CN202510045135.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2045-01-13
AI Technical Summary
Traditional agricultural pest and disease prediction methods have lags and limitations, making it difficult to detect potential risks in advance, and it is difficult to deal with complex multivariate time series and dynamic data.
A multivariate time series method is used to combine deep learning technology to construct an agricultural pest and disease prediction model. The model consists of feature conversion module, time correlation module, variable interaction module and nonlinear feature interaction fusion. By capturing the dependencies in the time series and the interrelationship between different variables, more complex feature representations are generated to improve prediction accuracy.
It significantly improves the accuracy and timeliness of pest and disease prediction, can understand the patterns of complex data more accurately, improve the accuracy and generalization capabilities of prediction, help agricultural managers make scientific decisions, and optimize prevention and control strategies.
Smart Images

Figure CN119443422B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of pest and disease prediction, and particularly relates to an optimization method for agricultural pest and disease prediction. Background Art
[0002] Agricultural pests and diseases are major problems affecting global agricultural production, causing a large amount of crop losses every year, which in turn affects farmers' incomes and food security. Traditional pest and disease prediction methods rely on manual observation and seasonal warnings, but this method has lag and limitations, and it is often difficult to detect potential risks in advance, resulting in the failure to take timely control measures. With climate change and the diversification of agricultural planting patterns, the occurrence patterns of pests and diseases have become more complex, and traditional methods are difficult to meet the needs of the rapidly changing agricultural environment. Therefore, it is particularly important to develop an intelligent and efficient optimization method for pest and disease prediction.
[0003] Artificial intelligence (AI) and machine learning (ML) provide new solutions for agricultural pest and disease prediction. By simulating the decision-making process of human experts, AI can automatically process complex non-linear problems. Machine learning uses a large amount of historical data and real-time data, and predicts the occurrence of future pests and diseases by learning the patterns in the data. Supervised learning and unsupervised learning are common machine learning methods. Among them, supervised learning trains a prediction model by annotating historical data, while unsupervised learning discovers potential pest and disease risk areas through data clustering. These technologies can improve the accuracy and timeliness of prediction, and provide more accurate pest and disease prevention and control guidance for agricultural production.
[0004] Agricultural pest and disease prediction is a dynamic and multi-variable complex system, and traditional models have limitations in dealing with multi-variable time series and dynamic data, and it is difficult to handle the cross-time dimension interaction effects. For such complex cross-effects, traditional models often cannot effectively model, resulting in low prediction accuracy. In this application, by taking crop type, crop growth stage, soil conditions, weather information, and agricultural management records as input variables, and combining the time series analysis ability of the deep learning network, the accuracy of pest and disease prediction can be significantly improved. The multi-variable time series method can further focus on key variables, so as to more accurately evaluate the sensitivity of agricultural plants to specific environmental conditions, and help growers adjust strategies in real time. Therefore, the agricultural pest and disease prediction method combining multi-variable time series and deep learning technology can provide a solid foundation for the pest and disease prediction model, help agricultural managers make scientific decisions, and optimize prevention and control strategies. Summary of the Invention
[0005] The main purpose of this application is to provide an optimized method for agricultural pest and disease prediction, aiming at an agricultural pest and disease prediction model. The agricultural pest and disease prediction model consists of a feature transformation module, a time correlation module, a variable interaction module, and a non-linear feature interaction fusion. Among them, the feature transformation module converts the input original data into a feature representation suitable for model processing; the time correlation module captures the dependencies between each time step in the time series; the variable interaction module focuses on the mutual relationships between different variables to improve the prediction accuracy of the multi-variable time series; through the comprehensive utilization of information in different dimensions by the non-linear feature interaction fusion, the prediction model can more accurately understand the patterns of complex data, improving the accuracy and generalization ability of the prediction.
[0006] To achieve the above object, the technical solution of this application is: an optimized method for agricultural pest and disease prediction, the method comprising:
[0007] S1. Collect key information for agricultural pest and disease prediction, where the key information for agricultural pest and disease prediction includes crop type, crop growth stage, soil condition information, weather information, and agricultural management records;
[0008] S2. Preprocess the key information data for agricultural pest and disease prediction, where the preprocessing is data cleaning and data normalization operations to improve the overall quality of the data set;
[0009] S3. Construct an agricultural pest and disease prediction model, the specific method comprising:
[0010] S31. Propose a feature transformation module to convert the input preprocessed data into a feature representation suitable for model processing;
[0011] S32. Propose a time correlation module, where the time correlation module focuses on capturing the dependencies between each time step in the time series;
[0012] S33. Propose a variable interaction module, where the variable interaction module is used to capture the relationships between different variables within the same time step;
[0013] S34. Propose a non-linear feature interaction fusion, where the feature interaction fusion is used to generate a more complex feature representation after the interaction of the output of the time correlation module with the time feature representation and frequency feature representation of the variable interaction module;
[0014] S35. Introduce a mapping layer, and calculate the output of the non-linear feature interaction fusion through the introduced mapping layer to output the final prediction result of the agricultural pest and disease prediction model;
[0015] S4. Train the agricultural pest and disease prediction model using the training set. By optimizing the parameters of the prediction model, minimize the error of the prediction model on the training set, enhance the learning ability of the model for the occurrence patterns of pests and diseases, and thus improve the prediction accuracy of the prediction model on unknown data;
[0016] S5. Test the agricultural pest and disease prediction model using the test set. By evaluating the performance of the model on the test set, calculate the prediction accuracy and error, and verify the generalization ability of the model, so as to ensure the reliability and accuracy of the prediction model in practical applications.
[0017] Further, in step S3, in S31, first perform a time series segmentation operation on the data. The time series segmentation divides the data set into samples, and each sample is a multivariate time series , where is the number of time steps, is the number of variables. For each sample , perform a slicing operation, divide each sample into multiple segments with a length of . The number of segments that each sample can generate is . Each segment contains consecutive time steps. Each segment after slicing is ;
[0018] Subsequently, use linear projection to map the sliced time series segments into a high-dimensional embedding space to provide rich feature representations for each segment. The specific method is to use a trainable linear projection matrix to project each segment into a -dimensional space. The linear projection formula is:
[0019] ;
[0020] In the formula, is the bias term of the linear projection, is the projected representation, with a shape of . Perform linear projection on each variable. Finally, the projected time series representation is passed to the next layer;
[0021] Finally, add positional encoding at each time step to increase the ability of the agricultural pest and disease prediction model to recognize the sequential information in the input data. Use the fixed positional encoding method of sine and cosine functions to add positional encoding. For each position and each embedding dimension , use the following formula to calculate the positional encoding:
[0022] For being even, the formula is ;
[0023] For being odd, the formula is ;
[0024] In the formula, and are the sine and cosine functions respectively, is the dimension index in the embedding vector, is the position index in the sequence, is the total dimension of the embedding vector, is the scaling factor, and as the embedding dimension increases, the value of this factor will grow exponentially; the final position encoding matrix is composed of the encoding values of all positions and embedding dimensions , and for each position the vector can be represented as:
[0025] {P}_{pos}=\left [ {sin\left ( {\frac {pos} {{10000}^{0 / D}}} \right ),cos\left ( {\frac {pos} {{10000}^{0 / D}}} \right ),sin\left ( {\frac {pos} {{10000}^{2 / D}}} \right ),...,sin\left ( {\frac {pos} {{10000}^{(D-2) / D}}} \right ),cos\left ( {\frac {pos} {{10000}^{(D-2) / D}}} \right )} \right ] , concatenate each vector into the position encoding matrix , with the shape of , and then add the position encoding matrix to each segment as the final output of the feature transformation module, the formula is:
[0026] ;
[0027] In the formula, is the projected time series representation, is the position encoding matrix, is the representation after position encoding, with the shape of .
[0028] Furthermore, in step S31, the time series slicing and position encoding techniques significantly improve the fault detection ability of the model by effectively segmenting and encoding time series data in the agricultural pest prediction model; slicing helps capture short-term and long-term patterns, isolate noise, and improve data utilization efficiency; position encoding ensures that the model understands the sequential relationship of time steps, enhances the ability to capture long-range dependencies and periodic changes. The combination of the two enables the model to process local and global information simultaneously, improving the accuracy and robustness of the prediction.
[0029] Further, in steps S3 and S32, the time correlation module captures the dependencies between each time step in the time series based on the dynamic multi-head attention mechanism, and selects data from the final output of the feature transformation module as , the high-dimensional representation of the th variable in a sample at different time periods;
[0030] In the dynamic multi-head attention mechanism, the input data is first converted into a query matrix , a key matrix , and a value matrix , and the conversion formulas are as follows:
[0031] ;
[0032] ;
[0033] ;
[0034] where , , are trainable weight matrices, is the number of the attention head; subsequently, the dynamic attention is used to calculate the output of a single attention head, and the dynamic attention calculation formula is as follows:
[0035] ;
[0036] where is the activation function, is the output of the dynamic attention of the attention head numbered , is transpose operation, is the scaling constant, is the dynamic function, and the calculation method is as follows:
[0037] f\left ( {{Q}^{h}_{:,n},{K}^{h}_{:,n}} \right )=Sigmoid({W}_{f}\left [ {{Q}^{h}_{:,n};{K}^{h}_{:,n}} \right ]) ;
[0038] where \left [ {{Q}^{h}_{:,n};{K}^{h}_{:,n}} \right ] is the concatenation of the query matrix and the key matrix, {W}_{f} is a trainable weight matrix, and Sigmoid is an activation function; each attention head weights the sum values according to the similarity between the query and the key, capturing the dependencies between different positions in the input data;
[0039] After all the attention outputs are independently calculated by the attention heads, the outputs are concatenated together to obtain a large attention output matrix, and the calculation formula is as follows:
[0040] ;
[0041] where {O}_{t} is the final output of the dynamic multi-head attention mechanism, Concat is the concatenation operation;
[0042] Finally, after the residual connection and layer normalization operations, it is used as the final output of the t-th variable of a sample in the time correlation module. The specific formula is as follows:
[0043] ;
[0044] where LN is the normalization operation, {O}_{t} is the final output of the t-th variable in the time correlation module; finally, the embedding representations of each variable in the sample at different stages are merged after being processed by the dynamic multi-head attention mechanism to obtain the final output of a sample after passing through the time correlation module .
[0045] Furthermore, in step S32, the time correlation module in the agricultural pest and disease prediction model significantly improves the fault detection performance of the model by capturing the dependencies between time steps, enhancing the modeling ability for long-term dependencies and fault characteristics at different time scales; the time correlation module can dynamically assign the importance of time steps, helping the model to identify complex fault patterns and improving the interpretability of the model, making the prediction process more transparent and accurate, thereby effectively improving the accuracy and reliability of the prediction.
[0046] Further, in the steps S3 and S33, the variable interaction module is used to capture the relationships between different variables within the same time step. The method is to perform temporal feature representation on the data and use the multi-feature attention mechanism for frequency feature representation, which is the final output of the feature transformation module for the specific time step in the embedded representations of all variables;
[0047] First, perform temporal feature representation. For each attention head , calculate different queries , keys and value matrices , and the calculation formulas are as follows:
[0048] ;
[0049] ;
[0050] ;
[0051] In the formula, , , are the weight matrices of this attention mechanism, , , are the matrices after linear transformation respectively, and are used for subsequent attention calculations; then for each attention head use scaled dot-product attention to calculate the attention output, and the calculation formula is as follows:
[0052] ;
[0053] In the formula, is the output of attention head , is the scaling constant; finally, concatenate the outputs of each attention head as the final output of the multi-head attention mechanism, and the concatenation formula is as follows:
[0054] ;
[0055] In the formula, is the number of attention heads, is the output of the multi-head attention mechanism in the temporal feature representation;
[0056] Subsequently, use a residual neural network to add the input feature and the output of the attention mechanism to retain the input feature, and the formula is as follows:
[0057] ;
[0058] In the formula, is a fully connected network, is a residual operation, adding the input feature to the output of the attention mechanism; finally, for each time step the embedding representations of all variables on are concatenated after the same multi-head attention calculation to form the time feature representation of a sample .
[0059] Furthermore, in the steps S3 and S33, the frequency feature representation uses the query calculated by each attention head , key and value matrix to obtain the query, key and value matrices used to calculate the frequency feature representation through three feature extractors;
[0060] First, convolution is used for feature extraction, and the formula is as follows:
[0061] ;
[0062] ;
[0063] ;
[0064] In the formula, is the result of convolution feature extraction for the query calculated by each attention head , key and value matrix , is the convolution operation;
[0065] Subsequently, a non-linear activation function is used for the output of the convolution feature extraction, and the formula is as follows:
[0066] ;
[0067] ;
[0068] ;
[0069] In the formula, , , are respectively the results after using the non-linear activation function for the output of the convolution feature extraction, is the activation function;
[0070] Subsequently, use Further process the extracted features to serve as the query, key, and value matrices for calculating the frequency feature representation. The specific calculation formulas are as follows:
[0071] ;
[0072] ;
[0073] ;
[0074] In the formula, and are the results of further feature extraction. The results of further extraction are used as the query, key, and value matrices for calculating the frequency feature representation. Subsequently, the obtained matrices are subjected to weighted attention calculation. By introducing a weighting mechanism, more attention is paid to specific attention heads. The weighting mechanism uses a linear layer to generate the weights for each attention head. The calculation formula is as follows: Further process the extracted features to serve as the query, key, and value matrices for calculating the frequency feature representation. The specific calculation formulas are as follows:
[0075] ;
[0076] In the formula, is the number of heads of the multi-head attention, is the initial weight parameter for each attention head, which is learned through training; the score for each attention head is calculated as follows:
[0077] ;
[0078] In the formula, is the attention score obtained by calculating the frequency feature representation, is the scaling constant;
[0079] Subsequently, each attention head is weighted, and the formula is as follows:
[0080] ;
[0081] In the formula, is the weighted value of attention head ;
[0082] Finally, the outputs of multiple attention heads are obtained to get the final output of the weighted attention mechanism , and the calculation formula is:
[0083] ;
[0084] Finally, the embedding representations of all variables at each time step are concatenated after the same weighted attention calculation to form the frequency feature representation of a sample ; The variable interaction module finally obtains the time feature representation after processing the data and the frequency feature representation .
[0085] Furthermore, in step S33, the variable interaction module in the agricultural pest and disease prediction model enhances the model's processing ability for multi-dimensional data by focusing on the dependencies between different features; the variable interaction module effectively captures the mutual influence between different variables, helps the model more accurately identify potential failure modes, and by adaptively assigning the importance of features, the variable interaction module enhances the model's understanding of complex multi-variable data, thereby improving the accuracy and comprehensiveness of prediction.
[0086] Further, in steps S3 and S34, by introducing non-linear feature interactions, the output of the time correlation module and the time feature representation and the frequency feature representation
[0087] of the variable interaction module generate more complex feature representations after interaction. The specific method includes: ; First, interact the outputs
[0088] ;
[0089] ;
[0090] ;
[0091] In the formula, is the element-wise multiplication operation, , , are the new features generated by pairwise interaction;
[0092] Subsequently, perform a non-linear transformation on the interacted features to obtain a new representation:
[0093] ;
[0094] ;
[0095] ;
[0096] In the formula, , , are the results of the non-linear transformation of the interacted features, , , is the weight parameter in the non - linear transformation calculation, , , is the bias term in the non - linear transformation calculation;
[0097] Finally, all the interacted non - linear features are weighted and summed, and the weighted sum formula is as follows:
[0098] ;
[0099] In the formula, , , are the weights after interaction, is the output , , is the final fusion result.
[0100] Furthermore, in step S34, the output results of the variable interaction module and the time correlation module are fused. In the agricultural pest and disease prediction model, it can simultaneously capture the dependencies between time steps and the relationships between different features. This fusion enables the model to comprehensively understand the complex patterns in multi - dimensional data, identify key time points in the time series, and insight into the synergistic effects between features, thus significantly improving the prediction accuracy and robustness. In addition, the fused attention mechanism enhances the interpretability of the model and makes the prediction process more transparent.
[0101] To sum up, due to the adoption of the above - mentioned technical solutions, the beneficial effects of the present invention are as follows:
[0102] In the present invention, an agricultural pest and disease prediction model is constructed. The agricultural pest and disease prediction model consists of a feature transformation module, a time correlation module, a variable interaction module, and a non - linear feature interaction fusion. Among them, the feature transformation module converts the input original data into a feature representation suitable for model processing; the time correlation module captures the dependencies between each time step in the time series; the variable interaction module focuses on the relationships between different variables and improves the prediction accuracy of multi - variable time series; the non - linear feature interaction fusion comprehensively utilizes information from different dimensions, enabling the agricultural pest and disease prediction model to more accurately understand the patterns of complex data, improve the prediction accuracy and generalization ability; the agricultural pest and disease prediction model of the present application can accurately predict the pest and disease situation of agriculture in the future for a period of time, reducing unnecessary losses. BRIEF DESCRIPTION OF THE DRAWINGS
[0103] Figure 1 is a flowchart of the steps of an agricultural pest and disease prediction optimization method.
[0104] Figure 2It is a flowchart of the steps of an agricultural pest and disease prediction model in an agricultural pest and disease prediction optimization method.
[0105] Figure 3 It is a structural diagram of the time correlation module in the agricultural pest and disease prediction model.
[0106] Figure 4 It is an internal calculation diagram of the time correlation module in the agricultural pest and disease prediction model.
[0107] Figure 5 It is a structural diagram of the variable interaction module in the agricultural pest and disease prediction model.
[0108] Figure 6 It is an internal calculation diagram of the variable interaction module in the agricultural pest and disease prediction model.
[0109] Figure 7 It is a comparison chart of the predicted value and other values of the agricultural pest and disease prediction model; Figure 7 (a) are the training values and predicted values of the agricultural pest and disease prediction model, Figure 7 (b) is a comparison chart of the predicted values and true values of each model. Specific implementation manners
[0110] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.
[0111] Please refer to Figures 1-7 , the present invention provides a technical solution: an agricultural pest and disease prediction optimization method, the steps of which include: collecting key information for agricultural pest and disease prediction, preprocessing key information data for agricultural pest and disease prediction, constructing an agricultural pest and disease prediction model, training the agricultural pest and disease prediction model using a training set, and testing the agricultural pest and disease prediction model using a test set.
[0112] Please refer to Figure 1 As shown, a specific agricultural pest and disease prediction optimization method in the embodiments of the present application is as follows:
[0113] S1. Collect key information for agricultural pest and disease prediction, where the key information for agricultural pest and disease prediction includes crop type, crop growth stage, soil condition information, weather information, and agricultural management records.
[0114] Further, in step S1, the key information is collected by means of manual inspection, sensor monitoring, and drone remote sensing; the crop type and crop growth stage information are collected by means of manual inspection; the soil condition information, including soil humidity, pH value, and nutrient content, is collected by means of sensors; the weather information, including temperature and humidity, is collected by means of sensors; the agricultural management record information, including fertilization, irrigation, and drug use records, is collected manually; the situation of crop diseases and pests is detected by means of drone remote sensing; and the collection frequency is set to once an hour.
[0115] S2. Preprocessing of key information data for agricultural pest and disease prediction. The preprocessing is data cleaning and data normalization operations to improve the overall quality of the data set.
[0116] Further, in step S2, the data cleaning corrects the outliers and missing values in the data. For the treatment of missing values, the mean value of this feature is used to fill in the missing values. The mean filling formula is:
[0117] ;
[0118] In the formula, is the element in the column where the th missing value is located, and N is the number of non-missing values. Then, the outlier detection uses the standard deviation method to detect and remove the outliers. The standard deviation method formula is as follows:
[0119] ;
[0120] In the formula, is the current data point, is the mean value of the data, and σ is the standard deviation of the data. When the Z-score exceeds the threshold, this point is an outlier.
[0121] The normalization is to process data with different dimensions and ranges. The normalization compresses the data into the [0,1] interval. The normalization formula is as follows:
[0122] ;
[0123] In the formula, is the original data, and are the minimum and maximum values of this feature respectively, is the normalized data;
[0124] S3. Construct an agricultural pest and disease prediction model. The step process is as Figure 2As shown below, it specifically includes: a feature transformation module, a time correlation module, a variable interaction module, a non-linear feature interaction fusion, and a mapping layer. The specific implementation is as follows.
[0125] S31. Propose a feature transformation module to transform the input preprocessed data into a feature representation suitable for model processing.
[0126] Furthermore, in steps S3 and S31, first perform a time series segmentation operation on the data. The time series segmentation divides the data set into samples, and each sample is a multivariate time series , where is the number of time steps, is the number of variables. For each sample , perform a slicing operation to divide each sample into multiple segments with a length of . The number of segments that each sample can generate is . Each segment contains consecutive time steps. Each segment after slicing is ;
[0127] Subsequently, use linear projection to map the sliced time series segments to a high-dimensional embedding space to provide rich feature representations for each segment. The specific method is to use a trainable linear projection matrix to project each segment into a -dimensional space. The linear projection formula is:
[0128] ;
[0129] In the formula, is the bias term of the linear projection, is the projected representation, with a shape of . Perform the same projection operation on each variable. Finally, the projected time series representation is passed to the next layer;
[0130] Finally, add positional encoding at each time step to increase the order information in the input data recognized by the agricultural pest and disease prediction model. Use a fixed positional encoding method of sine and cosine functions to add positional encoding. For each position and each embedding dimension , use the following formula to calculate the positional encoding:
[0131] For being even, the formula is ;
[0132] For is odd, and the formula is ;
[0133] In the formula, and are the sine and cosine functions respectively, is the dimension index in the embedding vector, is the position index in the sequence, is the total dimension of the embedding vector, is the scaling factor, and as the embedding dimension increases, the value of this factor will increase exponentially; the final position encoding matrix is composed of the encoding values of all positions and embedding dimensions . For each position on the vector can be expressed as:
[0134] , and each on the vector is concatenated into the position encoding matrix , with the shape of . Subsequently, the position encoding matrix is added to each segment as the final output of the feature transformation module, and the formula is:
[0135] ;
[0136] In the formula, is the projected time series representation, is the position encoding matrix, is the representation after position encoding, with the shape of .
[0137] S32. Propose a time correlation module, which focuses on capturing the dependencies between each time step in the time series.
[0138] Furthermore, in steps S3 and S32, the time correlation module captures the dependencies between each time step in the time series based on the dynamic multi-head attention mechanism, and selects data from the final output of the feature transformation module, is the high-dimensional representation of the th variable in a sample at different time periods, as shown in Figure 3 ;
[0139] In the dynamic multi-head attention mechanism, the input data is first converted into a query matrix , a key matrix , and a value matrix , as shown in Figure 4 . The conversion formula is as follows:
[0140] ;
[0141] ;
[0142] ;
[0143] In the formula, , , are trainable weight matrices, is the number of the attention head; Subsequently, the dynamic attention is passed through to calculate the output of a single attention head, and the dynamic attention calculation formula is as follows:
[0144] ;
[0145] In the formula, is the activation function, is the output of the dynamic attention of the attention head numbered , is transpose operation, is the scaling constant, is the dynamic function, and the calculation method is as follows:
[0146] ;
[0147] In the formula, is the concatenation of the query matrix and the key matrix, is a trainable weight matrix, is the activation function; Each attention head weights the sum value according to the similarity between the query and the key, and captures the dependencies between different positions in the input data;
[0148] After all attention heads independently calculate the attention output, the outputs are concatenated together to obtain a large attention output matrix, and the calculation formula is as follows:
[0149] ;
[0150] In the formula, is the final output of the dynamic multi-head attention mechanism, is the concatenation operation;
[0151] Finally, after the residual connection and layer normalization operations, it is used as the final output of the th variable of a sample in the temporal correlation module. The specific formula is as follows:
[0152] ;
[0153] In the formula, is the normalization operation, is the final output of the th variable in the time correlation module; finally, the embedding representations of each variable in the sample at different stages are merged after being processed by the dynamic multi-head attention mechanism to obtain the final output of a sample after passing through the time correlation module .
[0154] S33. A variable interaction module is proposed, and the variable interaction module is used to capture the relationship between different variables within the same time step.
[0155] Furthermore, in the steps S3 and S33, the variable interaction module is used to capture the relationship between different variables within the same time step. As Figure 5 shown, the method is to perform time feature representation on the data and use the multi-feature attention mechanism for frequency feature representation. is the final output of the feature transformation module for all variable embedding representations at the specific time step in
[0156] First, perform time feature representation. For each attention head , different queries , keys , and value matrices are calculated. As Figure 6 shown, the calculation formulas are as follows:
[0157] ;
[0158] ;
[0159] ;
[0160] In the formula, , , are the weight matrices of this attention mechanism. , , are the matrices after linear transformation, respectively used for subsequent attention calculations. Subsequently, for each attention head , the scaled dot-product attention is used to calculate the attention output. The calculation formula is as follows:
[0161] ;
[0162] In the formula, is the output of the attention head , is the scaling constant; finally, the outputs of each attention head are concatenated as the final output of the multi-head attention mechanism, and the concatenation formula is as follows:
[0163] ;
[0164] In the formula, is the number of attention heads, is the output of the multi-head attention mechanism in the temporal feature representation;
[0165] Subsequently, the residual neural network is used to add the input feature and the output of the attention mechanism to retain the input feature, and the formula is as follows:
[0166] ;
[0167] In the formula, is the fully connected network, is the residual operation, which adds the input feature and the output of the attention mechanism; finally, for each time step the embedding representations of all variables are concatenated after the same multi-head attention calculation to form the temporal feature representation of a sample.
[0168] Furthermore, in step S3 and S33, the frequency feature representation uses the query calculated by each attention head , key and value matrix to obtain the query, key, and value matrices used for calculating the frequency feature representation through three feature extractors;
[0169] First, convolution is used for feature extraction, and the formula is as follows:
[0170] ;
[0171] ;
[0172] ;
[0173] In the formula, is the result of convolutional feature extraction on the query calculated by each attention head , key and value matrix , is the convolution operation;
[0174] Subsequently, a non-linear activation function is used for the output of the convolutional feature extraction, and the formula is as follows:
[0175] ;
[0176] ;
[0177] ;
[0178] In the formula, , , are respectively the results after using a non - linear activation function on the output of convolutional feature extraction, is the activation function;
[0179] Subsequently, use to further process the extracted features as the query, key, and value matrices for calculating the frequency feature representation. The specific calculation formula is as follows:
[0180] ;
[0181] ;
[0182] ;
[0183] In the formula, , are the results of further feature extraction by . The results of further extraction are used as the query, key, and value matrices for calculating the frequency feature representation. Subsequently, the obtained matrices are subjected to weighted attention calculation. By introducing a weighting mechanism, more attention is paid to specific attention heads. The weighting mechanism uses a linear layer to generate the weights of each attention head. The calculation formula is as follows:
[0184] ;
[0185] In the formula, is the number of heads of the multi - head attention, is the initial weight parameter of each attention head, which is learned through training; The score of each attention head is calculated as follows:
[0186] ;
[0187] In the formula, is the attention score obtained by calculating the frequency feature representation, is the scaling constant;
[0188] Subsequently, each attention head is weighted, and the formula is as follows:
[0189] ;
[0190] In the formula, is the weighted value of the attention head ;
[0191] Finally, multiple attention heads are output to obtain the final output of the weighted attention mechanism , and the calculation formula is:
[0192] ;
[0193] Finally, for each time step after the embedding representations of all variables are subjected to the same weighted attention calculation, they are concatenated to form the frequency feature representation of a sample ; The variable interaction module finally obtains the time feature representation through the processing of the data and the frequency feature representation .
[0194] S34. Propose non-linear feature interaction fusion, which is used to fuse the outputs of the time correlation module and the variable interaction module
[0195] Furthermore, in steps S3 and S34, by introducing non-linear feature interaction, the output of the time correlation module and the time feature representation of the variable interaction module and the frequency feature representation generate more complex feature representations after interaction. The specific methods include:
[0196] First, interact the outputs , , to generate new features. The interaction operation is as follows:
[0197] ;
[0198] ;
[0199] ;
[0200] In the formula, is the element-wise multiplication operation, , , are the new features generated by pairwise interaction;
[0201] Subsequently, perform a non-linear transformation on the interacted features to obtain a new representation:
[0202] ;
[0203] ;
[0204] ;
[0205] In the formula, , , are the results of non - linear transformation for the features after interaction, , , are the weight parameters in the non - linear transformation calculation, , , are the bias terms in the non - linear transformation calculation;
[0206] Finally, all the non - linear features after interaction are weighted and summed, and the weighted sum formula is as follows:
[0207] ;
[0208] In the formula, , , are the weights after interaction, is the output , , is the final fusion result.
[0209] S35. Introduce a mapping layer, and calculate the output of the non - linear feature interaction and fusion through the introduced mapping layer to output the final prediction result of the agricultural pest and disease prediction model.
[0210] Furthermore, in the steps S3 and S35, the mapping layer uses a fully - connected neural network MLP for mapping, and the mapping result is the final predicted value. The formula used by the mapping layer is as follows:
[0211] ;
[0212] In the formula, is the weight matrix of the mapping layer, is the bias term of the mapping layer, is the final predicted value of the agricultural pest and disease prediction model; This application uses the L1 loss function to train the model, and the L1 loss function formula is:
[0213] ;
[0214] In the formula, is the number of batch samples, is the true value of the th sample, is the th sample's predicted value, is the loss value between the true value and the predicted value.
[0215] S4. Train the agricultural pest and disease prediction model using the training set. By optimizing the parameters of the prediction model, minimize the error of the prediction model on the training set, improve the learning ability of the model for the occurrence patterns of pests and diseases, and thus improve the prediction accuracy of the prediction model on unknown data.
[0216] Furthermore, in step S4, the reasonable selection of hyperparameters can accelerate the convergence of the model, improve the prediction accuracy, and avoid overfitting. The learning rate determines the step size when the model updates the weights each time. The learning rate LR is set to 0.002, and the RMSprop optimizer is used. The batch size batch is the number of samples used in each training, set to 128. The number of epochs is the number of times the model is completely trained on the entire training set. After each iteration, the model weights will be updated, and epochs is set to 500. In each iteration, the Dropout layer randomly shuts down a part of the neurons to prevent the model from relying on specific neurons. The neuron inactivation rate set by the Dropout layer is 0.2.
[0217] S5. Test the agricultural pest and disease prediction model using the test set. By evaluating the performance of the model on the test set, calculate the prediction accuracy and error, and verify the generalization ability of the model, so as to ensure the reliability and accuracy of the prediction model in practical applications.
[0218] Furthermore, in step S5, test the prediction accuracy of the trained prediction model using the test set to determine whether the prediction model can meet the actual requirements for deployment in the actual environment. Figure 7 In (a), the training values and prediction values of the model during the training process are shown. Use the training set data of the first 12 hours to predict the situation of agricultural plant pests and diseases within the next 6 hours. The prediction model predicts the probability of wheat getting wheat aphids. It can be seen from Figure (a) that as time goes by, the probability of wheat getting wheat aphids is getting larger and larger. It is recommended that farmers carry out a spraying control in advance. Figure 7 (b) shows the comparison between the prediction values and the true values of the prediction model. In addition, the prediction values of two recurrent neural networks and the LSTM network algorithm are also added for comparison. It can be seen from Figure 7 (b) that the prediction values of the agricultural pest and disease prediction model proposed in this application are closer to the true values and have higher prediction accuracy.
Claims
1. A method for optimizing agricultural pest and disease prediction, characterized in that: The following steps are involved: S1. Collect key information for agricultural pest and disease prediction, including crop type, crop growth stage, soil condition information, weather information and agricultural management records; S2, preprocessing of key information data for agricultural pest and disease prediction, mainly including data cleaning and normalization; S3. Construct an agricultural pest and disease prediction model. The specific methods include: S31, propose a feature conversion module to convert the input preprocessed data into a feature representation suitable for model processing; S32, a time association module is proposed, which focuses on capturing the dependencies between each time step in the time series, and from the final output X of the feature conversion module embed Select data It is the high-dimensional representation of the nth variable in a sample at different time periods; In the dynamic multi-head attention mechanism, the input data is first Convert to query matrix Key Matrix Sum Matrix The conversion formula is as follows: In the formula, is a trainable weight matrix, h is the number of the attention head; the output of a single attention head is then calculated through dynamic attention, and the dynamic attention calculation formula is as follows: In the formula, Softmax is the activation function, is the output of the dynamic attention of the attention head numbered h, for The transpose operation, is the scaling constant, It is a dynamic function and is calculated as follows: In the formula, is the connection between the query matrix and the key matrix, W f is a trainable weight matrix and Sigmoid is the activation function; each attention head weights the sum value according to the similarity between the query and the key to capture the dependencies between different positions in the input data; After all H attention heads have independently calculated the attention output, the outputs are concatenated together to obtain a large attention output matrix, which is calculated as follows: In the formula, is the final output of the dynamic multi-head attention mechanism, and Concat is the concatenation operation; Finally, after residual connection and layer normalization operations, the nth variable of a sample is used as the final output of the time association module. The specific formula is as follows: In the formula, LayerNorm is the normalization operation, X out1 is the final output of the nth variable in the time association module; finally, the embedded representations of each variable in the sample at different stages are merged after being processed by the dynamic multi-head attention mechanism to obtain the final output out of a sample after passing through the time association module hori ; S33, a variable interaction module is proposed, which is used to capture the relationship between different variables in the same time step and to Perform temporal feature representation and use multi-feature attention mechanism for frequency feature representation, is the final output X of the feature conversion module embed The embedded representation of all variables at a specific time step t in ; First, the time feature representation is performed. For each attention head h, different query key and the value matrix The calculation formula is as follows: In the formula, is the weight matrix of the attention mechanism, are matrices after linear transformation, which are used for subsequent attention calculations. Then, for each attention head h, the scaled dot product attention is used to calculate the attention output. The calculation formula is as follows: In the formula, is the output of the attention head h, is the scaling constant; finally, the output of each attention head is concatenated as the final output of the multi-head attention mechanism. The concatenation formula is as follows: Where H is the number of attention heads, is the output of the multi-head attention mechanism in temporal feature representation; Then the input features are transformed into Output of the attention mechanism Addition is used to retain input features, the formula is as follows: In the formula, MLP is a fully connected network, It is a residual operation, which adds the input features to the output of the attention mechanism; finally, the embedded representations of all variables at each time step t are concatenated after the same multi-head attention calculation to form a temporal feature representation of a sample out time ; The frequency feature represents the query calculated using each attention head h key and the value matrix The query, key, and value matrices used to calculate the frequency feature representation are obtained through three feature extractors; First, use convolution to extract features. The formula is as follows: Where, is the query calculated for each attention head h key and the value matrix The result of convolution feature extraction, Conv is the convolution operation; Then a nonlinear activation function is applied to the convolution feature extraction output, as follows: In the formula, They are the results of using nonlinear activation functions on the output of convolution feature extraction, and ReLU is the activation function; The extracted features are then further processed using MLP as the query, key, and value matrices for calculating the frequency feature representation. The specific calculation formula is as follows: In the formula, The result of further feature extraction after MLP is used as the query, key, and value matrix used to calculate the frequency feature representation. The obtained matrix is then subjected to weighted attention calculation. By introducing a weighting mechanism, more attention is paid to specific attention heads. The weighting mechanism uses a linear layer to generate the weight of each attention head. The calculation formula is as follows: Where H is the number of heads of multi-head attention, w h is the initial weight parameter for each attention head, which is learned through training; the score of each attention head is calculated as follows: In the formula, To calculate the attention score obtained by frequency feature representation, is the scaling constant; Each attention head is then weighted as follows: In the formula, head h is the weighted value of the attention head h; Finally, multiple attention heads are output to obtain the final output of the weighted attention mechanism. Attention , the calculation formula is: Finally, the embedding representations of all variables at each time step t are concatenated after the same weighted attention calculation to form a frequency feature representation of a sample out fre ; The variable interaction module After processing, the time feature representation out is finally obtained time With frequency characteristics out fre ; S34, proposing nonlinear feature interactive fusion, wherein the feature interactive fusion is used to generate a more complex feature representation after the output of the time association module interacts with the time feature representation and the frequency feature representation of the variable interaction module; S35, introducing a mapping layer, and calculating the output of the interactive fusion of nonlinear features through the introduced mapping layer; S4, training agricultural pest and disease prediction model, and minimizing the error of the prediction model on the training set by optimizing the prediction model parameters; S5. Test the agricultural pest and disease prediction model, evaluate the model's performance on the test set, calculate the prediction accuracy and error, and verify the model's generalization ability.
2. The agricultural pest prediction optimization method according to claim 1, characterized in that: In step S1, key information is collected by manual inspection, sensor monitoring and drone remote sensing; crop type and crop growth stage information is collected by manual inspection; soil condition information is collected by sensor, and the soil condition information includes soil moisture, pH value and nutrient content; Use sensors to collect weather information, including temperature and humidity; use manual methods to collect agricultural management record information, including fertilization, irrigation, and drug use records; use drone remote sensing to detect crop pests and diseases; and set the collection frequency to once an hour.
3. The agricultural pest prediction optimization method according to claim 2, characterized in that: In step S31, firstly, a time series segmentation operation is performed on the data. The time series segmentation divides the data set X into B samples, each of which is a multivariate time series X. s ∈R T×N , where T is the number of time steps and N is the number of variables. For each sample X s Perform a slicing operation to divide each sample into multiple segments of length P. The number of segments that can be generated for each sample is M = T / P. Each segment contains P consecutive time steps. Each segment after slicing is X slice,n ∈R M×P ; Linear projection is then used to map the sliced time series segments into a high-dimensional embedding space to provide rich feature representations for each segment. The specific method is to use a trainable linear projection matrix W p ∈R P×D Project each fragment into D-dimensional space, the linear projection formula is: X d, n=X slice,n W p +b p ; Where b p is the bias term of the linear projection, X d,n is the projection representation, the shape is X d,n ∈R M×D , linearly project each variable, and the final projected time series is represented by X d ∈R M×N× D is passed to the next layer; finally the positional encoding is added at each time step; Add position encoding using fixed position encoding of sine and cosine functions. For each position pos and each embedding dimension i, the position encoding is calculated using the following formula: For pos to be an even number, the formula is For pos is an odd number, the formula is Where sin and cos are sine and cosine functions, respectively, k is the dimension index in the embedding vector, pos is the position index in the sequence, and D is the total dimension of the embedding vector, 10000 2k / D is a scaling factor, and its value grows exponentially with the increase of embedding dimension k. The final position encoding matrix P consists of the encoding values of all positions pos and embedding dimension k. The vector at each position pos can be expressed as: Concatenate the vectors at each pos into a position encoding matrix P, with a shape of P∈R M×D , and then the position encoding matrix is added to each fragment as the final output of the feature conversion module, the formula is: X embed =X d +P; Where, X d is the time series representation after projection, P is the position encoding matrix, X embed is the representation after position encoding, with a shape of X embed ∈R M×N×D .
4. The agricultural pest prediction optimization method according to claim 3, characterized in that: In step S34, by introducing nonlinear feature interaction, the output out of the time association module hori The temporal feature representation of the variable interaction module out time With frequency characteristics out fre After the interaction, more complex feature representations are generated. The specific methods include: First, the output out hori ,out time ,out fre Interact to generate new features. The interactive operations are as follows: In the formula, is an element-by-element multiplication operation, Z 1,2 , Z 1,3 , Z 2,3 New features generated for pairwise interactions; Then the interacted features are transformed nonlinearly to obtain a new representation: In the formula, is the result of nonlinear transformation of the interactive features, W 1,2 , W 1,3 , W 2,3 is the weight parameter in the nonlinear transformation calculation, b 1,2 , b 1,3 , b 2,3 is the bias term in the nonlinear transformation calculation; Finally, all the nonlinear features after interaction are weighted and summed. The weighted summation formula is as follows: In the formula, γ 1,2 , γ 1,3 , γ 2,3 is the weight after interaction, Z final Output out hori ,out time ,out fre The final fusion result.
Citation Information
Patent Citations
Traffic flow prediction method and system based on trend space-time diagram convolution, and medium
CN116895157A
Personnel abnormal behavior identification system and method based on TSAFormer model
CN117935121A
Photovoltaic power generation power prediction method and system, and computer equipment
CN118316030A
Geological disaster risk partition automatic optimization method and system based on artificial intelligence
CN118822271A