Method for determining metal ions in seawater and detection system
By optimizing the hyperparameters and adaptive feature weighting layer of the BP neural network using the ant colony algorithm, and combining the peak height, peak width, and peak area characteristics of metal ions in seawater, the prediction error problem caused by a single feature value input in the electrochemical method is solved, and high-precision and robust detection of metal ion concentration in seawater is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- OCEANOGRAPHIC INSTR RES INST SHANDONG ACAD OF SCI
- Filing Date
- 2026-05-27
- Publication Date
- 2026-06-26
AI Technical Summary
In the prediction of metal ion concentration in seawater using existing electrochemical methods, the single feature value input method is easily affected by noise features, resulting in insufficient accuracy and robustness of the prediction model.
Ant colony optimization was used to optimize the hyperparameters of the BP neural network. The peak height, peak width and peak area of the metal ion voltammetry curve were used as input vectors. The concentration was predicted by the ACO-BP prediction model, and an adaptive feature weighting layer was introduced to dynamically allocate weights.
It significantly improves the accuracy of metal ion concentration prediction and the robustness of the model under different water quality conditions, and enables reliable detection of trace heavy metals in complex seawater matrices.
Smart Images

Figure CN122290773A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image data processing technology, specifically, it relates to a method and detection system for determining metal ions in seawater. Background Technology
[0002] There are many methods for determining metal ions in seawater, and in recent years, electrochemical methods have seen relatively rapid development. Based on classical polarography, electrochemical methods have evolved to include oscillometric polarography, differential pulse voltammetry, and others. Among these, differential pulse voltammetry (DPV) is a commonly used technique in electrochemical analysis that obtains detailed information about a target substance by measuring the relationship between current and potential. In seawater analysis, this method can be used to detect and quantify various components in seawater, especially trace amounts of metal ions, oxides, and reducing substances. DPV obtains a voltammetric curve related to potential changes by applying a series of pulsed voltages and measuring the current response. In this method, the electrode surface potential changes in a pulsed manner based on a baseline scan. The current difference before and after each pulse is recorded and compared with the potential, ultimately generating a voltammetric curve. By analyzing this curve, the type and concentration of metal ions in the target analyte can be determined.
[0003] When using voltammetric curves for quantitative analysis of metal ions, a univariate linear model is commonly used to predict the concentration of metal ions. This involves using a single characteristic value (usually peak height) of the characteristic peak of the voltammetric curve as the independent variable to establish a linear relationship for quantitative prediction. While this method is simple, the single characteristic value input ignores the inherent differences in importance between characteristics, making the prediction model susceptible to interference from irrelevant or noisy features, thus limiting the prediction accuracy and robustness. Summary of the Invention
[0004] This invention addresses at least one of the aforementioned technical problems in the background art by proposing a method for determining metal ions in seawater. By using the peak height, peak width, and peak area of the characteristic peaks of metal ions as input vectors for a newly constructed ACO-BP prediction model to predict concentration, the robustness of the prediction model and the accuracy of the prediction results can be significantly improved.
[0005] To solve the above-mentioned technical problems, the present invention adopts the following technical solution:
[0006] In one aspect, the present invention provides a method for determining metal ions in seawater, comprising:
[0007] Obtain the voltammetric curves of metal ions in seawater;
[0008] Obtain the characteristic peaks corresponding to different metal ions from the voltammetric curves;
[0009] Obtain the peak potential of each characteristic peak and calculate the peak height, peak width and peak area of each characteristic peak;
[0010] The type of metal ions in seawater can be identified based on the peak potential of each characteristic peak;
[0011] Assign optimal feature weights to the peak height, peak width, and peak area of each feature peak. After weighted calculation, the data is input into the trained ACO-BP prediction model to predict the concentration of metal ions in seawater.
[0012] Wherein, the optimal feature weight The trained ACO-BP prediction model was obtained using the following method:
[0013] The ant colony algorithm is used to optimize the hyperparameters in the BP neural network to construct the ACO-BP prediction model.
[0014] The input vector is constructed using the peak height, peak width, and peak area of different feature peaks, and then weighted element-wise with the trainable feature weights to obtain the weighted feature vector.
[0015] The weighted feature vector is input into the ACO-BP prediction model for forward propagation;
[0016] The trainable feature weights and the ACO-BP prediction model are trained using the backpropagation algorithm, and the optimal feature weights are output. And obtain the trained ACO-BP prediction model.
[0017] In another aspect, the present invention also proposes a detection system for metal ions in seawater, comprising:
[0018] The sample delivery module is used to automatically and quantitatively deliver seawater samples to be tested.
[0019] The detection module receives the seawater sample delivered by the sample delivery module and performs differential pulse voltammetry detection to obtain raw electrochemical data;
[0020] The discharge module is used to discharge seawater samples after testing.
[0021] The control module is used to coordinate the operation of the sample delivery module, detection module and sample sorting module, and to collect the raw electrochemical data and process it into detection data that meets communication requirements;
[0022] The host computer receives the detection data uploaded by the control module, generates a current-voltage curve based on the relationship between current and potential, and executes the following metal ion determination method:
[0023] Obtain the characteristic peaks corresponding to different metal ions from the voltammetric curves;
[0024] Obtain the peak potential of each characteristic peak and calculate the peak height, peak width and peak area of each characteristic peak;
[0025] The type of metal ions in seawater can be identified based on the peak potential of each characteristic peak;
[0026] Assign optimal feature weights to the peak height, peak width, and peak area of each feature peak. After weighted calculation, the data is input into the trained ACO-BP prediction model to predict the concentration of metal ions in seawater.
[0027] Wherein, the optimal feature weight The trained ACO-BP prediction model was obtained using the following method:
[0028] The ant colony algorithm is used to optimize the hyperparameters in the BP neural network to construct the ACO-BP prediction model.
[0029] The input vector is constructed using the peak height, peak width, and peak area of different feature peaks, and then weighted element-wise with the trainable feature weights to obtain the weighted feature vector.
[0030] The weighted feature vector is input into the ACO-BP prediction model for forward propagation;
[0031] The trainable feature weights and the ACO-BP prediction model are trained using the backpropagation algorithm, and the optimal feature weights are output. And obtain the trained ACO-BP prediction model.
[0032] Compared with the prior art, the advantages and positive effects of the present invention are mainly reflected in:
[0033] 1. This invention extracts three complementary feature parameters—peak height, peak width, and peak area—from the characteristic peaks of the voltammetric curves corresponding to different metal ions in seawater. These parameters are used to construct a multi-dimensional feature vector, which is then input into a deep learning model for ion concentration prediction. Compared to concentration prediction strategies that rely on only a single feature value (such as peak height) or two feature values, this multi-feature fusion approach can more comprehensively characterize the electrochemical response behavior of different metal ions, thereby effectively reducing misjudgments caused by fluctuations or interference from individual features. Experiments show that this method can significantly improve the accuracy of metal ion concentration prediction and the robustness of the model under different water quality conditions, providing a more reliable solution for the detection of trace heavy metals in complex seawater matrices.
[0034] 2. Before inputting the feature vector composed of peak height, peak width, and peak area into the prediction model, this invention designs and introduces a trainable adaptive feature weighting layer. This layer does not rely on manual experience to set fixed weights, but instead automatically learns and dynamically assigns different weight parameters to the three feature values of peak height, peak width, and peak area through the backpropagation algorithm during model training. This mechanism enables the model to autonomously focus on the key features that contribute more to the prediction task of the current specific metal ion or current concentration range, adaptively suppressing the interference of noise or redundant features, thereby optimizing the feature representation at the source and ultimately achieving a significant improvement in prediction accuracy.
[0035] 3. To address the problems of traditional BP neural networks relying on empirical tuning of hyperparameters, which is time-consuming, labor-intensive, and prone to getting trapped in local optima, this invention creatively employs an ant colony algorithm for intelligent global optimization of BP neural network hyperparameters. This method models the hyperparameter combination selection problem as an efficient combinatorial optimization problem by simulating the pheromone accumulation and path selection mechanism during ant colony foraging in nature. During the iteration process, the ant colony algorithm guides the search process to quickly converge to the high-performance hyperparameter region through the positive feedback and evaporation mechanism of pheromones, avoiding a large number of blind manual attempts. This not only shortens the model tuning time but also ensures that the constructed ACO-BP prediction model has higher accuracy, stronger stability, and better generalization ability.
[0036] 4. The detection system constructed in this invention achieves efficient, accurate, and real-time monitoring of heavy metal pollution in seawater. The system integrates functions such as automated sample introduction, electrochemical detection, data analysis, and result processing. The entire detection process is based on electrochemical principles, requiring no addition of any chemical reagents, simplifying pretreatment steps and accelerating detection speed.
[0037] Other features and advantages of the present invention will become clearer after reading the detailed description of the embodiments of the present invention in conjunction with the accompanying drawings. Attached Figure Description
[0038] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0039] Figure 1 This is a system architecture block diagram of one embodiment of the metal ion detection system in seawater proposed in this invention;
[0040] Figure 2This is a general flowchart of an embodiment of the method for determining metal ions in seawater proposed in this invention;
[0041] Figure 3 This is a flowchart of one embodiment of a method for obtaining characteristic values of metal ion characteristic peaks;
[0042] Figure 4 This is a schematic diagram of the peaks of cadmium and lead ions;
[0043] Figure 5 Yes Figure 4 The diagram shows the results of left and right boundary detection of the volt-ampere curve.
[0044] Figure 6 Is to acquire Figure 4 A schematic diagram showing the peak height, peak width, and peak area of the voltammetric curve;
[0045] Figure 7 This is a flowchart of optimizing hyperparameters in a backpropagation (BP) neural network using the ant colony optimization algorithm;
[0046] Figure 8 This is a flowchart of dynamically assigning weights to each feature value of a metal ion and training the model. Detailed Implementation
[0047] 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. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the protection scope of the present invention.
[0048] In the description of this invention, the consecutive numbers of the method steps are for ease of review and understanding. Considering the overall technical solution of this invention and the logical relationship between each step, adjusting the implementation order of the steps will not affect the technical effect achieved by the technical solution of this invention.
[0049] To achieve in-situ detection of seawater samples, this embodiment first designs a hardware system for automatically sampling and detecting metal ions in seawater, such as... Figure 1 As shown, it mainly includes a sample delivery module, a detection module, a sorting module, a control module, and a host computer. The control module coordinates the operation of the sample delivery module, the detection module, and the sorting module, while simultaneously collecting relevant data from each module and sending it to the host computer. The host computer then performs qualitative and quantitative analysis of heavy metal ions in the seawater sample.
[0050] Sample delivery module: This module is responsible for automatically and quantitatively delivering the seawater sample to the detection module. It mainly consists of a sample inlet tube and a peristaltic pump. The peristaltic pump operates under the command of the control module, precisely pumping a quantitative amount of seawater sample into the electrolytic cell of the detection module through the sample inlet tube to ensure that the sample volume used in each analysis is completely consistent.
[0051] The detection module is responsible for collecting seawater samples and performing differential pulse voltammetry to obtain raw electrochemical data. Its core components are an electrolytic cell and a potentiostat. The electrolytic cell contains a working electrode, a reference electrode, an auxiliary electrode, and a magnetic stirrer for mixing the sample. A magnetic stirrer can be installed below the electrolytic cell. After the seawater sample enters the electrolytic cell, the magnetic stirrer is activated, driving the magnetic stirrer to agitate the seawater sample, ensuring a uniform distribution of metal ions. Subsequently, with the cooperation of the three-electrode system and the potentiostat, the electrochemical deposition and dissolution process is completed, generating a detection signal.
[0052] Specifically, firstly, the working electrode, reference electrode, and auxiliary electrode are installed in the electrolytic cell. The working electrode can be a boron-doped diamond thin-film electrode, which possesses high electrochemical stability and is suitable for detecting trace substances in seawater samples. The reference electrode can be an Ag / AgCl electrode, which provides a stable reference potential, ensuring precise potential control during the experiment. The auxiliary electrode can be a carbon electrode to maintain current balance. A magnetic stir bar is placed in the electrolytic cell, and the sample is stirred using a provided magnetic stirrer to ensure uniform mixing of the seawater sample during electrochemical analysis and to prevent component stratification.
[0053] Secondly, the seawater samples in the electrolytic cell were subjected to electrochemical analysis, which included four stages: enrichment, quiescence, dissolution, and washing.
[0054] During the enrichment stage, the enrichment potential is set to -1.5V, and a magnetic stirrer is activated to agitate the sample, ensuring that the analyte is fully adsorbed onto the surface of the working electrode. To ensure sufficient adsorption, the enrichment time can be set to 340 seconds or more. At this point, by applying a specific potential, the target substance is adsorbed onto the surface of the working electrode, preparing it for the subsequent dissolution reaction.
[0055] The purpose of the resting phase is to stabilize the system and prevent unnecessary interference from stirring or potential changes in the electrolytic cell. During this phase, stirring is stopped, the potential is set to -1.36V, and the resting time is maintained for at least 20 seconds. The resting phase ensures that the substances in the electrolytic cell are not subject to external disturbances, thereby avoiding any impact on the stability of the electrochemical reaction.
[0056] During the dissolution phase, differential pulsed voltammetry was performed on the electrolytic cell. The scan potential could range from -1.35V to 0V, with a pulse duration of 50 milliseconds, a pulse amplitude of 50 mV, a step voltage of 4 mV, and a scan rate of 20 mV / s. By gradually increasing the potential on the working electrode, the substances adsorbed on the electrode surface gradually dissolve, generating a current response. The relationship between current and potential constitutes a voltammetric curve. By analyzing these data, the electrochemical characteristics of the sample can be determined.
[0057] The cleaning stage is to remove residual substances from the electrolytic cell to prevent contamination of the next experiment. The cleaning potential can be set to 0.3V, and the cleaning time should be at least 100 seconds. Simultaneously, a magnetic stirrer is activated to stir the sample. During the cleaning process, the residual impurities in the electrolytic cell are removed through the action of current, ensuring that the electrochemical reaction results in the next round of experiments are not contaminated.
[0058] The entire experiment was coordinated and controlled automatically by the control module. During the experiment, the control module directed the potentiostat to apply a potential waveform set according to the differential pulse voltammetry method to the three-electrode system of the electrolytic cell, and monitored the current response in real time, transmitting the detected voltage and current data to the control module. The potentiostat is a high-precision electrochemical measuring instrument whose core function is to precisely control the potential of the working electrode relative to the reference electrode and to measure the minute current signal generated on the working electrode.
[0059] Sample discharge module: This module discharges the sample to be tested from the electrolytic cell via a solenoid valve and a discharge pipe. The discharge pipe is connected to the electrolytic cell, and a solenoid valve is installed on the discharge pipe. The solenoid valve is controlled by the control module and automatically discharges the sample after the test is completed, ensuring the efficient circulation of the testing system.
[0060] The host computer receives the detection data uploaded by the control module, generates a current-voltage curve based on the relationship between current and potential, analyzes the current-voltage curve to identify the type of metal ions in the seawater sample, and uses deep learning algorithms to predict the concentration of metal ions.
[0061] The following is combined Figure 2 This paper provides a detailed explanation of the method for determining metal ions in seawater using a host computer.
[0062] S100. The adaptive characteristic peak feature value extraction algorithm is used to analyze the current-voltage curve, and the boundary detection is optimized by the dynamic threshold method to obtain the feature values of the metal ion characteristic peak.
[0063] Specifically, the following processes are involved, such as Figure 3 As shown:
[0064] S101. Preprocess the original voltammetric curve to generate the DPV voltammetric curve.
[0065] The current-voltage curve generated using the detection data is called the original current-voltage curve. The original current-voltage curve often contains high-frequency noise. To eliminate this interference and improve the purity of the current-voltage curve, this embodiment uses the Savitzky-Golay Filtering algorithm to smooth the original current-voltage curve.
[0066] SG filtering is a smoothing filtering technique based on local least squares, primarily used to eliminate noise in time series data. The core idea of SG filtering is to fit a polynomial within the local neighborhood of each data point, and then replace the original data point with the fitted polynomial value. This method eliminates noise while preserving the higher-order derivative information of the data, making it suitable for scenarios where data sharpness needs to be preserved.
[0067] In this embodiment, the highest order of the SG polynomial can be set to 4, and the bandwidth of the SG filter can be set to 13. After SG smoothing, high-frequency noise in the original volt-ampere curve is removed, and the smoothed curve ensures accurate acquisition of peak height and peak area. Therefore, the volt-ampere curve used in subsequent data analysis is the volt-ampere curve after SG smoothing. For clarity, it can be called the DPV volt-ampere curve.
[0068] S102. Obtain the peak of each characteristic peak from the DPV current-voltage curve.
[0069] Obtaining the peak is a crucial preparatory step for subsequent calculation of peak height, peak width, and peak area using algorithms. In this embodiment, the find_peaks function from the signal processing section of the SciPy library is used to identify the peak potential of each characteristic peak in the DPV current-voltage curve.
[0070] `find_peaks` is a function in the SciPy library used to detect local maxima (peaks) in one-dimensional data. It allows for precise control over peak identification through various parameter adjustments and is commonly used in signal processing, data analysis, and other fields to help identify important feature points in data.
[0071] This embodiment uses the find_peaks function to detect peak points in the DPV current-voltage curve and sets a minimum threshold (height=5µA, width=0.05V) to filter noise peaks. Figure 4 The peak positions of cadmium (Cd) and lead (Pb) ions are shown.
[0072] S103. The left and right boundaries of each characteristic peak are determined using the dynamic threshold method.
[0073] After determining the peak of each characteristic peak, it is necessary to define the left and right boundary points of each characteristic peak for subsequent calculation of the characteristic value of each characteristic peak.
[0074] Therefore, the following parameters are set in this embodiment:
[0075] window_size: This parameter represents the window size. When performing boundary detection, this parameter checks the range of the left and right data points of the current data point i. The purpose is to smooth the local data and avoid the influence of noise.
[0076] threshold_left_factor: This represents the left boundary threshold factor, which controls the sensitivity of left boundary determination.
[0077] threshold_right_factor: This represents the right boundary threshold factor, which controls the sensitivity of right boundary determination.
[0078] The above parameters can be set and dynamically adjusted by the user according to the actual application situation.
[0079] For each characteristic peak, the host computer runs a computer program that starts from the peak and moves to the left or right respectively until it finds the left and right boundary points that meet the conditions.
[0080] Specifically, we can start from the peak and move leftward, sequentially capturing data points within two window sizes, i.e., 2 × window_size, or the interval [i-window_size, i+window_size]. We calculate the current difference between adjacent data points within this window to obtain the local rate of change of the data within that window. Then, we calculate the mean square value (mean square of the squares) of each current difference within the window to reflect the overall intensity of change in the data within the window. We calculate the product of the left boundary threshold factor (threshold_left_factor) and the standard deviation of each current difference as the left boundary dynamic threshold. Next, we compare the mean square value with the left boundary dynamic threshold. If the mean square value is less than the left boundary dynamic threshold, it indicates that the data change within the current window is very gradual, and the data is in a relatively stable and flat region, meeting the boundary characteristics. In this case, we consider that the left boundary point has been found, and the coordinates of data point i are recorded. Conversely, if the mean square value is greater than or equal to the left boundary dynamic threshold, we consider that data point i is not a left boundary point and can be represented by 0. If the endpoints of the DPV current-voltage curve found still do not meet the condition of the left boundary point, the starting data point of the DPV current-voltage curve is defaulted to the left boundary point.
[0081] Secondly, starting from the peak and moving to the right, data points within a 2×window_size window are sequentially extracted in a step-by-step manner. The current difference between adjacent data points within this window is calculated to obtain the local rate of change of the data within the window. Then, the mean square value of each current difference within the window and the right boundary dynamic threshold are calculated. The right boundary dynamic threshold is the product of the right boundary threshold factor (threshold_right_factor) and the standard deviation of each current difference. Next, the mean square value is compared with the right boundary dynamic threshold. If the mean square value is less than the right boundary dynamic threshold, the right boundary point is considered found, and the coordinates of data point i are recorded. Conversely, if the mean square value is greater than or equal to the right boundary dynamic threshold, data point i is considered not a right boundary point and can be represented by 0. If the endpoint of the DPV volt-ampere curve still does not meet the right boundary point condition, the termination data point of the DPV volt-ampere curve is defaulted as the right boundary point.
[0082] The coordinates of the left and right boundary points of each characteristic peak are recorded separately, ultimately forming an index list containing the coordinates of the left and right boundary points corresponding to all characteristic peaks. This provides a foundation for subsequent analyses such as peak height, peak width, peak area calculation, and baseline correction, and allows for intuitive display of the detection results in a visualization interface. Figure 5 As shown.
[0083] S104. Calculate the peak height, peak width, and peak area of each characteristic peak.
[0084] For each characteristic peak, its left boundary point is denoted as (x_left, y_left), and its right boundary point is denoted as (x_right, y_right). The slope of the background current is calculated using the coordinates of these two points. Connecting the left and right boundary points yields the background current curve for that characteristic peak, as shown below. Figure 6 As shown. The width of the left and right boundary points is the peak width. A perpendicular line is drawn downwards from the peak to intersect the background current curve. The distance between this intersection point and the peak (the difference in the ordinate) is the peak height. The peak area is calculated by numerically integrating the region between the peak curve and the background current curve. Specifically, the `trapz()` function in the NumPy library can be used for integration to obtain the curve area `area_curve` and the baseline area `area_baseline`. The peak area is then the difference between the curve area and the baseline area, i.e., peak area `peak_area = area_curve - area_baseline`.
[0085] S200, perform qualitative analysis on the metal ions in the seawater sample to be tested.
[0086] Since different metal ions exhibit specific peak potentials on the DPV voltammetric curve, the types of metal ions in the seawater sample to be tested can be identified by comparing the peak potential with known potential values in the standard spectral library.
[0087] Of course, the problem of assigning multiple ion peaks can also be solved using Support Vector Machines (SVM). Specifically, features such as peak height, peak width, peak area, and peak potential can be extracted from the voltammetric curve data of each training sample. A radial basis function (RBF) kernel is selected, and the most suitable hyperparameters, C (penalty factor) and γ (RBF kernel parameters), are chosen through cross-validation. The dataset is divided into a 70% test set and a 30% validation set. The SVM model is trained using the test set, and the model's performance is optimized by adjusting C and the kernel parameter γ. The trained SVM model is then used to predict the types of metal ions in the DPV voltammetric curve data (i.e., the peak height, peak width, peak area, and peak potential determined above) during practical applications.
[0088] While theoretically peak potential can determine ion type, and peak height, width, and area are primarily concentration-dependent, in actual seawater, different metal ions exhibit varying electron transfer rates and diffusion coefficients on the electrode surface. By incorporating peak height, width, and area, the SVM model can identify the characteristic morphology of specific ions at different concentrations. This dual determination of position and shape effectively addresses baseline noise interference that easily occurs when relying solely on potential. Furthermore, the pH, salinity, and adsorption effects on the electrode surface of seawater samples can cause nonlinear shifts in peak potential. The SVM model can learn the correlation between potential shifts and changes in peak intensity and shape, thus accurately identifying metal ion types even with slight potential drifts using auxiliary features. Therefore, incorporating concentration-related features into the SVM model significantly improves the accuracy of ion peak assignment prediction.
[0089] S300, quantitative analysis of metal ions in the seawater sample to be tested.
[0090] To accurately predict the concentration of metal ions in seawater samples, this embodiment combines the Ant Colony Algorithm (ACO) with a Backpropagation (BP) neural network to form an ACO-BP prediction model. Simultaneously, the peak height, peak width, and peak area of the characteristic peaks of metal ions are used to form an input vector for training the ACO-BP prediction model and predicting concentration, thereby improving the accuracy of metal ion concentration detection.
[0091] This embodiment combines ant colony optimization (ACO) with neural networks to overcome some limitations that may be encountered in traditional neural network training, such as vanishing gradients and local optima. Utilizing ACO to optimize the neural network structure leverages the global search advantage of ACO during the optimization process, improving the training effect and adaptability of the neural network, especially demonstrating excellent performance in solving complex nonlinear and multimodal optimization problems. When used in conjunction with neural networks, ACO can enhance the network's global optimization capability and prevent it from getting trapped in local minima.
[0092] The basic idea of the ant colony algorithm is to gradually find the optimal solution to a problem by simulating the process of ants releasing and evaporating pheromones along a path. This embodiment uses the ant colony algorithm to optimize the hyperparameters in a backpropagation (BP) neural network, including the learning rate and the number of neurons. By simulating the pheromone communication mechanism during ant colony foraging in nature, the hyperparameter selection problem is modeled as a combinatorial optimization problem. Through a multi-round iterative strategy, the search process is guided to quickly converge to the high-performance hyperparameter region, thereby improving the accuracy and robustness of the final ACO-BP prediction model.
[0093] Specifically, optimizing the hyperparameters of a backpropagation (BP) neural network using the ant colony optimization algorithm involves determining the optimal combination of the number of neurons in the three hidden layers (layer1, layer2, layer3) and the learning rate (lr). This calculation is an iterative search process, such as... Figure 7 As shown, the specific steps include:
[0094] S311. Problem Definition and Pheromones Matrix Initialization.
[0095] Define a four-dimensional discrete hyperparameter space ,in:
[0096] layer1, the set of optional values ,For example ;
[0097] layer2, a set of optional values ,For example ;
[0098] layer3, a set of optional values ,For example ;
[0099] :lr, a set of optional values ,For example .
[0100] For each hyperparameter Each optional value Initialize a pheromone concentration In this embodiment, the following can be configured:
[0101] ;
[0102] in, Indicates the index of the hyperparameter, and ; In this embodiment, the index represents the optional value of the hyperparameter. Corresponding to different candidate values.
[0103] S312, Ant Path Construction (Generate Ant Solution).
[0104] In the In the nth iteration, the 1st Ants construct a solution through probabilistic selection. That is, a combination of hyperparameters.
[0105] For each hyperparameter ,Ant Select its optional value probability It is calculated using the following formula:
[0106] ;
[0107] in, ,here The minimum pheromone concentration is a probability normalization protection mechanism, set in this embodiment. This is to ensure that the denominator is not zero and to avoid algorithm stalling; Hyperparameters The number of possible values.
[0108] That is, for each hyperparameter ,Ant Choose probability Maximum optional value This constitutes a hyperparameter combination. .
[0109] S313, Fitness Assessment.
[0110] Ant Based on the combination of hyperparameters selected Instantiate a BP neural network model and train and evaluate it on a validation set.
[0111] To train the model, this embodiment prepares standard solutions of different concentrations based on the metal ions that may be present in seawater. These standard solutions are then combined to create various mixed solutions. These mixed solutions are input into the detection system of this embodiment to obtain corresponding voltammetric curves. The peak height, peak width, and peak area for each metal ion are calculated from these curves. The peak height, peak width, and peak area of each metal ion are used as independent variables, and their concentration as the dependent variable to form the training sample set. 70%-80% of the samples in the training sample set are divided into test samples to form the test set; the remaining 20%-30% are used as validation samples to form the validation set. The ACO-BP prediction model can be trained using the test set, and the coefficient of determination (R²) and root mean square error (RMSE) of the validation set can be used to evaluate the model's detection performance for cadmium (Cd²⁺) and lead (Pb²⁺) ions.
[0112] For example, to target the heavy metal ions "cadmium" and "lead" in seawater, seven standard solutions of cadmium and lead ions at different concentrations (5µg / L, 10µg / L, 20µg / L, 30µg / L, 40µg / L, 50µg / L, and 60µg / L) can be prepared, and these solutions can be mixed to form 49 cadmium ion (Cd) solutions. 2+ ) and lead ions (Pb 2+ A mixed solution was used to obtain voltammetric curves, and the peak height, peak width, and peak area were calculated. The peak height, peak width, and peak area of cadmium and lead were used as independent variables, and their concentrations as dependent variables. The 49 samples were randomly divided into 39 test samples to form a test set; and 10 validation samples to form a validation set, for use in model training and evaluation.
[0113] Define fitness function The coefficient of determination of the model on the validation set. ,Right now:
[0114] ;
[0115] in, This is the true concentration of the m-th sample. This is the model-predicted concentration for the m-th sample. It is the average value of the actual concentration. It is the number of samples in the validation set.
[0116] S314, Pheromone Update.
[0117] After each iteration, the pheromone will first evaporate, and then be enhanced based on the quality of the ant's solution.
[0118] Pheromone evaporation: Pheromone concentrations along all pathways are calculated according to the evaporation factor. To attenuate, that is:
[0119] ;
[0120] In this embodiment, a volatility factor can be set. .
[0121] Pheromon enhancement: An adaptive enhancement strategy is employed, focusing only on pheromone-enhanced pheromones with fitness higher than the current average fitness. A reward will be given for the solution.
[0122] The pheromone increment can be calculated using the following method. :
[0123] ;
[0124] Where Q is the pheromone intensity constant, and in this embodiment, Q can be set to 1.0; It is the average fitness of the t-th iteration, and , where M is the number of ants.
[0125] Combine pheromone volatilization and enhancement, and apply pheromone boundary control:
[0126] ;
[0127] in, In this embodiment, the maximum value of the pheromone concentration can be set to... The clip function is used to clip values. Limited to Within a certain range, to prevent pheromone levels from being too high or too low on certain paths.
[0128] S315. Iterate and output the optimal combination of hyperparameters.
[0129] Repeat steps S312-S314 above for a total of T iterations (in this embodiment, T=6 can be set). The algorithm finally outputs the hyperparameter combination with the highest fitness during the entire search process. ,Right now:
[0130] .
[0131] S316. Construct an ACO-BP prediction model using the optimal combination of hyperparameters.
[0132] Use the hyperparameter combination with the highest fitness The number of neurons in the three hidden layers (layer1, layer2, layer3) of the BP neural network is determined, and the optimizer in the BP neural network is configured using the optimized learning rate (lr) to form the ACO-BP prediction model.
[0133] Different eigenvalues of a characteristic peak contribute differently to concentration prediction, and this contribution changes dynamically due to factors such as sample differences and environmental noise. Using a single eigenvalue as input ignores the inherent differences in importance between features, making the prediction model susceptible to interference from irrelevant or noisy features, thus limiting the prediction accuracy and robustness of the model.
[0134] To address the aforementioned issues, this embodiment constructs an original feature vector u using three eigenvalues of each feature peak—peak height, peak width, and peak area—and preprocesses the original feature vector u to form an input vector x. Before inputting the input vector x into the prediction model, a trainable adaptive feature weighting layer is introduced. This layer automatically learns and dynamically assigns weights to each feature value through a backpropagation algorithm, enabling the prediction model to focus on features more critical to the current prediction task, ultimately achieving a significant improvement in prediction accuracy.
[0135] To achieve the above objectives, this embodiment adopts the following technical solution, combined with Figure 8 As shown:
[0136] S321. Construct the original feature vector using the peak height, peak width, and peak area of each metal ion.
[0137] Original feature vector: Where p represents the number of metal ions, and each metal ion contains 3 characteristic values, and Indicates the peak height of the p-th metal ion, Indicates the peak width of the p-th metal ion, This represents the peak area of the p-th metal ion.
[0138] During the model training phase, test samples from the test set can be used to adaptively adjust the ACO-BP prediction model and the trainable feature weights.
[0139] S322. Normalize the original feature vector to form the input vector.
[0140] The original feature vector u is preprocessed with normalization consistent with the test set to obtain the input vector x:
[0141] ;
[0142] Where n=3p, each element corresponds to a normalized result of a characteristic value of a metal ion.
[0143] S323. Assign initial weights to the input vector and perform normalization settings.
[0144] Define a set of trainable weight vectors with the same dimensions as the input vector x. And assign an initial value to each weight parameter. For example, assign an initial value of 1.
[0145] To ensure the stability of the weighting process and reflect the relative importance of the eigenvalues, the original weight parameters are normalized using the Softmax function, ensuring that the sum of all weight parameters is 1.
[0146] Normalized feature weights The calculation is as follows:
[0147] ;
[0148] in, This represents the normalized weight of the i-th eigenvalue.
[0149] S324, Eigenvalue weighted calculation.
[0150] Using normalized feature weights The input vector x is weighted element by element to obtain the weighted feature vector. :
[0151] ;
[0152] in, This represents element-wise multiplication (Hadamard product).
[0153] S325. The weighted eigenvectors... The data is input into the ACO-BP prediction model for forward propagation.
[0154] The neural network in this embodiment adopts the FNN (Feedforward Neural Network) structure and the BP (Back Propagation) training mechanism.
[0155] The weighted feature vector Input into the ACO-BP prediction model .in, It is a fully connected network mapping. The final output is a p-dimensional predicted concentration vector.
[0156] (1) First hidden layer:
[0157] ;
[0158] ;
[0159] in:
[0160] The weight matrix and bias vector of the first hidden layer;
[0161] The number of neurons in the first hidden layer, i.e., the number of neurons in the first layer optimized by ACO;
[0162] The output of the first hidden layer after linear transformation;
[0163] The activation value of the first hidden layer, that is, for The output after applying the ReLU activation function.
[0164] (2) Second hidden layer:
[0165] ;
[0166] ;
[0167] in:
[0168] The weight matrix and bias vector of the second hidden layer;
[0169] The number of neurons in the second hidden layer, i.e., the number of neurons in the second layer optimized by ACO;
[0170] The output of the second hidden layer after linear transformation;
[0171] The activation value of the second hidden layer, that is, for The output after applying the ReLU activation function.
[0172] (3) Third hidden layer:
[0173] ;
[0174] ;
[0175] in:
[0176] The weight matrix and bias vector of the third hidden layer;
[0177] The number of neurons in the third hidden layer, i.e., the number of neurons in the third layer optimized by ACO;
[0178] The output after linear transformation of the third hidden layer;
[0179] The activation value of the third hidden layer, that is, for The output after applying the ReLU activation function.
[0180] (4) Output layer (linear layer)
[0181] ;
[0182] in:
[0183] The weight matrix and bias vector of the output layer;
[0184] : represents the predicted concentration of p metal ions.
[0185] S326. Weight the features using the backpropagation algorithm. Train with the ACO-BP prediction model.
[0186] The entire ACO-BP prediction model includes feature weights. and classifier parameters Perform end-to-end training; where l=1,2,3,4.
[0187] Use ACO-optimized learning rate (lr) configuration optimizer.
[0188] The loss function is the predicted concentration. Compared with the true concentration The mean squared error (MSE) between them. For a batch The data loss function is:
[0189]
[0190] Return to step S324 for iterative calculations until the model's performance on the validation set no longer improves, at which point the iteration automatically terminates and the best historical model is saved.
[0191] This embodiment uses a validation set early stopping mechanism, the core of which is to monitor the model's performance on the validation set in real time and automatically terminate training when performance no longer improves. The specific scheme is as follows: After each iteration on the entire test set, the model uses data from the validation set for performance evaluation. The termination condition is based on the change in validation set loss: when the relative rate of change of validation set loss is less than a certain percentage threshold (e.g., less than 0.1%) for N consecutive iterations (e.g., N=20), the model is considered to have converged, and training terminates. If, during training, the validation set loss no longer decreases for M consecutive iterations (e.g., M=10) but instead begins to rise continuously, the model is considered to be overfitting. In this case, training is immediately terminated, and the model parameters corresponding to the lowest validation set loss are returned to obtain the model with the best generalization performance.
[0192] Through the backpropagation algorithm, the loss The gradient can update the classifier parameters. It also updated the trainable feature weights. This enables the adjustment of feature weights. Adaptive adjustment of network mapping.
[0193] S327, Output the optimal feature weights And obtain the trained ACO-BP prediction model.
[0194] S328. Utilizing optimal feature weights The trained ACO-BP prediction model was used to predict the concentration of metal ions in the seawater sample to be tested.
[0195] The peak height, peak width, and peak area of the characteristic peaks corresponding to each metal ion in the seawater sample to be tested are normalized to form an input vector x, which is then compared with the optimal feature weights. Perform element-wise weighting to obtain the weighted feature vector. Substitute the values into the trained ACO-BP prediction model to calculate the predicted concentration of each metal ion.
[0196] Using the three characteristic values of metal ion peaks—peak height, peak width, and peak area—to form the input vector of the prediction model significantly improves the accuracy of concentration prediction results compared to using only a single or two characteristic values.
[0197] The following sections describe the prediction of cadmium ions (Cd) in 49 training samples using a traditional univariate linear model, an ACO-BP prediction model using a single feature value "peak height" (named ACO-BP-H), an ACO-BP prediction model using two feature values "peak height" and "peak area" (named ACO-BP-HS), an ACO-BP prediction model using two feature values "peak height" and "peak width" (named ACO-BP-HW), and an ACO-BP prediction model using three feature values "peak height," "peak width," and "peak area" (named ACO-BP-HWS). 2+ ) and lead ions (Pb 2+ Concentration prediction was performed, and the prediction results are shown in the table below:
[0198]
[0199] In the table, R 2It is a commonly used metric to measure the goodness of fit of a regression model, representing the proportion of variance in the dependent variable explained by the model. Its value ranges from 0% to 100%, and the closer the value is to 100%, the better the model fits the data. RMSE (Root Mean Square Error) is an important statistical indicator for measuring the accuracy of a predictive model, used to assess the degree of deviation between predicted and actual values.
[0200] The data in the comparison table shows that, when using a traditional univariate linear model, the concentration of cadmium ions (Cd) in 49 training samples... 2+ ) and lead ions (Pb 2+ When performing concentration prediction, the univariate (peak height) linear model is used for cadmium ion (Cd) concentration prediction. 2+ ) and lead ions (Pb 2+ Under conditions of mutual interference, it is impossible to accurately measure cadmium ions (Cd). 2+ ) and lead ions (Pb 2+ The actual concentration of ).
[0201] The ACO-BP prediction model used in this embodiment is for predicting cadmium ions (Cd). 2+ ) and lead ions (Pb 2+ This method can be used to predict concentrations and has a stronger ability to suppress mutual interference compared to traditional univariate linear models.
[0202] Using the ACO-BP prediction model to predict cadmium ions (Cd) 2+ ) and lead ions (Pb 2+ When predicting concentrations, in addition to peak height, peak width and peak area also reflect the interaction information between metal ions, which helps to suppress the interaction interference between metal ions. Using peak height, peak width, and peak area as input variables, the concentration prediction results of the ACO-BP prediction model are more accurate than those using a single feature value or two feature values as input variables.
[0203] Of course, the above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for determining metal ions in seawater, characterized in that, include: Obtain the voltammetric curves of metal ions in seawater; Obtain the characteristic peaks corresponding to different metal ions from the voltammetric curves; Obtain the peak potential of each characteristic peak and calculate the peak height, peak width and peak area of each characteristic peak; The type of metal ions in seawater can be identified based on the peak potential of each characteristic peak; Assign optimal feature weights to the peak height, peak width, and peak area of each feature peak. After weighted calculation, the data is input into the trained ACO-BP prediction model to predict the concentration of metal ions in seawater. Wherein, the optimal feature weight The trained ACO-BP prediction model was obtained using the following method: The ant colony algorithm is used to optimize the hyperparameters in the BP neural network to construct the ACO-BP prediction model. The input vector is constructed using the peak height, peak width, and peak area of different feature peaks, and then weighted element-wise with the trainable feature weights to obtain the weighted feature vector. The weighted feature vector is input into the ACO-BP prediction model for forward propagation; The trainable feature weights and the ACO-BP prediction model are trained using the backpropagation algorithm, and the optimal feature weights are output. And obtain the trained ACO-BP prediction model.
2. The method for determining metal ions in seawater according to claim 1, characterized in that, The hyperparameters optimized by the ant colony algorithm include the number of neurons in the three hidden layers of the BP neural network: layer1, layer2, and layer3, as well as the learning rate lr.
3. The method for determining metal ions in seawater according to claim 2, characterized in that, The process of optimizing hyperparameters in a backpropagation neural network using the ant colony algorithm includes: Define a four-dimensional discrete hyperparameter space ,in: layer1, the set of optional values ; layer2, a set of optional values ; layer3, a set of optional values ; :lr, a set of optional values ; For each hyperparameter Each optional value Initialize a pheromone concentration ; Run the ant colony algorithm for each hyperparameter. ,Ant Choose probability Maximum optional value This constitutes a hyperparameter combination. ;in, ; ; It is the pheromone concentration in the t-th iteration; This is the minimum value set for pheromone concentration; Hyperparameters The number of possible values; Ant Based on the combination of hyperparameters selected Instantiate a BP neural network model, and perform training and fitness evaluation. Its fitness function is: ; After each iteration, the pheromone concentration is updated by first evaporating the pheromone and then enhancing it based on the quality of the ant's solution. After the iteration is complete, output the hyperparameter combination with the highest fitness. The number of neurons in the three hidden layers of the BP neural network is determined by using the hyperparameter combination with the highest fitness, and the optimizer in the BP neural network is configured using the optimized learning rate to form the ACO-BP prediction model.
4. The method for determining metal ions in seawater according to claim 3, characterized in that, The process of updating the pheromone concentration after each iteration includes: The pheromone concentration along all pathways was determined according to the volatile factor. To attenuate, that is: ; An adaptive enhancement strategy is adopted for pairs of computers with fitness levels higher than the current generation average fitness. The solution is rewarded, and the calculation formula is as follows: ; in, Q is the pheromone increment; Q is the pheromone intensity constant. It is the average fitness of the t-th iteration, and Where M is the number of ants; Combine pheromone volatilization and enhancement, and apply pheromone boundary control: ; The clip function is used to set the value... Limited to Within the range; This is the maximum value of the set pheromone concentration.
5. The method for determining metal ions in seawater according to claim 3, characterized in that, The fitness function for: ; in, This is the true concentration of the m-th sample. This is the model-predicted concentration for the m-th sample. It is the average value of the actual concentration. It refers to the number of samples.
6. The method for determining metal ions in seawater according to claim 1, characterized in that, The weighted feature vector is obtained using the following method: Construct the original feature vector using the peak height, peak width, and peak area of each metal ion. : ; Where p represents the number of metal ions, and each metal ion contains 3 characteristic values, and Indicates the peak height of the p-th metal ion, Indicates the peak width of the p-th metal ion, This represents the peak area of the p-th metal ion; Normalize the original feature vector u to obtain the input vector x: ; Where n=3p, each element corresponds to the normalized result of a characteristic value of a metal ion; Define a set of trainable weight vectors with the same dimensions as the input vector x. And assign initial values to each weight parameter; The original weight parameters are normalized using the Softmax function to obtain the normalized feature weights. The calculation formula is as follows: ; in, This represents the normalized weight of the i-th eigenvalue; Using normalized feature weights The input vector x is weighted element by element to obtain the weighted feature vector. : ; in, This indicates element-wise multiplication.
7. The method for determining metal ions in seawater according to any one of claims 1 to 6, characterized in that, The method for obtaining the peak potential is as follows: The peak points in the volt-ampere curve are detected using the find_peaks function in the signal processing section of the SciPy library. Set minimum thresholds height=5µA and width=0.05V to filter noise peaks.
8. The method for determining metal ions in seawater according to any one of claims 1 to 6, characterized in that, The methods for calculating peak height, peak width, and peak area include: Starting from the peak, move left or right respectively, and capture the data points in the left and right windows of each data point i in a step-by-step manner; Calculate the current difference between adjacent data points within the window to obtain the local rate of change of the data within the window; Calculate the mean square value of each current difference within the window; During the leftward movement, the left boundary threshold factor threshold_left_factor is calculated as the product of the standard deviation of each current difference, and this product is used as the left boundary dynamic threshold. During the rightward movement, the right boundary threshold factor threshold_right_factor is calculated as the product of the standard deviation of each current difference, and this product is used as the right boundary dynamic threshold. The calculated mean square value is compared with the dynamic threshold of the left boundary or the dynamic threshold of the right boundary; During the movement to the left, if the mean square value is less than the dynamic threshold of the left boundary, the left boundary point is considered to have been found, and the coordinates of data point i are recorded; otherwise, if the mean square value is greater than or equal to the dynamic threshold of the left boundary, data point i is considered not to be a left boundary point. During the movement to the right, if the mean square value is less than the dynamic threshold of the right boundary, the right boundary point is considered to have been found, and the coordinates of data point i are recorded; otherwise, if the mean square value is greater than or equal to the dynamic threshold of the right boundary, data point i is considered not to be a right boundary point. For each characteristic peak, its left boundary point is denoted as coordinates (x_left, y_left), and its right boundary point is denoted as coordinates (x_right, y_right). The slope of the background current is calculated using the coordinates of the two points, and the background current curve of the characteristic peak is obtained by connecting the left and right boundary points. The width of each characteristic peak is the width of the x-coordinate of its left and right boundary points; Draw a perpendicular line downwards from the peak of each characteristic peak and intersect the background current curve at the intersection point. Calculate the difference between the vertical coordinate of the intersection point and the peak peak, which is the peak height. The peak area of each characteristic peak is obtained by numerical integration over the region between the peak curve and the background current curve.
9. The method for determining metal ions in seawater according to claim 8, characterized in that, When searching for the left boundary point by moving from the peak to the left, if the endpoint of the current-voltage curve still does not meet the condition of the left boundary point, then the starting data point of the current-voltage curve is considered to be the left boundary point. When searching for the right boundary point by moving to the right from the peak, if the endpoint of the current-voltage curve still does not meet the condition of the right boundary point, then the termination data point of the current-voltage curve is considered to be the right boundary point.
10. A system for detecting metal ions in seawater, characterized in that, include: The sample delivery module is used to automatically and quantitatively deliver seawater samples to be tested. The detection module receives the seawater sample delivered by the sample delivery module and performs differential pulse voltammetry detection to obtain raw electrochemical data; The discharge module is used to discharge seawater samples after testing. The control module is used to coordinate the operation of the sample delivery module, detection module and sample sorting module, and to collect the raw electrochemical data and process it into detection data that meets communication requirements; The host computer receives the detection data uploaded by the control module, forms a current-voltage curve based on the relationship between current and potential, and executes the method for determining metal ions in seawater as described in any one of claims 1 to 9, so as to identify the type of metal ions in the seawater sample and predict the concentration of different metal ions.