X-ray fluorescence spectrum data anomaly detection method and equipment

By adopting a weakly supervised isolated forest approach, the problem of detecting anomalies in XRF spectral data under multiple scenarios and types was solved, achieving high-precision spectral data quality control and providing reliable data support.

CN121614749APending Publication Date: 2026-03-06BEIJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511893996.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-16
Publication Date
2026-03-06

AI Technical Summary

Technical Problem

Existing XRF spectral data quality control methods rely on human experience or fixed thresholds, making it difficult to adapt to multiple scenarios and types of spectral anomalies. Furthermore, traditional isolated forests have difficulty identifying local anomalies in high-dimensional spectral data, resulting in poor detection performance.

Method used

We employ a weakly supervised isolated forest approach, which involves spectral preprocessing, feature extraction, local region construction, and adaptive path length calculation to build an isolated forest model, enabling high-precision detection of various types of XRF spectral anomalies.

Benefits of technology

It improves the quality control capabilities of spectral data, can automatically identify multiple types of spectral anomalies, provides a reliable data foundation, and lays the groundwork for subsequent elemental analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121614749A_ABST
    Figure CN121614749A_ABST
Patent Text Reader

Abstract

The invention relates to an X-ray fluorescence spectrum data anomaly detection method, which comprises the following steps: S01, spectrum data acquisition and pretreatment: acquiring X-ray fluorescence spectrum original data to obtain a standardized spectrum; s02, spectral feature extraction: extracting features based on a standardized spectrum, and constructing a feature vector of a fixed dimension; s03, isolation forest model training: selecting a feature vector corresponding to a normal spectrum as a training set, obtaining a sub-sample set through random sampling, randomly selecting a feature dimension and a segmentation point in a feature value range for each sub-sample set, constructing T isolation trees to form an isolation forest, and learning feature space distribution of the normal spectrum; s04, abnormal score calculation: inputting the feature vector of the spectrum to be detected into the isolation forest; and S05, judging a threshold value and outputting a result. According to the technical scheme of the invention, the problem that the XRF spectrum is easily interfered by the environment, the instrument state and the noise in the actual measurement to cause the abnormal spectrum form is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of spectral analysis and artificial intelligence data processing technology, and proposes an anomaly detection method and system for X-ray fluorescence spectroscopy (XRF) data quality control based on weakly supervised isolated forests. It is applicable to the interdisciplinary field of intelligent identification of spectral measurement data and data processing of environmental monitoring instruments. Background Technology

[0002] With the widespread application of X-ray fluorescence spectroscopy (XRF) in environmental monitoring, materials analysis, industrial quality control, and geological exploration, ensuring the stability and accuracy of spectral data has become a key factor affecting the precision of XRF measurements. As a typical multi-channel counting sequence data, XRF spectra are easily affected by multiple factors such as environmental pollutants, instrument drift, electronic noise, and changes in scattering background. These factors can all lead to anomalies in the spectral data, including spectral line shifts, count anomalies, local peak intensity anomalies, and abrupt background changes, thus affecting subsequent qualitative and quantitative elemental analysis.

[0003] Existing XRF spectral data quality control methods primarily rely on human experience or rule-based threshold judgments. Traditional anomaly detection methods largely depend on high-quality labeled data. However, in practical XRF applications, labeling "normal spectra" and "abnormal spectra" requires extensive human experience and is highly dependent on instrument type and application scenario, resulting in high labeling costs and difficulty in widespread adoption. Furthermore, screening for anomalous samples by setting upper / lower limits for peak intensity, noise thresholds, and spectral line ratio ranges is ill-suited to the complex variations across different instruments, environments, and sample types. Simultaneously, the high dimensionality and complex distribution of spectral data, coupled with the fact that anomalies often exhibit multi-type mixed characteristics such as local peak abrupt changes, overall count fluctuations, and abnormal background increases, makes rule-based methods based on fixed thresholds difficult to generalize.

[0004] Weakly supervised or unsupervised anomaly detection methods for high-dimensional spectral data have gradually become a research hotspot. Among them, Isolation Forest has attracted widespread attention due to its independence from labeled data, its friendliness to high-dimensional data, and its ability to identify multiple types of anomalies. However, the direct application of traditional Isolation Forest to XRF spectral data still faces several challenges: spectral sequences contain strong statistical fluctuations, and the counting noise follows a Poisson distribution, making it difficult to accurately isolate local anomalies in the original spectrum within the tree partitioning structure; secondly, XRF spectra have complex peak structures, with significant differences between background and peak regions, making it easy to confuse anomalies when simply applying Isolation Forest to the entire spectrum; furthermore, continuous background anomalies caused by environmental pollution, local distortions caused by instrument errors, and peak shifts caused by detector drift inherently possess different structural characteristics, requiring more reasonable feature construction, path length modeling, and anomaly scoring mechanisms. Therefore, it is necessary to construct an anomaly detection method specifically for XRF spectral data, achieving automatic identification of anomalies caused by various reasons through improved feature representation, tree structure construction, and anomaly scoring mechanisms.

[0005] Against this backdrop, this invention proposes an XRF spectral data anomaly detection method and system based on weakly supervised isolated forest. By performing feature extraction, local region construction, weakly supervised modeling, adaptive path length calculation, and anomaly scoring on spectral sequences, it achieves high-precision detection of multiple types of XRF spectral anomalies, effectively improves the quality control capability of spectral data, and provides a reliable data foundation for subsequent XRF elemental analysis. Summary of the Invention

[0006] The present invention aims to solve at least one of the technical problems existing in the prior art or related art.

[0007] Therefore, one objective of this invention is to provide a method and device for detecting anomalies in X-ray fluorescence spectroscopy data based on weakly supervised isolated forests. This method can solve the problem that XRF spectra are easily affected by environmental factors, instrument conditions, and noise interference in actual measurements, leading to abnormal spectral morphology. It also addresses the shortcomings of existing quality control methods based on manual thresholds or annotation, which are difficult to adapt to multiple scenarios and types of spectral anomalies.

[0008] To achieve the above objectives, the first aspect of the present invention provides a method for detecting anomalies in X-ray fluorescence spectroscopy data based on weakly supervised isolated forests, comprising the following steps:

[0009] S01: Spectral data acquisition and preprocessing: Acquire raw X-ray fluorescence spectral data, which includes energy values, raw counts, background counts and net counts corresponding to N channels. Perform amplitude normalization, energy axis correction and smoothing and noise reduction on the raw data to obtain a standardized spectrum.

[0010] S02: Spectral Feature Extraction: Based on standardized spectra, extract global statistical features, energy distribution features, background features, energy band features, features of the region of interest, roughness features, and alignment-related features to construct a fixed-dimensional feature vector f=[f1,f2,…,f K ]ᵀ, where K is the feature dimension;

[0011] S03: Training the isolated forest model: Select the feature vector corresponding to the normal spectrum as the training set, obtain a sub-sample set through random sampling, randomly select the feature dimension and the split point within the range of the feature value for each sub-sample set, construct T isolated trees to form an isolated forest, and learn the feature space distribution of the normal spectrum;

[0012] S04: Anomaly Score Calculation: Input the feature vector of the spectrum to be detected into the isolated forest, and calculate the anomaly score for any training sample x. i Calculate its path length in the t-th isolation tree. The average path length is obtained by averaging. Based on standardization factor Where ψ is the number of samples, For harmonic numbers: Calculate anomaly scores : ;

[0013] S05: Threshold Determination and Result Output: Sort the anomaly scores of normal spectra in ascending order, according to the given false alarm rate. Sure quantile as threshold τ If the abnormal score of the spectrum to be detected If it is not, it is considered abnormal; otherwise, it is considered normal.

[0014] In the above technical solution, preferably, the amplitude normalization in step S01 is used to eliminate the overall intensity difference of the spectrum caused by changes in acquisition time or tube flow, and the energy axis correction is based on the reference peak position to achieve consistent alignment of peak positions between different samples.

[0015] In any of the above technical solutions, preferably, the global statistical features in step S02 include the total intensity, average intensity, variance, maximum value, minimum value and contrast of the net count sequence; the energy distribution features include the spectral center position, spectral width, skewness and kurtosis, which are obtained by weighted calculation of energy and net count; the background features include the background mean, background variance, background proportion and signal-to-noise ratio, which are obtained based on background region statistics.

[0016] In any of the above technical solutions, preferably, the energy band characteristics in step S02 include the average count, standard deviation, peak-to-background ratio, and number of local peaks for each energy band (low, medium, and high); the region of interest characteristics include the regional integral intensity and the ratio between regions; the roughness characteristics include the derivative mean, derivative energy, and number of zero crossovers, obtained based on the first-order difference of the net count; and the alignment correlation characteristics include the energy offset and linear calibration parameters.

[0017] In any of the above technical solutions, preferably, when constructing the isolation tree in step S03, the node partitioning rule is: if the value of the selected feature fⱼ is less than the random split point... If the sample enters the left subtree; if If the sample enters the right subtree, the division is repeated until the maximum depth of the tree is reached or the number of samples in a node is 1.

[0018] In any of the above technical solutions, preferably, the harmonic number mentioned in step S04 The standardization factor c(ψ) is used to standardize the path lengths for different tree depths and different subsample sizes.

[0019] In any of the above technical solutions, preferably, the false alarm rate α in step S05 ranges from 1% to 5%, and the threshold τ is determined by the scoring of normal samples. Quantiles are determined adaptively, eliminating the need for manually setting fixed thresholds.

[0020] The second aspect of the present invention provides a system for detecting anomalies in X-ray fluorescence spectroscopy data based on weakly supervised isolated forests, comprising:

[0021] Data acquisition and preprocessing module: used to acquire raw XRF spectral data, perform amplitude normalization, energy axis correction and smoothing and noise reduction, and output standardized spectra;

[0022] Feature extraction module: used to extract multi-dimensional features from standardized spectra and construct feature vectors;

[0023] Model training module: used to generate an isolated forest consisting of T isolated trees based on feature vectors from the normal spectrum through random sampling, random feature selection, and random splitting points;

[0024] Anomaly scoring module: used to calculate the average path length of the feature vector to be detected in the isolated forest, and combine it with a standardization factor to obtain anomaly score;

[0025] Threshold determination module: used to determine an adaptive threshold based on the abnormal score distribution of normal samples, compare the score of the sample to be detected with the threshold, and output the abnormal or normal determination result.

[0026] In the above technical solution, preferably, the data acquisition preprocessing module is also used to read instrument status parameters such as acquisition time, tube current, voltage and dead time, so as to provide instrument status-related data support for feature extraction.

[0027] In the above technical solution, preferably, the feature extraction module further includes an energy segmentation unit, which is used to divide the standardized spectrum into low-energy region, medium-energy region and high-energy region according to energy distribution, and separate the peak region and background region, so as to provide a structural basis for local feature extraction.

[0028] Compared with existing technologies, the advantages of the X-ray fluorescence spectral data anomaly detection method and equipment based on weakly supervised isolated forest provided by this invention are as follows: by performing feature extraction, local region construction, weakly supervised modeling, adaptive path length calculation and anomaly scoring on spectral sequences, it can achieve high-precision detection of multiple types of XRF spectral anomalies, effectively improve the quality control capability of spectral data, and provide a reliable data foundation for subsequent XRF elemental analysis. Attached Figure Description

[0029] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:

[0030] Figure 1 The overall flowchart of the X-ray fluorescence spectroscopy data anomaly detection method based on weakly supervised isolated forests involved in the embodiments of the present invention is shown;

[0031] Figure 2 A flowchart illustrating the XRF data feature extraction process according to an embodiment of the present invention is shown.

[0032] Figure 3 The diagram shows the structure of the isolated forest model according to an embodiment of the present invention. Detailed Implementation

[0033] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.

[0034] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.

[0035] To address the issue of XRF spectroscopy being susceptible to spectral morphology abnormalities due to environmental factors, instrument conditions, and noise interference in practical measurements, and the limitations of existing quality control methods based on manual thresholding or annotation in adapting to various scenarios and types of spectral anomalies, this invention provides a weakly supervised X-ray fluorescence spectroscopy anomaly detection method. This method preprocesses and constructs features from the spectrum, and utilizes a weakly supervised isolated forest model to characterize the normal structural distribution of the spectrum in the feature space, thereby achieving automatic identification of spectral anomalies. The method includes the following steps:

[0036] First, data preprocessing and feature extraction are performed to obtain a large amount of normal XRF spectral data. Each raw spectrum is treated as an independent sample. The XRF spectral data is essentially composed of a counting sequence of N energy channels, with each energy channel i corresponding to a specific energy E. i and includes the original count Raw i Background Counting (BG) i Net Count i Information such as these can be used to represent the entire spectrum as follows: ;

[0037] This sequence typically exhibits a distinct multi-peak structure, a gradually varying background, and random noise characteristics that change with count size. Furthermore, the overall spectral intensity, peak positions, and noise levels are affected by factors such as acquisition time, tube flow, and instrument temperature stability. To ensure the comparability of spectra obtained under different measurement conditions, this invention first preprocesses the spectral data, including amplitude normalization of the raw counts to eliminate overall intensity differences caused by variations in acquisition time or tube flow; and corrects the energy axis using reference peak positions to ensure consistent peak positions across different samples. In addition, considering the distinct regional characteristics of the spectral energy structure, this invention organizes the spectrum by energy segment after preprocessing to facilitate the subsequent extraction of local statistical features, peak region features, and background features.

[0038] Multi-dimensional features that characterize the overall intensity distribution, spectral structure, and noise properties of the spectrum are extracted from the original count, background count, and net count. Specifically, these include:

[0039] 1. Global statistical features such as total intensity, average intensity, variance, maximum value, minimum value, and contrast are calculated based on the net count sequence;

[0040] 2. Energy distribution characteristics such as spectral center position, spectral width, skewness, and kurtosis, obtained by weighting energy and net count, are used to characterize the spectral shape and energy distribution structure;

[0041] 3. Based on the background mean, background variance, background percentage, and signal-to-noise ratio obtained from background region statistics, these characteristics are used to reflect the noise level and quality of the spectrum.

[0042] 4. Average count, standard deviation, peak-to-background ratio, and number of local peaks for each energy range (low, medium, and high);

[0043] 5. Based on the predefined Region of Interest (ROI), the regional integral intensity and inter-regional ratio characteristics are calculated to describe the differences in elemental response within a specific energy range;

[0044] 6. Roughness features such as the mean of derivatives, derivative energy, and number of zero crossovers obtained from the first-order difference of net counts are used to measure the local fluctuations and noise distribution of the spectrum;

[0045] 7. Alignment-related features such as energy offset and linear calibration parameters obtained during energy axis alignment are used to characterize instrument drift.

[0046] Ultimately, a spectrum After preprocessing, it is mapped to a set of feature vectors: It is sent into the isolated forest as input for training and testing.

[0047] After completing spectral preprocessing and eigenvector construction, the eigenvectors corresponding to each spectrum are denoted as follows: ;

[0048] Where K is the feature dimension and N is the number of normal spectral samples. The isolated forest method forms a subset of samples by randomly sampling the normal spectral feature data multiple times, with each sampling containing a certain number of samples. During the construction of each tree, the feature dimension set is... Randomly select a feature and within its value range Randomly generate split points within. This constitutes the node partitioning rules:

[0049] .

[0050] This process is repeated until the maximum depth of the tree is reached or the number of samples in a node decreases to 1. The training phase constructs the tree by repeating the above random partitioning process. A single isolation tree for any training sample The path length of the tree in the t-th tree is denoted as . The average over all trees is: .

[0051] According to the IsolationForest theory, a single tree with a sample size of When the expected average path length is ,in For harmonic numbers: .

[0052] This expectation is used to standardize data for different tree depths and subsample sizes. Based on the average path length and the standardization factor, an anomaly score can be obtained for each spectrum. : .

[0053] The closer the score is to 1, the easier it is for the spectrum to be isolated in the feature space, and it belongs to a high-probability anomalous spectrum; the closer the score is to 0, the more consistent the spectral features are with normal samples, and it belongs to normal spectrum.

[0054] Finally, the obtained normal spectral anomaly scores were evaluated. The result is obtained by sorting in ascending order.

[0055] .

[0056] Given the expected false alarm rate 'a' (where a = 1% - 5%), the threshold is defined as the score of normal samples. Quantiles: ;

[0057] When the new spectrum is anomaly scored If the condition is met, it is considered abnormal; otherwise, it is considered normal.

[0058] like Figure 1 This is an overall flowchart of the X-ray fluorescence spectroscopy data anomaly detection method based on weakly supervised isolated forests according to the present invention.

[0059] S01: Spectral Data Acquisition and Preprocessing: This step acquires the raw spectral data output by the XRF instrument, including energy values ​​arranged by energy channel and the corresponding raw count (Raw), background count (BG), and net count (Net), while reading instrument status parameters such as acquisition time, tube current, and voltage; preprocessing operations such as count normalization, energy axis alignment, and smoothing and denoising are performed on the raw spectrum to unify the spectra obtained under different measurement conditions into comparable standardized spectra.

[0060] S02: Spectral Feature Extraction: Based on the preprocessed spectrum, this step performs structural analysis on the spectrum and extracts global statistical features such as total count, centroid, and variance; energy band features such as average count, standard deviation, and peak-to-background ratio of different energy bands; peak-related features such as peak height, peak area, full width at half maximum (FWHM), and peak position shift of characteristic peaks; and background and state features such as background level, background slope, and instrument operating parameters. The above-mentioned features are combined to form a fixed-dimensional spectral feature vector, which is used as the input for subsequent models.

[0061] S03: Training the isolated forest model: This step is based on a large number of spectral feature vectors in normal working condition. Multiple isolated trees are constructed by randomly selecting feature dimensions and randomly generating partition thresholds to form an isolated forest model, which is used to characterize the statistical distribution structure of normal spectra in the feature space and realize the learning of the feature regions of normal samples.

[0062] S04: Anomaly Score Calculation: In this step, the feature vector of the spectrum to be detected is input into the trained isolated forest model, and the path length of the spectrum in each isolated tree is calculated. The average path depth of the sample is obtained by averaging the path lengths of all isolated trees, and the corresponding anomaly score is calculated based on the average path depth. The shorter the path, the higher the anomaly score is obtained, which reflects the degree to which the spectrum deviates from the normal distribution.

[0063] S05: Threshold Determination and Result Output: This step adaptively determines the anomaly determination threshold based on the anomaly score distribution of the normal spectrum. The anomaly score of the spectrum to be tested is compared with the threshold. When the anomaly score is greater than or equal to the threshold, it is determined to be an abnormal spectrum. When the anomaly score is less than the threshold, it is determined to be a normal spectrum. The corresponding anomaly mark or alarm information is then output.

[0064] like Figure 2 As shown in the flowchart, the XRF spectral data feature extraction flowchart provided by this invention illustrates the main processing steps from raw spectral input to the formation of spectral feature vectors. First, the spectral data output by the XRF instrument, including Raw, BG, and Net data, as well as instrument status parameters such as acquisition time, current, voltage, and dead time, are input into the data preprocessing module. Normalization eliminates counting differences under different test conditions, peak position shifts are corrected through energy axis alignment, and high-frequency noise is suppressed using a smoothing algorithm to obtain a structurally stable preprocessed spectrum. Subsequently, based on the energy distribution characteristics of the spectrum, it is divided into different energy ranges such as low-energy, medium-energy, and high-energy regions, and the main peak region and background region are separated, providing a structural basis for the extraction of local features.

[0065] Based on preprocessing and energy band segmentation, this invention further extracts multiple types of spectral features, including global statistical features describing the overall intensity and distribution of the spectrum, energy band statistical features characterizing the variation trends of different energy bands, peak correlation features reflecting the peak morphology of elemental characteristics, and background and state features characterizing background changes and instrument operating status. By combining these features, a fixed-dimensional spectral feature vector is constructed, providing input data for the subsequent isolated forest anomaly detection model.

[0066] Figure 3 This is a structural diagram of the isolated forest model of the present invention, which shows the flow path of spectral feature vectors in the model and the anomaly detection process.

[0067] The spectral feature vector input module receives the spectral feature vectors obtained through preprocessing and feature extraction, providing a unified input format for the subsequent isolated forest model. This feature vector contains information reflecting the overall spectral morphology, energy range variations, peak shapes, and background trends, comprehensively characterizing the statistical and structural features of the spectral data.

[0068] The isolation forest construction module: By randomly partitioning the normal spectral features input during the training phase, multiple isolation trees with distinct structures are formed, collectively constituting the isolation forest. The path depths across all isolation trees are statistically analyzed and averaged to obtain the average path depth of each data point in the isolation forest model. This average path depth is then normalized and used as the anomaly score.

[0069] Threshold determination module: Sorts the abnormal scores of each normal data point in ascending order, and calculates its quantile as the threshold according to a given proportion. For the test data entering the model, its abnormal score is calculated and compared with the threshold; if it is greater than the threshold, it is determined to be abnormal data, otherwise it is normal data.

[0070] Based on the above, Figures 1 to 3 Accordingly, this application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the X-ray fluorescence spectral data anomaly detection method based on weakly supervised isolated forests of any of the above embodiments.

[0071] Based on this understanding, the technical solution of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as CD-ROM, USB flash drive, mobile hard drive, etc.) and includes several instructions to cause a computer device (such as personal computer, server, or network device, etc.) to execute the methods of various implementation scenarios of this application.

[0072] Based on the above, Figures 1 to 3 To achieve the above objectives, this application also provides a computer device, including a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to implement the steps of the X-ray fluorescence spectral data anomaly detection method based on weakly supervised isolated forests in any of the above embodiments.

[0073] Optionally, the computer device may also include a user interface, a network interface, a camera, radio frequency (RF) circuitry, sensors, audio circuitry, a Wi-Fi module, etc. The user interface may include a display screen, input units such as a keyboard, etc., and optional user interfaces may also include USB ports, card reader ports, etc. The network interface may optionally include standard wired interfaces, wireless interfaces (such as Bluetooth interfaces, Wi-Fi interfaces), etc.

[0074] Those skilled in the art will understand that the computer device structure provided in this embodiment does not constitute a limitation on the computer device, and may include more or fewer components, or combine certain components, or have different component arrangements.

[0075] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages and stores the hardware and software resources of a computer device, supporting the operation of information processing programs and other software and / or programs. The network communication module is used to enable communication between the various components within the storage medium, as well as communication with other hardware and software within the physical device.

[0076] In this invention, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance; the term "multiple" refers to two or more unless otherwise explicitly defined. The terms "install," "connect," "link," and "fix" should be interpreted broadly. For example, "connect" can be a fixed connection, a detachable connection, or an integral connection; "link" can be a direct connection or an indirect connection through an intermediate medium. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.

[0077] In the description of this invention, it should be understood that the terms "upper," "lower," "left," "right," "front," "rear," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or unit referred to must have a specific orientation or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this invention.

[0078] In the description of this specification, the terms "one embodiment," "some embodiments," "specific embodiment," etc., refer to a specific feature, structure, material, or characteristic described in connection with that embodiment or example, which is included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0079] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A weakly supervised Isolation Forest based X-ray fluorescence spectroscopy data anomaly detection method, characterized in that, Comprising the following steps: S01: spectral data acquisition and preprocessing: obtaining X-ray fluorescence spectrum original data, the original data containing energy values corresponding to N energy channels, original counts, background counts and net counts, performing amplitude normalization, energy axis correction and smoothing denoising processing on the original data to obtain standardized spectrum; S02: Spectral feature extraction: Based on the normalized spectrum, extract global statistical features, energy distribution features, background features, energy segment features, energy region of interest features, roughness features, and alignment features, and construct a fixed dimension feature vector f = [f1, f2, …, fK], where K is the feature dimension. K ]ᵀ, where K is the feature dimension. S03: isolation forest model training: selecting the feature vector corresponding to the normal spectrum as the training set, obtaining a sub-sample set by random sampling, randomly selecting feature dimensions and split points in the feature value range of each sub-sample set, constructing T isolation trees to form an isolation forest, and learning the feature space distribution of the normal spectrum; S04: Anomaly score calculation: input the feature vector of the spectrum to be detected into the Isolation Forest, calculate the path length of any training sample x i in the tth Isolation Tree , and average to get the average path length based on the standardization factor , where ψ is the number of samples, is the harmonic number: , and calculate the anomaly score : ; S05: Threshold decision and result output: Sort the abnormal scores of normal spectra in ascending order, and output the results according to the given false positive rate determining the quantile as the threshold τ, if the abnormal score of the spectrum to be detected is greater than τ, it is determined to be abnormal, otherwise it is determined to be normal.

2. The method of claim 1, wherein, The amplitude normalization in step S01 is used to eliminate the overall intensity difference of the spectrum caused by the change of the acquisition time or the tube flow, and the energy axis correction is based on the reference peak position to realize the consistent alignment of the peak position between different samples.

3. The method of claim 1, wherein, The global statistical features in step S02 include total intensity, average intensity, variance, maximum value, minimum value and contrast of the net count sequence; the energy distribution features include spectrum center position, spectrum width, skewness and kurtosis, which are calculated by energy and net count weighting; the background features include background mean, background variance, background proportion and signal-to-noise ratio, which are obtained based on background area statistics.

4. The method of claim 1, wherein, The energy segment features in step S02 include average count, standard deviation, peak-to-background ratio and local peak number of low, medium and high energy segments; the energy region of interest features include regional integral intensity and inter-region ratio; the roughness features include derivative mean, derivative energy and zero-crossing number, which are obtained based on the first-order difference of the net count; the alignment-related features include energy offset and linear calibration parameters.

5. The method of claim 1, wherein, In step S03, when constructing the isolation tree, the node division rule is: if the value of the selected feature is less than the random split point , the sample enters the left subtree; if , the sample enters the right subtree, and the division is repeated until the maximum depth of the tree is reached or the number of node samples is 1.

6. The method of claim 1, wherein, The harmony number in step S04 The standardization factor c(ψ) is used to normalize the path length for different tree depths and different sub-sample sizes.

7. The method of claim 1, wherein, The false positive rate a in step S05 ranges from 1% to 5%, and the threshold value t is determined by the score of the normal sample The quantile self-adaptive determination does not need to manually set a fixed threshold value.

8. A weakly supervised Isolation Forest based X-ray fluorescence spectroscopy data anomaly detection system, characterized in that, Comprising: A data acquisition and preprocessing module for obtaining XRF original spectrum data, performing amplitude normalization, energy axis correction and smoothing denoising processing, and outputting standardized spectrum; A feature extraction module for extracting multi-dimensional features from the standardized spectrum to construct a feature vector; A model training module for generating T isolation trees based on the feature vector of the normal spectrum through random sampling, random selection of features and random split points to construct an isolation forest; An anomaly scoring module for calculating the average path length of the feature vector to be detected in the isolation forest, and obtaining the anomaly score combined with the standardization factor; A threshold determination module for determining an adaptive threshold based on the anomaly score distribution of normal samples, comparing the score of the sample to be detected with the threshold, and outputting the abnormal or normal determination result.

9. The system of claim 8, wherein, The data acquisition and preprocessing module is also used to read instrument state parameters such as acquisition time, tube flow, voltage and dead time, to provide instrument state related data support for feature extraction.

10. The system of claim 8, wherein, The feature extraction module further includes an energy segment division unit for dividing the standardized spectrum into low energy region, medium energy region and high energy region according to energy distribution, and separating peak region and background region to provide a structural basis for local feature extraction.