A method for intelligent prediction and early warning of water bloom based on cluster embedding enhanced attention
By processing algal bloom prediction data through cluster embedding enhanced attention mechanism and SMOTE method, the problems of sample imbalance and ordinal classification in algal bloom prediction are solved, the accuracy and sensitivity of algal bloom early warning are improved, and efficient identification and prediction of algal bloom levels are achieved.
Patent Information
- Application Number
- CN202611072054.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-20
- Publication Date
- 2026-11-27
AI Technical Summary
Existing algal bloom prediction technologies struggle to accurately identify and classify extreme events such as algal blooms. The standard Transformer model lacks ordinal classification capabilities when processing water quality time-series data, and the algal bloom level samples are imbalanced, resulting in limited prediction accuracy and poor early warning sensitivity.
A cluster-embedded attention-enhanced approach is adopted. The cluster-embedded attention-enhanced mechanism module processes water quality time-series data. By combining residual connectivity and dynamic temperature parameters, a bidirectional attention structure is designed to dynamically filter the importance of different clusters. The SMOTE method is introduced to balance the samples and generate a balanced time-series dataset. A fully connected classifier is trained under FocalLoss supervision for risk level prediction.
It improves the ability to identify and warn of extreme algal blooms, enhances the accuracy of high-risk algal bloom discrimination, ensures that the model can learn the complex laws and dynamic trends of algal blooms during training, and improves the reliability and accuracy of prediction.
Smart Images

Figure CN123179153A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence and water environment monitoring technology, specifically relating to an intelligent prediction and early warning method for algal blooms based on cluster embedding and enhanced attention. Background Technology
[0002] Algal blooms are a typical ecological disaster in eutrophic water bodies. Their occurrence is sudden, rapid, and potentially harmful, posing a direct threat to water source security, aquatic ecosystem stability, and public health. With the development of the Internet of Things and high-frequency online monitoring technology, by deploying high-frequency online monitoring networks in water profiles, on the shoreline, and at river mouths, multi-dimensional time-series data such as water temperature, dissolved oxygen, pH value, and chlorophyll a concentration can be obtained in real time, providing rich real-time information for algal bloom risk analysis.
[0003] Existing algal bloom prediction technologies mainly include ecological mechanism models and data-driven machine learning and deep learning models. Ecological mechanism models simulate the physical, chemical, and biological processes of water bodies by establishing mathematical equations. However, due to the nonlinear, time-varying, and multi-factor interactions inherent in aquatic ecosystems, these models only focus on immediate effects and struggle to reflect the cumulative effects and lagged responses of environmental factors over time. Data-driven methods can learn the complex patterns of algal bloom occurrence through historical and real-time water quality data, but most existing models are regression-based, and their prediction objects are typically continuous variables. When dealing with extreme events like algal blooms, regression models tend to treat them as noise and ignore them, failing to accurately identify the bloom level or outbreak risk, and thus failing to meet the practical needs of water source areas for risk level classification.
[0004] In deep learning methods, the Transformer model, as a crucial module for temporal modeling, boasts advantages such as capturing long-term temporal dependencies and high parallel computing capabilities, enabling it to handle large-scale, multivariate water quality data. However, existing Transformer models were primarily designed for continuous numerical prediction or natural language processing tasks, lacking optimization mechanisms for ordinal classification tasks. When directly using the standard Transformer for ordinal classification in high-dimensional, multivariate water quality time-series data, problems remain, including difficulty in fully modeling class order relationships, limited feature processing efficiency, and complex training processes.
[0005] Existing intelligent early warning technologies for algal blooms still have several shortcomings: First, regression-based models struggle to accurately identify and classify extreme events such as algal blooms, failing to meet the requirements for ordinal risk level prediction. Second, standard Transformer models lack a mechanism for effectively modeling the sequential relationship of ordinal categories when processing water quality time-series data, resulting in low utilization of high-dimensional features and limited prediction accuracy. Third, the algal bloom level sample categories are severely imbalanced, making it difficult for existing methods to effectively utilize minority (high-risk) samples without disrupting temporal dependencies, leading to poor model sensitivity to high-risk events. Therefore, we need to provide an intelligent algal bloom prediction and early warning method based on cluster embedding and enhanced attention. Summary of the Invention
[0006] The purpose of this invention is to provide an intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention. Balanced time-series data is input into a pre-constructed cluster embedding enhanced attention mechanism module. A bidirectional attention structure is constructed by introducing trainable cluster embedding parameters, where "input features aggregate into the cluster space – cluster features feed back into the input space," replacing the traditional global pairwise self-attention calculation of the Transformer. A gating mechanism is introduced in the cluster space to dynamically filter the importance of different clusters, and residual connections are used to retain original fine-grained information. When cluster features are fed back into the input space, an adaptive dynamic temperature parameter is introduced to achieve soft-weight attention allocation, enabling the model to automatically adjust its attention to key water quality features and time-series patterns according to different algal bloom evolution stages, capturing the intrinsic correlation and time-dependent characteristics between indicators.
[0007] To achieve the above objectives, the present invention adopts the following technical solution: an intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention, comprising: Multidimensional water quality time-series data are collected in real time from monitoring points at water sources. Chlorophyll a concentration is a mandatory indicator in the multidimensional water quality time-series data, and the data also includes at least one or more of the following indicators: water temperature, dissolved oxygen, pH value, and several types of nutrients. Based on the preset threshold range of total chlorophyll a concentration, each monitoring sample is labeled with an ordinal algal bloom risk level label with a clear progressive relationship, forming a labeled time-series monitoring dataset. Missing value imputation and standardization are performed on the multidimensional water quality time series data in the labeled time series monitoring dataset to obtain complete and dimensionless standardized time series data; wherein, the missing value imputation adopts the Kalman filtering method and the standardization adopts Z-score standardization. Based on the standardized time-series data, to address the imbalance problem of algal bloom risk level sample categories, a time-series-constrained SMOTE enhancement method, namely time-SMOTE, is adopted. While maintaining time dependence, weighted interpolation oversampling is performed on minority class samples within the time-series neighborhood to generate a balanced time-series dataset. The balanced time-series data is input into a pre-constructed cluster embedding enhanced attention mechanism module. Through trainable cluster embedding parameters, bidirectional cluster attention calculation, cluster gating dynamic screening, and soft weight feature fusion are performed to enhance the encoding of multidimensional water quality time-series features and output the enhanced time-series feature representation. The enhanced temporal feature representation is input into a fully connected classifier trained under FocalLoss supervision to calculate the probability of occurrence of each algal bloom risk level and output the probability distribution corresponding to each level. Based on the probability distribution, an ordinal determination strategy based on cumulative probability is adopted to map the probability distribution to the corresponding algal bloom risk level, and generate early warning information containing risk level and / or risk probability, and output real-time early warning results for water source management.
[0008] Preferably, the multidimensional water quality time series data also includes conductivity, turbidity, permanganate index, ammonia nitrogen content, total nitrogen concentration, total phosphorus concentration, and one or more of green algae concentration, cyanobacterial concentration, diatom concentration and cryptophyte concentration; all monitoring data are collected according to a preset sampling frequency, which is once every 0.5 to 2 hours.
[0009] Preferably, the number of algal bloom risk level labels is three, namely low risk level, medium risk level and high risk level, and there is a clear progressive relationship between the three risk levels; the historical data collected must cover at least one complete algal bloom cycle and include data from both the algal bloom season and the non-blossom season.
[0010] Preferably, the Kalman filtering method fills in missing values in time series data based on a state-space model, wherein the state-space model includes state equations and observation equations.
[0011] Preferably, when performing weighted interpolation oversampling within the temporal neighborhood, the time-SMOTE defines the temporal neighborhood of any minority class sample as the set of adjacent minority class samples within the radius of the time window; the generation of new samples adopts a weighted interpolation method, assigning higher weight coefficients to neighboring samples with closer temporal distances, and the weight coefficients decay exponentially as the temporal distance between samples increases.
[0012] Preferably, the cluster embedding enhanced attention mechanism module is constructed based on the induced set attention structure. By introducing K trainable cluster embedding parameters to replace the global pairwise self-attention calculation in the traditional Transformer, the input sequence achieves feature aggregation through a bidirectional information interaction structure of "input features, cluster embedding, input features", thereby reducing the computational complexity from the quadratic level of the input sequence length to the product level of the input sequence length and the number of clusters.
[0013] Preferably, the cluster embedding parameters adopt an initialization method based on data distribution, including: firstly performing cluster analysis on the training data to obtain K cluster centers, and then adding a small random perturbation to each cluster center as the initial cluster embedding to avoid degradation during model training.
[0014] Preferably, the bidirectional cluster attention calculation includes two directions: input-to-cluster attention aggregation and cluster-to-input attention feedback; wherein, input-to-cluster attention is used to aggregate the original high-dimensional input features into a finite number of cluster representations to achieve global temporal pattern compression; cluster-to-input attention is used to feed back the aggregated cluster features to the input feature space.
[0015] Preferably, the cluster-gated dynamic screening introduces a gating function into the cluster space, calculates the importance weights of each cluster using a multilayer perceptron, and maps the weights to between zero and one using an activation function to dynamically screen the importance of different clusters; the screened cluster features are combined with the original cluster embeddings for residual connection and normalization to retain the original cluster embedding information and suppress invalid noise features; the soft-weight feature fusion introduces a dynamic temperature parameter to adjust the smoothness of the attention distribution, and the dynamic temperature parameter is adaptively adjusted according to the volatility of the input data.
[0016] Preferably, the ordinal determination strategy based on cumulative probability includes: calculating the cumulative probability of the predicted probability of each risk level, setting a set of incremental risk thresholds, determining the corresponding algal bloom risk level when the cumulative probability crosses the corresponding threshold, and automatically triggering an early warning mechanism when the prediction result reaches the preset risk level threshold. The early warning output includes the future algal bloom risk level and the risk probability information of each level.
[0017] Technical effects and advantages of the present invention: The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention proposed in this invention has the following advantages compared with the prior art: During the time-series data balancing stage, this invention addresses the imbalance problem of algal bloom classification by designing time-SMOTE, while preserving the time dependence of the data. It strictly limits sample selection to the time-series neighborhood and introduces a weight coefficient that decreases with the time distance between samples. This ensures that the generated samples not only expand the number of minority class samples but also preserve the continuous evolution and dynamic trend of water quality indicators over time. It avoids generating abnormal samples that violate the natural evolution process of algal blooms, enabling the model to fully learn the characteristic patterns of high-risk algal bloom samples during training and improving the ability to identify and warn of extreme algal bloom events.
[0018] In the model training and feature encoding stages, a cluster embedding-enhanced attention mechanism is designed to automatically capture the potential correlations and category order relationships among multidimensional water quality indicators through end-to-end cluster feature learning. This mechanism replaces traditional global self-attention with bidirectional cluster attention constructed using trainable cluster embeddings, achieving global pattern compression and enhanced expression of high-dimensional temporal features. A gating mechanism is introduced in the cluster space to dynamically filter the importance of different clusters, and soft weight fusion is achieved based on dynamic temperature parameters, enabling the model to automatically adjust the degree of attention to key water quality features and temporal patterns according to different algal bloom evolution stages. Compared with most existing algal bloom prediction methods that rely on regression models, this mechanism can better handle ordinal algal bloom levels, avoid smoothing or ignoring extreme events, and improve the accuracy of high-level algal bloom discrimination and the reliability of model prediction.
[0019] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures pointed out in the description and the drawings. Attached Figure Description
[0020] Figure 1 This is a system flowchart of the present invention; Figure 2 This is a diagram of the cluster embedding initialization architecture of the present invention; Figure 3 This is a diagram of the bidirectional attention computation, cluster gating, and soft-weighted attention architecture of the present invention. Detailed Implementation
[0021] 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 specific embodiments described herein are merely used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] This invention provides, for example Figure 1-3 The method shown is an intelligent prediction and early warning method for algal blooms based on cluster embedding and enhanced attention, which includes: Data Acquisition and Sample Labeling: Multidimensional water quality time-series data are collected in real time from monitoring points at water sources. Chlorophyll a concentration is a mandatory indicator in the multidimensional water quality time-series data, and the data also includes at least one or more of the following indicators: water temperature, dissolved oxygen, pH value, and several types of nutrients. Based on the preset threshold range of total chlorophyll a concentration, each monitoring sample is labeled with an ordinal algal bloom risk level label with a clear progressive relationship, forming a labeled time-series monitoring dataset. Data preprocessing: The multidimensional water quality time series data in the labeled time series monitoring dataset are imputed and standardized to obtain complete and dimensionless standardized time series data; wherein, the missing value imputation adopts the Kalman filter method and the standardization adopts Z-score standardization. Time-series data balancing: Based on the standardized time-series data, to address the imbalance problem of algal bloom risk level sample categories, a time-series-constrained SMOTE enhancement method is adopted, namely time-SMOTE. While maintaining time dependence, weighted interpolation oversampling is performed on minority class samples within the time-series neighborhood to generate a balanced time-series dataset. Cluster embedding enhanced attention feature encoding: The balanced time series data is input into the pre-constructed cluster embedding enhanced attention mechanism module. Through trainable cluster embedding parameters, bidirectional cluster attention calculation, cluster gating dynamic screening and soft weight feature fusion are performed to enhance the encoding of multidimensional water quality time series features and output the enhanced time series feature representation. Risk probability calculation: Input the enhanced temporal feature representation into a fully connected classifier trained under FocalLoss supervision, calculate the probability of occurrence of each algal bloom risk level, and output the probability distribution corresponding to each level; Algal bloom level determination and early warning output: Based on the probability distribution, an ordinal determination strategy based on cumulative probability is adopted to map the probability distribution to the corresponding algal bloom risk level, and generate early warning information containing risk level and / or risk probability, and output real-time early warning results for water source management.
[0023] The multidimensional water quality time series data also includes conductivity, turbidity, permanganate index, ammonia nitrogen content, total nitrogen concentration, total phosphorus concentration, and one or more of the following: green algae concentration, cyanobacteria concentration, diatom concentration, and cryptophyte concentration; all monitoring data are collected according to a preset sampling frequency, which is once every 0.5 to 2 hours.
[0024] The number of algal bloom risk level labels is three: low risk, medium risk and high risk, with a clear progressive relationship between the three risk levels; the historical data collected must cover at least one complete algal bloom cycle and include data from both the algal bloom season and the non-algal bloom season.
[0025] The Kalman filtering method fills in missing values in time series data based on a state-space model, which includes state equations and observation equations.
[0026] When performing weighted interpolation oversampling within the temporal neighborhood, the time-SMOTE defines the temporal neighborhood of any minority class sample as the set of adjacent minority class samples within the radius of the time window. The generation of new samples adopts a weighted interpolation method, assigning higher weight coefficients to neighboring samples with closer temporal distances. The weight coefficients decay exponentially as the temporal distance between samples increases.
[0027] The cluster embedding enhanced attention mechanism module is built based on the induced set attention structure. By introducing K trainable cluster embedding parameters to replace the global pairwise self-attention calculation in the traditional Transformer, the input sequence achieves feature aggregation through a bidirectional information interaction structure of "input features, cluster embedding, input features", thereby reducing the computational complexity from the quadratic level of the input sequence length to the product level of the input sequence length and the number of clusters.
[0028] The cluster embedding parameters adopt an initialization method based on data distribution, which includes: firstly performing cluster analysis on the training data to obtain K cluster centers, and then adding a small random perturbation to each cluster center as the initial cluster embedding to avoid degradation during model training.
[0029] The bidirectional cluster attention computation includes two directions: input-to-cluster attention aggregation and cluster-to-input attention feedback. The input-to-cluster attention is used to aggregate the original high-dimensional input features into a finite number of cluster representations to achieve global temporal pattern compression. The cluster-to-input attention is used to feed the aggregated cluster features back into the input feature space.
[0030] The cluster-gated dynamic screening introduces a gating function into the cluster space, calculates the importance weights of each cluster using a multilayer perceptron, and maps the weights to between zero and one using an activation function to dynamically screen the importance of different clusters. The screened cluster features are combined with the original cluster embeddings for residual connection and normalization to preserve the original cluster embedding information and suppress invalid noise features. The soft-weight feature fusion introduces a dynamic temperature parameter to adjust the smoothness of the attention distribution, and the dynamic temperature parameter is adaptively adjusted according to the volatility of the input data.
[0031] The ordinal determination strategy based on cumulative probability includes: calculating the cumulative probability of the predicted probability of each risk level, setting a set of incremental risk thresholds, determining the corresponding algal bloom risk level when the cumulative probability crosses the corresponding threshold, and automatically triggering an early warning mechanism when the prediction result reaches the preset risk level threshold. The early warning output includes the future algal bloom risk level and the risk probability information of each level.
[0032] Example
[0033] This module focuses on data related to water temperature, water quality, and phytoplankton communities at monitoring points in water sources. The main indicators collected include water temperature, pH, dissolved oxygen concentration, conductivity, turbidity, permanganate index, ammonia nitrogen content, total nitrogen / total phosphorus concentration, and concentrations of green algae, cyanobacteria, diatoms, cryptophytes, and total chlorophyll a content. The above indicators are only examples; in specific implementations, other water quality or ecological parameters can be added as needed to meet the monitoring requirements of different water sources.
[0034] All monitoring data are collected at a preset sampling frequency (e.g., but not limited to once per hour) and can be aggregated and analyzed according to a preset time scale (e.g., but not limited to calculating daily averages for diurnal analysis), thereby forming continuous multidimensional time-series monitoring data. in For feature dimension, For sequence length, In order to be in Real-time collection The data includes different monitoring indicators. Preferably, the preset sampling frequency is once every 0.5 to 2 hours; more preferably, the preset sampling frequency is once per hour.
[0035] Total chlorophyll a content, as a key indicator for algal bloom early warning, can directly reflect algal biomass and provide the main discrimination information for the model. To ensure the sufficiency of model training, the historical data used should cover at least one complete algal bloom cycle (usually more than one year) and include data from both the bloom and non-bloom periods, so as to ensure that the model can learn the characteristics of algal blooms under different environmental conditions and improve the reliability and adaptability of the early warning system.
[0036] After data collection, this module further labels the risk levels based on the total chlorophyll a concentration, constructing ordinal classification labels. Specifically, based on a preset algal bloom risk threshold, the monitored samples are divided into three levels: low risk, medium risk, and high risk, and corresponding supervised learning labels are generated. Since there is a clear sequential relationship between the various risk levels, this invention defines it as an ordinal classification task, providing supervision information for subsequent time-preserving SMOTE data augmentation and ordinal classification model training.
[0037] During system operation, data collected by sensors is uploaded to the data processing platform in real time via wireless or wired communication interfaces and stored in the database, enabling unified management of historical and real-time data. Furthermore, the data acquisition module can perform preliminary monitoring and labeling of sensor anomalies, communication packet loss, or measurement noise, providing a reliable data foundation for subsequent data preprocessing and model training.
[0038] Data preprocessing In the intelligent early warning system for algal blooms of the present invention, the data preprocessing module is used to process the collected multidimensional water quality time-series data. Data preprocessing involves cleaning, smoothing, and standardization to ensure data integrity, usability, and modeling quality. Specifically, the data preprocessing module includes the following steps: Kalman filter missing value imputation Because water quality data is dynamic and continuous, using Kalman filtering to fill in missing values can combine historical data with current observations to make the optimal estimate of missing values, which is more in line with the physical laws of water body changes than simple interpolation.
[0039] Typically, time-series monitoring data usually includes the system's inherent dynamic evolution patterns and the actual observations acquired by sensors. To accurately describe the generation process of monitoring data and achieve effective missing value imputation, this invention uses a state-space model that includes state equations and observation equations to model the time-series monitoring data.
[0040] Let the monitoring sequence be With multidimensional time-series monitoring data This refers to a unified dataset where some time points contain missing values, which are marked as null values (NULL).
[0041] The state equation is defined as follows:
[0042] in, Indicates the first The state vector at any given time; This represents the state transition matrix, used to describe the evolution of the system state over time. Indicates the first The process noise at time t, has a mean of 0 and a covariance matrix of . The Gaussian distribution.
[0043] The observation equation is:
[0044] in, Indicates the first The observation vector at any given time, i.e., the data actually monitored; This represents the observation matrix, used to describe the mapping relationship between the system state and the observed values; Indicates the first The observation noise at time t follows a pattern with a mean of 0 and a covariance matrix of . The Gaussian distribution.
[0045] Kalman filtering uses a state-space model to predict and update sequences, achieving reasonable estimation of missing values. It predicts the water quality index status at the current time point by combining the state of the previous time step and the state transition matrix. The prediction formula is as follows:
[0046] in, For time The predicted state vector, This is the state vector from the previous time point. To predict the covariance matrix, For the first The posterior error covariance matrix at time t.
[0047] When there are valid observations at the current time point At this point, the system first calculates the Kalman gain matrix:
[0048] Next, the posterior state estimate is calculated:
[0049] Simultaneously update the posterior error covariance matrix:
[0050] in, For the first The Kalman gain matrix at time step is used to balance the weights of the predicted and observed values. For the first The posterior state estimate at time 1, i.e., the optimal state estimate after fusing the observation data; It is the identity matrix. Indicates the first The posterior error covariance matrix at time t reflects the uncertainty of the posterior state estimation.
[0051] When the Observations of time When missing values are included, use the predicted values directly. As the fill value for that time point, i.e. To predict the covariance matrix As the error covariance matrix at that moment, i.e. This ensures the continuity and integrity of time-series data. Using this method, missing values in multidimensional water quality time-series data can be reasonably estimated, providing a reliable foundation for subsequent data smoothing, feature enhancement, and ordinal algal bloom level prediction.
[0052] Dataset partitioning The sequences with missing values filled in are divided into training, validation, and test sets in a 7:1:2 ratio. The training set is used for model training, the validation set is used for model parameter optimization, and the test set is used for model performance evaluation.
[0053] Z-score standardization Based on the statistics of the training set, Z-score standardization is performed on the training, validation, and test sets. This involves subtracting the mean of the corresponding feature and dividing by the standard deviation, transforming the data into a distribution with a mean of 0 and a standard deviation of 1. This eliminates differences in the dimensions of different features, improves the model's training stability and generalization ability, and yields the target multivariate time series data. The formula for Z-score standardization is:
[0054] in, This is the data after missing values have been filled in. It is standardized data. As a statistical factor, For all moments of this feature The corresponding mean, For all moments of this feature The corresponding standard deviation.
[0055] time-SMOTE time series data balancing Because the number of samples at different risk levels in algal bloom warning data is significantly imbalanced, with a higher proportion of low-risk samples and a smaller number of high-risk samples, the model is prone to bias towards the majority class during training, thus reducing its ability to identify extreme algal bloom events. Traditional SMOTE methods mainly generate new samples by random linear interpolation of minority class samples in the feature space, but this generation process does not consider the temporal dependencies and dynamic evolution patterns in the time series data. In algal bloom warning scenarios, indicators such as water temperature, algae concentration, and nutrients all exhibit significant temporal continuity. Directly using traditional SMOTE for random interpolation can easily disrupt the temporal correlation structure, causing the generated samples to deviate from the actual algal bloom evolution process, thereby affecting the model training effect and warning accuracy.
[0056] To address the aforementioned issues, this invention proposes a time-SMOTE time-series data balancing method based on time-series constraints. By interpolating samples within the time-series neighborhood, the method expands the minority class of samples while maintaining the time-dependent characteristics and dynamic trends of water quality data.
[0057] In practice, for any minority class sample Its temporal neighborhood is defined as:
[0058] in, For time proximity A minority class sample set; Indicates the current time point Adjacent minority class samples; The time window radius is used to limit the time distance between neighboring samples and the current sample; This represents the minority class sample set. Unlike the traditional SMOTE method that randomly selects global nearest neighbors, this invention selects samples only within a temporally proximate range, thereby avoiding the generation of anomalous samples that violate the laws of temporal evolution.
[0059] When generating new samples, first start from the temporal neighborhood. We select neighboring minority class samples and combine them with time decay weights to generate new enhanced samples. The weighted interpolation formula is as follows:
[0060] in, For new minority class samples generated through interpolation, These are random interpolation coefficients. The time decay weight is defined as follows:
[0061] in, Indicates the time distance between samples. This is the time decay coefficient, used to control the decay rate of the time weight. positive real number ( The larger the value of , the slower the time decay and the smaller the weight difference of samples within the neighborhood; the smaller the value, the faster the time decay and the higher the weight of closer samples. In a preferred embodiment, The value range is [1, 10], more preferably, =7 (in days), this value can better balance the short-term fluctuations and long-term trends in the process of algal bloom evolution.
[0062] By assigning higher weights to samples that are closer in time, the generated samples can maintain the temporal continuity of the algal bloom evolution process, reducing the temporal distortion problem caused by the traditional SMOTE method in the process of time series data augmentation.
[0063] Cluster embedding enhanced attention mechanism To address the problems of high computational complexity, low efficiency of global dependency modeling, and difficulty in adapting to the dynamic evolution of algal blooms in processing high-dimensional water quality time-series data, this invention proposes a cluster embedding-enhanced attention mechanism. This mechanism achieves efficient enhancement of time-series features through the following four design aspects: (1) introducing trainable cluster embeddings to replace global pairwise attention calculations to reduce complexity; (2) constructing a bidirectional attention mechanism of "input → cluster → input" to achieve interaction between global and local information; (3) designing residual connections to maintain the original fine-grained information; and (4) introducing a gating mechanism and dynamic temperature parameters to achieve adaptive feature selection.
[0064] In this invention, after passing through the time-SMOTE time-series data balancing module, a balanced time-series dataset is obtained. Subsequently, the balanced data input clusters are embedded into an enhanced attention mechanism to perform dynamic association learning and enhanced representation of multidimensional water quality time-series features.
[0065] The cluster embedding-enhanced attention mechanism proposed in this invention is based on the induced set attention structure in SetTransformer. By introducing trainable cluster embedding parameters to replace the global self-attention calculation in traditional Transformer, the input sequence no longer directly undergoes pairwise attention interactions. Instead, it achieves the aggregation and reinforcement learning of high-dimensional temporal features through a bidirectional information interaction structure of "input features - cluster embedding - input features," thereby reducing model complexity and improving the model's ability to identify complex algal bloom evolution patterns. The time complexity of the traditional Transformer sub-attention mechanism is... This invention reduces the complexity to zero by replacing global pairwise attention computation with cluster-embedded intermediate representations. ,and .
[0066] Cluster embedding definition This invention defines Cluster embedding parameters ,in The aforementioned cluster embedding parameters are used as model training parameters in network optimization and are dynamically updated through backpropagation. The update method is as follows:
[0067] in, For learning rate, This is the model loss function.
[0068] Cluster embedding parameters can be initialized using a data distribution-based method, which involves first performing K-Means clustering on the training data to obtain the output. Cluster centers Each cluster center represents the typical characteristics of all samples in that cluster (such as low risk, medium risk, high risk).
[0069] Then random perturbation was added. To avoid model degradation, among which To incorporate cluster embeddings with random perturbations, With a mean of 0 and a covariance matrix of Gaussian distribution, This is the disturbance coefficient, typically between 0.001 and 0.1 (0.01 is used here). This is the identity matrix. The corresponding content for this section can be found here. Figure 2 As shown, the above method enables cluster embedding to dynamically learn potential temporal patterns based on different algal bloom risk tasks.
[0070] Bidirectional cluster attention computation See the bidirectional cluster attention calculation module. Figure 3 As shown in (A). Let the input features be represented as... First, linear projections are performed on the input features and cluster embeddings respectively:
[0071] in, This represents the input query, key, and value vector. Represents the query, key, and value vector of a cluster. Represents the input feature matrix. This represents the obtained cluster embedding matrix. This represents the corresponding trainable mapping matrix.
[0072] Next, the present invention further constructs the attention weights input to the cluster. By aggregating input features into the cluster embedding space, key temporal patterns are compressed and expressed. The attention formula is as follows:
[0073] in, The scaling factor represents the dimension of the key vector; This is the normalization function.
[0074] Next, cluster feature aggregation is completed. ,in, The dimension of the value vector is represented. Through the above process, the original high-dimensional input features are aggregated into a finite number of cluster representations, achieving global temporal pattern compression.
[0075] Subsequently, this invention further constructs cluster-to-input attention weights. The aggregated cluster features are then fed back into the input feature space, and the corresponding attention calculation formula is:
[0076] The corresponding enhanced features are represented as This bidirectional attention structure enables the aggregation of input features into the global pattern space and the feedback of cluster features into important features of the input space, thereby enhancing the model's ability to express complex algal bloom evolution patterns.
[0077] Cluster gating mechanism In particular, this invention introduces a cluster gating mechanism (such as...) in the cluster space. Figure 3 As shown, the importance of different clusters is dynamically filtered. Gating function The definition is as follows:
[0078] in, Cluster aggregation characteristics This is the Sigmod activation function. This is a gated multilayer perceptron. Next, the cluster features are gated and weighted:
[0079] Finally, the updated clusters are generated by combining residual joins and normalization operations. express:
[0080] Through the aforementioned residual connections, the original cluster embedding information is preserved, avoiding excessive suppression of effective features by the gating mechanism, while enhancing the expressive power of key cluster features and suppressing the impact of invalid noise features on the model's prediction results.
[0081] Soft weight attention allocation When feeding the aggregated cluster features back into the input feature space, a soft-weight attention allocation mechanism (such as...) is introduced. Figure 3 (as shown in (C)), through dynamic temperature parameters The formula for adjusting attention distribution is updated as follows:
[0082] in, This is the initial temperature parameter (usually taken as 1.0). For adjustment coefficients, The volatility of the input data can be calculated from the standard deviation or sliding window volatility statistic of the input time series data. Through a dynamic temperature adjustment mechanism, the model can automatically adjust the attention distribution according to different stages of algal bloom evolution, improving the model's adaptability to complex time series changes.
[0083] The enhanced output features are then obtained. The final features are enhanced by the cluster embedding attention mechanism. The output is:
[0084] in, This indicates a cluster embedding-enhanced attention mechanism. , It is the hidden layer dimension.
[0085] Through residual connections, the original fine-grained information and the global aggregated information are complemented and fused, ensuring that the model enhances its feature representation capabilities without losing important details in the original input, thereby significantly improving the model's learning ability and prediction stability for complex algal bloom evolution patterns.
[0086] Multi-head cluster embedding enhanced attention mechanism To capture temporal correlations in different feature subspaces, this invention further employs a multi-head attention structure (such as...). Figure 3 (as shown in (D)):
[0087] in, Indicates the first The output of each attention head, This indicates the number of attention heads. The outputs of all attention heads are concatenated and mapped using an output mapping matrix. Perform a linear transformation to obtain the final multi-head attention output:
[0088] Through a multi-head mechanism, the model can extract multi-scale algal bloom evolution features from different feature subspaces, thereby improving the model's ability to learn complex algal bloom risk patterns.
[0089] Risk probability calculation module In this invention, after processing by the cluster embedding enhanced attention mechanism, an enhanced temporal feature representation is obtained. Subsequently, the enhanced features are input into the classifier to calculate the risk probability, obtaining the probability distribution corresponding to different algal bloom risk levels. Specifically, the classification output is first obtained through a fully connected mapping:
[0090] in, For unnormalized category scores, This is the output layer weight matrix. This is the bias term. Subsequently, through... The function calculates the probability distribution corresponding to each risk level:
[0091] in, Indicates the first The predicted probability of each risk level. Indicates the number of risk level categories (in this embodiment) (Corresponding to low, medium, and high risk levels).
[0092] In the model training phase, to improve the model's ability to identify minority class risk samples, this invention uses FocalLoss as the classification loss function. :
[0093] in, The predicted probability corresponding to the true category. To focus on the parameters, FocalLoss is introduced to reduce the impact of a large number of easily classifiable low-risk samples on the training process, thereby improving the model's ability to learn from high-risk and extreme algal bloom events. The model achieves this by minimizing the aforementioned loss function. This updates the network parameters and completes the training process.
[0094] During the model inference phase, the trained model no longer uses FocalLoss, but directly uses... probability distribution of function output The predicted probabilities of each algal bloom risk level are used for subsequent risk level determination.
[0095] Algal bloom level determination and early warning output module After completing the risk probability calculation, the model outputs the probability distribution corresponding to each algal bloom risk level:
[0096] in, Indicates the prediction time step. Indicates the first The predicted probability of the grade This represents the number of risk levels. The system employs an ordinal determination strategy based on cumulative probability to fully utilize the sequential information among risk levels. Specifically, the cumulative probability function is defined as:
[0097] in, This indicates a risk level no higher than The cumulative probability. Set a set of increasing risk thresholds. (satisfy In this embodiment, take The final risk level. The judgment is as follows:
[0098] In practice, algal bloom risks can be categorized into low, medium, and high risks, each corresponding to a different warning status. Low risk indicates the water body is in a normal state, medium risk indicates a tendency for algal blooms to occur, and high risk indicates a significant risk of an algal bloom outbreak. When the predicted risk level reaches a preset threshold, the system automatically triggers the warning mechanism and generates corresponding warning information. The warning output includes, but is not limited to, information such as the future algal bloom risk level and the probability of each level. Subsequently, the warning results can be output through a monitoring platform, database, visualization interface, or remote communication module, enabling real-time monitoring and early warning of algal bloom risks in water source areas.
[0099] System Deployment and Application The intelligent early warning method for algal blooms proposed in this invention can be deployed in online monitoring platforms for water sources, edge computing devices, or cloud servers to achieve real-time monitoring and intelligent early warning of algal bloom risks in water bodies.
[0100] During system operation, monitoring sensors collect water quality indicators such as water temperature, dissolved oxygen, chlorophyll a concentration, and nutrients in real time, and transmit the data to the early warning model. After preprocessing the input data, enhancing its temporal features, and calculating risk probabilities, the model outputs the algal bloom risk level and probability results for future time periods.
[0101] When the prediction results reach the preset risk threshold, the system automatically triggers the early warning mechanism and outputs early warning information through the monitoring platform, visualization interface, database or remote communication module, thereby providing auxiliary decision support for water source management, algal bloom prevention and control and emergency dispatch.
[0102] As one possible implementation of the present invention, the above-mentioned intelligent early warning method for algal blooms can be programmed into a computer program, stored in a non-volatile storage medium, and read and executed by one or more processors, thereby realizing some or all of the steps of data acquisition, preprocessing, time-series balancing, cluster embedding enhanced attention calculation, risk probability calculation, and early warning output described in the present invention.
[0103] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A smart prediction and early warning method for algal blooms based on cluster embedding and enhanced attention, characterized in that, include: Multidimensional water quality time-series data are collected in real time from monitoring points at water sources. Chlorophyll a concentration is a mandatory indicator in the multidimensional water quality time-series data, and the data also includes at least one or more of the following indicators: water temperature, dissolved oxygen, pH value, and several types of nutrients. Based on the preset threshold range of total chlorophyll a concentration, each monitoring sample is labeled with an ordinal algal bloom risk level label with a clear progressive relationship, forming a labeled time-series monitoring dataset. Missing value imputation and standardization are performed on the multidimensional water quality time series data in the labeled time series monitoring dataset to obtain complete and dimensionless standardized time series data; wherein, the missing value imputation adopts the Kalman filtering method and the standardization adopts Z-score standardization. Based on the standardized time-series data, to address the imbalance problem of algal bloom risk level sample categories, a time-series-constrained SMOTE enhancement method, namely time-SMOTE, is adopted. While maintaining time dependence, weighted interpolation oversampling is performed on minority class samples within the time-series neighborhood to generate a balanced time-series dataset. The balanced time-series data is input into a pre-constructed cluster embedding enhanced attention mechanism module. Through trainable cluster embedding parameters, bidirectional cluster attention calculation, cluster gating dynamic screening, and soft weight feature fusion are performed to enhance the encoding of multidimensional water quality time-series features and output the enhanced time-series feature representation. The enhanced temporal feature representation is input into a fully connected classifier trained under FocalLoss supervision to calculate the probability of occurrence of each algal bloom risk level and output the probability distribution corresponding to each level. Based on the probability distribution, an ordinal determination strategy based on cumulative probability is adopted to map the probability distribution to the corresponding algal bloom risk level, and generate early warning information containing risk level and / or risk probability, and output real-time early warning results for water source management.
2. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention as described in claim 1, characterized in that: The multidimensional water quality time series data also includes conductivity, turbidity, permanganate index, ammonia nitrogen content, total nitrogen concentration, total phosphorus concentration, and one or more of the following: green algae concentration, cyanobacteria concentration, diatom concentration, and cryptophyte concentration; all monitoring data are collected according to a preset sampling frequency, which is once every 0.5 to 2 hours.
3. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention as described in claim 1, characterized in that: The number of algal bloom risk level labels is three: low risk, medium risk and high risk, with a clear progressive relationship between the three risk levels; the historical data collected must cover at least one complete algal bloom cycle and include data from both the algal bloom season and the non-algal bloom season.
4. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention as described in claim 1, characterized in that: The Kalman filtering method fills in missing values in time series data based on a state-space model, which includes state equations and observation equations.
5. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention as described in claim 1, characterized in that: When performing weighted interpolation oversampling within the temporal neighborhood, the time-SMOTE defines the temporal neighborhood of any minority class sample as the set of adjacent minority class samples within the radius of the time window. The generation of new samples adopts a weighted interpolation method, assigning higher weight coefficients to neighboring samples with closer temporal distances. The weight coefficients decay exponentially as the temporal distance between samples increases.
6. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention as described in claim 1, characterized in that: The cluster embedding enhanced attention mechanism module is built based on the induced set attention structure. By introducing K trainable cluster embedding parameters to replace the global pairwise self-attention calculation in the traditional Transformer, the input sequence achieves feature aggregation through a bidirectional information interaction structure of "input features, cluster embedding, input features", thereby reducing the computational complexity from the square of the input sequence length to the product of the input sequence length and the number of clusters.
7. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention as described in claim 6, characterized in that: The cluster embedding parameters adopt an initialization method based on data distribution, which includes: firstly performing cluster analysis on the training data to obtain K cluster centers, and then adding a small random perturbation to each cluster center as the initial cluster embedding to avoid degradation during model training.
8. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention as described in claim 1, characterized in that: The bidirectional cluster attention computation includes two directions: input-to-cluster attention aggregation and cluster-to-input attention feedback. The input-to-cluster attention is used to aggregate the original high-dimensional input features into a finite number of cluster representations to achieve global temporal pattern compression. The cluster-to-input attention is used to feed the aggregated cluster features back into the input feature space.
9. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention as described in claim 1, characterized in that: The cluster-gated dynamic screening introduces a gating function into the cluster space, calculates the importance weight of each cluster through a multilayer perceptron, and uses an activation function to map the weight to a range of zero to one, thereby dynamically screening the importance of different clusters. The filtered cluster features are combined with the original cluster embeddings and then subjected to residual connection and normalization to preserve the original cluster embedding information and suppress invalid noise features; The soft-weight feature fusion introduces a dynamic temperature parameter to adjust the smoothness of the attention distribution, and the dynamic temperature parameter is adaptively adjusted according to the volatility of the input data.
10. The intelligent prediction and early warning method for algal blooms based on cluster embedding enhanced attention according to claim 1, characterized in that: The ordinal determination strategy based on cumulative probability includes: calculating the cumulative probability of the predicted probability of each risk level, setting a set of incremental risk thresholds, determining the corresponding algal bloom risk level when the cumulative probability crosses the corresponding threshold, and automatically triggering an early warning mechanism when the prediction result reaches the preset risk level threshold. The early warning output includes the future algal bloom risk level and the risk probability information of each level.
