A method and device for predicting water quality

By using the Bi-directional GRU-CNN model based on the attention mechanism in aquaculture, automatic collection and prediction of water quality dissolved oxygen and water temperature are achieved, solving the problems of low prediction accuracy and efficiency in the existing technology, and improving Efficiency and accuracy in aquaculture.

CN114169638BActive Publication Date: 2024-09-17CHINA AGRI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111587243.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-23
Publication Date
2024-09-17
Estimated Expiration
2041-12-23

AI Technical Summary

Technical Problem

Existing water quality prediction methods are difficult to achieve accurate and efficient multi-step prediction of short-term dissolved oxygen changes, and manual monitoring consumes a lot of manpower and financial resources and has a large time lag.

Method used

The Bi-directional GRU-CNN model based on the attention mechanism is used to collect historical water temperature and dissolved oxygen data through multiple sensors for preprocessing and fusion, and establish a time series model to predict the next 6 steps to achieve automatic water quality dissolved oxygen and water temperature. Collection and prediction.

Benefits of technology

It improves the accuracy and efficiency of water quality prediction, reduces human and material costs, enables early detection and early warning, and makes up for the shortcomings of existing technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114169638B
    Figure CN114169638B
Patent Text Reader

Abstract

The present invention discloses a water quality prediction method, device, electronic device and storage medium belonging to the field of aquaculture technology. The water quality prediction method includes step S1: collecting historical water temperature and dissolved oxygen monitoring data by multiple sensors in the breeding scene and preprocessing; step S2: fusing the data preprocessed in step S1 to obtain a water quality time series; step S3: introducing an attention mechanism and establishing a Bi-directional GRU-CNN model based on the attention mechanism; step S4: recombining the fused water quality time series in step S2 into a prediction training sample, inputting it into the model established in step S3 for training, and obtaining a trained water quality prediction model; step S5: collecting real-time data for water quality prediction. The present invention realizes the automatic collection and prediction of water quality dissolved oxygen and water temperature, improves the accuracy and efficiency of prediction, and saves a lot of manpower and material costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of aquaculture, and in particular to a water quality prediction method and device. Background Art

[0002] Aquaculture is an important part of agricultural production. China's aquaculture output has ranked first in the world for many years, and it is one of the world's major aquatic product producers and exporters. Aquaculture has become an important part of my country's agricultural production and a pillar industry for rural economic development in many places. In order to monitor changes in aquaculture water quality, people often need to regularly grasp the changes in the concentration and temperature of dissolved oxygen in the water. However, existing methods often use physical or chemical methods to measure the concentration of dissolved oxygen in water, and often use timed monitoring and fixed-point measurement for temperature data. These traditional methods have a certain lag, and it is difficult to grasp the changing rules of water quality in the future.

[0003] Most water quality prediction methods based on historical data also use single-factor historical data as training samples for curve fitting. Since there are many direct and indirect factors affecting water quality parameters, and they have characteristics such as high nonlinearity, time lag, and multivariate coupling, single-factor prediction methods often cannot meet the needs of prediction accuracy and are difficult to achieve accurate and efficient multi-step prediction of short-term dissolved oxygen changes. Therefore, a new water quality prediction method and device are urgently needed to solve the above problems.

[0004] The present invention is based on a time series model and provides a water quality prediction method and device based on a Bi-directional GRU-CNN with an attention mechanism, which predicts the time series of the next 6 steps and realizes the automatic collection and prediction of water quality dissolved oxygen and water temperature, so as to overcome or at least partially solve the problems existing in the prior art, and can make early detection and early warning of changes in aquaculture water quality, make up for the shortcomings of manual monitoring methods that consume a lot of manpower and financial resources, have high equipment costs and large time lag, thereby improving the efficiency of aquaculture. Summary of the invention

[0005] The purpose of the invention is to provide a water quality prediction method and device.

[0006] A water quality prediction method, characterized in that it comprises the following steps:

[0007] Step S1: multiple sensors collect historical water temperature and dissolved oxygen monitoring data in the aquaculture scene and perform preprocessing;

[0008] Step S2: Fusing the data preprocessed in step S1 to obtain a water quality time series;

[0009] Step S3: Introduce the attention mechanism and establish a Bi-directional GRU-CNN model based on the attention mechanism;

[0010] Step S4: Recombining the fused water quality time series in step S2 into prediction training samples, inputting them into the Bi-directional GRU-CNN model based on the attention mechanism established in step S3 for training, and obtaining a trained water quality prediction model;

[0011] Step S5: Collect real-time data for water quality prediction.

[0012] The step S1 specifically includes the following sub-steps:

[0013] Step S11: Identify and delete extremely large abnormal values ​​and non-numeric data in the historical water temperature and dissolved oxygen monitoring data indicating monitoring abnormalities;

[0014] Step S12: Fill in the missing values ​​generated by monitoring and the missing values ​​generated after deleting outliers by linear interpolation or cubic spline interpolation;

[0015] Step S13: normalizing the historical water temperature and dissolved oxygen monitoring data processed by steps S11 and S12.

[0016] The normalization processing formula in step S13 is as follows:

[0017]

[0018] Among them, x i is the i-th input data, x min is the minimum value in the input data, x max is the maximum value in the input data, n is the total number of data, f(x i ) are normalized data.

[0019] The specific steps of fusing the pre-processed data in step S2 are as follows:

[0020] Step T1: Divide the data returned by N sensors of the same type at the same time into two groups, each group contains N / 2 data;

[0021] Step T2: The two groups of data divided in step T1 are T 1i and T 2i , calculate T 1i and T 2i The arithmetic mean is:

[0022]

[0023]

[0024] Step T3: Calculate the standard deviations σ1 and σ2 as:

[0025]

[0026]

[0027] Step T4: Use the following formula to complete data fusion:

[0028]

[0029] The establishment process of the Bi-directional GRU-CNN model based on the attention mechanism is as follows:

[0030] Step A1: Input water temperature T + and dissolved oxygen content D + The prediction training samples [T + , D + ], introduce the attention mechanism Attention:

[0031]

[0032] Among them, Q is an n×d k A sequence of , representing the query vector corresponding to each element, Q = [q1, q2, ..., q n ] T , the sequence Q is encoded into an n×d v A new sequence; K and V represent the Key-Value relationship, K = [k1, k2, ..., k m ] T , represents the key vector corresponding to each element, V = [v1, v2, ..., v m ] T , represents the value vector corresponding to each element; n represents the number of queries, m represents the number of sampling points, d k and d v Represents dimension;

[0033] Step A2: Perform an Attention operation within the same sequence to find the connection between different positions within the sequence X, that is, Attention(X,X,X);

[0034] Step A3: Use the GRU structure to train historical observation data, calculate the hidden state at the current moment, and control the amount of information transferred from the previous hidden state to the current hidden state through the update gate; the calculation formula for the hidden state at the current moment is:

[0035]

[0036] The calculation formula of the update gate is as follows:

[0037] z t =σ(W2[h t-1 , T + t ])

[0038] In the formula, is the candidate state, σ is the sigmoid function, W2 represents merging two matrices, T + t is the input at the current moment, h t-1 is the hidden state at the previous moment, h t is the hidden state at the current moment;

[0039] Step A4: Use the extended convolution of CNN to extract common features, add the skip-layer connection of residual convolution, jump-connect the feature map of the lower layer to the upper layer, add 1×1 convolution operation to reduce the dimension, so that the number of feature maps is the same when the two layers are added together, and obtain the Bi-directional GRU-CNN model based on the attention mechanism; among them, the extended convolution is

[0040]

[0041] Among them, d is the expansion coefficient, k is the convolution kernel size, f represents the filter size, s represents the stride step size, i represents the number of filters, and g is the derivative of G.

[0042] A water quality prediction device, characterized in that the device comprises a data processing module, a prediction model construction module and a training module; the data processing module preprocesses and fuses data collected by multiple sensors; the prediction model construction module establishes a Bi-directional GRU-CNN model based on an attention mechanism; the training module trains the Bi-directional GRU-CNN model based on the attention mechanism according to prediction training samples to obtain a trained water quality prediction model.

[0043] The beneficial effects of the present invention are:

[0044] Based on the time series model and the historical water quality parameter sequence, the present invention predicts the time series of the next 6 steps and establishes a Bi-directional GRU-CNN model based on the attention mechanism. By combining the bidirectional GRU based on the attention mechanism with the CNN network model, the automatic collection and prediction of water quality dissolved oxygen and water temperature are realized, the accuracy and efficiency of the prediction are improved, and a lot of manpower and material costs are saved. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 A flow chart of the water quality prediction method based on the attention mechanism Bi-directional GRU-CNN provided by the present invention;

[0046] Figure 2 This is a schematic structural diagram of the water quality prediction device provided by the present invention. DETAILED DESCRIPTION

[0047] The present invention provides a water quality prediction method, device, electronic device and storage medium, which will be further described below in conjunction with the accompanying drawings and specific embodiments.

[0048] Figure 1 A schematic diagram of a water quality prediction method based on a Bi-directional GRU-CNN with an attention mechanism provided in an embodiment of the present invention is shown in FIG. Figure 1 As shown, the embodiment of the present invention provides a water quality prediction method based on a Bi-directional GRU-CNN of an attention mechanism, including:

[0049] Step S1: multiple sensors collect historical water temperature and dissolved oxygen monitoring data in the aquaculture scene and perform preprocessing;

[0050] Step S2: Fusing the data preprocessed in step S1 to obtain a water quality time series;

[0051] Step S3: Introduce the attention mechanism and establish a Bi-directional GRU-CNN model based on the attention mechanism;

[0052] Step S4: Recombining the fused water quality time series in step S2 into prediction training samples, inputting them into the Bi-directional GRU-CNN model based on the attention mechanism established in step S3 for training, and obtaining a trained water quality prediction model;

[0053] Step S5: Collect real-time data for water quality prediction.

[0054] In an embodiment of the present invention, a plurality of water temperature sensors and dissolved oxygen concentration sensors are arranged respectively to collect the historical time series of water quality parameters, wherein the sensor collection time interval is 30 minutes. For a certain environmental factor in the breeding environment, multiple sensors collect data for it at the same time. For the same indicator, the data collected by multiple sensors have certain differences, and there may even be a situation where sensor failures make it impossible to collect valid data. In order to more objectively and accurately reflect the conditions of the aquatic product growth environment, it is necessary to fuse these data collected by multiple sensors at a certain moment. Multi-sensor data fusion can make full use of the data collected by the sensors and effectively reduce the impact of data redundancy or errors on the results.

[0055] In this embodiment, the collected historical water temperature monitoring data and historical dissolved oxygen monitoring data are preprocessed respectively, and the preprocessing includes but is not limited to deleting abnormal values, making up for missing values, and normalizing the data.

[0056] Identify and delete extremely large outliers and non-numeric data that represent monitoring anomalies in historical observation data. Among them, extremely large outliers include outliers that serve as abnormal signs and monitoring anomalies that are obviously not in the same order of magnitude as other data of the same type.

[0057] Missing values ​​generated by monitoring and after outliers are removed are filled in using linear interpolation or cubic spline interpolation.

[0058] The historical observation data after the above processing is normalized. The normalization formula is:

[0059]

[0060] Among them, x i is the i-th input data, x min is the minimum value in the input data, x max is the maximum value in the input data, n is the total number of data, f(x i ) are normalized data.

[0061] For a certain environmental factor in the breeding scene, multiple sensors collect data at the same time, and the data collected by multiple sensors at a certain moment are fused.

[0062] Taking the temperature sensor as an example to illustrate data fusion, the data transmitted by N air temperature sensors at the same time are evenly divided into two groups, each group contains N / 2 data. Suppose the two groups of data are T 1i and T 2i , then the arithmetic mean of each group of data is:

[0063]

[0064]

[0065] The standard deviations σ1 and σ2 are:

[0066]

[0067]

[0068] Finally, the data fusion is completed using the following formula:

[0069]

[0070] Similarly, the dissolved oxygen in water D is also obtained by the above method. + .

[0071] The fused water quality time series data are recombined into prediction training samples, that is, each water quality parameter is combined in series to obtain [T + , D + ], that is, predicting training samples. After establishing the water quality prediction model of Bi-directionalGRU-CNN based on attention mechanism, the predicted training samples are input into the prediction model of Bi-directionalGRU-CNN based on attention mechanism for training to obtain the water quality prediction model.

[0072] In the establishment of the Bi-directional GRU-CNN model based on the attention mechanism, the attention mechanism is introduced, the Transformer encoder is used to extract information, the history of the time series is used as input, the high-performance multi-level prediction is combined with interpretable insights, the temporal relationship at different scales is learned, and the interpretable self-attention layer is used to learn long-term dependencies to solve the gradient explosion problem of the bidirectional GRU and the redundancy of water quality prediction. And masked self-attention is used so that the network will not obtain future values ​​during training, which will not cause information leakage. At the same time, CNN is used as a decoder and dilated convolution is used. In this way, the decoder can learn to pay attention to the most useful part of the historical value of the time series before making a prediction. Each hidden layer is the same size as the input sequence, and the computational complexity is reduced, and the receptive field is large enough. This structure is more applicable to time series problems and can solve the shortcomings of existing water quality prediction methods in water quality prediction at different scales, such as low interpretability and poor generalization ability.

[0073] First, the fused historical time series, i.e., water temperature T + and dissolved oxygen content D + The prediction training samples [T + , D+ ], introduce the attention mechanism Attention, defined as:

[0074]

[0075] Among them, Q is an n×d k The sequence of Q = [q1,q2,…,q n ] T ,K=[k1,k2,…,k m ] T ,V=[v1,v2,…,v m ] T , the sequence Q is encoded into an n×d v new sequence.

[0076] The attention mechanism used in this model is self-attention, that is, the Attention operation is performed within the same sequence to find the connection between different positions within the sequence X, that is, Attention(X,X,X).

[0077] Use the GRU structure to train a large amount of historical observation data. Take water temperature as an example, T + t is the input at the current moment, h t-1 is the hidden state at the previous moment, h t is the hidden state calculated at the current moment.

[0078] When calculating the hidden state at the current moment, it first calculates a candidate state And by updating the gate to control how much information from the previous hidden state can be passed to the current hidden state, GRU can remember long-term information. The calculation formula of the update gate is as follows:

[0079] z t =σ(W2[h t-1 , T + t ])

[0080] Calculate the hidden state at the current moment:

[0081]

[0082] The GRU structure can retain important information through various gates to ensure that it will not be lost during long-term transmission.

[0083] In the prediction model, not only the time series memory ability but also the feature expression ability should be considered. The good feature expression ability of the convolutional neural network (CNN) can automatically extract common features at different levels of time series data, and the prediction effect is more stable. Sparse weights, parameter sharing and equivariant representation are the three major characteristics of CNN. These characteristics significantly reduce the complexity of the model and improve the computational efficiency. Therefore, the one-dimensional convolution deformation of the CNN structure is used as a decoder to make it more suitable for time series prediction problems.

[0084] Use dilated convolution:

[0085]

[0086] Where d is the expansion coefficient. The calculation method of dissolved oxygen is similar.

[0087] The higher the extended convolution layer is, the larger the convolution window is, so that each hidden layer can be the same size as the input sequence, the amount of calculation is reduced, and the receptive field is large enough.

[0088] In order to improve the accuracy, a skip-layer connection of residual convolution is added to directly jump-connect the feature map of the lower layer to the upper layer. At this time, the number of each corresponding feature map is inconsistent. To solve this problem, a 1×1 convolution operation is added to reduce the dimension so that the number of feature maps when the two layers are added together matches.

[0089] Finally, the obtained Bi-directional GRU-CNN water quality prediction model based on the attention mechanism is used to predict water quality.

[0090] Figure 2 The schematic diagram of the structure of the water quality prediction device provided by the present invention; the device includes a data processing module, a prediction model construction module and a training module. Among them, the data processing module pre-processes the collected data and fuses the data collected by multiple sensors; the prediction model construction module establishes a Bi-directional GRU-CNN model based on the attention mechanism, combines the bidirectional GRU based on the attention mechanism with the CNN network model to establish a recurrent neural network model based on the spatiotemporal attention mechanism, and combines the fish school behavior characteristics with the recurrent neural network model; the training module is used to train the network model according to the sample data set to obtain a trained water quality prediction model.

[0091] In an embodiment of the present invention, based on the time series model and the historical water quality parameter sequence, the time series of the next 6 steps is predicted, and a Bi-directional GRU-CNN model based on the attention mechanism is established. By combining the bidirectional GRU based on the attention mechanism with the CNN network model, the automatic collection and prediction of water quality dissolved oxygen and water temperature are realized. The Bi-directional GRU-CNN prediction method based on the attention mechanism provided in the embodiment of the present invention is suitable for water quality prediction based on various aquaculture environments.

[0092] The Bi-directional GRU-CNN water quality prediction method based on the attention mechanism provided in the embodiment of the present invention realizes the prediction of water quality by combining the bidirectional GRU based on the attention mechanism with the CNN network model. It can quickly and conveniently predict the changes in water quality, improve the accuracy and efficiency of the prediction, and save a lot of manpower and material costs.

[0093] This embodiment is only a preferred specific implementation of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A water quality prediction method, It is characterized in that The following steps are involved: Step S1: multiple sensors collect historical water temperature and dissolved oxygen monitoring data in the aquaculture scene and perform preprocessing; Step S2: Fusing the data preprocessed in step S1 to obtain a water quality time series; The specific steps of fusing the pre-processed data in step S2 are as follows: Step T1: Divide the data returned by N sensors of the same type at the same time into two groups, each group contains N / 2 data; Step T2: The two groups of data divided in step T1 are T 1i and T 2i , calculate T 1i and T 2i The arithmetic mean is: Step T3: Calculate the standard deviation σ 1 and σ 2 for: Step T4: Use the following formula to complete data fusion: Step S3: Introduce the attention mechanism and establish a Bi-directional GRU-CNN model based on the attention mechanism; The establishment process of the Bi-directional GRU-CNN model based on the attention mechanism is as follows: Step A1: Input water temperature T + and dissolved oxygen content D + The prediction training samples [T + , D + ], introduce the attention mechanism Attention: Among them, Q is an n×d k A sequence of , indicating the query vector corresponding to each element, Q = [q 1 ,q 2 ,…,q n ] T , the sequence Q is encoded into an n×d v A new sequence; K and V represent the relationship between Key-Value, K = [k 1 ,k 2 ,…,k m ] T , represents the key vector corresponding to each element, V = [v 1 ,v 2 ,…,v m ] T , represents the value vector corresponding to each element; n represents the number of queries, m represents the number of sampling points, d k and d v Represents dimension; Step A2: Perform an Attention operation within the same sequence to find the connection between different positions within the sequence X, that is, Attention(X,X,X); Step A3: Use the GRU structure to train historical observation data, calculate the hidden state at the current moment, and control the amount of information transferred from the previous hidden state to the current hidden state through the update gate; the calculation formula for the hidden state at the current moment is: The calculation formula of the update gate is as follows: z t =σ(W 2 [h t-1 ,T + t ]) In the formula, is the candidate state, σ is the sigmoid function, W 2 Indicates merging two matrices, T + t is the input at the current moment, h t-1 is the hidden state at the previous moment, h t is the hidden state at the current moment; Step A4: Use the extended convolution of CNN to extract common features, add the skip-layer connection of residual convolution, jump-connect the feature map of the lower layer to the upper layer, add 1×1 convolution operation to reduce the dimension, so that the number of feature maps is the same when the two layers are added together, and obtain the Bi-directional GRU-CNN model based on the attention mechanism; among them, the extended convolution is Among them, d is the expansion coefficient, k is the convolution kernel size, f is the filter size, s is the stride step size, i is the number of filters, and g is the derivative of G; Step S4: Recombining the fused water quality time series in step S2 into prediction training samples, inputting them into the Bi-directional GRU-CNN model based on the attention mechanism established in step S3 for training, and obtaining a trained water quality prediction model; Step S5: Collect real-time data for water quality prediction.

2. The water quality prediction method according to claim 1, It is characterized in that The step S1 specifically includes the following sub-steps: Step S11: Identify and delete extremely large abnormal values ​​and non-numeric data in the historical water temperature and dissolved oxygen monitoring data indicating monitoring abnormalities; Step S12: Fill in the missing values ​​generated by monitoring and the missing values ​​generated after deleting outliers by linear interpolation or cubic spline interpolation; Step S13: normalizing the historical water temperature and dissolved oxygen monitoring data processed by steps S11 and S12.

3. The water quality prediction method according to claim 2, It is characterized in that The normalization processing formula in step S13 is as follows: Among them, x i is the i-th input data, x min is the minimum value in the input data, x max is the maximum value in the input data, n is the total number of data, f(x i ) are normalized data.