Agricultural pest prediction optimization method
By constructing a multivariate time series model and combining deep learning technology to capture the relationship between time series and variables, the problem that traditional methods are difficult to deal with complex data is solved, and more efficient and accurate prediction of agricultural pests and diseases is achieved.
Patent Information
- Application Number
- CN202510045135.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-02-14
- 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 CN119443422A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of pest and disease prediction, and in particular relates to an agricultural pest and disease prediction optimization method. Background Art
[0002] Agricultural pests and diseases are a major problem affecting global agricultural production, causing large amounts of crop losses every year, which in turn affects farmers' income and food security. Traditional pest and disease prediction methods rely on manual observation and seasonal warnings, but this method has lags and limitations, and it is often difficult to detect potential risks in advance, resulting in the failure to take timely prevention and 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 pest and disease prediction optimization method.
[0003] Artificial intelligence (AI) and machine learning (ML) provide new solutions for agricultural pest and disease prediction. AI can automatically handle complex nonlinear problems by simulating the decision-making process of human experts. Machine learning uses a large amount of historical data and real-time data to predict the occurrence of future pests and diseases by learning patterns in the data. Supervised learning and unsupervised learning are common machine learning methods. Supervised learning trains prediction models 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 predictions and provide more accurate pest and disease prevention and control guidance for agricultural production.
[0004] Agricultural pest and disease prediction is a dynamic, multivariate complex system, and traditional models have limitations when dealing with multivariate time series and dynamic data, and it is difficult to deal with interactions across time dimensions. For this complex cross-impact, traditional models are often unable to effectively model, resulting in low prediction accuracy. This application uses crop types, crop growth stages, soil conditions, weather information, and agricultural management records as input variables, combined with the time series analysis capabilities of deep learning networks, to significantly improve the accuracy of pest and disease prediction. Multivariate time series methods can also further focus on key variables, thereby more accurately assessing the sensitivity of agricultural plants to specific environmental conditions and helping planting personnel adjust strategies in real time. Therefore, by combining multivariate time series with deep learning technology, agricultural pest and disease prediction methods can provide a solid foundation for pest and disease prediction models, 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 agricultural pest and disease prediction optimization method, which is aimed at an agricultural pest and disease prediction model, wherein the agricultural pest and disease prediction model consists of a feature conversion module, a time association module, a variable interaction module and a nonlinear feature interaction fusion, wherein the feature conversion module converts the input raw data into a feature representation suitable for model processing; the time association module captures the dependency between each time step in the time series; the variable interaction module focuses on the relationship between different variables to improve the prediction accuracy of multivariate time series; the nonlinear feature interaction fusion makes comprehensive use of information from different dimensions, so that the prediction model can more accurately understand the pattern of complex data and improve the accuracy and generalization ability of the prediction.
[0006] To achieve the above objectives, the technical solution of the present application is: a method for optimizing agricultural pest prediction, the method comprising: 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, which includes data cleaning and data normalization operations to improve the overall quality of the data set; 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, propose a time association module, which focuses on capturing the dependencies between each time step in the time series; S33, proposing a variable interaction module, wherein the variable interaction module is used to capture the relationship between different variables in the same time step; 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, calculating the output of the interactive fusion of nonlinear features through the introduced mapping layer, and outputting the final prediction result of the agricultural pest prediction model; S4. Use the training set to train the agricultural pest and disease prediction model. By optimizing the prediction model parameters, the prediction model can minimize the error on the training set, improve the model's ability to learn the pest and disease occurrence pattern, and thus improve the prediction accuracy of the prediction model on unknown data. S5. Use the test set to test the agricultural pest and disease prediction model. By evaluating the performance of the model on the test set, calculating the prediction accuracy and error, and verifying the generalization ability of the model, the reliability and accuracy of the prediction model in practical applications are ensured.
[0007] Furthermore, in the steps S3 and S31, the data is firstly segmented into time series. Split into samples, each sample is a multivariate time series ,in is the number of time steps, is the number of variables, for each sample Perform a slicing operation to divide each sample into multiple pieces of length The number of fragments that can be generated for each sample is , each fragment contains continuous time steps, each segment after slicing is ; 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 Project each fragment onto dimensional space, the linear projection formula is: ; In the formula, is the bias term of the linear projection, is the projection representation, and the shape is , linearly project each variable, and the final projected time series is represented by is passed to the next layer; Finally, position coding is added at each time step to increase the order information in the input data recognized by the agricultural pest prediction model. Position coding is added using the fixed position coding method of sine and cosine functions. For each position and each embedding dimension , the positional encoding is calculated using the following formula: for is an even number, the formula is ; for is an odd number, the formula is ; 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, as the embedding dimension As the value of this factor increases, it will grow exponentially; the final position encoding matrix By all locations and embedding dimension The coded value is composed of The vector on can be expressed as: {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 ] , each The vectors on the matrix are concatenated into a position encoding matrix , the shape is , and then the position encoding matrix is added to each fragment as the final output of the feature conversion module, the formula is: ; In the formula, is the time series representation after projection, is the position encoding matrix, is the representation after position encoding, and its shape is .
[0008] Furthermore, in step S31, time series slicing and position coding technology significantly improves the fault detection capability of the model in the agricultural pest and disease prediction model by effectively segmenting and encoding time series data; slicing helps to capture short-term and long-term patterns, isolate noise, and improve data utilization efficiency; position coding ensures that the model understands the sequential relationship of time steps and 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, thereby improving the accuracy and robustness of the prediction.
[0009] Furthermore, in the steps S3 and S32, the time association module captures the dependencies between the time steps in the time series based on the dynamic multi-head attention mechanism, and obtains the final output of the feature conversion module. Select data , For a sample High-dimensional representation of variables at different time periods; In the dynamic multi-head attention mechanism, the input data is first Convert to query matrix , key matrix , and value matrix , the conversion formula is as follows: ; ; ; In the formula, , , is the trainable weight matrix, is the number of the attention head; the output of a single attention head is then calculated through dynamic attention. The dynamic attention calculation formula is as follows: ; In the formula, is the activation function, For the number The output of the dynamic attention of the attention head, for The transpose operation, is the scaling constant, It is a dynamic function and is calculated as follows: f\left ( {{Q}^{h}_{:,n},{K}^{h}_{:,n}} \right )=Sigmoid({W}_{f}\left [ {{Q}^{h}_{:,n};{K}^{h}_{:,n}} \right ]) ; Where, \left [ {{Q}^{h}_{:,n};{K}^{h}_{:,n}} \right ] To connect the query matrix with the key matrix, is the trainable weight matrix, is the activation function; each attention head weights the sum value according to the similarity between the query and the key, capturing the dependencies between different positions in the input data; In all After each attention head independently calculates the attention output, the outputs are concatenated together to obtain a large attention output matrix. The calculation formula is as follows: ; In the formula, is the final output of the dynamic multi-head attention mechanism, For splicing operation; Finally, after residual connection and layer normalization operation, it is used as a sample The final output of the variable in the time association module is as follows: ; In the formula, For normalization operation, For the The final output of the variable in the time association module; finally, the embedded representation of each variable in the sample at different stages is merged after being processed by the dynamic multi-head attention mechanism to obtain the final output of a sample after passing through the time association module .
[0010] 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 and enhancing the modeling capabilities of long-term dependencies and fault characteristics at different time scales; the time correlation module can dynamically allocate the importance of time steps, help the model identify complex fault modes, and improve the interpretability of the model, making the prediction process more transparent and accurate, thereby effectively improving the accuracy and reliability of the prediction.
[0011] Furthermore, in the steps S3 and S33, the variable interaction module is used to capture the relationship between different variables in the same time step by Perform temporal feature representation and use multi-feature attention mechanism for frequency feature representation, The final output of the feature conversion module Specific time step Embedding representation of all variables above; First, the temporal feature representation is performed for each attention head , calculate different queries ,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 The attention output is calculated using scaled dot product attention, which is calculated as follows: ; In the formula, For the attention head The output, 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: ; In the formula, 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, For a fully connected network, is the residual operation, which adds the input features to the output of the attention mechanism; finally, for each time step The embedding representations of all the variables above are concatenated after the same multi-head attention calculation to form a temporal feature representation of a sample .
[0012] Furthermore, in the steps S3 and S33, the frequency feature representation uses each attention head Calculated Queries ,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: ; ; ; In the formula, is for each attention head Calculated Queries ,key and the value matrix The result of convolution feature extraction is: 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 function on the convolution feature extraction output. is the activation function; Subsequent use The extracted features are further processed as query, key, and value matrices representing the calculated frequency features. The specific calculation formula is as follows: ; ; ; In the formula, , For passing The result of further feature extraction 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: ; In the formula, is the number of heads of multi-head attention, 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, The attention head is The weighted value of Finally, multiple attention heads are output to obtain the final output of the weighted attention mechanism. , the calculation formula is: ; Finally, for each time step The embedding representations of all the variables above are concatenated after the same weighted attention calculation to form a frequency feature representation of a sample ; The variable interaction module After processing, the final time feature representation is obtained Represented by frequency characteristics .
[0013] Furthermore, in step S33, the variable interaction module in the agricultural pest and disease prediction model improves the model's ability to process multi-dimensional data by paying attention to the dependencies between different features; the variable interaction module effectively captures the mutual influence between different variables, helping the model to more accurately identify potential failure modes, and by adaptively allocating the importance of features, the variable interaction module enhances the model's understanding of complex multivariate data, thereby improving the accuracy and comprehensiveness of the prediction.
[0014] Furthermore, in the steps S3 and S34, by introducing nonlinear feature interaction, the output of the time association module Temporal feature representation with variable interaction modules Represented by frequency characteristics Generate more complex feature representations after interaction. Specific methods include: First, the output , , Interact to generate new features. The interactive operations are as follows: ; ; ; In the formula, is an element-by-element multiplication operation, , , 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. , , is the weight parameter in the nonlinear transformation calculation, , , 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, , , is the weight after interaction, Output , , The final fusion result.
[0015] Furthermore, in step S34, the output results of the variable interaction module and the time association module are fused, which can simultaneously capture the dependencies between time steps and the relationships between different features in the agricultural pest and disease prediction model. This fusion enables the model to fully understand the complex patterns in multi-dimensional data, identify key time points in time series, and gain insight into the synergy between various features, thereby significantly improving the accuracy and robustness of the prediction; in addition, the fused attention mechanism enhances the interpretability of the model and makes the prediction process more transparent.
[0016] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are: In the present invention, an agricultural pest and disease prediction model is constructed, and the agricultural pest and disease prediction model consists of a feature conversion module, a time association module, a variable interaction module and a nonlinear feature interaction fusion, wherein the feature conversion module converts the input raw data into a feature representation suitable for model processing; the time association module captures the dependency between each time step in the time series; the variable interaction module focuses on the relationship between different variables to improve the prediction accuracy of multivariate time series; the nonlinear feature interaction fusion comprehensively utilizes information of different dimensions, and the agricultural pest and disease prediction model can more accurately understand the pattern of complex data and improve the accuracy and generalization ability of the prediction; the agricultural pest and disease prediction model described in the present application can accurately predict the pest and disease situation of agriculture in the future period of time and reduce unnecessary losses. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 The figure is a flowchart of the steps of an agricultural pest and disease prediction optimization method.
[0018] Figure 2 This is a flow chart of the steps of an agricultural pest and disease prediction model in an agricultural pest and disease prediction optimization method.
[0019] Figure 3 This is the structural diagram of the time-related module in the agricultural pest and disease prediction model.
[0020] Figure 4 This is the internal computational graph of the time-correlation module in the agricultural pest prediction model.
[0021] Figure 5 This is a structural diagram of the variable interaction module in the agricultural pest and disease prediction model.
[0022] Figure 6 This is the internal calculation diagram of the variable interaction module in the agricultural pest and disease prediction model.
[0023] Figure 7 This is a graph comparing the predicted values of the agricultural pest and disease prediction model with other values; Figure 7 (a) is the training value and prediction value of the agricultural pest prediction model, Figure 7 (b) is a comparison chart of the predicted values and true values of each model. DETAILED DESCRIPTION
[0024] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only 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 ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0025] See also Figure 1-Figure 7 The present invention provides a technical solution: an agricultural pest and disease prediction optimization method, the method comprising the steps of: collecting key information for agricultural pest and disease prediction, preprocessing key information data for agricultural pest and disease prediction, building 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.
[0026] Please refer to Figure 1 As shown, an agricultural pest prediction optimization method in an embodiment of the present application, the specific steps are as follows:
[0027] S1. Collect key information for agricultural pest and disease prediction, wherein the key information for agricultural pest and disease prediction includes crop type, crop growth stage, soil condition information, weather information, and agricultural management records.
[0028] Furthermore, in step S1, key information is collected by manual inspection, sensor monitoring and drone remote sensing; crop type and crop growth stage information are collected by manual inspection; soil condition information is collected by sensors, and the soil condition information includes soil moisture, pH value, and nutrients; weather information is collected by sensors, including temperature and humidity; agricultural management record information is collected manually, including fertilization, irrigation, and drug use records; drone remote sensing is used to detect crop diseases and pests; and the collection frequency is set to once an hour.
[0029] S2. Preprocessing of key information data for agricultural pest and disease prediction, which includes data cleaning and data normalization operations to improve the overall quality of the data set.
[0030] Furthermore, in step S2, the data cleaning corrects the outliers and missing values in the data. For missing value processing, the mean of the feature is used to fill the missing value. The mean filling formula is: ; In the formula, For the The elements of the column where the missing values are located, N is the number of non-missing values; the outlier detection uses the standard deviation method to detect and remove outliers. The formula of the standard deviation method is as follows: ; In the formula, is the current data point, is the mean of the data, σ is the standard deviation of the data; when the Z-score exceeds the threshold, the point is an outlier; The normalization is to process data of different dimensions and ranges. Normalization compresses the data to the interval [0,1]. The normalization formula is as follows: ; In the formula, is the original data, and are the minimum and maximum values of the feature, respectively. is the normalized data;
[0031] S3. Construct an agricultural pest prediction model. The steps are as follows: Figure 2 As shown, it specifically includes: proposing a feature conversion module, proposing a time association module, proposing a variable interaction module, proposing a nonlinear feature interaction fusion and introducing a mapping layer. The specific implementation methods are as follows.
[0032] S31. Propose a feature conversion module to convert the input preprocessed data into a feature representation suitable for model processing.
[0033] Furthermore, in the steps S3 and S31, the data is firstly segmented into time series. Split into samples, each sample is a multivariate time series ,in is the number of time steps, is the number of variables, for each sample Perform a slicing operation to divide each sample into multiple pieces of length The number of fragments that can be generated for each sample is , each fragment contains continuous time steps, each segment after slicing is ; 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 Project each fragment onto dimensional space, the linear projection formula is: ; In the formula, is the bias term of the linear projection, is the projection representation, and the shape is , perform the same projection operation on each variable, and the final projected time series is represented by is passed to the next layer; Finally, position coding is added at each time step to increase the order information in the input data recognized by the agricultural pest prediction model. Position coding is added using the fixed position coding method of sine and cosine functions. For each position and each embedding dimension , the positional encoding is calculated using the following formula: for is an even number, the formula is ; for is an odd number, the formula is ; 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, as the embedding dimension As the value of this factor increases, it will grow exponentially; the final position encoding matrix By all locations and embedding dimension The coded value is composed of The vector on can be expressed as: , each The vectors on the matrix are concatenated into a position encoding matrix , the shape is , and then the position encoding matrix is added to each fragment as the final output of the feature conversion module, the formula is: ; In the formula, is the time series representation after projection, is the position encoding matrix, is the representation after position encoding, and its shape is .
[0034] S32. A time association module is proposed, which focuses on capturing the dependencies between each time step in a time series.
[0035] Furthermore, in the steps S3 and S32, the time association module captures the dependencies between the time steps in the time series based on the dynamic multi-head attention mechanism, and obtains the final output of the feature conversion module. Select data , For a sample The high-dimensional representation of variables at different time periods, such as Figure 3 As shown; In the dynamic multi-head attention mechanism, the input data is first Convert to query matrix , key matrix , and value matrix ,like Figure 4 As shown, the conversion formula is as follows: ; ; ; In the formula, , , is the trainable weight matrix, is the number of the attention head; the output of a single attention head is then calculated through dynamic attention. The dynamic attention calculation formula is as follows: ; In the formula, is the activation function, For the number The output of the dynamic attention of the attention head, for The transpose operation, is the scaling constant, It is a dynamic function and is calculated as follows: ; In the formula, To connect the query matrix with the key matrix, is the trainable weight matrix, is the activation function; each attention head weights the sum value according to the similarity between the query and the key, capturing the dependencies between different positions in the input data; In all After each attention head independently calculates the attention output, the outputs are concatenated together to obtain a large attention output matrix. The calculation formula is as follows: ; In the formula, is the final output of the dynamic multi-head attention mechanism, For splicing operation; Finally, after residual connection and layer normalization operation, it is used as a sample The final output of the variable in the time association module is as follows: ; In the formula, For normalization operation, For the The final output of the variable in the time association module; finally, the embedded representation of each variable in the sample at different stages is merged after being processed by the dynamic multi-head attention mechanism to obtain the final output of a sample after passing through the time association module .
[0036] S33. Propose a variable interaction module, which is used to capture the relationship between different variables in the same time step.
[0037] Furthermore, in the steps S3 and S33, the variable interaction module is used to capture the relationship between different variables in the same time step, such as Figure 5 As shown, the method is to Perform temporal feature representation and use multi-feature attention mechanism for frequency feature representation, The final output of the feature conversion module Specific time step Embedding representation of all variables above; First, the temporal feature representation is performed for each attention head , calculate different queries ,key and the value matrix ,like Figure 6 As shown, 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 The attention output is calculated using scaled dot product attention, which is calculated as follows: ; In the formula, For the attention head The output, 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: ; In the formula, 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, For a fully connected network, is the residual operation, which adds the input features to the output of the attention mechanism; finally, for each time step The embedding representations of all the variables above are concatenated after the same multi-head attention calculation to form a temporal feature representation of a sample .
[0038] Furthermore, in the steps S3 and S33, the frequency feature representation uses each attention head Calculated Queries ,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: ; ; ; In the formula, is for each attention head Calculated Queries ,key and the value matrix The result of convolution feature extraction is: 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 function on the convolution feature extraction output. is the activation function; Subsequent use The extracted features are further processed as query, key, and value matrices representing the calculated frequency features. The specific calculation formula is as follows: ; ; ; In the formula, , For passing The result of further feature extraction 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: ; In the formula, is the number of heads of multi-head attention, 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, The attention head is The weighted value of Finally, multiple attention heads are output to obtain the final output of the weighted attention mechanism. , the calculation formula is: ; Finally, for each time step The embedding representations of all the variables above are concatenated after the same weighted attention calculation to form a frequency feature representation of a sample ; The variable interaction module After processing, the final time feature representation is obtained Represented by frequency characteristics .
[0039] S34. Propose nonlinear feature interaction fusion, where the feature interaction fusion is used to fuse the outputs of the time association module and the variable interaction module.
[0040] Furthermore, in the steps S3 and S34, by introducing nonlinear feature interaction, the output of the time association module Temporal feature representation with variable interaction modules Represented by frequency characteristics After the interaction, more complex feature representations are generated. The specific methods include: First, the output , , Interact to generate new features. The interactive operations are as follows: ; ; ; In the formula, is an element-by-element multiplication operation, , , 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. , , is the weight parameter in the nonlinear transformation calculation, , , 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, , , is the weight after interaction, Output , , The final fusion result.
[0041] S35. Introduce a mapping layer, calculate the output of the interactive fusion of nonlinear features through the introduced mapping layer, and output the final prediction result of the agricultural pest and disease prediction model.
[0042] 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 prediction value. The formula used by the mapping layer is as follows: ; 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 prediction model; this application uses the L1 loss function to train the model, and the L1 loss function formula is: ; In the formula, is the number of batch samples, For the The true value of the samples, For the The predicted value of samples, is the loss between the true value and the predicted value.
[0043] S4. Use the training set to train the agricultural pest and disease prediction model. By optimizing the prediction model parameters, the prediction model can minimize the error on the training set, improve the model's ability to learn the pest and disease occurrence pattern, and thus improve the prediction accuracy of the prediction model on unknown data.
[0044] Furthermore, in step S4, reasonable selection of hyperparameters can accelerate the convergence of the model, improve prediction accuracy, and avoid overfitting; the learning rate determines the step size each time the model updates the weight, 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, which is set to 128; the number of iterations epochs is the number of times the model is fully trained on the entire training set, and the model weights will be updated after each iteration, and epochs is set to 500; in each iteration, the Dropout layer is used to randomly close a part of the neurons to prevent the model from relying on specific neurons, and the neuron deactivation rate set by the Dropout layer is 0.2.
[0045] S5. Use the test set to test the agricultural pest and disease prediction model. By evaluating the performance of the model on the test set, calculating the prediction accuracy and error, and verifying the generalization ability of the model, the reliability and accuracy of the prediction model in practical applications are ensured.
[0046] Furthermore, in step S5, the prediction accuracy of the trained prediction model is tested using a test set to determine whether the prediction model can meet actual requirements to be deployed in an actual environment. Figure 7 (a) shows the training value and prediction value of the model during the training process. The training set data of the first 12 hours are used to predict the situation of agricultural plant diseases and insect pests in the next 6 hours. The prediction model predicts the probability of wheat getting wheat aphids. As can be seen from Figure (a), as time goes by, the probability of wheat getting wheat aphids is getting higher and higher. It is recommended that farmers spray pesticides in advance for prevention and control. Figure 7 (b) is the comparison between the predicted value of the prediction model and the true value. In addition, two recurrent neural networks and the predicted value of the LSTM network algorithm are added for comparison. Figure 7 (b) It can be seen that the predicted value of the agricultural pest and disease prediction model proposed in this application is closer to the true value and has 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, propose a time association module, which focuses on capturing the dependencies between each time step in the time series; S33, proposing a variable interaction module, wherein the variable interaction module is used to capture the relationship between different variables in the same time step; 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 into Split into samples, each sample is a multivariate time series ,in is the number of time steps, is the number of variables, for each sample Perform a slicing operation to divide each sample into multiple pieces of length The number of fragments that can be generated for each sample is , each fragment contains continuous time steps, each segment after slicing is ; 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 Project each fragment onto dimensional space, the linear projection formula is: ; In the formula, is the bias term of the linear projection, is the projection representation, and the shape is , linearly project each variable, and the final projected time series is represented by is passed to the next layer; Finally, position encoding is added at each time step; Add position encoding using fixed position encoding of sine and cosine functions. For each position and each embedding dimension , the positional encoding is calculated using the following formula: for is an even number, the formula is ; for is an odd number, the formula is ; 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, as the embedding dimension As the value of this factor increases, it will grow exponentially; the final position encoding matrix By all locations and embedding dimension The coded value is composed of The vector on can be expressed as: , each The vectors on the position encoding matrix are concatenated into , the shape is , and then the position encoding matrix is added to each fragment as the final output of the feature conversion module, the formula is: ; In the formula, is the time series representation after projection, is the position encoding matrix, is the representation after position encoding, and its shape is .
4. The agricultural pest prediction optimization method according to claim 3, characterized in that: In step S32, the time association module captures the dependencies between each time step in the time series based on the dynamic multi-head attention mechanism, and obtains the final output of the feature conversion module. Select data , For a sample High-dimensional representation of variables at different time periods; In the dynamic multi-head attention mechanism, the input data is first Convert to query matrix , key matrix , and value matrix , the conversion formula is as follows: ; ; ; In the formula, , , is the trainable weight matrix, is the number of the attention head; the output of a single attention head is then calculated through dynamic attention. The dynamic attention calculation formula is as follows: ; In the formula, is the activation function, For the number The output of the dynamic attention of the attention head, for The transpose operation, is the scaling constant, It is a dynamic function and is calculated as follows: ; In the formula, To connect the query matrix with the key matrix, is the trainable weight matrix, is the activation function; each attention head weights the sum value according to the similarity between the query and the key, capturing the dependencies between different positions in the input data; In all After each attention head independently calculates the attention output, the outputs are concatenated together to obtain a large attention output matrix. The calculation formula is as follows: ; In the formula, is the final output of the dynamic multi-head attention mechanism, For splicing operation; Finally, after residual connection and layer normalization operation, it is used as a sample The final output of the variable in the time association module is as follows: ; In the formula, For normalization operation, For the The final output of the variable in the time association module; finally, the embedded representation of each variable in the sample at different stages is merged after being processed by the dynamic multi-head attention mechanism to obtain the final output of a sample after passing through the time association module .
5. The agricultural pest prediction optimization method according to claim 4, characterized in that: In step S33, the variable interaction module is used to capture the relationship between different variables in the same time step by Perform temporal feature representation and use multi-feature attention mechanism for frequency feature representation, The final output of the feature conversion module Specific time step Embedding representation of all variables above; First, the temporal feature representation is performed for each attention head , calculate different queries ,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 The attention output is calculated using scaled dot product attention, which is calculated as follows: ; In the formula, For the attention head The output, 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: ; In the formula, 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, For a fully connected network, is the residual operation, which adds the input features to the output of the attention mechanism; finally, for each time step The embedding representations of all the variables above are concatenated after the same multi-head attention calculation to form a temporal feature representation of a sample. .
6. The agricultural pest prediction optimization method according to claim 5, characterized in that: In step S33, the frequency feature representation uses each attention head Calculated Queries ,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: ; ; ; In the formula, is for each attention head Calculated Queries ,key and the value matrix The result of convolution feature extraction is: 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 function on the convolution feature extraction output. is the activation function; Subsequent use The extracted features are further processed as query, key, and value matrices representing the calculated frequency features. The specific calculation formula is as follows: ; ; ; In the formula, , For passing The result of further feature extraction 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: ; In the formula, is the number of heads of multi-head attention, 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, The attention head is The weighted value of Finally, multiple attention heads are output to obtain the final output of the weighted attention mechanism. , the calculation formula is: ; Finally, for each time step The embedding representations of all the variables above are concatenated after the same weighted attention calculation to form a frequency feature representation of a sample ; The variable interaction module After processing, the time feature representation is finally obtained Represented by frequency characteristics .
7. The agricultural pest prediction optimization method according to claim 6, characterized in that: In step S34, by introducing nonlinear feature interaction, the output of the time association module Temporal feature representation with variable interaction modules Represented by frequency characteristics Generate more complex feature representations after interaction. Specific methods include: First, the output , , Interact to generate new features. The interactive operations are as follows: ; ; ; In the formula, is an element-by-element multiplication operation, , , 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. , , is the weight parameter in the nonlinear transformation calculation, , , 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, , , is the weight after interaction, Output , , The final fusion result.
Citation Information
Patent Citations
Traffic flow long-time prediction method and system based on improved Transform model
CN115587454A
Crop disease identification method based on local selection and feature interaction
CN116824366A
Traffic flow prediction method and system based on trend space-time diagram convolution, and medium
CN116895157A
Plant disease and severity identification method based on multi-label strategy
CN117274815A
Personnel abnormal behavior identification system and method based on TSAFormer model
CN117935121A
Cited By
In-vehicle intelligent mosquito repelling method
CN120910790A
An intelligent mosquito-repelling method in a vehicle
CN120910790B
Soybean pod borer predicting and forecasting method based on machine learning
CN121660484A