Heavy metal ion spectrum identification method based on deep learning
By combining the SNGP feature extraction backbone and the Gaussian process classification head, the problems of peak position drift and cross-domain migration in heavy metal ion detection are solved, achieving accurate and stable identification and uncertainty quantification, which is suitable for engineering configuration.
Patent Information
- Application Number
- CN202511643333.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-11
- Publication Date
- 2026-02-13
AI Technical Summary
Existing technologies for heavy metal ion detection suffer from several drawbacks: peak position shifts with instrument and matrix changes, signal-to-noise ratio variations lead to a lack of distance-aware classification probability, and the wavelength index and feature correspondence are difficult to maintain consistency during cross-domain migration, resulting in a lack of adaptability and accuracy.
The SNGP feature extraction backbone is combined with the Gaussian process classification head to construct a wavelength prior mask by combining elemental spectral lines. The training phase updates the hierarchical Lipschitz upper bound and performs spectral norm projection by using position-dependent modulation kernel amplitude and length scale. The verification phase determines the recognition threshold and uncertainty threshold. The deployment phase outputs the ion class and key wavelength range.
Under conditions of slight peak shift and matrix differences, it improves the accuracy and robustness of identification, reduces the impact of cross-domain drift, provides stable identification output and uncertainty quantification, and supports the reusability of engineering configurations.
Smart Images

Figure CN121521767A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of spectral analysis and intelligent detection technology, and in particular to a method for spectral identification of heavy metal ions based on deep learning. Background Technology
[0002] One-dimensional spectroscopy is widely used in the detection of heavy metal ions. The engineering process usually starts with smoothing, baseline correction and standardization. Traditional methods rely on manual features combined with support vector machines or partial least squares to complete the discrimination. Deep learning methods use convolutional networks to learn spectral patterns, but under the conditions that the peak position drifts with the instrument and the matrix and the signal-to-noise ratio changes, resulting in local morphological instability, the classification probability lacks a distance perception basis and overconfidence occurs. Furthermore, it is difficult to keep the wavelength index and feature correspondence consistent when transferring across domains.
[0003] Research on uncertainty quantification has led to the emergence of modeling approaches centered on Gaussian processes. Common implementations employ stationary kernels and model uniformly across the entire wavelength range. However, they fail to convert elemental spectral information into computable wavelength prior masks to limit the spatial variation of kernel amplitude and length scale. Identification thresholds are often selected empirically and are not bound to the validation set process as reusable configurations. The one-to-one correspondence between spectra, priors, and features is disrupted at different stages due to the lack of unified rules.
[0004] To address the pain points in the industry, there is still a lack of an end-to-end process that involves: preprocessing the spectrum to enter the SNGP feature extraction backbone and outputting distance-aware feature representations; then using a Gaussian process classification head to construct non-stationary kernels under wavelength prior mask constraints to calculate the posterior of each ion class; updating the hierarchical Lipschitz upper bound parameters using posterior variance and implementing constraints with spectral norm projection during the training phase; determining the recognition threshold and uncertainty threshold and writing them into the model during the validation phase; and completing the labeling of key wavelength ranges based on the posterior response and wavelength prior mask during the deployment phase.
[0005] Therefore, how to provide a deep learning-based method for the spectral identification of heavy metal ions is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0006] One objective of this invention is to propose a deep learning-based method for the spectral identification of heavy metal ions. This invention employs an SNGP feature extraction backbone and a Gaussian process classification head, and combines a wavelength prior mask constructed from elemental spectral lines to perform position-dependent modulation of the kernel amplitude and length scale. During the training phase, the hierarchical Lipschitz upper bound is updated based on the posterior variance, and spectral norm projection is performed. During the verification phase, the identification threshold and uncertainty threshold are determined and solidified. During the deployment phase, the ion class, posterior mean, and posterior variance are output, and key wavelengths are labeled. This method has the advantages of high accuracy, strong robustness, and reusable engineering configuration.
[0007] A method for heavy metal ion spectral identification based on deep learning according to an embodiment of the present invention includes the following steps:
[0008] One-dimensional spectra and ion category labels are acquired, and smoothing, baseline correction and normalization are performed on the one-dimensional spectra in sequence to obtain preprocessed spectra;
[0009] Generate and store wavelength prior masks based on the element spectral line table;
[0010] A feature extraction backbone based on SNGP is constructed, spectral normalization is applied to each hidden layer and the upper bound parameter of the hierarchy Lipschitz is set, the preprocessed spectrum is input, and the distance-aware feature representation is output.
[0011] A Gaussian process classification head is set up, and the wavelength prior mask is used to perform position-dependent modulation of the kernel amplitude and length scale to form a non-stationary kernel. The distance-aware feature representation is received, and the posterior mean and posterior variance of each ion class are output.
[0012] The backbone parameters and non-stationary kernel parameters are extracted by minimizing the classification loss of labeled samples and jointly optimizing the features. The upper bound parameters of the layer Lipschitz are updated according to the posterior variance and the spectral norm projection is performed on the hidden layer weights to obtain the trained model.
[0013] Determine the recognition threshold and uncertainty threshold on the validation set and embed them into the trained model;
[0014] During the deployment phase, the spectrum to be measured is input and preprocessing consistent with that in the training phase is performed. The Gaussian process posterior is calculated, and the set of heavy metal ion categories and corresponding uncertainties are output based on the recognition threshold and uncertainty threshold. The key wavelength range is marked by combining the wavelength prior mask and posterior response to generate the recognition output.
[0015] Optionally, the SNGP includes:
[0016] The feature extraction backbone includes hidden layers;
[0017] For each hidden layer weight, spectral normalization is applied and the upper bound parameter of the layer Lipschitz is set;
[0018] The hierarchical Lipschitz upper bound parameter is updated based on the posterior variance output by the Gaussian process classification head;
[0019] During training, the hidden layer weights are constrained by spectral norm projection to ensure that the spectral norm does not exceed the corresponding level Lipschitz upper bound parameter.
[0020] During the deployment phase, the feature extraction backbone outputs distance-aware feature representations, which are then input into the Gaussian process classification head to calculate the posterior.
[0021] Optionally, the generation of the preprocessed spectrum specifically includes:
[0022] One-dimensional spectra are acquired and ion category labels are recorded. The start and end ranges of wavelengths, the number of sampling points and the wavelength sampling interval are determined to form wavelength and intensity data arranged in the sampling order.
[0023] Smoothing is performed by setting the window length and polynomial order, and then performing sliding polynomial fitting and replacement on the intensity data along the wavelength direction to obtain smooth intensity data.
[0024] Perform baseline correction, set the baseline smoothing coefficient and weighting coefficient, fit the background baseline intensity, and generate the corrected intensity data by subtracting the background baseline intensity from the smoothed intensity;
[0025] Perform standardization processing, calculate the mean and standard deviation of the correction intensity, and obtain standardized intensity data by removing the mean and scaling by the standard deviation;
[0026] Wavelength data and standardized intensity data are mapped according to the sampling index to generate preprocessed spectra, which are then stored after establishing a correspondence with ion category labels.
[0027] Optionally, the generation and storage of the wavelength prior mask specifically includes:
[0028] Determine a list of reference wavelengths from the elemental spectral line table and assign a number to each reference wavelength;
[0029] A wavelength neighborhood half-width is set for each reference wavelength to form a reference wavelength neighborhood parameter set;
[0030] A wavelength prior mask structure is established based on the wavelength sequence of the preprocessed spectrum. The sampling position that falls into the neighborhood of any reference wavelength is marked as one, and the sampling position that does not fall into the neighborhood of the reference wavelength is marked as zero. The nearest reference wavelength number and the corresponding neighborhood half width are recorded.
[0031] Prior weights are assigned to sampling positions marked as one, and are monotonically decreasing in the neighborhood according to the distance from the sampling wavelength to the nearest reference wavelength. Prior weights are set to zero for sampling positions marked as zero.
[0032] The wavelength prior mask is stored in a one-to-one correspondence with the wavelength sequence. The stored fields include mask label, prior weight, nearest reference wavelength number and neighborhood half width.
[0033] Optionally, the construction of the SNGP-based feature extraction backbone and the generation of distance-aware feature representations specifically include:
[0034] Using the wavelength sequence and normalized intensity sequence of the preprocessed spectrum as input, an index number is established according to the sampling order, and it corresponds one-to-one with the index position of the wavelength prior mask;
[0035] Determine the number and calculation order of hidden layers in the feature extraction backbone, establish weight parameters and bias parameters for each hidden layer, and mark the correspondence with the hidden layer number.
[0036] Configure spectral normalization for each hidden layer, set the level Lipschitz upper bound parameter for each hidden layer, and establish a mapping table of "hidden layer number - level Lipschitz upper bound parameter";
[0037] In the parameter update phase, the spectral norm of the hidden layer weights is estimated by exponential iteration, and the spectral norm projection is performed according to the mapping table to ensure that the spectral norm of the hidden layer weights does not exceed the corresponding level Lipschitz upper bound parameter.
[0038] Linear transformation and nonlinear activation are performed sequentially according to the hidden layer calculation order to generate intermediate representations, keeping the sampling index order unchanged and aligning with the index position of the wavelength prior mask;
[0039] At the output of the feature extraction backbone, a distance-aware feature representation is generated, the correspondence between "sampling index and distance-aware feature representation" is recorded, and the distance-aware feature representation is provided to the Gaussian process classification head.
[0040] Optionally, the setting of the Gaussian process classification head and the construction of the non-stationary kernel specifically include:
[0041] Determine the set of ion categories, establish sample numbers, and map each preprocessed spectrum, distance-sensing feature representation, and wavelength prior mask to the sample number and sampling index one by one;
[0042] For each preprocessed spectrum, the mask marker and prior weight are read from the wavelength prior mask according to the sampling index to form a position prior sequence, and the index is kept aligned with the distance-aware feature representation;
[0043] Set the kernel amplitude parameter generation rules and the length scale parameter generation rules. Use the position prior sequence as input to generate kernel amplitude parameter sequence and length scale parameter sequence. The two types of parameters correspond one-to-one with the wavelength sequence and record the correspondence with the sampling index.
[0044] Construct a non-stationary kernel, traverse the sampling index by sample pair, read two parameter sequences and the corresponding distance-aware feature representation components, calculate the position kernel weights and accumulate them along the wavelength direction to obtain the kernel values of the sample pairs, and write them into the kernel matrix in the order of sample numbers.
[0045] Inference is performed in the Gaussian process classification head using kernel matrix and distance-aware feature representation as input. For each category in the ion category set, the posterior mean and posterior variance are output and a correspondence is established with the sample number.
[0046] Store the correspondence between "sample number - ion category - posterior mean - posterior variance" for updating the hierarchical Lipschitz upper bound parameter and determining and calling the identification threshold and uncertainty threshold.
[0047] Optionally, the joint optimization training and hierarchical Lipschitz upper bound parameter update and spectral norm projection specifically include:
[0048] A labeled sample set is established, with each element consisting of a preprocessed spectrum, ion category label, sample number, sampling index, and wavelength prior mask index, and the order of the fields is fixed.
[0049] Initialize the feature extraction backbone parameters, non-stationary kernel parameters, Gaussian process classification head parameters, and hierarchical Lipschitz upper bound parameters to generate a mapping table of "hidden layer number - hierarchical Lipschitz upper bound parameters";
[0050] Set training control parameters, including batch size, maximum number of training epochs, learning rate plan, and stopping conditions;
[0051] Batch input is organized according to sample number and sampling index. The preprocessed spectrum is received by the feature extraction backbone and the distance-aware feature representation corresponding to the sampling index is output and aligned with the wavelength prior mask at the index position.
[0052] Based on the wavelength prior mask and wavelength sequence, kernel amplitude parameters and length scale parameters are generated. The Gaussian process classification head and distance-aware feature representation are input together to calculate the posterior mean and posterior variance corresponding to the ion category set, and establish a correspondence with the sample number and ion category.
[0053] The classification loss is calculated based on the ion category label and the posterior mean. The feature extraction backbone parameters and non-stationary kernel parameters are updated according to the preset optimization algorithm to maintain the consistency of the index alignment relationship.
[0054] Based on the posterior variance output by the Gaussian process classification head, the hierarchical Lipschitz upper bound parameter is updated using a monotonic mapping function and written into the "hidden layer number - hierarchical Lipschitz upper bound parameter" mapping table;
[0055] In the parameter update phase, spectral norm projection is performed to constrain the spectral norm of each hidden layer weight to not exceed the corresponding level Lipschitz upper bound parameter.
[0056] After the stopping condition is met, the main parameters, non-stationary kernel parameters, and Gaussian process classification head parameters are solidified to generate the trained model.
[0057] Optionally, the determination and solidification of the identification threshold and the uncertainty threshold specifically include:
[0058] Construct a validation set, whose elements consist of preprocessed spectra, ion class labels, sample numbers, sampling indexes, and wavelength prior mask indexes, with the field order consistent with the training phase.
[0059] Load the trained model, input the preprocessed spectrum of the validation set, and output the posterior mean and posterior variance of the ion class set from the Gaussian process classification head;
[0060] For each category in the ion category set, extract the posterior mean sequence and the binary label sequence according to the sample number. The binary label is derived from the value of the ion category label in that category.
[0061] A candidate identification threshold list is generated by taking the unique value of the posterior mean sequence. For each candidate identification threshold, the number of true positives, true negatives, false positives, and false negatives are counted. The identification threshold is selected according to the preset evaluation criteria, and the identification threshold value and the corresponding category are recorded.
[0062] For each category in the ion category set, the posterior variance sequence is extracted, the target coverage is set, the uncertainty threshold is determined according to the quantile position, and the uncertainty threshold value and the corresponding category are recorded.
[0063] The identification threshold and uncertainty threshold are written into the parameter storage area of the trained model to form a fixed configuration for deployment.
[0064] Optionally, the inference and key wavelength range labeling during the deployment phase specifically includes:
[0065] Receive the spectrum to be measured, establish a sampling index according to wavelength order, and perform smoothing, baseline correction and normalization in sequence to generate a preprocessed spectrum;
[0066] Load the wavelength prior mask, align it with the sampling index, and establish a one-to-one correspondence with the preprocessed spectrum;
[0067] The feature extraction backbone receives the preprocessed spectrum and outputs distance-aware feature representations according to the sampling index.
[0068] In the Gaussian process classification head, based on the non-stationary kernel parameters and distance-sensing features, the posterior mean and posterior variance are calculated according to the ion category set.
[0069] The threshold dictionary is read from the parameter storage area, the recognition threshold and uncertainty threshold are extracted according to the ion category, the posterior mean is compared with the recognition threshold, and the posterior variance is compared with the uncertainty threshold to generate the ion category set and uncertainty label.
[0070] Based on the wavelength prior mask, posterior mean, and posterior variance, key wavelength intervals are located on the sampling index, and key wavelength interval labels are generated.
[0071] The output identification results include the ion category set, posterior mean, posterior variance, and key wavelength range labeling.
[0072] The beneficial effects of this invention are:
[0073] This method completes the following steps within the same workflow: preprocessing the spectrum into the SNGP feature extraction backbone, generating distance-aware feature representations, constructing a non-stationary kernel based on wavelength prior masks for the Gaussian process classification head, and calculating the inference link of posterior mean and posterior variance for each ion class. During the training phase, the posterior variance drives the hierarchical Lipschitz upper bound parameters and performs spectral norm projection during parameter updates. During the validation phase, the recognition threshold and uncertainty threshold are determined according to a unified criterion and fixed into the model. During the deployment phase, the threshold configuration is read, the ion class set and corresponding uncertainty are output, and key wavelength interval labels are generated by combining wavelength prior masks and posterior responses under the premise of index alignment.
[0074] Under conditions of peak position shift, matrix differences, and instrument switching, distance-sensing feature representation, combined with wavelength position-dependent modulation of non-stationary nuclei, reduces the impact of cross-domain drift on the discrimination boundary. The classification probability is given by the Gaussian process classification head and the uncertainty is quantified by the posterior variance information. The identification threshold and the uncertainty threshold have the same source and are bound to the validation set process. The output includes the posterior mean, posterior variance, and ion class set. The key wavelength interval labeling is consistent with the element spectral table, which facilitates comparison and traceability.
[0075] At the engineering implementation level, the data structure always maintains a one-to-one correspondence between the preprocessed spectrum, wavelength prior mask, and distance-aware feature representation. The hierarchical Lipschitz upper bound parameters and non-stationary kernel parameters are fixed together with the threshold configuration after training. During the deployment phase, only preprocessing, feature extraction, and inference are executed sequentially to generate the recognition output. If it is necessary to expand the ion set, only the reference wavelength and neighborhood parameters need to be added to the element spectral table, and the wavelength prior mask and threshold configuration are updated synchronously. The maintenance process is clear, and the cost of going online and reviewing is controllable. Attached Figure Description
[0076] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:
[0077] Figure 1 This is a flowchart of a deep learning-based spectral identification method for heavy metal ions proposed in this invention.
[0078] Figure 2 This is a schematic diagram of the SNGP feature extraction backbone structure of a deep learning-based heavy metal ion spectral recognition method proposed in this invention. Detailed Implementation
[0079] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.
[0080] refer to Figure 1-2 A deep learning-based method for spectral identification of heavy metal ions includes the following steps:
[0081] One-dimensional spectra and ion category labels are acquired, and smoothing, baseline correction and normalization are performed on the one-dimensional spectra in sequence to obtain preprocessed spectra;
[0082] Generate and store wavelength prior masks based on the element spectral line table;
[0083] A feature extraction backbone based on SNGP is constructed, spectral normalization is applied to each hidden layer and the upper bound parameter of the hierarchy Lipschitz is set, the preprocessed spectrum is input, and the distance-aware feature representation is output.
[0084] A Gaussian process classification head is set up, and the wavelength prior mask is used to perform position-dependent modulation of the kernel amplitude and length scale to form a non-stationary kernel. The distance-aware feature representation is received, and the posterior mean and posterior variance of each ion class are output.
[0085] The backbone parameters and non-stationary kernel parameters are extracted by minimizing the classification loss of labeled samples and jointly optimizing the features. The upper bound parameters of the layer Lipschitz are updated according to the posterior variance and the spectral norm projection is performed on the hidden layer weights to obtain the trained model.
[0086] Determine the recognition threshold and uncertainty threshold on the validation set and embed them into the trained model;
[0087] During the deployment phase, the spectrum to be measured is input and preprocessing consistent with that in the training phase is performed. The Gaussian process posterior is calculated, and the set of heavy metal ion categories and corresponding uncertainties are output based on the recognition threshold and uncertainty threshold. The key wavelength range is marked by combining the wavelength prior mask and posterior response to generate the recognition output.
[0088] This invention utilizes a unified preprocessing spectral-SNGP feature extraction backbone-Gaussian process classification header link. It employs wavelength prior masks to perform position-dependent modulation of kernel amplitude and length scale to form a non-stationary kernel. With the cooperation of joint optimization and threshold solidification during the training phase, it simultaneously outputs ion class, posterior mean, posterior variance, and key wavelength range labeling. Therefore, it maintains stable recognition under peak position shifts, matrix changes, and cross-instrument conditions, and achieves uncertainty quantification and traceable interpretation.
[0089] In this embodiment, the SNGP includes:
[0090] The feature extraction backbone includes hidden layers;
[0091] For each hidden layer weight, spectral normalization is applied and the upper bound parameter of the layer Lipschitz is set;
[0092] The hierarchical Lipschitz upper bound parameter is updated based on the posterior variance output by the Gaussian process classification head;
[0093] During training, the hidden layer weights are constrained by spectral norm projection to ensure that the spectral norm does not exceed the corresponding level Lipschitz upper bound parameter.
[0094] During the deployment phase, the feature extraction backbone outputs distance-aware feature representations, which are then input into the Gaussian process classification head to calculate the posterior.
[0095] This invention introduces spectral normalization and sets hierarchical Lipschitz upper bound parameters in the feature extraction backbone. During the inference stage, the backbone outputs distance-aware feature representations and submits them to the Gaussian process classification head to calculate the posterior. During the training stage, the upper bound constraint is maintained through spectral norm projection, making the sensitivity of features to input perturbations controllable and consistent with the sample distance, thereby improving probability calibration and noise resistance performance and reducing the risk of overconfidence.
[0096] In this embodiment, the generation of the preprocessed spectrum specifically includes:
[0097] One-dimensional spectra are acquired and ion category labels are recorded. The start and end ranges of wavelengths, the number of sampling points and the wavelength sampling interval are determined to form wavelength and intensity data arranged in the sampling order.
[0098] Smoothing is performed by setting the window length and polynomial order, and then performing sliding polynomial fitting and replacement on the intensity data along the wavelength direction to obtain smooth intensity data.
[0099] Perform baseline correction, set the baseline smoothing coefficient and weighting coefficient, fit the background baseline intensity, and generate the corrected intensity data by subtracting the background baseline intensity from the smoothed intensity;
[0100] Perform standardization processing, calculate the mean and standard deviation of the correction intensity, and obtain standardized intensity data by removing the mean and scaling by the standard deviation;
[0101] Wavelength data and standardized intensity data are mapped according to the sampling index to generate preprocessed spectra, which are then stored after establishing a correspondence with ion category labels.
[0102] This invention performs smoothing, baseline correction, and standardization sequentially after acquiring one-dimensional spectra and ion tags to form preprocessed spectra. It unifies the start and end wavelengths, the number of sampling points, and the sampling interval, and establishes a one-to-one correspondence with the tags, thereby stabilizing the input distribution and suppressing baseline drift and amplitude differences. This provides a consistent index and dimension for wavelength prior mask construction, feature extraction, and subsequent inference.
[0103] In this embodiment, the generation and storage of the wavelength prior mask specifically includes:
[0104] Determine a list of reference wavelengths from the elemental spectral line table and assign a number to each reference wavelength;
[0105] A wavelength neighborhood half-width is set for each reference wavelength to form a reference wavelength neighborhood parameter set;
[0106] A wavelength prior mask structure is established based on the wavelength sequence of the preprocessed spectrum. The sampling position that falls into the neighborhood of any reference wavelength is marked as one, and the sampling position that does not fall into the neighborhood of the reference wavelength is marked as zero. The nearest reference wavelength number and the corresponding neighborhood half width are recorded.
[0107] Prior weights are assigned to sampling positions marked as one, and are monotonically decreasing in the neighborhood according to the distance from the sampling wavelength to the nearest reference wavelength. Prior weights are set to zero for sampling positions marked as zero.
[0108] The wavelength prior mask is stored in a one-to-one correspondence with the wavelength sequence. The stored fields include mask label, prior weight, nearest reference wavelength number and neighborhood half width.
[0109] This invention determines the reference wavelength and neighborhood parameters based on the elemental spectral line table, establishes a wavelength prior mask that corresponds one-to-one with the wavelength sequence, and assigns prior weights, the nearest reference wavelength number, and the neighborhood half-width. This enables the modeling side to focus in the key wavelength region and modulate the kernel amplitude and length scale in a position-dependent manner, thereby improving local discrimination ability and interpretability while maintaining index consistency.
[0110] In this embodiment, the construction of the SNGP-based feature extraction backbone and the generation of distance-aware feature representations specifically include:
[0111] Using the wavelength sequence and normalized intensity sequence of the preprocessed spectrum as input, an index number is established according to the sampling order, and it corresponds one-to-one with the index position of the wavelength prior mask;
[0112] Determine the number and calculation order of hidden layers in the feature extraction backbone, establish weight parameters and bias parameters for each hidden layer, and mark the correspondence with the hidden layer number.
[0113] Configure spectral normalization for each hidden layer, set the level Lipschitz upper bound parameter for each hidden layer, and establish a mapping table of "hidden layer number - level Lipschitz upper bound parameter";
[0114] In the parameter update phase, the spectral norm of the hidden layer weights is estimated by exponential iteration, and the spectral norm projection is performed according to the mapping table to ensure that the spectral norm of the hidden layer weights does not exceed the corresponding level Lipschitz upper bound parameter.
[0115] Linear transformation and nonlinear activation are performed sequentially according to the hidden layer calculation order to generate intermediate representations, keeping the sampling index order unchanged and aligning with the index position of the wavelength prior mask;
[0116] At the output of the feature extraction backbone, a distance-aware feature representation is generated, the correspondence between "sampling index and distance-aware feature representation" is recorded, and the distance-aware feature representation is provided to the Gaussian process classification head.
[0117] This invention configures spectral normalization and hierarchical Lipschitz upper bound parameters for each hidden layer in the SNGP feature extraction backbone, performs linear transformation and nonlinear activation in index order while maintaining alignment with the wavelength prior mask, generates distance-aware feature representation at the output end and establishes sampling index mapping, so that the front-end representation has bounded sensitivity and retains spectral structure, thereby providing a stable and usable input for the Gaussian process classification head.
[0118] In this embodiment, the setting of the Gaussian process classification head and the construction of the non-stationary kernel specifically include:
[0119] Determine the set of ion categories, establish sample numbers, and map each preprocessed spectrum, distance-sensing feature representation, and wavelength prior mask to the sample number and sampling index one by one;
[0120] For each preprocessed spectrum, the mask marker and prior weight are read from the wavelength prior mask according to the sampling index to form a position prior sequence, and the index is kept aligned with the distance-aware feature representation;
[0121] Set the kernel amplitude parameter generation rules and the length scale parameter generation rules. Use the position prior sequence as input to generate kernel amplitude parameter sequence and length scale parameter sequence. The two types of parameters correspond one-to-one with the wavelength sequence and record the correspondence with the sampling index.
[0122] Construct a non-stationary kernel, traverse the sampling index by sample pair, read two parameter sequences and the corresponding distance-aware feature representation components, calculate the position kernel weights and accumulate them along the wavelength direction to obtain the kernel values of the sample pairs, and write them into the kernel matrix in the order of sample numbers.
[0123] Inference is performed in the Gaussian process classification head using kernel matrix and distance-aware feature representation as input. For each category in the ion category set, the posterior mean and posterior variance are output and a correspondence is established with the sample number.
[0124] Store the correspondence between "sample number - ion category - posterior mean - posterior variance" for updating the hierarchical Lipschitz upper bound parameter and determining and calling the identification threshold and uncertainty threshold.
[0125] This invention utilizes wavelength prior masks to perform position-dependent modulation of kernel amplitude and length scale in the Gaussian process classification head to construct a non-stationary kernel. It uses distance-aware feature representation as input to calculate the posterior mean and posterior variance according to ion category, enabling the model to have differentiated characterization capabilities in different wavelength ranges and simultaneously providing quantitative uncertainty, thereby providing reliable distribution information for threshold selection and result interpretation.
[0126] In this embodiment, the joint optimization training and hierarchical Lipschitz upper bound parameter update and spectral norm projection specifically include:
[0127] A labeled sample set is established, with each element consisting of a preprocessed spectrum, ion category label, sample number, sampling index, and wavelength prior mask index, and the order of the fields is fixed.
[0128] Initialize the feature extraction backbone parameters, non-stationary kernel parameters, Gaussian process classification head parameters, and hierarchical Lipschitz upper bound parameters to generate a mapping table of "hidden layer number - hierarchical Lipschitz upper bound parameters";
[0129] Set training control parameters, including batch size, maximum number of training epochs, learning rate plan, and stopping conditions;
[0130] Batch input is organized according to sample number and sampling index. The preprocessed spectrum is received by the feature extraction backbone and the distance-aware feature representation corresponding to the sampling index is output and aligned with the wavelength prior mask at the index position.
[0131] Based on the wavelength prior mask and wavelength sequence, kernel amplitude parameters and length scale parameters are generated. The Gaussian process classification head and distance-aware feature representation are input together to calculate the posterior mean and posterior variance corresponding to the ion category set, and establish a correspondence with the sample number and ion category.
[0132] The classification loss is calculated based on the ion category label and the posterior mean. The feature extraction backbone parameters and non-stationary kernel parameters are updated according to the preset optimization algorithm to maintain the consistency of the index alignment relationship.
[0133] Based on the posterior variance output by the Gaussian process classification head, the hierarchical Lipschitz upper bound parameter is updated using a monotonic mapping function and written into the "hidden layer number - hierarchical Lipschitz upper bound parameter" mapping table;
[0134] In the parameter update phase, spectral norm projection is performed to constrain the spectral norm of each hidden layer weight to not exceed the corresponding level Lipschitz upper bound parameter.
[0135] After the stopping condition is met, the main parameters, non-stationary kernel parameters, and Gaussian process classification head parameters are solidified to generate the trained model.
[0136] This invention minimizes the classification loss of labeled samples and jointly optimizes the extraction of backbone parameters and non-stationary kernel parameters. It updates the hierarchical Lipschitz upper bound parameters based on the posterior variance and performs spectral norm projection during the parameter update stage to maintain the constraint, forming a training closed loop that uses uncertainty feedback to adjust the smoothness of the representation, thereby reducing gradient instability and overfitting and improving cross-domain generalization ability.
[0137] In this embodiment, the determination and solidification of the identification threshold and the uncertainty threshold specifically include:
[0138] Construct a validation set, whose elements consist of preprocessed spectra, ion class labels, sample numbers, sampling indexes, and wavelength prior mask indexes, with the field order consistent with the training phase.
[0139] Load the trained model, input the preprocessed spectrum of the validation set, and output the posterior mean and posterior variance of the ion class set from the Gaussian process classification head;
[0140] For each category in the ion category set, extract the posterior mean sequence and the binary label sequence according to the sample number. The binary label is derived from the value of the ion category label in that category.
[0141] A candidate identification threshold list is generated by taking the unique value of the posterior mean sequence. For each candidate identification threshold, the number of true positives, true negatives, false positives, and false negatives are counted. The identification threshold is selected according to the preset evaluation criteria, and the identification threshold value and the corresponding category are recorded.
[0142] For each category in the ion category set, the posterior variance sequence is extracted, the target coverage is set, the uncertainty threshold is determined according to the quantile position, and the uncertainty threshold value and the corresponding category are recorded.
[0143] The identification threshold and uncertainty threshold are written into the parameter storage area of the trained model to form a fixed configuration for deployment.
[0144] This invention derives the identification threshold and uncertainty threshold from the posterior mean and posterior variance using a unified criterion on the validation set and solidifies them into the trained model. This makes the discriminant boundary and verification rules in the inference stage clear in origin and reusable in configuration, reduces fluctuations caused by manual parameter tuning and ensures consistent output across different batches and devices, thereby providing stable support for engineering deployment.
[0145] In this embodiment, the inference and key wavelength range labeling during the deployment phase specifically includes:
[0146] Receive the spectrum to be measured, establish a sampling index according to wavelength order, and perform smoothing, baseline correction and normalization in sequence to generate a preprocessed spectrum;
[0147] Load the wavelength prior mask, align it with the sampling index, and establish a one-to-one correspondence with the preprocessed spectrum;
[0148] The feature extraction backbone receives the preprocessed spectrum and outputs distance-aware feature representations according to the sampling index.
[0149] In the Gaussian process classification head, based on the non-stationary kernel parameters and distance-sensing features, the posterior mean and posterior variance are calculated according to the ion category set.
[0150] The threshold dictionary is read from the parameter storage area, the recognition threshold and uncertainty threshold are extracted according to the ion category, the posterior mean is compared with the recognition threshold, and the posterior variance is compared with the uncertainty threshold to generate the ion category set and uncertainty label.
[0151] Based on the wavelength prior mask, posterior mean, and posterior variance, key wavelength intervals are located on the sampling index, and key wavelength interval labels are generated.
[0152] The output identification results include the ion category set, posterior mean, posterior variance, and key wavelength range labeling.
[0153] In the deployment phase, this invention reuses the consistent preprocessing and index alignment from the training phase, calculates the Gaussian process posterior, and generates an ion category set and corresponding uncertainty based on the recognition threshold and uncertainty threshold. At the same time, it combines the wavelength prior mask and posterior response to generate key wavelength interval labels, so that the output contains three types of information: judgment, confidence, and basis, thereby meeting the needs of quality control record keeping, error auditing, and online review.
[0154] Example 1:
[0155] To verify the feasibility of this invention in practice, it was applied to a one-dimensional spectral identification task for heavy metal ions. The samples covered water solutions, soil digestion solutions, and industrial wastewater standard mixtures. The target ion set included Pb, Cd, Hg, As, Cu, Zn, and a blank class. The spectra were acquired by two spectrometers participating in the training, and an additional spectrometer not participating in the training was used for cross-instrument verification. The raw data were sampled within a unified wavelength range and the intensity dimensions were unified. Preprocessing was performed in the order of smoothing, baseline correction, and standardization to generate preprocessed spectra.
[0156] The application process follows the pipeline defined in the claims. First, a wavelength prior mask is constructed based on the elemental spectral table and stored in alignment with the sampling index. Then, the preprocessed spectrum is input into the SNGP feature extraction backbone. Spectral normalization is performed in the hidden layer, and hierarchical Lipschitz upper bound parameters are set to obtain distance-aware feature representations. Subsequently, the Gaussian process classification head is entered. The wavelength prior mask is used to perform position-dependent modulation of the kernel amplitude and length scale to form a non-stationary kernel, and the posterior mean and posterior variance of each ion class are calculated. During the training phase, the hierarchical Lipschitz upper bound parameters are updated based on the posterior variance, and spectral norm projection is performed during parameter updates. During the validation phase, the recognition threshold and uncertainty threshold are determined according to a unified criterion and fixed in the model parameter storage area. During the deployment phase, the ion class set, posterior mean, posterior variance, and key wavelength interval labels are output under the same preprocessing and index alignment.
[0157] The data was organized using a fixed partitioning: 4,800 training data points paired with ion category labels, 1,200 validation data points used for threshold determination, and 2,000 test data points in the same domain and 800 cross-instrument data points. Evaluation was conducted using five metrics: macro-average F1, AUROC, ECE, cross-instrument F1, and key wavelength overlap rate. Macro-average F1 characterizes the multi-class recognition level, AUROC assesses ranking ability, ECE characterizes probability calibration, cross-instrument F1 measures migration stability, and key wavelength overlap rate is calculated using the cross-union ratio (CUNR) average with reference to the element's spectral line neighborhood.
[0158] The comparison settings select a one-dimensional ResNet structure with Softmax as the baseline, maintain the same preprocessing and data partitioning as the present invention, do not introduce wavelength prior masks and non-stationary kernels, and do not include the SNGP feature extraction backbone and the update of the upper bound parameters of the layer Lipschitz. The evaluation is repeated multiple times and the median is taken to reduce random fluctuations.
[0159] Table 1. Performance Comparison of Heavy Metal Ion Spectral Recognition Models under In-Domain and Cross-Instrument Conditions
[0160] index This invention model Baseline model (ResNet-1D+Softmax) Same domain macro average F1 0.951 0.923 Same domain AUROC 0.987 0.974 Same domain ECE↓ 0.021 0.067 Cross-instrument F1 0.918 0.846 Key wavelength overlap rate 0.73 0.36
[0161] Table 1 shows that, under the same instrument conditions, the model of this invention outperforms the baseline in macro-average F1 and AUROC and significantly reduces ECE. In cross-instrument testing, F1 remains at a higher level. The improved key wavelength overlap rate indicates that the key wavelength interval labeling is more consistent with the element spectral line neighborhood. Combined with the identification threshold and uncertainty threshold solidified in the verification stage, the deployment stage can stably generate ion class sets, posterior mean, posterior variance and key wavelength interval labeling.
[0162] The engineering process has two entry points: laboratory batch testing and on-site single-sample verification. The laboratory entry point imports spectrum and label files in batch processing mode. The system automatically loads the wavelength prior mask and completes index alignment. The SNGP feature extraction backbone and Gaussian process classification head are calculated sequentially and result reports are generated. The on-site entry point receives single spectra uploaded in real time by portable spectrometers. The system uses the preprocessing, feature extraction and inference configuration from the training. If the posterior mean exceeds the recognition threshold and the posterior variance is lower than the uncertainty threshold, the system directly returns the ion class and key wavelength interval label. If the posterior variance is higher than the threshold, the system returns a retest suggestion and retains the interval label for rapid comparison of elemental spectral line positions.
[0163] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for spectral identification of heavy metal ions based on deep learning, characterized in that, Includes the following steps: One-dimensional spectra and ion category labels are acquired, and smoothing, baseline correction and normalization are performed on the one-dimensional spectra in sequence to obtain preprocessed spectra; Generate and store wavelength prior masks based on the element spectral line table; A feature extraction backbone based on SNGP is constructed, spectral normalization is applied to each hidden layer and the upper bound parameter of the hierarchy Lipschitz is set, the preprocessed spectrum is input, and the distance-aware feature representation is output. A Gaussian process classification head is set up, and the wavelength prior mask is used to perform position-dependent modulation of the kernel amplitude and length scale to form a non-stationary kernel. The distance-aware feature representation is received, and the posterior mean and posterior variance of each ion class are output. The backbone parameters and non-stationary kernel parameters are extracted by minimizing the classification loss of labeled samples and jointly optimizing the features. The upper bound parameters of the layer Lipschitz are updated according to the posterior variance and the spectral norm projection is performed on the hidden layer weights to obtain the trained model. Determine the recognition threshold and uncertainty threshold on the validation set and embed them into the trained model; During the deployment phase, the spectrum to be measured is input and preprocessing consistent with that in the training phase is performed. The Gaussian process posterior is calculated, and the set of heavy metal ion categories and corresponding uncertainties are output based on the recognition threshold and uncertainty threshold. The key wavelength range is marked by combining the wavelength prior mask and posterior response to generate the recognition output.
2. The method for heavy metal ion spectral identification based on deep learning according to claim 1, characterized in that, The SNGP includes: The feature extraction backbone includes hidden layers; For each hidden layer weight, spectral normalization is applied and the upper bound parameter of the layer Lipschitz is set; The hierarchical Lipschitz upper bound parameter is updated based on the posterior variance output by the Gaussian process classification head; During training, the hidden layer weights are constrained by spectral norm projection to ensure that the spectral norm does not exceed the corresponding level Lipschitz upper bound parameter. During the deployment phase, the feature extraction backbone outputs distance-aware feature representations, which are then input into the Gaussian process classification head to calculate the posterior.
3. The method for heavy metal ion spectral identification based on deep learning according to claim 1, characterized in that, The generation of the preprocessed spectrum specifically includes: One-dimensional spectra are acquired and ion category labels are recorded. The start and end ranges of wavelengths, the number of sampling points and the wavelength sampling interval are determined to form wavelength and intensity data arranged in the sampling order. Smoothing is performed by setting the window length and polynomial order, and then performing sliding polynomial fitting and replacement on the intensity data along the wavelength direction to obtain smooth intensity data. Perform baseline correction, set the baseline smoothing coefficient and weighting coefficient, fit the background baseline intensity, and generate the corrected intensity data by subtracting the background baseline intensity from the smoothed intensity; Perform standardization processing, calculate the mean and standard deviation of the correction intensity, and obtain standardized intensity data by removing the mean and scaling by the standard deviation; Wavelength data and standardized intensity data are mapped according to the sampling index to generate preprocessed spectra, which are then stored after establishing a correspondence with ion category labels.
4. The method for heavy metal ion spectral identification based on deep learning according to claim 1, characterized in that, The generation and storage of the wavelength prior mask specifically includes: Determine a list of reference wavelengths from the elemental spectral line table and assign a number to each reference wavelength; A wavelength neighborhood half-width is set for each reference wavelength to form a reference wavelength neighborhood parameter set; A wavelength prior mask structure is established based on the wavelength sequence of the preprocessed spectrum. The sampling position that falls into the neighborhood of any reference wavelength is marked as one, and the sampling position that does not fall into the neighborhood of the reference wavelength is marked as zero. The nearest reference wavelength number and the corresponding neighborhood half width are recorded. Prior weights are assigned to sampling positions marked as one, and are monotonically decreasing in the neighborhood according to the distance from the sampling wavelength to the nearest reference wavelength. Prior weights are set to zero for sampling positions marked as zero. The wavelength prior mask is stored in a one-to-one correspondence with the wavelength sequence. The stored fields include mask label, prior weight, nearest reference wavelength number and neighborhood half width.
5. The method for heavy metal ion spectral identification based on deep learning according to claim 1, characterized in that, The construction of the SNGP-based feature extraction backbone and the generation of distance-aware feature representations specifically include: Using the wavelength sequence and normalized intensity sequence of the preprocessed spectrum as input, an index number is established according to the sampling order, and it corresponds one-to-one with the index position of the wavelength prior mask; Determine the number and calculation order of hidden layers in the feature extraction backbone, establish weight parameters and bias parameters for each hidden layer, and mark the correspondence with the hidden layer number. Configure spectral normalization for each hidden layer, set the hierarchical Lipschitz upper bound parameter for each hidden layer, and establish a mapping table of "hidden layer number - hierarchical Lipschitz upper bound parameter"; In the parameter update phase, the spectral norm of the hidden layer weights is estimated by exponential iteration, and the spectral norm projection is performed according to the mapping table to ensure that the spectral norm of the hidden layer weights does not exceed the corresponding level Lipschitz upper bound parameter. Linear transformation and nonlinear activation are performed sequentially according to the hidden layer calculation order to generate intermediate representations, keeping the sampling index order unchanged and aligning with the index position of the wavelength prior mask; At the output of the feature extraction backbone, a distance-aware feature representation is generated, and the correspondence between "sampling index - distance-aware feature representation" is recorded.
6. The method for heavy metal ion spectral identification based on deep learning according to claim 1, characterized in that, The setting of the Gaussian process classification head and the construction of the non-stationary kernel specifically include: Determine the set of ion categories, establish sample numbers, and map each preprocessed spectrum, distance-sensing feature representation, and wavelength prior mask to the sample number and sampling index one by one; For each preprocessed spectrum, the mask marker and prior weight are read from the wavelength prior mask according to the sampling index to form a position prior sequence, and the index is kept aligned with the distance-aware feature representation; Set the kernel amplitude parameter generation rules and the length scale parameter generation rules. Use the position prior sequence as input to generate kernel amplitude parameter sequence and length scale parameter sequence. The two types of parameters correspond one-to-one with the wavelength sequence and record the correspondence with the sampling index. Construct a non-stationary kernel, traverse the sampling index by sample pair, read two parameter sequences and the corresponding distance-aware feature representation components, calculate the position kernel weights and accumulate them along the wavelength direction to obtain the kernel values of the sample pairs, and write them into the kernel matrix in the order of sample numbers. Using kernel matrix and distance-aware feature representation as input, inference is performed in the Gaussian process classification head. For each category in the ion category set, the posterior mean and posterior variance are output and a correspondence is established with the sample number.
7. The method for heavy metal ion spectral identification based on deep learning according to claim 1, characterized in that, The joint optimization training and hierarchical Lipschitz upper bound parameter update and spectral norm projection specifically include: A labeled sample set is established, with each element consisting of a preprocessed spectrum, ion category label, sample number, sampling index, and wavelength prior mask index, and the order of the fields is fixed. Initialize the feature extraction backbone parameters, non-stationary kernel parameters, Gaussian process classification head parameters, and hierarchical Lipschitz upper bound parameters, and generate a mapping table of "hidden layer number - hierarchical Lipschitz upper bound parameters"; Set training control parameters, including batch size, maximum number of training epochs, learning rate plan, and stopping conditions; Batch input is organized according to sample number and sampling index. The preprocessed spectrum is received by the feature extraction backbone and the distance-aware feature representation corresponding to the sampling index is output and aligned with the wavelength prior mask at the index position. Based on the wavelength prior mask and wavelength sequence, kernel amplitude parameters and length scale parameters are generated. The Gaussian process classification head and distance-aware feature representation are input together to calculate the posterior mean and posterior variance corresponding to the ion category set, and establish a correspondence with the sample number and ion category. The classification loss is calculated based on the ion category label and the posterior mean. The feature extraction backbone parameters and non-stationary kernel parameters are updated according to the preset optimization algorithm to maintain the consistency of the index alignment relationship. Based on the posterior variance output by the Gaussian process classification head, the hierarchical Lipschitz upper bound parameter is updated using a monotonic mapping function and written into the "hidden layer number - hierarchical Lipschitz upper bound parameter" mapping table; In the parameter update phase, spectral norm projection is performed to constrain the spectral norm of each hidden layer weight to not exceed the corresponding level Lipschitz upper bound parameter. After the stopping condition is met, the main parameters, non-stationary kernel parameters, and Gaussian process classification head parameters are solidified to generate the trained model.
8. The method for heavy metal ion spectral identification based on deep learning according to claim 1, characterized in that, The determination and solidification of the identification threshold and uncertainty threshold specifically include: Construct a validation set, whose elements consist of preprocessed spectra, ion class labels, sample numbers, sampling indexes, and wavelength prior mask indexes, with the field order consistent with the training phase. Load the trained model, input the preprocessed spectrum of the validation set, and output the posterior mean and posterior variance of the ion class set from the Gaussian process classification head; For each category in the ion category set, extract the posterior mean sequence and the binary label sequence according to the sample number. The binary label is derived from the value of the ion category label in that category. A candidate identification threshold list is generated by taking the unique value of the posterior mean sequence. For each candidate identification threshold, the number of true positives, true negatives, false positives, and false negatives are counted. The identification threshold is selected according to the preset evaluation criteria, and the identification threshold value and the corresponding category are recorded. For each category in the ion category set, the posterior variance sequence is extracted, the target coverage is set, the uncertainty threshold is determined according to the quantile position, and the uncertainty threshold value and the corresponding category are recorded. The identification threshold and uncertainty threshold are written into the parameter storage area of the trained model to form a fixed configuration for deployment.
9. The method for heavy metal ion spectral identification based on deep learning according to claim 1, characterized in that, The inference and key wavelength range labeling during the deployment phase specifically include: Receive the spectrum to be measured, establish a sampling index according to wavelength order, and perform smoothing, baseline correction and normalization in sequence to generate a preprocessed spectrum; Load the wavelength prior mask, align it with the sampling index, and establish a one-to-one correspondence with the preprocessed spectrum; The feature extraction backbone receives the preprocessed spectrum and outputs distance-aware feature representations according to the sampling index. In the Gaussian process classification head, based on the non-stationary kernel parameters and distance-sensing features, the posterior mean and posterior variance are calculated according to the ion category set. The threshold dictionary is read from the parameter storage area, the recognition threshold and uncertainty threshold are extracted according to the ion category, the posterior mean is compared with the recognition threshold, and the posterior variance is compared with the uncertainty threshold to generate the ion category set and uncertainty label. Based on the wavelength prior mask, posterior mean, and posterior variance, key wavelength intervals are located on the sampling index, and key wavelength interval labels are generated. The output identification results include the ion category set, posterior mean, posterior variance, and key wavelength range labeling.
Citation Information
Cited By
Real-time remote sensing open world target detection method based on large model prior guidance
CN122090042A