Contrast learning coagulant addition prediction method based on characteristic disturbance enhancement
By constructing a three-branch model through a contrastive learning method enhanced by feature perturbation, and combining unsupervised and supervised learning, the problems of dynamic changes in water quality and scarcity of labeled samples were solved, achieving accurate prediction of coagulant dosage and improving the model's generalization ability and prediction accuracy.
Patent Information
- Application Number
- CN202511554346.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-29
- Publication Date
- 2025-11-28
AI Technical Summary
Existing methods for predicting coagulant dosage are difficult to achieve accurate and stable predictions when faced with dynamic changes in water quality and a scarcity of labeled samples. Traditional methods are highly subjective, have slow response times, or poor adaptability. Deep learning methods have not fully explored the temporal and frequency domain correlation features of water quality data, and comparative learning has not been adapted to the characteristics of water quality data, resulting in weak model generalization ability.
A contrastive learning method based on feature perturbation enhancement is adopted. By constructing a three-branch model, including an unsupervised contrastive learning branch, a supervised contrastive learning branch, and time-frequency domain feature capture, the model utilizes historical sensor data for partial labeling and Fourier transform to generate unlabeled and labeled samples. Combined with channel attention, gating units, and convolutional structures, data augmentation and backpropagation optimization are performed to achieve accurate prediction of coagulant dosage.
It achieves accurate and stable prediction of coagulant dosage under complex water quality environments, reduces dependence on labeled samples, improves the model's generalization ability and prediction accuracy, avoids dosage imbalance problems, ensures the stability of effluent water quality, and reduces operating costs.
Smart Images

Figure CN121034480A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of coagulant prediction, and in particular relates to a coagulant dosing prediction method based on feature disturbance enhancement and contrast learning. BACKGROUND
[0002] In the water treatment process, accurate control of coagulant dosage is crucial to guarantee water quality, improve treatment efficiency and reduce operating costs. The source water quality parameters (such as pH, temperature, water intake flow, turbidity, etc.) are constantly changing, so the coagulant dosage needs to be adjusted in real time, which puts high demands on the accuracy and robustness of the prediction method.
[0003] Traditional coagulant dosage determination methods, such as empirical method and mathematical model method, have significant limitations. The empirical method relies on manual observation of alum flowers and other operations, which is highly subjective and has a lagging response, making it difficult to respond to rapid water quality fluctuations. The mathematical model method is limited by the nonlinearity and time-varying nature of water quality changes, and has poor adaptability to complex scenarios. With the development of deep learning technology, its application in the field of water treatment prediction has become a research hotspot, providing a new path to break through the bottleneck of traditional methods.
[0004] Deep learning methods have shown potential in handling water quality time series data and mining complex feature relationships. To enhance feature utilization and model robustness, contrast learning technology has been gradually introduced. Contrast learning can effectively enhance feature discrimination by constructing positive and negative sample pairs and learning the similarities and differences between samples. However, directly transferring contrast learning to the coagulant dosage prediction scenario faces the challenge of adapting to the characteristics of water quality data: the temporal continuity and feature correlation of water quality data are special, and conventional contrast learning cannot accurately mine the dynamic change rules of water quality parameters. Moreover, there is a lack of consideration of model stability under feature disturbance (such as data noise and outliers). At the same time, there are abundant unlabeled samples and scarce labeled samples in actual production. How to fully utilize unlabeled samples to mine general features and combine labeled samples to achieve accurate prediction has become a technical pain point. Existing methods lack sufficient design of feature learning and prediction fusion mechanisms in semi-supervised scenarios, making it difficult to efficiently apply in water treatment scenarios with high data labeling costs. SUMMARY
[0005] The present application aims to provide a coagulant dosing prediction method based on feature disturbance enhancement and contrast learning to improve the above technical problems.
[0006] To achieve the above application purpose, the embodiments of the present application provide the following technical solutions:
[0007] A coagulant dosing prediction method based on feature disturbance enhancement and contrast learning, comprising:
[0008] Receive historical data from the sensor and perform partial labeling and Fourier transform to generate unlabeled samples, Fourier split samples, and labeled samples;
[0009] Based on channel attention, gating units, and convolutional structures, a feature perturbation enhancement module is constructed. Based on the encoder-decoder Transformer backbone network and the feature perturbation enhancement module, a first unsupervised contrastive learning branch, a second unsupervised contrastive learning branch, and a supervised contrastive learning branch are generated to construct an initial coagulant addition prediction model.
[0010] After data augmentation, the unlabeled samples, Fourier split samples, and labeled samples were input into the initial coagulant dosing prediction model, and the time-frequency unsupervised-prediction contrast function and the labeled sample supervised-prediction contrast function were calculated respectively.
[0011] Based on the time-frequency unsupervised prediction comparison function and the labeled sample supervised prediction comparison function, the parameters of the initial coagulant addition prediction model are adjusted by the network backpropagation algorithm to obtain the coagulant addition prediction model.
[0012] Sensor data is collected in real time and the addition is predicted using a coagulant addition prediction model to obtain the predicted coagulant addition result.
[0013] In existing coagulant dosage prediction processes, empirical methods rely on manual observation of flocs and other operations, resulting in strong subjectivity and delayed response. This can easily lead to over- or under-dosing of coagulants due to judgment errors, causing fluctuations in effluent quality and increased treatment costs. Furthermore, mathematical modeling is limited by the nonlinear and dynamic nature of water quality changes, failing to effectively adapt to scenarios with seasonal changes and sudden pollution events that cause data distribution shifts, leading to a significant decrease in prediction accuracy. Conventional deep learning methods not only rely on a large number of labeled samples (which require manual recording / experimental verification at water plants, resulting in high costs and scarcity, making them difficult to meet training needs), but also fail to fully exploit the time-frequency correlation features of water quality data, ignoring the implicit periodic patterns (such as seasonal fluctuations) and latent fluctuations (such as subtle changes before pollution) of source water parameters. Their feature representation capabilities are insufficient, and even with the introduction of contrastive learning techniques, they struggle to construct effective contrastive sample pairs due to their incompatibility with time-series data characteristics, resulting in weak model generalization ability and poor prediction stability when facing complex water quality changes.
[0014] Therefore, this invention effectively alleviates the problem of scarce labeled samples by partially labeling and Fourier transforming historical sensor data, making full use of the time-frequency domain features of massive unlabeled samples and water quality data. By leveraging a feature perturbation enhancement module that integrates channel attention, gating units, and convolutional structures, and constructing a three-branch model with an encoder-decoder, it can accurately capture the temporal dynamic correlation of water quality parameters, and make the periodic patterns and implicit fluctuations in the frequency domain explicit, thus enhancing feature discrimination. Through data augmentation, contrast function calculation, and backpropagation parameter optimization, this coagulant dosage prediction model can adapt to distribution drift scenarios such as seasonal water quality changes and sudden pollution, achieving accurate and stable prediction of coagulant dosage, avoiding dosage imbalance problems, ensuring stable effluent water quality, and reducing operating costs.
[0015] Furthermore, the feature perturbation enhancement module includes a first convolution module, a depthwise convolution parallel module, a channel attention gating module, and a gated convolution module; the first convolution module includes a LayerNorm layer and two conv layers connected in series; the depthwise convolution parallel module includes a DW-conv layer connected in parallel; the channel attention gating module includes a gated unit, a channel attention layer, and a conv layer connected in series; the gated convolution module includes a LayerNorm layer, a conv layer, a gated unit, and a conv layer connected in series.
[0016] In the above scheme, the present invention generates multiple perturbation versions of the enhanced sample data by adding noise of different intensities and adjusting the time series period through the feature perturbation enhancement module. This unsupervised expansion of the training set alleviates the problem of scarce labeled samples. At the same time, it makes the perturbed features containing elements of real scene more robust and discriminative (after optimization of contrastive learning loss, the features of similar samples are more compact and dissimilar samples are more dispersed). Thus, it can solve the problems of insufficient model training due to the scarcity of labeled samples in water plants, the weak generalization of traditional models due to large differences in data distribution, and the prediction bias caused by insufficient expression of original water quality data features. It also serves as a bridge connecting the "characteristics of water quality time series data" and the "needs of contrastive learning". By actively constructing a differentiated feature space, it meets the requirements of contrastive learning for robust and discriminative features, and finally achieves accurate and stable prediction of coagulant dosage under complex water quality conditions.
[0017] Furthermore, the first unsupervised contrastive learning branch, the second unsupervised contrastive learning branch, and the supervised contrastive learning branch all include an encoder and a decoder composed of a Transformer backbone network; a feature perturbation enhancement module is inserted into each encoder and its corresponding decoder.
[0018] In the above scheme, to adapt to the characteristics of water quality data—"many unlabeled samples, few labeled samples, coexistence of time-frequency features and the need to be associated with prediction targets"—and to compensate for the shortcomings of a single branch in data utilization, feature capture, and prediction accuracy, three branches were designed:
[0019] The first unsupervised contrastive learning branch (time domain) processes unlabeled time domain samples and mines the temporal dynamic correlation of water quality parameters (such as the continuous fluctuation trend of turbidity over time) through unsupervised contrastive learning.
[0020] The second unsupervised contrastive learning branch (frequency domain) processes Fourier split samples to capture frequency domain periodic patterns (such as the water quality fluctuation cycle during the rainy season) and latent fluctuations (such as small frequency changes before pollution).
[0021] From the perspectives of time and frequency domains, this method utilizes massive amounts of unlabeled data to learn general time-frequency features, addressing the problems of insufficient training due to scarce labeled samples and incomplete representation of single time / frequency domain features.
[0022] The supervised contrastive learning branch processes the labeled samples and accurately associates the general time-frequency features learned from the first two branches with the coagulant dosage label. The prediction accuracy is ensured through supervised contrastive learning and prediction loss optimization, avoiding the defect that unsupervised learning cannot directly map the prediction target.
[0023] The three branches work together to achieve complementary time-frequency features and efficient use of semi-supervised data. This allows the model to fully grasp the dynamic trends, periodic patterns and implicit fluctuations of water quality, solving the problem of insufficient feature utilization depth in traditional models. It also improves the model's generalization ability to data distribution drift such as seasonal changes and sudden pollution, and reduces the dependence on labeled samples.
[0024] Furthermore, the computation of the time-frequency unsupervised prediction contrast function and the labeled sample supervised prediction contrast function includes:
[0025] Data augmentation is performed on unlabeled samples, Fourier split samples, and labeled samples to obtain unlabeled augmented samples, Fourier split augmented samples, and labeled augmented samples;
[0026] Unlabeled samples and unlabeled augmented samples are input into the first unsupervised contrastive learning branch to perform unsupervised contrastive learning, generate temporal prediction results and temporal augmentation prediction results, and calculate the temporal context loss function;
[0027] The Fourier split samples and Fourier split enhancement samples are input into the second unsupervised contrastive learning branch for unsupervised contrastive learning, generating frequency domain prediction results and frequency domain enhancement prediction results, and calculating the frequency domain context loss function.
[0028] Labeled samples and augmented labeled samples are input into the supervised contrastive learning branch to perform supervised contrastive learning, generate initial prediction results and augmented prediction results, and calculate the supervised-prediction contrastive function for labeled samples;
[0029] Based on the time-domain prediction results, time-domain enhanced prediction results, frequency-domain prediction results, and frequency-domain enhanced prediction results, the time-frequency consistency loss function is calculated.
[0030] Based on the time-frequency consistency loss function, the time-domain context loss function, and the frequency-domain context loss function, the time-frequency unsupervised prediction comparison function is calculated.
[0031] The frequency domain context loss function The corresponding formula is:
[0032] ;
[0033] ;
[0034] ;
[0035] in, This represents a logarithmic function with the natural constant as its base. This represents an exponential function with base e. This represents the summation function. Indicates amplitude, , They represent the first In the frequency group, the first The amplitude feature vector of the first Fourier split sample, the first Frequency domain prediction results corresponding to the amplitude feature vectors of each Fourier split sample. Represents absolute value. Indicates the first In the frequency group, the first Frequency domain enhancement prediction results corresponding to the amplitude feature vectors of each Fourier shunt enhancement sample. , They represent the first In the frequency group, the first The phase eigenvector of the first Fourier shunt sample, the first The phase eigenvectors of a Fourier split sample. This represents the encoding of the phase. This represents the phase eigenvector after processing by the feature perturbation module. This represents the total number of samples.
[0036] In the above scheme, this invention expands the training set size (especially scarce labeled samples) by augmenting the data of three types of samples, simulating real disturbances such as water quality fluctuations and sensor errors, and providing a differentiated basis for comparative learning. It not only captures the dynamic correlation of water quality over time, but also uncovers frequency domain periodic patterns and latent fluctuations. Furthermore, it accurately correlates the learned time-frequency features with the coagulant dosage, avoiding deviation from the prediction target and achieving precise mapping between features and the target. This solves problems such as scarce labels, incomplete features, and learning disconnect, significantly improving the model's generalization ability and dosage prediction accuracy for complex water quality scenarios.
[0037] Furthermore, the data enhancement includes:
[0038] For both unlabeled and labeled samples, perform time-based augmentation; generate unlabeled augmented samples and labeled augmented samples by scaling and adjusting the range of parameter values, adding small Gaussian jitter, and randomly discarding masks for local time nodes.
[0039] For the Fourier shunt sample, adjust the amplitude and fine-tune the phase of the target frequency band of the Fourier shunt sample, and then perform an inverse Fourier transform to obtain the Fourier shunt enhanced sample.
[0040] In the above scheme, the present invention enhances the temporal basis of unlabeled and labeled samples (scaling, Gaussian jitter, random masking) to simulate real-world disturbances such as natural fluctuations in water quality, sensor errors, and temporary data loss. While expanding the sample size, it retains the core information of temporal correlation, providing differentiated temporal sample pairs for comparative learning. The frequency domain enhancement of Fourier split samples (amplitude adjustment, phase fine-tuning) can simulate changes in the intensity of periodic fluctuations (such as amplification of the periodic amplitude during the rainy season) and shifts in the start time of fluctuations. By using inverse Fourier transform, the frequency domain disturbances are transformed into reliable time domain samples, strengthening the model's ability to capture periodic and latent fluctuations in the frequency domain.
[0041] Further, the calculation of the temporal context loss function includes:
[0042] Unlabeled samples and unlabeled augmented samples are input into the coding layer to extract high-dimensional temporal features and generate unlabeled coded features and unlabeled augmented coded features.
[0043] The unlabeled augmented encoded features are input into the feature perturbation enhancement module, and feature perturbation is applied using a gating unit and channel attention to generate unlabeled augmented perturbation features;
[0044] The unlabeled coded features and unlabeled enhanced perturbation features are respectively input into the decoder for dimensionality reduction and reconstruction, and then output as temporal prediction results and temporal enhanced prediction results through a fully connected layer;
[0045] Based on the temporal prediction results and the temporal augmentation prediction results, the temporal context loss function is calculated.
[0046] The temporal context loss function The corresponding formula is:
[0047] ;
[0048] in, Represents the total number of samples. This represents a logarithmic function with the natural constant as its base. This represents an exponential function with base e. Represents the cosine similarity function. This represents the summation function. Represents time-temperature (used to control the time-domain context loss function). Indicates the first Temporal prediction results for each unlabeled sample Indicates an indicator function, Representing the time domain, , They represent the first The temporal prediction results for the first unlabeled sample and the first... Temporal prediction augmentation results for each unlabeled augmented sample , These represent the amplitude context loss function and the phase context loss function, respectively.
[0049] In the above scheme, this invention captures deep temporal correlations by extracting high-dimensional temporal features and combines them with a feature perturbation enhancement module to generate differentiated perturbation features that fit the real scene, thus preserving core temporal information while introducing reasonable differences. The prediction results of decoding reconstruction and the output of the fully connected layer provide an accurate basis for calculating temporal context loss, making similar temporal features more compact and dissimilar features more dispersed. Attached Figure Description
[0050] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0051] Figure 1 This is a flowchart of the method in an embodiment of the present invention;
[0052] Figure 2 This is a schematic diagram of the initial coagulant addition prediction model in an embodiment of the present invention;
[0053] Figure 3This is a schematic diagram of the feature perturbation enhancement module structure in an embodiment of the present invention;
[0054] Figure 4 This is a schematic diagram of the initial coagulant addition prediction model training process in an embodiment of the present invention. Detailed Implementation
[0055] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0056] Please see Figure 1 This embodiment provides a comparative learning method for predicting coagulant dosing based on feature perturbation enhancement. Figure 1 The execution entity of the method shown can be a software and / or hardware device. The execution entity of this application can include, but is not limited to, at least one of the following: user equipment, network equipment, etc. User equipment can include, but is not limited to, computers, smartphones, personal digital assistants (PDAs), and the aforementioned electronic devices. Network equipment can include, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of computers or network servers. Cloud computing is a type of distributed computing, consisting of a super virtual computer composed of a group of loosely coupled computers. This embodiment does not impose any limitations on this.
[0057] A contrastive learning-based coagulant dosing prediction method based on feature perturbation enhancement includes:
[0058] S1. Receive historical data from the sensor and perform partial labeling and Fourier transform to generate unlabeled samples, Fourier split samples, and labeled samples; among which, the historical data from the sensor includes source water temperature, source water pH, source water turbidity, source water intake flow rate, and turbidity of the treated water.
[0059] Specifically, historical sensor data is collected from the cloud. Sensor historical data This is a collected semi-labeled time-series historical dataset, containing two subsets: a labeled subset and an unlabeled subset. The labeled subset... Contains M labeled samples Each labeled sample The tag is Unlabeled subsets Contains NM unlabeled samples N represents the total number of samples.
[0060] Due to sensor historical data The essence of this is that it contains a large number of implicit periodic patterns (such as seasonal changes and diurnal rhythms) and implicit frequency features (such as small fluctuations before a sudden pollution event). However, this information is easily masked by short-term noise in the time domain. Fourier transform can convert the time-dimensional signal into frequency-dimensional features (amplitude, phase), directly making these patterns explicit. Furthermore, if only the time domain is used as the comparison data for contrastive learning, it cannot effectively support the learning capabilities of unsupervised contrastive learning and solve the problem of data drift, thus affecting the learning of unlabeled subsets. Perform a Fourier transform to calculate the value of each unlabeled sample. From the frequency domain data, a Fourier split sample subset is obtained. The Fourier split sample subset consists of NM Fourier split samples. .
[0061] S2. Based on channel attention, gating units, and convolutional structures, a feature perturbation enhancement module is constructed. Based on the encoder-decoder Transformer backbone network and the feature perturbation enhancement module, a first unsupervised contrastive learning branch, a second unsupervised contrastive learning branch, and a supervised contrastive learning branch are generated to construct an initial coagulant dosing prediction model, such as... Figure 2 As shown.
[0062] In actual water plant operations, labeled samples are extremely scarce due to the need for manual recording or experimental verification, while unlabeled water quality time-series data exists in vast quantities. Traditional data augmentation methods, such as image rotation and cropping, are not applicable. Furthermore, the natural fluctuations (e.g., seasonal variations, flow velocity disturbances) and sudden anomalies (e.g., pollution, sensor drift) inherent in water quality data are uniformly distributed in the original data, failing to meet the needs of contrastive learning for differentiated samples. Therefore, such as Figure 3 As shown, the feature perturbation enhancement module includes a first convolutional module, a depthwise convolutional parallel module, a channel attention gating module, and a gated convolutional module; the first convolutional module includes LayerNorm layers connected in series, with a kernel size of [missing information]. The size of the conv layer and the convolution kernel is The conv layers. The depthwise convolutional parallel module includes parallel convolutional kernels, all of which have a size of [missing information]. The three DW-conv layers (depth convolutional layers), the dilation rate of the three DW-conv layers They are 1, 4, and 9 respectively.
[0063] The channel attention gating module includes cascaded gating units, channel attention layers, and convolutional kernels of size [size missing]. The convolutional layer consists of a channel attention layer and a convolutional kernel with a size of [missing information]. The conv layer.
[0064] The gated convolution module includes cascaded LayerNorm layers and a kernel size of [missing value]. The size of the conv layer, gate unit, and convolution kernel is The convolutional layer. Each gated unit performs a splitting and summing operation.
[0065] This embodiment uses a feature perturbation enhancement module to generate multiple perturbation versions of the enhanced sample data, adding noise of varying intensities and adjusting the time series period. This unsupervised expansion of the training set alleviates the problem of scarce labeled samples. Simultaneously, it makes the perturbed features, which contain elements of the real-world scenario, more robust (less sensitive to noise, fluctuations, and other interferences) and discriminative (optimized by contrastive learning loss, resulting in more compact features for similar samples and more dispersed features for dissimilar samples). Therefore, it solves the problems of insufficient model training due to scarce labeled samples in water plants, the weak generalization ability of traditional models due to large data distribution differences, and prediction bias caused by insufficient representation of original water quality data features. It also serves as a bridge connecting "water quality time series data characteristics" and "contrastive learning needs," actively constructing a differentiated feature space to meet the robustness and discriminative features required by contrastive learning, ultimately achieving accurate and stable prediction of coagulant dosage under complex water quality conditions.
[0066] Labeled samples with coagulant dosage tags are extremely scarce (requiring manual recording / experimental verification, which is costly), while massive amounts of unlabeled water quality time-series data (temperature, pH, turbidity, etc.) collected by real-time sensors exist. Three branches utilize the general features of unlabeled data through a two-branch approach (time domain + frequency domain), while another branch utilizes a small number of labels for precise mapping, achieving semi-supervised collaborative learning to maximize data value and compensate for the shortcomings of single-dimensional feature representation. Water quality data information is simultaneously distributed in the time domain (dynamic trends, such as continuous fluctuations in turbidity over time) and the frequency domain (periodic / latent fluctuations, such as seasonal water quality cycles and minute frequency changes before sudden pollution). Using only the time or frequency domain would lose crucial information in the other half of the dimension. Setting up three branches helps the initial coagulant dosage prediction model form a complete understanding of the time series, periodicity, and latent fluctuations of water quality, solving the industrial pain points of "complex, scarce, and volatile distribution" of water quality data. Furthermore, it improves model performance from multiple dimensions, including feature extraction, generalization ability, and data utilization, ultimately achieving accurate prediction of coagulant dosage.
[0067] Therefore, the first unsupervised contrastive learning branch, the second unsupervised contrastive learning branch, and the supervised contrastive learning branch all include encoders and decoders composed of a Transformer backbone network, with a feature perturbation enhancement module inserted into each encoder and its corresponding decoder. The first unsupervised contrastive learning branch is a time-domain branch, processing unlabeled samples; the second unsupervised contrastive learning branch is a frequency-domain branch, processing Fourier-split samples; and the supervised contrastive learning branch processes labeled samples.
[0068] This embodiment sets up three branches. The combination of the time domain branch and the frequency domain branch expands the water quality characteristics from a single time domain to a time-frequency fusion, solving the problem of insufficient feature utilization depth. This allows the model to simultaneously capture temporal dynamic correlations and frequency domain periodic / latent fluctuations. The time domain branch learns general time-frequency features that are independent of specific scenarios through unsupervised learning, while the supervised contrastive learning branch accurately correlates general time-frequency features with dosage, significantly improving the model's generalization ability to data distribution drift such as seasonal changes and sudden pollution. The time domain branch and the frequency domain branch utilize massive amounts of unlabeled data to pre-train feature extraction capabilities, while the supervised contrastive learning branch only requires a small number of labels to complete the mapping between features and dosage, reducing the dependence on scarce labeled samples and solving the problem of insufficient training.
[0069] S3. After data augmentation, the unlabeled samples, Fourier split samples, and labeled samples are input into the initial coagulant addition prediction model, and the time-frequency unsupervised-prediction contrast function and the labeled sample supervised-prediction contrast function are calculated respectively.
[0070] S3 includes:
[0071] S3-1. Perform data augmentation on unlabeled samples, Fourier split samples, and labeled samples to obtain unlabeled augmented samples, Fourier split augmented samples, and labeled augmented samples.
[0072] Specifically, for unlabeled samples, time-based enhancement is performed, which involves scaling and adjusting the parameter value range, adding small Gaussian jitter, and randomly discarding masks for local time nodes (simulating brief data gaps) to generate unlabeled enhanced samples. For Fourier split samples, a Fourier transform (FFT) is first performed on the unlabeled samples to obtain frequency domain data (i.e., Fourier split samples). The amplitude of the target frequency band is adjusted (e.g., amplifying the amplitude of frequencies corresponding to the rainy season to simulate changes in the intensity of periodic fluctuations), and the phase is fine-tuned (simulating the shift in the start time of fluctuations). Then, an inverse Fourier transform (IFFT) is performed to transform it back to the time domain to obtain Fourier split enhanced samples. For labeled samples, to ensure consistency with the labels, the same operations as for unlabeled samples are performed to generate labeled enhanced samples.
[0073] S3-2. Input the unlabeled samples and unlabeled augmented samples into the first unsupervised contrastive learning branch to perform unsupervised contrastive learning. Generate temporal prediction results and temporal augmentation prediction results through the encoder, feature perturbation enhancement module and decoder, and calculate the temporal context loss function.
[0074] S3-2 includes:
[0075] S3-2-1. Input the unlabeled samples and unlabeled augmented samples into the coding layer respectively, extract high-dimensional temporal features, and generate unlabeled coding features and unlabeled augmented coding features.
[0076] S3-2-2: Input the unlabeled enhanced encoded features into the feature perturbation enhancement module, apply feature perturbation through gating units and channel attention, and generate unlabeled enhanced perturbation features;
[0077] The feature perturbation enhancement module performs feature perturbation operations on the low-level information encoded by the Transformer layer. In the contrastive learning framework, the unlabeled enhanced perturbation features generated by the feature perturbation enhancement module can form positive sample pairs (homogeneous but different) with the unlabeled enhanced samples, and form negative sample pairs with the features of other samples. Through this design, when calculating the contrastive loss, the discriminative boundary of "features of the same type should remain similar, and features of different types should be far apart" can be learned more clearly, thereby strengthening the ability of the contrastive loss function to constrain feature similarity. The formula corresponding to the feature perturbation enhancement module is:
[0078] ;
[0079] ;
[0080] ;
[0081] ;
[0082] in, This indicates unlabeled augmented coding features. This indicates a normalization operation. Indicates the kernel size as Operations on the conv layer, Indicates the kernel size as Operations on the conv layer, This indicates the channel attention mechanism. Indicates a gating unit. , , These represent convolution kernel sizes of 1 and 2, respectively. And depthwise convolutional operations with dilation rates of 1, 4, and 9, This represents the output data of the first convolutional module. This represents the output data of the module consisting of a depthwise convolutional parallel module and a channel attention gating module. Indicates intermediate data. This indicates unlabeled enhanced perturbation features.
[0083] Water quality data includes multiple dimensions such as temperature, pH, and turbidity. While turbidity and pH significantly impact coagulant dosage prediction, temperature has a weaker effect. Channel attention can assess the importance of each channel's features, accurately locating and highlighting the characteristic channels for these key water quality parameters, preventing critical information from being obscured by secondary channels. Furthermore, because water quality data contains dynamic noise (such as sensor fluctuations) and redundant information, the gating unit can control the flow of feature information, autonomously deciding to transmit valuable features and suppress useless interference, ensuring targeted feature processing.
[0084] Therefore, a collaborative mechanism of "key channel localization - effective information filtering" is formed by combining channel attention and gating units. First, channel attention is used to identify feature channels strongly correlated with coagulant dosage (such as the turbidity channel). Then, the gating unit filters and enhances the features of key channels based on this localization, while filtering out interfering information from secondary channels, allowing the model to focus on the core features related to coagulant dosage. For positive sample pairs with similar water quality and dosage conditions, the consistency of key features is strengthened, helping the model accurately learn the dosage patterns under similar water quality. For negative sample pairs with large differences in water quality and dosage conditions, the differences in key features are amplified, helping the model clearly distinguish the dosage requirements corresponding to different water qualities, ultimately improving the accuracy and stability of coagulant dosage prediction.
[0085] The formula for each gating unit is:
[0086] ;
[0087] in, , These represent the input and output data of the gating unit, respectively. , Both represent intermediate variables in the gating unit. This represents the tensor splitting operation in the PyTorch deep learning framework. This represents the Hadamard product operation of a matrix.
[0088] The formula corresponding to the channel attention mechanism is:
[0089] ;
[0090] in, , These represent the input and output data of the channel attention mechanism, respectively. This indicates the average pooling operation. This represents matrix multiplication.
[0091] The Feature Perturbation Enhancement Module (FPEM) of this invention first encodes the input data using LayerNorm (normalization) and 1×1 and 3×3 convolutions. Then, it generates perturbation differences through depthwise separable convolutional branches with different dilation rates, providing diverse "homogeneous variants" for contrastive learning. Next, it fuses features through addition, gate units, and channel attention (CA), preserving perturbation differences while enhancing discriminative dimensions, helping the model accurately distinguish between similar and dissimilar feature boundaries. Subsequently, it is continuously optimized through LayerNorm, convolution, etc., gradually refining the core pattern suitable for contrastive loss calculation. The final output features enable the contrastive loss to more efficiently constrain feature similarity, keeping similar features related and effectively separating dissimilar features, thereby improving the contrastive learning effect.
[0092] S3-2-3. Input the unlabeled coded features and the unlabeled enhanced perturbation features into the decoder for dimensionality reduction and reconstruction, and output the temporal prediction results and temporal enhanced prediction results through the fully connected layer.
[0093] Based on S3-2-1 to S3-2-3, the formula corresponding to the processing procedure of the first unsupervised contrastive learning branch is:
[0094] ;
[0095] ;
[0096] ;
[0097] ;
[0098] ;
[0099] ;
[0100] ;
[0101] ;
[0102] ;
[0103] ;
[0104] in, , They represent the first The first unlabeled sample and the first One unlabeled augmented sample, , These represent unlabeled coded features and unlabeled augmented coded features, respectively. Indicates unlabeled samples, This indicates data augmentation. Indicates encoder, This indicates unlabeled enhanced perturbation features. Indicates decoder, This indicates a feature perturbation enhancement module. Indicates a fully connected operation. , These represent the decoder output data for unlabeled samples and unlabeled augmented samples, respectively. , They represent the first The temporal prediction results for the first unlabeled sample and the first... The temporal prediction enhancement results for each unlabeled augmented sample. Except for the unlabeled augmented encoded features needing to be processed by the feature perturbation module, the other processing procedures for unlabeled samples and unlabeled augmented samples are the same.
[0105] S3-2-4. Based on the temporal prediction results and temporal augmentation prediction results, calculate the temporal context loss function.
[0106] It's important to note that the temporal context loss function explores the temporal correlation and differences between the original data stream and the data stream enhanced by the feature perturbation module. It provides precise constraints for constructing a contrastive loss based on the predicted feature results of the two types of data streams. The temporal context loss function captures the dynamic evolution of different data streams over time, strengthening the inherent consistency of the temporal patterns between the original data and the perturbated data. Simultaneously, it captures the differentiated feature expressions brought about by the feature perturbation module, highlighting the subtle differences in the detailed patterns of the two types of data streams. The contrastive loss constructed based on this function enables the model to learn the core temporal features shared by both types of data streams (ensuring that similar features remain similar during temporal evolution) while amplifying the feature differences between them (pushing dissimilar features away from each other in the temporal dimension). Ultimately, this dual constraint improves the model's feature discrimination ability and prediction stability for temporal data.
[0107] Therefore, the temporal context loss function The corresponding formula is:
[0108] ;
[0109] in, This represents a logarithmic function with the natural constant as its base. This represents an exponential function with base e. Represents the cosine similarity function. This represents the summation function. Represents time-temperature (used to control the time-domain context loss function). Indicates the first Temporal prediction results for each unlabeled sample Indicates the first Temporal prediction results for each unlabeled sample
[0110] Indicates an indicator function, Represents the time domain. When , When they are equal, the indicator function The value is 1.
[0111] S3-3. Input the Fourier split samples and Fourier split enhancement samples into the second unsupervised contrastive learning branch for unsupervised contrastive learning. Generate frequency domain prediction results and frequency domain enhancement prediction results through the encoder, feature perturbation enhancement module, and Fourier transform. Calculate the frequency domain context loss function; the frequency domain context loss function includes the amplitude context loss function. and phase context loss function ;
[0112] Specifically, the processing of the second unsupervised contrastive learning branch is the same as that of the first unsupervised contrastive learning branch in S3-2. The only difference is that the last fully connected layer is replaced with a Fourier layer. That is, the Fourier encoded features output by the encoder and the Fourier enhanced perturbation features output by the feature perturbation module in the second unsupervised contrastive learning branch are respectively input to the decoder for dimensionality reduction and reconstruction, and then Fourier transform is performed through the Fourier layer to output the frequency domain prediction result and the frequency domain enhanced prediction result.
[0113] Therefore, the formula corresponding to the processing procedure of the second unsupervised contrastive learning branch is:
[0114] ;
[0115] ;
[0116] ;
[0117] ;
[0118] ;
[0119] ;
[0120] ;
[0121] ;
[0122] ;
[0123] in, , They represent the first The first Fourier split sample and the second Fourier split enhancement samples, , They represent , The corresponding encoder output data, express The Fourier enhanced perturbation features are obtained after the feature perturbation module. , They represent , The corresponding decoder output data, , These represent the frequency domain prediction result and the frequency domain enhancement prediction result, respectively.
[0124] The amplitude and phase features are extracted from the Fourier split samples and Fourier split enhancement samples to obtain amplitude feature vectors and phase feature vectors. An amplitude context loss function is constructed based on the amplitude feature vectors corresponding to each Fourier split sample and each Fourier split enhancement sample. A phase context loss function is constructed based on the phase feature vectors corresponding to each Fourier split sample and each Fourier split enhancement sample.
[0125] Therefore, the frequency domain context loss function The corresponding formula is:
[0126] ;
[0127] ;
[0128] ;
[0129] in, Indicates amplitude, , They represent the first In the frequency group, the first The amplitude feature vector of the first Fourier split sample, the first Frequency domain prediction results corresponding to the amplitude feature vectors of each Fourier split sample. Represents absolute value. Indicates the first In the frequency group, the first Frequency domain enhancement prediction results corresponding to the amplitude feature vectors of each Fourier shunt enhancement sample. , They represent the first In the frequency group, the first The phase eigenvector of the first Fourier shunt sample, the first The phase eigenvectors of a Fourier split sample. This represents the encoding of the phase. This represents the phase eigenvector after processing by the feature perturbation module.
[0130] This invention provides both time-domain and frequency-domain perspectives. The frequency domain helps to further reveal the spectral characteristics of time series, such as periodicity, which is beneficial to the model's prediction process and improves accuracy.
[0131] S3-4. Input the labeled samples and the labeled enhanced samples into the supervised contrastive learning branch to perform supervised contrastive learning. Generate the initial prediction result and the enhanced prediction result through the encoder, feature perturbation enhancement module and decoder. Calculate the supervised loss function and the prediction loss function to obtain the labeled sample supervised-prediction contrastive function.
[0132] Specifically, the processing procedure of the supervised contrastive learning branch is exactly the same as that of the first unsupervised contrastive learning branch in S3-2, and the outputs are the initial prediction results and the enhanced prediction results.
[0133] Based on the prediction results and the enhanced prediction results, a supervised loss function is constructed. The corresponding formula is:
[0134] ;
[0135] The initial prediction results are then processed by a fully connected layer to obtain the predicted labels. (Final prediction result). Based on prediction labels and real labels Construct the prediction loss function The corresponding formula is:
[0136] ;
[0137] Based on the prediction loss function and the supervision loss function, a labeled sample supervision-prediction comparison function is constructed, and the corresponding formula is:
[0138] ;
[0139] in, , They represent the first The initial prediction result of the labeled sample, the first Augmentation prediction results for each labeled augmented sample. This represents the hyperparameter (used to control the degree of influence of the difference in predicted values between samples on the loss). This represents the scaling difference hyperparameter (the absolute difference between predicted values between samples). , Indicates the number of respectively The labeled sample, the first The final prediction results for each labeled sample. Indicates the first The initial prediction results for each labeled sample, Indicates the first The labeled sample, the first The differences between the labeled samples are normalized to map them within a reasonable numerical range, ensuring the stability and rationality of the loss function calculation.
[0140] S3-5. Based on the time-domain prediction results, time-domain enhanced prediction results, frequency-domain prediction results, and frequency-domain enhanced prediction results, calculate the time-frequency consistency loss function.
[0141] Using the mean squared error loss function as the consistency loss function, and by pairwise constraining the consistency between unlabeled samples and the unlabeled samples after Fourier transform, the model can learn the common features of the data in both the time and frequency domains, reducing the bias between the two representation forms. This constraint allows the model to not only capture the time-domain patterns of the original data but also take into account key information such as the periodicity and amplitude in the frequency domain after Fourier transform, thereby enhancing the completeness and robustness of feature representation. This provides a more comprehensive basis for the effective differentiation of features in subsequent comparative learning, further improving the model's adaptability to complex data patterns and prediction accuracy. Therefore, the time-frequency consistency loss function... The corresponding formula is:
[0142] ;
[0143] in, This represents the operation of the consistency loss function.
[0144] S3-6. Calculate the time-frequency unsupervised prediction comparison function based on the time-frequency consistency loss function, the time-domain context loss function, and the frequency-domain context loss function.
[0145] The time-frequency unsupervised prediction comparison function The corresponding formula is:
[0146] .
[0147] S4. Based on the time-frequency unsupervised prediction comparison function and the labeled sample supervised prediction comparison function, the parameters of the initial coagulant addition prediction model are adjusted by the network backpropagation algorithm to obtain the coagulant addition prediction model.
[0148] The overall objective function is calculated based on the time-frequency unsupervised prediction contrast function and the labeled sample supervised prediction contrast function. The corresponding formula is:
[0149] ;
[0150] , , All of these represent hyperparameters. This represents minimization. Where, This is used to balance the contributions of various loss terms during network training.
[0151] like Figure 4 As shown, historical sensor data is first fed into the initial coagulant dosing prediction model to extract high-dimensional features. These high-dimensional features are then passed to the fully connected layer, which outputs the predicted coagulant dosing amount. Simultaneously, the high-dimensional features participate in the calculation of the time-frequency unsupervised prediction contrast function, and the prediction result participates in the labeled sample supervised prediction contrast function. Subsequently, the network integrates the labeled sample supervised prediction contrast function and the time-frequency unsupervised prediction contrast function through forward training, and then backpropagates the loss gradient to optimize the parameters of the initial coagulant dosing prediction model and the fully connected layer, achieving end-to-end training.
[0152] This invention employs a joint training approach combining unsupervised contrastive loss and supervised loss. Unsupervised contrastive learning (combined with feature perturbation enhancement) fully leverages the temporal and frequency feature correlations of unlabeled data, making similar water quality features more compact and dissimilar features more dispersed (improving feature discrimination and generalization). Simultaneously, supervised loss precisely constrains the mapping relationship between "water quality features → coagulant dosage," ensuring prediction accuracy. Furthermore, feature perturbation enhancement constructs a differentiated feature space for contrastive learning, further strengthening the robustness of feature representation. Ultimately, this enables the model to accurately and stably predict coagulant dosage even in industrial scenarios where labeled samples are scarce, balancing the generalization ability of feature learning with the accuracy of the prediction task.
[0153] S5. Real-time acquisition of sensor data and prediction of coagulant dosage using a coagulant dosage prediction model to obtain the coagulant dosage prediction result. The coagulant dosage prediction result is the coagulant dosage.
[0154] In summary, this invention alleviates the problem of scarce labeled samples by expanding the training set through a feature perturbation enhancement module, fully explores the temporal dynamics and frequency domain periodic / latent fluctuation features of water quality data using time-frequency dual-branch unsupervised contrastive learning, making the features more robust and discriminative; then, it accurately establishes the mapping between "water quality features and coagulant dosage" through supervised contrastive learning, and combines the joint loss function with backpropagation to optimize the model. Finally, in industrial scenarios where labeled samples are scarce, it effectively improves the model's generalization ability to complex situations such as water quality distribution drift and latent fluctuations, achieving accurate and stable prediction of coagulant dosage, and balancing the generalization of feature learning with the accuracy of the prediction task.
[0155] It should be noted that the specific methods by which each module performs operations in the system described in the above embodiments have been described in detail in the embodiments related to the method, and will not be elaborated here.
[0156] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
[0157] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A contrastive learning method for predicting coagulant dosing based on feature perturbation enhancement, characterized in that, include: Receive historical data from the sensor and perform partial labeling and Fourier transform to generate unlabeled samples, Fourier split samples, and labeled samples; Based on channel attention, gating units, and convolutional structures, a feature perturbation enhancement module is constructed; Based on the encoder-decoder Transformer backbone network and the feature perturbation enhancement module, the first unsupervised contrastive learning branch, the second unsupervised contrastive learning branch and the supervised contrastive learning branch are generated respectively to construct the initial coagulant addition prediction model. After data augmentation, the unlabeled samples, Fourier split samples, and labeled samples were input into the initial coagulant dosing prediction model, and the time-frequency unsupervised-prediction contrast function and the labeled sample supervised-prediction contrast function were calculated respectively. Based on the time-frequency unsupervised prediction comparison function and the labeled sample supervised prediction comparison function, the parameters of the initial coagulant addition prediction model are adjusted by the network backpropagation algorithm to obtain the coagulant addition prediction model. Sensor data is collected in real time and the addition is predicted using a coagulant addition prediction model to obtain the predicted coagulant addition result.
2. The contrastive learning method for predicting coagulant dosing based on feature perturbation enhancement according to claim 1, characterized in that, The feature perturbation enhancement module includes a first convolution module, a depthwise convolution parallel module, a channel attention gating module, and a gated convolution module; the first convolution module includes a LayerNorm layer and two conv layers connected in series; the depthwise convolution parallel module includes three DW-conv layers connected in parallel; the channel attention gating module includes a gated unit, a channel attention layer, and a conv layer connected in series; the gated convolution module includes a LayerNorm layer, a conv layer, a gated unit, and a conv layer connected in series.
3. The method for predicting coagulant dosing based on feature perturbation enhancement according to claim 1, characterized in that, The first unsupervised contrastive learning branch, the second unsupervised contrastive learning branch, and the supervised contrastive learning branch all include an encoder and a decoder composed of a Transformer backbone network; a feature perturbation enhancement module is inserted into each encoder and its corresponding decoder.
4. The method for predicting coagulant dosing based on feature perturbation enhancement according to claim 3, characterized in that, The computational time-frequency unsupervised prediction contrast function and the labeled sample supervised prediction contrast function include: Data augmentation is performed on unlabeled samples, Fourier split samples, and labeled samples to obtain unlabeled augmented samples, Fourier split augmented samples, and labeled augmented samples; Unlabeled samples and unlabeled augmented samples are input into the first unsupervised contrastive learning branch to perform unsupervised contrastive learning, generate temporal prediction results and temporal augmentation prediction results, and calculate the temporal context loss function; The Fourier split samples and Fourier split enhancement samples are input into the second unsupervised contrastive learning branch for unsupervised contrastive learning, generating frequency domain prediction results and frequency domain enhancement prediction results, and calculating the frequency domain context loss function. Labeled samples and augmented labeled samples are input into the supervised contrastive learning branch to perform supervised contrastive learning, generate initial prediction results and augmented prediction results, and calculate the supervised-prediction contrastive function for labeled samples; Based on the time-domain prediction results, time-domain enhanced prediction results, frequency-domain prediction results, and frequency-domain enhanced prediction results, the time-frequency consistency loss function is calculated. Based on the time-frequency consistency loss function, the time-domain context loss function, and the frequency-domain context loss function, the time-frequency unsupervised prediction comparison function is calculated.
5. The contrastive learning method for predicting coagulant dosing based on feature perturbation enhancement according to claim 4, characterized in that, The data enhancements include: For both unlabeled and labeled samples, perform time-based augmentation; generate unlabeled augmented samples and labeled augmented samples by scaling and adjusting the range of parameter values, adding small Gaussian jitter, and randomly discarding masks for local time nodes. For the Fourier shunt sample, adjust the amplitude and fine-tune the phase of the target frequency band of the Fourier shunt sample, and then perform an inverse Fourier transform to obtain the Fourier shunt enhanced sample.
6. The method for predicting coagulant dosing based on feature perturbation enhancement according to claim 4, characterized in that, The calculation of the temporal context loss function includes: Unlabeled samples and unlabeled augmented samples are input into the coding layer to extract high-dimensional temporal features and generate unlabeled coded features and unlabeled augmented coded features. The unlabeled augmented encoded features are input into the feature perturbation enhancement module, and feature perturbation is applied using a gating unit and channel attention to generate unlabeled augmented perturbation features; The unlabeled coded features and unlabeled enhanced perturbation features are respectively input into the decoder for dimensionality reduction and reconstruction, and then output as temporal prediction results and temporal enhanced prediction results through a fully connected layer; Based on the temporal prediction results and the temporal augmentation prediction results, the temporal context loss function is calculated.
7. The method for predicting coagulant dosing based on feature perturbation enhancement according to claim 4, characterized in that, The temporal context loss function The corresponding formula is: ; in, Represents the total number of samples. This represents a logarithmic function with the natural constant as its base. This represents an exponential function with base e. Represents the cosine similarity function. This represents the summation function. Indicates time and temperature. Indicates the first Temporal prediction results for each unlabeled sample Indicates an indicator function, Representing the time domain, , They represent the first The temporal prediction results for the first unlabeled sample and the first... Temporal prediction augmentation results corresponding to unlabeled augmented samples.
8. The contrastive learning method for predicting coagulant dosing based on feature perturbation enhancement according to claim 4, characterized in that, The frequency domain context loss function The corresponding formula is: ; ; ; in, This represents a logarithmic function with the natural constant as its base. This represents an exponential function with base e. This represents the summation function. Represents the total number of samples. Indicates amplitude. , They represent the first In the frequency group, the first The amplitude feature vector of the nth Fourier split sample, the nth Frequency domain prediction results corresponding to the amplitude feature vectors of each Fourier split sample. Represents absolute value. Indicates the first In the frequency group, the first Frequency domain enhancement prediction results corresponding to the amplitude feature vectors of each Fourier shunt enhancement sample. , They represent the first In the frequency group, the first The phase eigenvector of the first Fourier shunt sample, the first The phase eigenvectors of a Fourier split sample. This represents the encoding of the phase. This represents the phase eigenvector after processing by the feature perturbation module. , These represent the amplitude context loss function and the phase context loss function, respectively.
Citation Information
Patent Citations
Semi-supervised medical image segmentation method based on collaborative comparative learning and mixed disturbance
CN117975017A
Model training method and device, equipment and medium
CN118013287A
Multivariable time sequence classification method and system based on time-frequency mixed contrast learning
CN118097306A
Unsupervised domain adaptive fault diagnosis method and system for rotating machinery
CN118708931A
Water supply network acoustic leakage detection method based on enhanced semi-supervised model
CN119649848A
Cited By
Contrast learning and space-time double-branch fused coagulant addition prediction method
CN121278360A