Data optimization and early warning method, system and equipment of ammonia gas sensor and medium

By preprocessing and optimizing the historical data of low-cost ammonia sensors and using neural network models for prediction and early warning, the problems of reduced monitoring accuracy and reduced safety caused by sensor failure and data drift are solved, and higher measurement accuracy and safety monitoring are achieved.

CN119539185APending Publication Date: 2025-02-28INST OF AUTOMATION CHINESE ACAD OF SCI
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411665836.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-20
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

In livestock and poultry production scenarios, low-cost ammonia sensors are prone to failure or data drift due to material problems of sensitive components, resulting in reduced accuracy and safety of ammonia monitoring.

Method used

By obtaining the historical measurement data of the target ammonia sensor for preprocessing and optimization processing, noise is eliminated, and data is predicted using pre-trained neural network models to achieve real-time early warning.

Benefits of technology

It improves the measurement accuracy and accuracy of ammonia sensors and enhances the safety of livestock and poultry production environment monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119539185A_ABST
    Figure CN119539185A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of sensor data processing, and discloses an ammonia gas sensor data optimization and early warning method, which comprises the following steps: acquiring historical measurement data of a target ammonia gas sensor; preprocessing the historical measurement data; segmenting the preprocessed historical measurement data according to a time window to obtain multiple segments of historical measurement data; performing optimization processing on each section of historical measurement data; inputting the optimized historical measurement data of the target section into a target ammonia gas sensor data prediction model to obtain a first prediction value set; and determining an early warning result of the target ammonia gas sensor according to the plurality of first predicted value sets corresponding to the plurality of sections of historical measurement data. According to the embodiment of the invention, the ammonia gas sensor data prediction model constructed based on the GRU network and the feature enhancement network is adopted to predict the historical measurement data, and early warning is carried out according to the prediction result, so that the ammonia gas monitoring accuracy and the safety degree are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of sensor data processing technology, and in particular to a data optimization and early warning method, system, equipment and medium for an ammonia sensor. Background Art

[0002] High concentrations of ammonia can damage the health of animals and feeders in livestock and poultry production scenarios. Therefore, it is necessary to install ammonia sensors in livestock and poultry production scenarios.

[0003] In the related technologies, low-cost ammonia sensors can be deployed over a large area and at a high density due to their low cost, forming a grid monitoring network, and can also be deployed densely in key areas. Therefore, low-cost ammonia sensors have become the first choice for ammonia detection in livestock and poultry production scenarios. However, as the time of use after deployment goes by, low-cost ammonia sensors will inevitably have quality problems such as sensor failure or data drift and anomalies caused by other factors due to material problems of sensitive components, resulting in reduced accuracy of ammonia monitoring in livestock and poultry production scenarios, and thus unable to guarantee the health of animals and feeding personnel, that is, the safety level will also decrease. Summary of the invention

[0004] In view of this, the present invention provides a data optimization and early warning method, system, device and medium for an ammonia sensor to solve the technical problem of reduced accuracy and safety of ammonia monitoring in related technologies.

[0005] In a first aspect, the present invention provides a data optimization and early warning method for an ammonia sensor, the method comprising:

[0006] Acquire historical measurement data of the target ammonia sensor; the historical measurement data includes: a measurement value at a current moment and a measurement value at a moment before the current moment;

[0007] Preprocessing the historical measurement data;

[0008] The preprocessed historical measurement data is segmented according to the time window to obtain multiple segments of historical measurement data; wherein each segment of historical measurement data includes multiple measurement values; and the moments corresponding to the multiple measurement values ​​are continuous;

[0009] Optimize the processing of each section of historical measurement data;

[0010] Inputting the optimized target segment historical measurement data into the target ammonia sensor data prediction model to obtain a first prediction value set; each first prediction value in the first prediction value set is a prediction value at a time after a time step corresponding to a time of each measurement value in the optimized target segment historical measurement data;

[0011] Determine a warning result of a target ammonia sensor according to a plurality of first prediction value sets corresponding to a plurality of segments of historical measurement data;

[0012] The target ammonia sensor data prediction model is a pre-trained neural network, and the target ammonia sensor data prediction model includes: a first gated recurrent unit network, and a feature enhancement network connected in series with the first gated recurrent unit network;

[0013] Among them, the feature enhancement network includes: a dropout layer, two linear layers and a fully connected layer connected in sequence.

[0014] In an optional implementation, the optimizing process for each section of historical measurement data includes:

[0015] When there is a target measurement value greater than the abnormal threshold in multiple sections of historical measurement data, the mean is used to replace the target measurement value to obtain optimized multiple sections of historical measurement data; the mean is the average of the non-zero measurement values ​​of the target measurement value at the previous moment and the next moment;

[0016] The abnormal threshold is determined based on the trained second gated recurrent unit network.

[0017] In an optional implementation, time alignment, outlier removal and normalization operations are performed on the historical measurement data;

[0018] The time alignment includes:

[0019] Get the sampling time interval of the target ammonia sensor;

[0020] Determine the complete sampling time corresponding to the historical measurement data according to the sampling time interval;

[0021] According to the complete sampling time, determine whether there is a missing target measurement value in the historical measurement data; if so, use a cubic spline interpolation method to complete it;

[0022] The outlier elimination includes: when there is a target measurement value in the historical measurement data that suddenly changes to 0 or full scale, the target measurement value is eliminated and replaced by the mean; the mean is the average of the non-zero measurement values ​​of the target measurement value at the previous moment and the next moment.

[0023] In an optional implementation, determining the warning result of the target ammonia sensor according to a plurality of first prediction value sets corresponding to a plurality of segments of historical measurement data includes:

[0024] The first prediction value set corresponding to each section of historical measurement data is spliced ​​to obtain a set of prediction values ​​at continuous moments; the continuous moments are from the start moment to the current moment;

[0025] When there is a first prediction value subset in the prediction value collection, the first prediction value subset is calibrated with historical data according to the first reference value; the first prediction value subset is the prediction value corresponding to the current moment and the moment before the current moment; the first reference value is the true value corresponding to the current moment and the moment before the current moment;

[0026] When there is a second prediction value subset in the prediction value collection, the second prediction value subset is calibrated for future data according to a second reference value; the first prediction value subset is the prediction value corresponding to the moment after the current moment; the second reference value is the true value corresponding to the moment after the current moment;

[0027] When the set of predicted values ​​calibrated with historical data and future data meets the first condition, an alarm is issued;

[0028] The first condition is that all first prediction values ​​corresponding to the set time period are greater than the safety threshold of ammonia concentration.

[0029] In an optional implementation, the abnormal threshold is determined as follows:

[0030] Acquire a sample data set of the ammonia sensor; the sample data set includes: a measurement value at a current moment and a measurement value at a moment before the current moment;

[0031] Preprocess the sample data set;

[0032] The preprocessed sample data set is segmented according to the time window to obtain multiple sample data subsets;

[0033] Divide multiple sample data subsets into training sets and test sets;

[0034] Inputting the training set into the trained second gated recurrent unit network to obtain a plurality of second prediction value sets; each second prediction value in the second prediction value set is a prediction value at the next moment corresponding to a target measurement value of a target sample data subset in the training set;

[0035] Inputting the test set into the trained second gated recurrent unit network to obtain a plurality of third prediction value sets; each third prediction value in the third prediction value set is a prediction value at the next moment corresponding to a target measurement value of a target sample data subset in the test set;

[0036] Denormalizing and concatenating the plurality of second prediction value sets and the plurality of third prediction value sets to obtain a sample prediction value set; the sample prediction value set is a prediction value at the next moment corresponding to each measurement value in the sample data set;

[0037] Determine a difference absolute value set according to the sample data set and the sample prediction value set; each difference absolute value in the difference absolute value set is an absolute value of the difference between a target prediction value in the sample prediction value and a measured value at a corresponding moment;

[0038] Determine the mean of the absolute value set of the difference values ​​according to the absolute value set of the difference values ​​and the total number of measured values ​​in the sample data set;

[0039] The abnormal threshold corresponding to the sample data set is determined based on the mean, the total number of measured values ​​in the sample data set, and the absolute value set of the difference.

[0040] In an optional implementation, the target ammonia sensor data prediction model uses a combination of root mean square error and shape and time distortion loss value to perform model evaluation.

[0041] In a second aspect, the present invention provides a data optimization and prediction device for an ammonia sensor, comprising:

[0042] A data acquisition module, used to acquire historical measurement data of a target ammonia sensor; the historical measurement data includes: measurement values ​​at the current moment and at moments before the current moment;

[0043] A data preprocessing module, used for preprocessing the historical measurement data;

[0044] The data segmentation module is used to segment the preprocessed historical measurement data according to the time window to obtain multiple segments of historical measurement data; wherein each segment of historical measurement data includes multiple measurement values; and the moments corresponding to the multiple measurement values ​​are continuous;

[0045] Data optimization module, used to optimize each section of historical measurement data;

[0046] A data prediction module, used for inputting the optimized target segment historical measurement data into the target ammonia sensor data prediction model to obtain a first prediction value set; each first prediction value in the first prediction value set is a prediction value at a time after a time step corresponding to a time of each measurement value in the optimized target segment historical measurement data;

[0047] A data warning module, used to determine a warning result of a target ammonia sensor according to a plurality of first prediction value sets corresponding to a plurality of segments of historical measurement data;

[0048] The target ammonia sensor data prediction model is a pre-trained neural network, and the target ammonia sensor data prediction model includes: a gated recurrent unit network, and a feature enhancement network connected in series with the gated recurrent unit network;

[0049] Among them, the feature enhancement network includes: a dropout layer, two linear layers and a fully connected layer connected in sequence.

[0050] In a second aspect, the present invention provides an electronic device, comprising:

[0051] a memory storing computer-readable instructions;

[0052] The processor reads the computer-readable instructions stored in the memory to execute the method of the first aspect or any corresponding embodiment thereof.

[0053] In a third aspect, the present invention provides a computer-readable storage medium having computer-readable instructions stored thereon. When the computer-readable instructions are executed by a processor of a computer, the computer executes the method of the first aspect or any corresponding embodiment thereof.

[0054] The embodiment of the present invention preprocesses and optimizes the historical measurement results of the target ammonia sensor to eliminate noise in the data, and uses a target ammonia sensor prediction model constructed based on a GRU network and a feature enhancement network to perform real-time prediction of the future data of the target ammonia sensor. The GRU network can learn historical data patterns, effectively capture long-term dependencies in time series, and obtain trends and patterns of ammonia sensor data changing over time. Then, the feature enhancement network is used to enhance the time features between sequence points and output the predicted value after the time step. Finally, real-time warning is issued according to the prediction results, thereby improving the measurement precision and accuracy of the ammonia sensor, and thereby improving the safety of livestock and poultry production environment monitoring. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0056] Figure 1 is a flow chart of a data optimization and early warning method for an ammonia sensor according to an embodiment of the present invention;

[0057] Figure 2 is a schematic diagram of the structure of a gated recurrent unit network according to an embodiment of the present invention;

[0058] Figure 3 is a structural diagram of a data optimization and early warning device for an ammonia sensor according to an embodiment of the present invention;

[0059] Figure 4It is a schematic diagram of the hardware structure of the electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0060] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution 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 part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0061] High concentrations of ammonia can damage the health of animals and feeders in livestock and poultry production scenarios. Therefore, it is necessary to install ammonia sensors in livestock and poultry production scenarios.

[0062] In the related technologies, low-cost ammonia sensors can be deployed over a large area and at a high density due to their low cost, forming a grid monitoring network. They can also be deployed densely in key areas. Therefore, low-cost ammonia sensors have become the first choice for ammonia detection in livestock and poultry production scenarios. However, as the deployment and use time goes by, low-cost ammonia sensors will inevitably have quality problems such as sensor failure or data drift and anomalies caused by material problems of sensitive components or other factors, resulting in reduced accuracy of ammonia monitoring in livestock and poultry production scenarios, and thus unable to guarantee the health of animals and feeding personnel, that is, the safety level will also decrease. How to improve the accuracy and safety of ammonia monitoring has become a problem that needs to be solved.

[0063] Based on this, an embodiment of the present invention provides a data optimization and early warning method for an ammonia sensor, which is applied to livestock and poultry production scenarios. Figure 1 FIG. 1 is a flow chart of a method for data optimization and early warning of an ammonia sensor according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0064] Step S101, obtaining historical measurement data of a target ammonia sensor; the historical measurement data includes: a measurement value at a current moment, and a measurement value at a moment before the current moment.

[0065] The historical measurement data represents the measurement values ​​of all sampling points of the target ammonia sensor from the start time to the current time.

[0066] The target ammonia sensor samples according to the sampling time interval, such as: 1s, 2s, 1min, 3min, etc.; the sampling time interval is determined according to the sampling rate, for example: the sampling rate is 0.5Hz, which means that one measurement value is collected every 2 seconds, that is, the sampling time interval is 1 / 0.5Hz, that is, 2s.

[0067] It should be noted that the sampling rate needs to be set according to the specific design structure, working principle and application scenario of the ammonia sensor, and is not specifically limited here. In addition, the target ammonia sensor can adopt a low-cost ammonia sensor.

[0068] As an example, the historical measurement data X can be expressed as {x 1 、x 2 ,……,x i}, where x 1 represents the measured value at the start time, x i represents the measurement value at the current moment, that is, the measurement value at the i-th moment, and i represents the index number of the measurement value in the historical measurement data X.

[0069] Step S102: pre-process the historical measurement data.

[0070] In some optional implementations, preprocessing the historical measurement data includes:

[0071] Perform time alignment, outlier removal and normalization operations on historical measurement data;

[0072] Among them, time alignment includes:

[0073] Get the sampling time interval of the target ammonia sensor;

[0074] According to the sampling time interval, determine the complete sampling time corresponding to the historical measurement data;

[0075] According to the complete sampling time, it is determined whether there are missing target measurement values ​​in the historical measurement data; if so, the cubic spline interpolation method is used to complete it.

[0076] Outlier elimination includes: when there is a target measurement value in the historical measurement data that suddenly changes to 0 or full scale, the target measurement value is eliminated and replaced by the mean value; the mean value is the average value of the non-zero measurement values ​​of the target measurement value at the previous moment and the next moment. For example: x 2 If missing, use x 1 、x 3 The average value of x 2 .

[0077] Among them, due to the aging of the ammonia sensor, environmental interference and other reasons, there are some missing measurement values ​​in the ammonia sensor. The embodiment of the present invention can use the cubic spline interpolation method to complete the missing measurements through time alignment, thereby ensuring the accuracy and completeness of the data, and thereby improving the reliability of subsequent data analysis and prediction.

[0078] In addition, when the ammonia sensor is monitoring the ammonia concentration, there may be some abnormal measurement values. This is due to erroneous readings caused by ammonia sensor failure, environmental interference or other external factors. The embodiment of the present invention eliminates the measurement values ​​whose readings of the target ammonia sensor suddenly change to 0 or full scale, and uses the average of the non-zero measurement values ​​before and after to complete the value, thereby ensuring the accuracy and integrity of the data and avoiding the impact of erroneous data on subsequent analysis and prediction. For example: 2 If there is an exception, use x 1 、x 3 The average value of x 2 ; where x 1 and x 3 Non-zero.

[0079] Finally, the normalization operation is used to eliminate the dimension, which can increase the convergence speed and generalization function of the algorithm and improve the robustness and accuracy of the target ammonia sensor data prediction model.

[0080] Step S103, segmenting the preprocessed historical measurement data according to the time window to obtain multiple segments of historical measurement data; wherein each segment of historical measurement data includes multiple measurement values; and the moments corresponding to the multiple measurement values ​​are continuous;

[0081] As an example, assuming that the historical measurement data has 20 measurement values, the sampling rate is 0.5 Hz, the sampling interval is 2 seconds, and the time window L is 5, then the historical measurement data X is {x 1 、x 2 ,……,x 20 Then the historical measurement data X is divided into four segments according to the time window. The first segment is X 1 ={x 1 、x 2 ,……,x 5}, the second paragraph is X 2 ={x 6 、x 7 ,……,x 10}、The third paragraph is X 3 ={x 11 、x 12 ,……,x 15}、The fourth paragraph is X 4 ={x 16 、x 17 ,……,x 20}, the index numbers corresponding to each measurement value in each segment of historical measurement data are continuous, that is, the moments are continuous.

[0082] It should be noted that the time window L can be set according to the output results of the target ammonia sensor data prediction model or actual needs, and is not specifically limited here.

[0083] Step S104: Optimize each section of historical measurement data.

[0084] In some optional implementations, optimizing each section of historical measurement data includes:

[0085] When there is a target measurement value greater than the abnormal threshold in multiple sections of historical measurement data, the mean is used to replace the target measurement value to obtain optimized multiple sections of historical measurement data; the mean is the average of the non-zero measurement values ​​of the target measurement value at the previous moment and the next moment;

[0086] The anomaly threshold is determined based on the trained second gated recurrent unit network.

[0087] In some optional implementations, the abnormality threshold is determined as follows:

[0088] Step a, obtaining a sample data set of the ammonia sensor; the sample data set includes: a measurement value at the current moment and a measurement value at a moment before the current moment;

[0089] Step b, preprocessing the sample data set;

[0090] Step c, segmenting the preprocessed sample data set according to the time window to obtain multiple sample data subsets;

[0091] Step d, dividing the multiple sample data subsets into training sets and test sets;

[0092] Step e: input the training set into the trained second gated recurrent unit network to obtain multiple second prediction value sets; each second prediction value in the second prediction value set is a prediction value at the next moment corresponding to the target measurement value of the target sample data subset in the training set;

[0093] Step f, inputting the test set into the trained second gated recurrent unit network to obtain a plurality of third prediction value sets; each third prediction value in the third prediction value set is a prediction value at the next moment corresponding to a target measurement value of a target sample data subset in the test set;

[0094] Step g: Denormalize and concatenate the multiple second prediction value sets and the multiple third prediction value sets to obtain a sample prediction value set; the sample prediction value set is the prediction value at the next moment corresponding to each measurement value in the sample data set;

[0095] Step h, determining a difference absolute value set according to the sample data set and the sample prediction value set; each difference absolute value in the difference absolute value set is an absolute value of the difference between a target prediction value in the sample prediction value and a measured value at a corresponding moment;

[0096] Step i, determining the mean of the difference absolute value set according to the difference absolute value set and the total number of measurement values ​​in the sample data set;

[0097] Step j: Determine the abnormal threshold corresponding to the sample data set according to the mean, the total number of measured values ​​in the sample data set and the absolute value set of the difference.

[0098] Specifically, the calculation formula of the abnormal threshold T is:

[0099]

[0100] Among them, e i is the absolute value of the difference; is the target prediction value in the sample prediction value; X is the measurement value at the corresponding moment of the target prediction value; i represents the index number of the target measurement value; N represents the total number of all measurement values ​​in the sample data subset; where N L is the number of time windows, L is the time window, N=N L *L; E is the mean of the absolute value set of differences.

[0101] The pre-training may mean that: before the first execution of step e or f, the pre-training of the second gated recurrent unit network (Gated Recurrent Unit, GRU for short) is completed.

[0102] In addition, the second gated recurrent unit network may also be pre-trained and fine-tuned. Fine-tuning may mean that the second gated recurrent unit network is fine-tuned before the first execution of step e or f.

[0103] The embodiment of the present invention optimizes the acquired measurement values ​​through the second gated cyclic unit network based on the time correlation between the measurement values ​​of the ammonia sensor, can discover the change pattern between the historical measurement data, and set the outlier threshold, and optimize the abnormal data exceeding the outlier threshold. It can detect and eliminate any data points that do not conform to the expected pattern, thereby realizing anomaly detection and data optimization.

[0104] The following is an example of the process of determining the abnormal threshold:

[0105] Step A, obtaining a sample data set of the ammonia sensor; the sample data set includes: a measurement value at the current moment and a measurement value at a moment before the current moment;

[0106] As an example, suppose the sample data set has 100 measurements, the sampling rate is 0.5 Hz, the sampling interval is 2 seconds, and the time window L is 5. Then the sample data set X is {x 1 、x 2 ,……,x 100}.

[0107] Step B, preprocessing the sample data set to obtain a preprocessed sample data set X;

[0108] Step C: segment the preprocessed sample data set X according to the time window L to obtain multiple sample data subsets; each sample data subset is represented in a one-dimensional vector format.

[0109] For example, the sample data set X is divided into 20 sample data subsets according to the time window, namely: X 1 ={x 1 、x 2 ,……,x 5}、X 2 ={x 6 、x 7 ,……,x 10}、X 3 ={x 11 、x 12 ,……,x 15}, ..., X 20 ={x 95 、x 96 ,……,x 100}. The index numbers corresponding to each measurement value in each sample data subset are continuous, that is, the moments are continuous.

[0110] Step D: Subset multiple sample data sets X 1 , X 2 , X 3 ,……,X 20 Divided into training set and test set. Each sample data subset is represented in the format of a one-dimensional vector.

[0111] Continuing with the example, multiple sample data subsets X 1 , X 2 , X 3 ,……,X 10 The training set and the test set are divided into a ratio of 1:1. Of course, the division ratio can be adjusted according to actual needs, and can also be 8:2, 7:3, 6:4, etc., which is not specifically limited here.

[0112] At this time, the training set includes X 1 , X 2 , X 3 ,……,X 10 , the test set includes X 11 , X 12 , X 13 ,……,X 20 . Then a 10% validation set is divided from the test set to evaluate the performance of the model during training without participating in training.

[0113] Remove 10% of the validation set from the training set X 1 , X 2 , X 3 ,……,X 9 Input to the second gated recurrent unit network for training.

[0114] The parameters of the second gated recurrent unit network are set and trained. The training round epoch is set to 100, and the number of samples used each time the network weight is updated is set to 1. 10 When the loss function value when input to the second gated recurrent unit network reaches the expected level, the training is stopped. At the same time, the early termination training strategy early_stopping is set. If the performance does not improve before the set number of epochs are completed, that is, the loss function value no longer changes, the training is stopped early to avoid overfitting.

[0115] The optimization function is preferably Adam, the final model saving format is preferably pt format, and the loss function is preferably root mean square error.

[0116] Step E: input the training set into the trained second gated recurrent unit network to obtain multiple second prediction value sets; each second prediction value in the second prediction value set is a prediction value at the next moment corresponding to the target measurement value of the target sample data subset in the training set;

[0117] Continuing with the example, let X 1 , X 2 , X 3 ,……,X 10 Input to the trained second gated recurrent unit network, each time inputting a sample data subset X i , then output the sample data subset X i The corresponding second predicted value set. Where i represents the index number of the measured value in the sample data set.

[0118] Then, the second predicted value corresponding to each measured value in each sample data subset constitutes a second predicted value set. And each second predicted value output is the predicted value corresponding to the next moment of each corresponding measured value. 1 Input into the trained second gated recurrent unit network to obtain the first sample data subset X 1 ={x 1 、x 2 ,……,x 5 The second prediction value set Y corresponding to 1 ={y 2 ,y 3 ,……,y 6}, that is, input the measured value at the i-th moment and output the predicted value at the i+1th moment; similarly, 2 , X 3 , X 4 ,……,X 10 Input into the trained second gated recurrent unit network to get Y 2 , Y 3 , Y 4 ,……,Y 10 .

[0119] Step F, inputting the test set into the trained second gated recurrent unit network to obtain a plurality of third prediction value sets; each third prediction value in the third prediction value set is a prediction value at the next moment corresponding to the target measurement value of the target sample data subset in the test set;

[0120] Continuing with the example, let X 11 , X 12 , X 13 ,……,X 20 Input to the trained second gated recurrent unit network, and similarly, X 11 Input into the trained second gated recurrent unit network to obtain the 11th sample data subset X 11 ={x 51 、x 52 ,……,x 55 The third prediction value set Y corresponding to 11 ={y 52 ,y 53 ,……,y 56}, that is, input the measured value at the i-th moment and output the predicted value at the i+1th moment; similarly, 12 , X 13 , X 14 ,……,X 20 Input into the trained second gated recurrent unit network to get Y 12 , Y 13 , Y 14 ,……,Y 20 .

[0121] Step G: Denormalize and concatenate the multiple second prediction value sets and the multiple third prediction value sets to obtain a sample prediction value set; the sample prediction value set is the prediction value at the next moment corresponding to each measurement value in the sample data set;

[0122] Continuing with the example, let Y 1 , Y 2 , Y 3 , Y 4 ,……,Y 10 and Y 11 , Y 12, Y 13 ,……,Y 20 Denormalize and concatenate to obtain the sample prediction value set Y.

[0123] Step H: determining a difference absolute value set according to the sample data set and the sample prediction value set; each difference absolute value in the difference absolute value set is an absolute value of the difference between the target prediction value in the sample prediction value and the measured value at the corresponding moment;

[0124] Continuing with the example, at this time, the sample prediction value set Y = {y 2 ,y 3 ,y 3 ..., y 101}、Sample data set X={x 1 、x 2 ,……,x 100}; The difference absolute value set includes multiple difference absolute values ​​e, each of which is the absolute value of the difference between the target prediction value in the sample prediction value and the measured value at the corresponding time. Finally, x is obtained. 2 With y 2 、x 3 With y 3 ,……,x 100 With y 100 The absolute value set of the difference between them is e={e 2 、e 3 ,……,e 100}.

[0125] The specific calculation formula is:

[0126]

[0127] Where i represents the index number of the target measurement value.

[0128] Step I: According to the absolute value set of difference e={e 2 、e 3 ,……,e 100} and the total number of measurements N in the sample data set, determine the mean E of the set of absolute values ​​of the differences.

[0129] The specific calculation formula is:

[0130]

[0131] Step J: Based on the mean E, the total number of measured values ​​N in the sample data set and the absolute value set of the difference e={e 2 、e 3 ,……,e 100}, determine the anomaly threshold T corresponding to the sample data set.

[0132] The specific calculation formula is:

[0133]

[0134] Step S105: input the optimized target segment historical measurement data into the target ammonia sensor data prediction model to obtain a first prediction value set; each first prediction value in the first prediction value set is a prediction value at a time after a time step has passed at a time corresponding to each measurement value in the optimized target segment historical measurement data;

[0135] The target ammonia sensor data prediction model is a pre-trained neural network, and the target ammonia sensor data prediction model includes: a first gated recurrent unit network (Gated Recurrent Unit, referred to as GRU), a feature enhancement network connected in series with the first gated recurrent unit network;

[0136] Among them, the feature enhancement network includes: a dropout layer, two linear layers and a fully connected layer connected in sequence.

[0137] The pre-training may mean that the pre-training of the target ammonia sensor data prediction model is completed before the first execution of step S105.

[0138] In addition, the target ammonia sensor data prediction model may also be pre-trained and fine-tuned. Fine-tuning may mean that fine-tuning of the target ammonia sensor data prediction model is completed before the first execution of step S105.

[0139] In some optional embodiments, the target ammonia sensor data prediction model uses a combination of root mean square error and shape and time distortion loss value to perform model evaluation.

[0140] Specifically, when pre-training the target ammonia sensor data prediction model, the input data is each segment of historical measurement data that has been optimized, and each segment of historical measurement data is divided into a test set and a training set in a ratio of 7:3. The model is implemented based on the pytorch platform, and the hyperparameters can be set as follows: batch-size is 1, epochs is 200, the optimization function is set to Adam, and the model is finally saved in pt format.

[0141] It should be noted that the hyperparameters can be adjusted in real time according to the specific evaluation results of the model and are not specifically limited here.

[0142] The prediction model is then evaluated based on the root mean square error and the shape and time distortion loss combined in the form of an indicator, as follows:

[0143] loss second =αlossMSE +βloss shape

[0144] Among them, α and β are set to 0.095 and 0.9 respectively, and loss MSE is the root mean square error, loss shape It is the shape and time distortion loss.

[0145] When loss second When the value reaches the expected level, the training ends and the trained target ammonia sensor data prediction model is obtained.

[0146] It should be noted that the input of the target ammonia sensor data prediction model is the historical measurement data of the target segment after optimization processing, wherein the historical measurement data of the target segment after optimization processing can be represented as a one-dimensional vector.

[0147] Specifically, the target ammonia sensor data prediction model includes a gated recurrent unit network and a feature enhancement network, and the two networks are connected in series.

[0148] Among them, the gated recurrent unit network structure is as follows Figure 2 As shown, x i represents the target measurement value, i.e., the input data of the target ammonia sensor data prediction model, i represents the index number of the target measurement value, h i-1 Represents the previous moment of the moment corresponding to the target measurement value, that is, the i-1th hidden state output. The GRU network structure contains an update gate and a reset gate, and the update gate is used to implement the forgetting and selective memory of the neural network. Specifically, the update gate determines how much historical information and current information are used to update the current hidden state. The update gate at the i-th moment is:

[0149] z i =σ(W z *[h i-1 ,x i ]

[0150] Among them, z i is the gated update signal, whose size determines the memory degree of the candidate hidden state, h i-1 is the historical implicit state, x i represents the input data at the i-th moment, W z is the weight matrix, and σ is the sigmoid function.

[0151] The reset gate determines how much historical information is retained. The reset gate at time t is:

[0152] r i =σ(W r *[h i-1 ,x i ]

[0153] Among them, r i The larger its value is, the more historical information needs to be remembered. r is the weight matrix.

[0154] Under the action of the update gate and the reset gate, the candidate hidden state and hidden output state at the i-th moment are:

[0155]

[0156]

[0157] The candidate hidden state is responsible for fusing the information features of the input data and historical data. This operation is related to the reset signal obtained by the reset gate, and h i represents the i-th moment x i The final unit state includes two processes, forgetting and remembering, (1-z i )*h i-1 represents the forgetting process, z i The closer it is to 1, the more information from the previous moment will be forgotten. represents the memory process, z i The size determines how well the candidate hidden state is remembered.

[0158] Among them, the feature enhancement network is dropout layer-linear layer-linear layer-fully connected layer;

[0159] For the dropout layer, its function is to prevent overfitting.

[0160] For the feed-forward connection layer, that is, two linear layers connected in sequence, the activation function of the first layer is ReLU, and the second layer does not use an activation function.

[0161] The formula is as follows:

[0162] X F =max(0,H L W 1 +b 1 )W 2 +b 2

[0163] Among them, H L All the measured values ​​x in the historical measurement data of the target segment i After the gated recurrent unit, the output h i ; L is the set time window, that is, the number of all measurement values ​​in each historical measurement data; W 1 is the weight of the first linear layer, W 2 is the weight of the second linear layer, b 1 and b2 are the biases of the first and second linear layers, respectively, and the output matrix X obtained by the feedforward connection layer F The dimension and H L The dimensions are consistent.

[0164] Output matrix X F After the last fully connected layer, the output is The output of this layer is the first prediction value set of the target ammonia sensor prediction model.

[0165]

[0166] Among them, W 3 is the weight of the fully connected layer, b 3 is the bias of the fully connected layer.

[0167] As an example, suppose the optimized historical measurement data are X 1 '={x 1 ', x 2 ', ..., x 5 '}, the second paragraph is X 2 '={x 6 ', x 7 ', ..., x 10 '}, the third paragraph is X 3 '={x 11 ', x 12 ', ..., x 15 '}, the fourth paragraph is X 4 ={x 16 ', x 17 ', ..., x 20 '}. Taking the first section of historical measurement data after optimization as an example, X 1 '={x 1 ', x 2 ', ..., x 5 '} Input into the pre-trained target ammonia sensor data prediction model to obtain the first historical measurement data X 1 'The first predicted value set Y 1 '={y 1+m ',y 2+m ', ..., y 5+m '}, which means that if the measured value at the i-th moment after the optimization is input, the predicted value at the i+m-th moment will be output, where m is the time step. Similarly, if X 2 ', X 3 ', X 4 'Input into the target ammonia sensor data prediction model to obtain Y 2 ', Y 3 ', Y 4'.

[0168] Step S106, determining the warning result of the target ammonia sensor according to the multiple first prediction value sets corresponding to the multiple sections of historical measurement data.

[0169] In some optional implementations, determining the warning result of the target ammonia sensor according to multiple first prediction value sets corresponding to multiple segments of historical measurement data includes:

[0170] The first prediction value set corresponding to each section of historical measurement data is spliced ​​to obtain a set of prediction values ​​at continuous moments; the continuous moments are from the start moment to the current moment;

[0171] When there is a first prediction value subset in the prediction value collection, the first prediction value subset is calibrated with historical data according to the first reference value; the first prediction value subset is the prediction value corresponding to the current moment and the moment before the current moment; the first reference value is the true value corresponding to the current moment and the moment before the current moment;

[0172] When there is a second prediction value subset in the prediction value collection, the second prediction value subset is calibrated for future data according to a second reference value; the first prediction value subset is the prediction value corresponding to the moment after the current moment; the second reference value is the true value corresponding to the moment after the current moment;

[0173] When the set of predicted values ​​calibrated with historical data and future data meets the first condition, an alarm is issued;

[0174] The first condition is that all first prediction values ​​corresponding to the set time period are greater than the safety threshold of ammonia concentration.

[0175] Continuing with the example, let Y 1 ', Y 2 ', Y 3 ', Y 4 'Splice and get the complete set of predicted values ​​Y' = {y 1+m ',y 2+m ', ..., y i ',y i+1 ', ..., y i+m '}, m is the time step, i is the measurement index, y i ' is the first predicted value at the current moment. 1+m ',y 2+m ', ..., y i '} is the first prediction value subset, that is, historical data, {y i+1 ',y i+2 '…、y i+m'} is the second prediction value subset, that is, future data; each first prediction value in the first prediction value subset and the second prediction value subset is compared with the reference value at the corresponding moment to calibrate the historical data and the future data to obtain the calibrated historical data and the future data.

[0176] It should be noted that the reference value may be a measurement value of a high-precision sensor under the same measurement environment.

[0177] Then, when the set of predicted values ​​calibrated with historical data and future data meets the first condition, an alarm is issued;

[0178] Among them, the first condition is that the first predicted values ​​corresponding to the set time period are all greater than the safety threshold of the ammonia concentration.

[0179] It should be noted that the safety thresholds of the setting time and ammonia concentration can be set according to actual conditions.

[0180] The embodiment of the present invention can use the measurement value of the high-precision sensor as a reference value to calibrate the historical data of the low-cost ammonia sensor acquired in real time, thereby improving the measurement accuracy of the low-cost ammonia sensor. At the same time, it can also predict future data to improve the safety monitoring factor of livestock and poultry production scenarios. If the predicted value exceeds the safety threshold and continues to rise, an early warning will be issued after a certain period of time.

[0181] In summary, the embodiment of the present invention optimizes the data of the ammonia sensor through the gated cyclic unit network, and can detect and eliminate any data points that do not conform to the expected pattern, thereby achieving anomaly detection and data optimization.

[0182] In addition, since the measurement results of the sensor are dependent on the time changes before and after the measurement values, the embodiment of the present invention inputs the optimized historical measurement data into a data prediction model constructed by a gated recurrent unit network in series with a feature reinforcement network. This can learn historical data patterns, effectively capture long-term dependencies in time series, obtain trends and patterns of changes in the measurement data of the ammonia sensor over time, and mine the time correlation of non-stationary time series, thereby improving the accuracy of ammonia concentration prediction. In addition, the historical data and predicted future data are calibrated with the measurement values ​​of the high-precision sensor as true values, and safety warnings are issued for the calibrated historical data and future data. This is simple and easy to operate, thereby improving the detection accuracy of the ammonia sensor and the environmental monitoring safety capability.

[0183] In this embodiment, a data optimization and early warning device for an ammonia sensor is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and will not be repeated hereafter. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0184] This embodiment provides a data optimization and early warning device for an ammonia sensor, such as Figure 3 As shown, including:

[0185] The data acquisition module 301 is used to acquire the historical measurement data of the target ammonia sensor; the historical measurement data includes: the measurement values ​​at the current moment and the moments before the current moment;

[0186] A data preprocessing module 302 is used to preprocess historical measurement data;

[0187] The data segmentation module 303 is used to segment the preprocessed historical measurement data according to the time window to obtain multiple segments of historical measurement data; wherein each segment of historical measurement data includes multiple measurement values; and the moments corresponding to the multiple measurement values ​​are continuous;

[0188] The data optimization module 304 is used to optimize each section of historical measurement data;

[0189] The data prediction module 305 is used to input the optimized target segment historical measurement data into the target ammonia sensor data prediction model to obtain a first prediction value set; each first prediction value in the first prediction value set is a prediction value at a time after a time step corresponding to a time of each measurement value in the optimized target segment historical measurement data;

[0190] A data warning module 306, configured to determine a warning result of a target ammonia sensor according to a plurality of first prediction value sets corresponding to a plurality of segments of historical measurement data;

[0191] The target ammonia sensor data prediction model is a pre-trained neural network, and the target ammonia sensor data prediction model includes: a gated recurrent unit network, and a feature enhancement network connected in series with the gated recurrent unit network;

[0192] Among them, the feature enhancement network includes: a dropout layer, two linear layers and a fully connected layer connected in sequence.

[0193] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0194] refer to Figure 4, which shows a schematic diagram of the structure of a computer device provided by an embodiment of the present invention, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the computer device, including instructions stored in or on the memory to display graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system).

[0195] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0196] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.

[0197] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0198] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0199] The computer device further includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means.

[0200] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.

[0201] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0202] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A data optimization and early warning method for an ammonia sensor, characterized in that: The method comprises: Acquire historical measurement data of the target ammonia sensor; the historical measurement data includes: a measurement value at a current moment and a measurement value at a moment before the current moment; Preprocessing the historical measurement data; The preprocessed historical measurement data is segmented according to the time window to obtain multiple segments of historical measurement data; wherein each segment of historical measurement data includes multiple measurement values; and the moments corresponding to the multiple measurement values ​​are continuous; Optimize the processing of each historical measurement data; Inputting the optimized target segment historical measurement data into the target ammonia sensor data prediction model to obtain a first prediction value set; each first prediction value in the first prediction value set is a prediction value at a time after a time step corresponding to a time of each measurement value in the optimized target segment historical measurement data; Determine a warning result of a target ammonia sensor according to a plurality of first prediction value sets corresponding to a plurality of segments of historical measurement data; The target ammonia sensor data prediction model is a pre-trained neural network, and the target ammonia sensor data prediction model includes: a first gated recurrent unit network, and a feature enhancement network connected in series with the first gated recurrent unit network; Among them, the feature enhancement network includes: a dropout layer, two linear layers and a fully connected layer connected in sequence.

2. The method according to claim 1, characterized in that The optimizing process for each section of historical measurement data includes: When there is a target measurement value greater than the abnormal threshold in multiple sections of historical measurement data, the mean is used to replace the target measurement value to obtain optimized multiple sections of historical measurement data; the mean is the average of the non-zero measurement values ​​of the target measurement value at the previous moment and the next moment; The abnormal threshold is determined based on the trained second gated recurrent unit network.

3. The method according to claim 2, characterized in that The preprocessing of the historical measurement data comprises: Performing time alignment, outlier removal and normalization operations on the historical measurement data; The time alignment includes: Get the sampling time interval of the target ammonia sensor; Determine the complete sampling time corresponding to the historical measurement data according to the sampling time interval; According to the complete sampling time, determine whether there is a missing target measurement value in the historical measurement data; if so, use a cubic spline interpolation method to complete it; The outlier elimination includes: when there is a target measurement value in the historical measurement data that suddenly changes to 0 or full scale, the target measurement value is eliminated and replaced by the mean; the mean is the average of the non-zero measurement values ​​of the target measurement value at the previous moment and the next moment.

4. The method according to claim 2 or 3, characterized in that: The step of determining the warning result of the target ammonia sensor according to the plurality of first prediction value sets corresponding to the plurality of historical measurement data segments includes: The first prediction value set corresponding to each section of historical measurement data is spliced ​​to obtain a set of prediction values ​​at continuous moments; the continuous moments are from the start moment to the current moment; When there is a first prediction value subset in the prediction value collection, the first prediction value subset is calibrated with historical data according to the first reference value; the first prediction value subset is the prediction value corresponding to the current moment and the moment before the current moment; the first reference value is the true value corresponding to the current moment and the moment before the current moment; When there is a second prediction value subset in the prediction value collection, the second prediction value subset is calibrated for future data according to a second reference value; the first prediction value subset is the prediction value corresponding to the moment after the current moment; the second reference value is the true value corresponding to the moment after the current moment; When the set of predicted values ​​calibrated with historical data and future data meets the first condition, an alarm is issued; The first condition is that all first prediction values ​​corresponding to the set time period are greater than the safety threshold of ammonia concentration.

5. The method according to claim 2, characterized in that: The process of determining the abnormal threshold is as follows: Acquire a sample data set of the ammonia sensor; the sample data set includes: a measurement value at a current moment and a measurement value at a moment before the current moment; Preprocess the sample data set; The preprocessed sample data set is segmented according to the time window to obtain multiple sample data subsets; Divide multiple sample data subsets into training sets and test sets; Inputting the training set into the trained second gated recurrent unit network to obtain a plurality of second prediction value sets; each second prediction value in the second prediction value set is a prediction value at the next moment corresponding to a target measurement value of a target sample data subset in the training set; Inputting the test set into the trained second gated recurrent unit network to obtain a plurality of third prediction value sets; each third prediction value in the third prediction value set is a prediction value at the next moment corresponding to a target measurement value of a target sample data subset in the test set; Denormalizing and concatenating the plurality of second prediction value sets and the plurality of third prediction value sets to obtain a sample prediction value set; the sample prediction value set is a prediction value at the next moment corresponding to each measurement value in the sample data set; Determine a difference absolute value set according to the sample data set and the sample prediction value set; each difference absolute value in the difference absolute value set is an absolute value of the difference between a target prediction value in the sample prediction value and a measured value at a corresponding moment; Determine the mean of the absolute value set of the difference values ​​according to the absolute value set of the difference values ​​and the total number of measured values ​​in the sample data set; The abnormal threshold corresponding to the sample data set is determined based on the mean, the total number of measured values ​​in the sample data set, and the absolute value set of the difference.

6. The method according to claim 4, characterized in that The target ammonia sensor data prediction model uses a combination of root mean square error and shape and time distortion loss value to perform model evaluation.

7. A data optimization and early warning device for an ammonia sensor, characterized in that: include: A data acquisition module, used to acquire historical measurement data of a target ammonia sensor; The historical measurement data includes: measurement values ​​at the current moment and at moments before the current moment; A data preprocessing module, used for preprocessing the historical measurement data; The data segmentation module is used to segment the preprocessed historical measurement data according to the time window to obtain multiple segments of historical measurement data; wherein each segment of historical measurement data includes multiple measurement values; and the moments corresponding to the multiple measurement values ​​are continuous; Data optimization module, used to optimize each section of historical measurement data; A data prediction module, used for inputting the optimized target segment historical measurement data into the target ammonia sensor data prediction model to obtain a first prediction value set; each first prediction value in the first prediction value set is a prediction value at a time after a time step corresponding to a time of each measurement value in the optimized target segment historical measurement data; A data warning module, used to determine a warning result of a target ammonia sensor according to a plurality of first prediction value sets corresponding to a plurality of segments of historical measurement data; The target ammonia sensor data prediction model is a pre-trained neural network, and the target ammonia sensor data prediction model includes: a gated recurrent unit network, and a feature enhancement network connected in series with the gated recurrent unit network; Among them, the feature enhancement network includes: a dropout layer, two linear layers and a fully connected layer connected in sequence.

8. An electronic device, characterized in that: include: a memory storing computer-readable instructions; A processor reads the computer-readable instructions stored in the memory to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the method according to any one of claims 1 to 6.

Citation Information

Cited By

  • Data optimization and early warning method and system based on recurrent neural network

    CN119903974A

  • Kitchen air detection method and system

    CN120559167A