Quality Detection Method for Chinese Medicine Processing Based on Spectral Analysis
The NIR spectrum and HPLC fingerprint of traditional Chinese medicine samples were analyzed through the isolated forest algorithm, which solved the problem of insufficient accuracy of quality detection of traditional Chinese medicine preparation, achieved accurate quality evaluation and abnormal detection of traditional Chinese medicine samples, and improved the accuracy and efficiency of detection.
Patent Information
- Application Number
- CN202510551396.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-04-29
AI Technical Summary
During the preparation of traditional Chinese medicine, the existing technology lacks standard instrument analysis methods, resulting in insufficient quality detection accuracy. Especially for Chinese herbal medicines with complex ingredients such as Gastrodia elata, there is noise and error in NIR spectral detection, making it difficult to accurately evaluate the quality of the medicinal material.
The isolated forest algorithm was used to analyze the NIR spectrum and HPLC fingerprint of traditional Chinese medicine samples. By establishing characteristic wave numbers, isolated forests and coding information, the abnormal scores of traditional Chinese medicine samples were calculated and their quality was accurately evaluated.
It improves the accuracy and efficiency of quality testing of traditional Chinese medicine preparation, can identify abnormal samples, and provides scientific quality control support.
Smart Images

Figure CN120064203B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of traditional Chinese medicine quality detection, and particularly to a method for detecting the quality of processed traditional Chinese medicine based on spectral analysis. Background Art
[0002] Traditional Chinese medicine processing is a traditional technique and method for processing Chinese medicinal materials into Chinese medicine decoction pieces according to traditional Chinese medicine theory, in accordance with the needs of dialectical treatment and medication, the nature of the drugs themselves, and different requirements for dispensing and preparation. During the process of traditional Chinese medicine processing, there will be an increase in the content of active ingredients, the destruction of toxic substances, and chemical changes in other components. The processing effect, that is, the quality of Chinese medicinal materials, directly determines the quality of Chinese patent medicines. For a long time, the quality detection of traditional Chinese medicine processing has relied on empirical discrimination and lacks standard instrumental analysis. Traditional quality detection methods, such as microscopic identification and chromatographic analysis, mostly require sample pretreatment, and the analysis process is complex and time-consuming, and the capital cost is also relatively high.
[0003] Near-infrared spectroscopy (NIR) can achieve rapid, non-destructive, and on-line quality detection of Chinese medicinal materials. However, in practical applications, especially for Chinese medicinal materials with complex components, taking Gastrodia elata as an example, as a plant-based traditional Chinese medicine with complex components, its main active ingredients mainly include phenolic components such as gastrodin, sugars, and active proteins. Due to factors such as the source of the medicinal materials, cultivation conditions, growth years, and harvesting seasons, these factors all affect the quality of the medicinal materials. Therefore, the NIR spectra of different samples of the same processed traditional Chinese medicine may have significant differences. And due to the complex light absorption characteristics of solid traditional Chinese medicine, it is easy to introduce spectral noise and errors, resulting in insufficient accuracy in directly evaluating the quality of medicinal materials through the characteristic peaks of NIR spectra. Summary of the Invention
[0004] In order to solve the technical problem of insufficient accuracy in the quality detection of medicinal materials, the purpose of the present invention is to provide a method for detecting the quality of processed traditional Chinese medicine based on spectral analysis, and the specific technical solutions adopted are as follows:
[0005] Establish a first Isolation Forest based on the wave numbers in the NIR spectrum of the processed traditional Chinese medicine sample, calculate the possibility and the final possibility that the wave number is a characteristic wave number, and select the wave number according to the final possibility and remove adjacent repeated wave numbers to obtain the characteristic wave number;
[0006] Obtain the reference value of the characteristic wave number according to the HPLC fingerprint spectrum of the traditional Chinese medicine sample, select the processed traditional Chinese medicine sample and place it at the root node, use the reference value of the characteristic wave number randomly selected for the first time as the splitting value, and when the characteristic wave number is randomly selected non-first time, set the splitting value as a random number between the maximum value and the minimum value of the sample, and establish a second Isolation Forest;
[0007] In the second isolation forest, the traditional Chinese medicine samples in the right subtree and the left subtree of the isolation tree are respectively encoded as a first value and a second value, and the probability that the target characteristic wave number is qualified is obtained according to the final possibility, the tree depth difference value between the traditional Chinese medicine sample and the target characteristic wave number in the isolation tree, and the encoding information, and the anomaly score of the traditional Chinese medicine sample is obtained according to the probability.
[0008] Obtain a reference sample of the traditional Chinese medicine sample to be tested, and determine the quality of the traditional Chinese medicine sample to be tested according to the anomaly score of the reference sample.
[0009] Further, the process of obtaining the possibility includes:
[0010] Take the opposite of the absolute value of the balance factor of the j-th isolation tree in the isolation forest of the i-th wave number as the input value of the exponential function with the natural constant e as the base, and obtain the splitting absolute value by subtracting the minimum splitting value from the maximum splitting value in the j-th isolation tree of the isolation forest of the i-th wave number and then taking the absolute value;
[0011] Multiply the splitting absolute value by the output value of the exponential function as the possibility component that the i-th wave number is the characteristic wave number in the j-th isolation tree, and repeat the process of obtaining the possibility component to obtain the possibility component that the i-th wave number is the characteristic wave number in each isolation tree, where the value range of i is from 1 to the number of wave numbers, and the value range of j is from 1 to the number of isolation trees;
[0012] Obtain the normalized value of the average value of the possibility components as the possibility that the i-th wave number is the characteristic wave number.
[0013] Further, the process of obtaining the final possibility includes:
[0014] In the isolation forest of the i-th wave number, obtain the sum of the absolute values of the differences in tree depth distances between any two traditional Chinese medicine samples with different backgrounds in different isolation trees;
[0015] Multiply the normalized value of the sum of the absolute values by the possibility that the i-th wave number is the characteristic wave number to obtain the final possibility that the i-th wave number is the characteristic wave number.
[0016] Further, the removal of adjacent repeated wave numbers includes:
[0017] Obtain the change consistency value between two adjacent wave numbers, and when the change consistency value is greater than the preset change threshold, remove the wave number with the smaller final possibility among the two adjacent wave numbers.
[0018] Further, the process of obtaining the change consistency value includes:
[0019] Obtain the first absolute value of the difference between the difference values of the reflectance changes of any two of the traditional Chinese medicine samples, where the reflectance change difference value represents the second absolute value of the difference in reflectance between two adjacent wave numbers;
[0020] Successively add up the first absolute values to obtain the sum of the first absolute values, and use the opposite of the sum of the first absolute values as the input value of the exponential function with the natural constant e as the base. The output value of the exponential function is the change consistency value.
[0021] Furthermore, the process of obtaining the reference value of the characteristic wave number includes:
[0022] According to the HPLC fingerprint, obtain the content of the active ingredients of any of the processed traditional Chinese medicine samples. The average reflectance of the characteristic wave number corresponding to the traditional Chinese medicine sample with the lowest qualified content is used as the reference value of the characteristic wave number.
[0023] Furthermore, the process of obtaining the probability includes:
[0024] In any of the isolated trees, calculate the sum of the coding ratios. The coding ratio is the a-th coding divided by the serial number of the a-th coding, where the value range of a is from 1 to the tree depth difference value, and the tree depth difference value is the difference between the depth of the leaf node where the traditional Chinese medicine sample is located and the depth at which the i-th wave number first appears;
[0025] Calculate the sum value of the sums of the coding ratios corresponding to each of the isolated trees. The normalized value after multiplying the sum value by the final possibility that the i-th wave number is the characteristic wave number is used as the probability that the target characteristic wave number is qualified, where the i-th wave number is the target characteristic wave number.
[0026] Furthermore, the process of obtaining the anomaly score includes:
[0027] Use the opposite of the probability that the target characteristic wave number is qualified as the input value of the exponential function with the natural constant e as the base. The output value of the exponential function is used as the anomaly score component, where the value range of the target characteristic wave number is from 1 to the number of characteristic wave numbers;
[0028] Use the normalized value of the sum of the anomaly score components as the anomaly score of the traditional Chinese medicine sample.
[0029] Furthermore, the process of obtaining the reference sample includes:
[0030] Calculate the minimum value after cumulatively summing the absolute values of the differences in reflectance between the traditional Chinese medicine sample to be measured and the characteristic wave numbers corresponding to the traditional Chinese medicine sample. The traditional Chinese medicine sample corresponding to the minimum value is the reference sample.
[0031] Further, determining the quality of the traditional Chinese medicine sample to be tested according to the anomaly score of the reference sample includes:
[0032] When the anomaly score of the reference sample is greater than the first anomaly threshold, the quality of the traditional Chinese medicine sample to be tested is unqualified; when the anomaly score of the reference sample is greater than the second anomaly threshold and less than or equal to the first anomaly threshold, the quality of the traditional Chinese medicine sample to be tested is passing; when the anomaly score of the reference sample is less than or equal to the second anomaly threshold, the quality of the traditional Chinese medicine sample to be tested is good.
[0033] The present invention has the following beneficial effects:
[0034] First, a first isolation forest is established according to the wave numbers in the NIR spectrum of the traditional Chinese medicine sample after processing, the possibility and the final possibility of the wave numbers being characteristic wave numbers are calculated, and the wave numbers are selected according to the final possibility and adjacent repeated wave numbers are removed to obtain the characteristic wave numbers. The characteristic wave numbers are regarded as the characteristics of the traditional Chinese medicine sample, and the characteristics can play a role in distinguishing the traditional Chinese medicine sample.
[0035] Second, a reference value of the characteristic wave number is obtained according to the HPLC fingerprint of the traditional Chinese medicine sample. The traditional Chinese medicine sample after processing is placed at the root node, and the reference value of the characteristic wave number randomly selected for the first time is used as the splitting value. When the characteristic wave number is randomly selected non-first time, the splitting value is set to a random number between the maximum value and the minimum value of the sample, and a second isolation forest is established. The second isolation forest is the basis for obtaining the anomaly score subsequently.
[0036] Furthermore, in the second isolation forest, the traditional Chinese medicine samples in the right subtree and the left subtree of the isolation tree are respectively encoded as the first value and the second value, the probability of the target characteristic wave number being qualified is obtained according to the final possibility, the tree depth difference value between the traditional Chinese medicine sample in the isolation tree and the target characteristic wave number, and the coding information, and the anomaly score of the traditional Chinese medicine sample is obtained according to the probability. Each traditional Chinese medicine sample has a corresponding anomaly score.
[0037] Finally, a reference sample of the traditional Chinese medicine sample to be tested is obtained, and the quality of the traditional Chinese medicine sample to be tested is determined according to the anomaly score of the reference sample. The reference sample is the traditional Chinese medicine sample with the smallest difference from the traditional Chinese medicine sample to be tested, and the anomaly score of the reference sample is the anomaly score of the traditional Chinese medicine sample to be tested. The higher the anomaly score, the worse the sample quality.
[0038] This method uses an isolation forest algorithm to analyze the correlation and characteristic performance between wavelengths in spectral data from multiple traditional Chinese medicine samples, extracting key features for anomaly detection. It then accurately calculates the anomaly score of each sample and uses this score to assess its quality, thereby enabling quality testing of the traditional Chinese medicine preparation process. This application significantly improves detection accuracy and provides strong support for traditional Chinese medicine quality control. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions and advantages of the embodiments of the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0040] Figure 1 Flowchart of the method for detecting the quality of Chinese medicine preparation based on spectral analysis provided by the first embodiment of the present invention;
[0041] Figure 2 A flow chart of the acquisition process of the possibilities provided by the second embodiment of the present invention;
[0042] Figure 3 A flowchart of a process for obtaining the final possibility provided by the third embodiment of the present invention;
[0043] Figure 4 A flowchart of a process for obtaining a change consistency value provided in a fourth embodiment of the present invention;
[0044] Figure 5 A flowchart of a probability acquisition process provided by the fifth embodiment of the present invention;
[0045] Figure 6 This is a flowchart of the process of obtaining anomaly scores provided by the sixth embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to further illustrate the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following, in conjunction with the accompanying drawings and preferred embodiments, is a detailed description of the method for detecting the quality of Chinese medicine preparation based on spectral analysis proposed by the present invention, its specific implementation, structure, characteristics and effects. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. In addition, the specific features, structures or characteristics of one or more embodiments may be combined in any suitable form.
[0047] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0048] The following specifically describes the specific solution of the traditional Chinese medicine processing quality detection method based on spectral analysis provided by the present invention in conjunction with the accompanying drawings.
[0049] Please refer to Figure 1 , which shows the flowchart of the traditional Chinese medicine processing quality detection method based on spectral analysis provided by the first embodiment of the present invention. The method includes:
[0050] S101. Establish a first isolation forest based on the wave numbers in the NIR spectrum of the processed traditional Chinese medicine samples, calculate the possibility and final possibility of the wave numbers being characteristic wave numbers, and select the wave numbers according to the final possibility and remove adjacent repeated wave numbers to obtain the characteristic wave numbers.
[0051] Data preparation: Taking Gastrodia elata as an example, obtain several Gastrodia elata from different origins, different production years, and different collection seasons. Gastrodia elata with the same origin, the same production year, and the same collection time is recorded as Gastrodia elata of the same background. All Gastrodia elata are processed under the same conditions according to the processing description in the Chinese Pharmacopoeia. After completion, each Gastrodia elata is divided into several samples.
[0052] The processing of Gastrodia elata slices is as follows: Wash, moisten thoroughly or steam until soft, cut into thin slices, and dry.
[0053] Conditions: The steaming condition is 42 minutes at 100 °C, and the drying condition is 48 minutes at 50 °C.
[0054] Take thin slices of one sample of all Gastrodia elata every 10 minutes. Use a spectrometer, fiber optic sampling, with a scanning range of 4000 - 10000 (wave number / cm), the resolution is 8 , scan each thin slice three times, perform preprocessing of polynomial filtering and multivariate signal correction on each scanned thin slice spectrum, and use the mean value of the three scanned spectra after preprocessing (the vertical axis is the logarithm of the reflectance corresponding to the wave number log(1 / R), hereinafter referred to as reflectance) as the spectrum of the sample.
[0055] The core of the isolation forest algorithm lies in its ability to efficiently identify outliers that deviate from the main aggregation area in the dataset. When processing the spectral data of all samples, each wave number is regarded as a unique feature. Given that light produces different responses when interacting with different components, the range of characteristic values of each sample and the feedback on the active ingredients are different. Therefore, using the principle of the isolation forest, the key characteristic wave numbers can be accurately screened out. On the other hand, during the traditional Chinese medicine processing process, the content of active ingredients increases, toxic substances are degraded, and the interaction between components also leads to an enhanced correlation between spectral features. By analyzing the spectral changes of Gastrodia elata samples of the same background during the processing process, the wave numbers most relevant to the processing technology can be identified, thereby further determining the characteristic wave numbers.
[0056] For the processed samples, each characteristic wave number can be analyzed as an independent feature. Since the characteristic values of different samples vary, and the characteristic values of unqualified Gastrodia elata tend to be unique, the Isolation Forest algorithm can be used again to identify abnormal samples. However, considering the complex background differences, there may be significant characteristic differences between different Gastrodia elata. Therefore, the aggregated regions do not necessarily fully represent normal samples, and the outlier data is not necessarily abnormal data. Therefore, after training the Isolation Forest, the calculation of the anomaly score needs to consider the characteristic values rather than just the splitting speed.
[0057] Regarding the reflectance of traditional Chinese medicine samples at any wave number as one-dimensional data, an ordered binary tree is established (the data of any node is greater than the data of all its left subtrees and less than the data of all its right subtrees). All the data is placed at the root node, and a splitting value is randomly selected between the maximum and minimum values. The one-dimensional data is continuously split until all the data is separately placed at the leaf nodes. In this isolation tree, for any leaf node, the more times of splitting required, the higher the degree of data aggregation, and the less the wave number should be used as a characteristic wave number. And the more average the number of splits between leaf nodes, the more average the data distribution, and thus the more it can play a role in distinguishing samples. Therefore, it can be used as a characteristic wave number more.
[0058] Due to the correlation of features, for example, as the processing progresses, there is a high consistency in the change of the characteristic values of samples at some wave numbers, and they change by the same amplitude at the same time. Then, not all of these wave numbers need to be used as characteristic wave numbers. The changes at different times reflect the sequence of component changes and can also be used as characteristic wave numbers.
[0059] The process of obtaining the said possibility will be described in detail in the second embodiment and will not be elaborated here.
[0060] The process of obtaining the said final possibility will be described in detail in the third embodiment and will not be elaborated here.
[0061] Selecting the wave numbers according to the said final possibility and removing adjacent duplicate wave numbers to obtain the characteristic wave numbers specifically includes:
[0062] Arrange the said final possibility in descending order, and select the wave numbers of the top preset percentage. The preset percentage can be set independently, preferably 10%.
[0063] The said removing adjacent duplicate wave numbers includes:
[0064] Calculate the change consistency value of two adjacent wave numbers. When the change consistency value is greater than the preset change threshold, remove the wave number with the smaller final possibility among the two adjacent wave numbers.
[0065] The preset change threshold can be set independently, preferably 0.7.
[0066] Remove adjacent duplicate wavenumbers until all wavenumbers are non - adjacent.
[0067] The process of obtaining the change consistency value will be described in detail in the fourth embodiment and will not be elaborated here.
[0068] S102. Obtain the reference value of the characteristic wavenumber according to the HPLC fingerprint of the traditional Chinese medicine sample. Place the processed traditional Chinese medicine sample at the root node. The reference value of the characteristic wavenumber randomly selected for the first time is used as the splitting value. When the characteristic wavenumber is randomly selected non - for the first time, the splitting value is set as a random number between the maximum value and the minimum value of the sample, and a second isolation forest is established.
[0069] The processed traditional Chinese medicine samples include all traditional Chinese medicine samples in the background. Regarding the characteristic wavenumber as a feature, select some traditional Chinese medicine samples. Each time, any feature is used as the splitting feature, and a splitting value is randomly selected between the maximum value and the minimum value until all traditional Chinese medicine samples become single leaf nodes, and an isolation tree is established. In this process, the leaf nodes with larger tree depths are more difficult to distinguish. If the number of unqualified traditional Chinese medicine samples is small, the leaf nodes with smaller tree depths are more likely to be unqualified traditional Chinese medicine samples. However, there are two problems in this process. One is that the selection of features is accidental, and only the features related to the active ingredients and harmful ingredients can prove the unqualified nature of the samples. The other is that the number of unqualified traditional Chinese medicine samples is uncertain, which leads to the uncertainty of the tree depth for unqualified traditional Chinese medicine samples.
[0070] To solve the above problems, in - depth learning can be carried out on the various features of qualified traditional Chinese medicine samples and used as a reference for setting the splitting value. In this way, the unqualified degree of traditional Chinese medicine samples can be more scientifically quantified, thereby improving the accuracy and efficiency of detection.
[0071] The process of obtaining the reference value of the characteristic wavenumber includes:
[0072] Obtain the content of the active ingredient of any processed traditional Chinese medicine sample according to the HPLC fingerprint. The average reflectance of the characteristic wavenumber corresponding to the traditional Chinese medicine sample with the content being the lowest qualified content is used as the reference value of the characteristic wavenumber.
[0073] All characteristic wave numbers are regarded as features, and a sample space consisting of all processed traditional Chinese medicine samples (i.e., excluding samples obtained during the processing) is constructed. A certain proportion (preferably 50%) of traditional Chinese medicine samples is randomly selected from this sample space by sampling with replacement, and these traditional Chinese medicine samples are placed at the root node of the isolation tree. During the construction of the isolation tree, a feature is randomly selected from all features with replacement as the splitting basis. When a feature is selected for the first time, its splitting value is set to the reference value. When the feature is selected again in the subsequent process, its splitting value is randomly set to a random number between the maximum and minimum values of this feature in the current traditional Chinese medicine sample set. By continuously splitting into left and right subtrees and continuing this process until all traditional Chinese medicine samples are placed separately at the leaf nodes, a complete isolation tree is obtained. Repeat the above sampling and isolation tree construction process a preset number of times (preferably 100 times), and finally an isolation forest consisting of a preset number of isolation trees is obtained.
[0074] S103. In the second isolation forest, the traditional Chinese medicine samples in the right subtree and the left subtree of the isolation tree are respectively encoded as the first value and the second value, the probability that the target characteristic wave number is qualified is obtained according to the final possibility, the tree depth difference value between the traditional Chinese medicine sample and the target characteristic wave number in the isolation tree, and the encoding information, and the anomaly score of the traditional Chinese medicine sample is obtained according to the probability.
[0075] For any one feature, an inorder traversal can be performed on all splitting values of the binary tree. The splitting value corresponding to the reference value is usually located in the middle of the traversal sequence. In the traversal sequence, the splitting value closest to the reference value is often located in the right subtree. Therefore, in the isolation tree, the right subtree with a greater depth and belonging to more nodes usually has a greater probability of being qualified.
[0076] Encoding starts from the position of the feature of any isolation tree. If the traditional Chinese medicine sample is in the right subtree, it is encoded as the first value (preferably 1), and if it is in the left subtree, it is encoded as the second value (preferably -1) to obtain the encoding information of the traditional Chinese medicine sample.
[0077] Using the final possibility of the characteristic wave number as the weight, the probability that any feature of any traditional Chinese medicine sample is qualified is obtained.
[0078] The process of obtaining the probability will be described in detail in the fifth embodiment and will not be elaborated here.
[0079] The process of obtaining the anomaly score will be described in detail in the sixth embodiment and will not be elaborated here.
[0080] S104. Obtain the reference sample of the traditional Chinese medicine sample to be tested, and determine the quality of the traditional Chinese medicine sample to be tested according to the anomaly score of the reference sample.
[0081] The process of obtaining the reference sample includes:
[0082] Calculating the minimum value after summing up the absolute values of the differences in reflectance of each characteristic wave number corresponding to the traditional Chinese medicine sample to be measured and the traditional Chinese medicine sample, and the traditional Chinese medicine sample corresponding to the minimum value is the reference sample.
[0083] Determining the quality of the traditional Chinese medicine sample to be measured according to the anomaly score of the reference sample includes:
[0084] When the anomaly score of the reference sample is greater than the first anomaly threshold, the quality of the traditional Chinese medicine sample to be measured is unqualified. When the anomaly score of the reference sample is greater than the second anomaly threshold and less than or equal to the first anomaly threshold, the quality of the traditional Chinese medicine sample to be measured is passing. When the anomaly score of the reference sample is less than or equal to the second anomaly threshold, the quality of the traditional Chinese medicine sample to be measured is good.
[0085] The first anomaly threshold can be set independently, preferably 0.6. The second anomaly threshold can also be set independently, preferably 0.4.
[0086] For any wave number, all traditional Chinese medicine samples form a sample space. Some traditional Chinese medicine samples are randomly selected from the sample space with replacement, preferably with a sampling ratio of 1 / 2. These traditional Chinese medicine samples are placed at the root node, and a splitting value is randomly selected between the maximum value and the minimum value of these traditional Chinese medicine samples, and split into a left subtree and a right subtree (the data of any node is greater than the data of all its left subtrees and less than the data of all its right subtrees), until all samples are separately placed at the leaf nodes to obtain an isolation tree; after several (preferably 100) samplings, several isolation trees are obtained to form an isolation forest.
[0087] In the isolation forest of any wave number, in order to avoid the influence of extreme values and error values on the splitting process, the range of the splitting value is used to characterize the range of the wave number characteristic value. Obtain the maximum value and the minimum value of the splitting values of any isolation tree in the isolation forest of any wave number. The larger the overall range of the isolation forest, the more distinguishable the traditional Chinese medicine samples are, and therefore, the greater the possibility that the wave number is a characteristic wave number.
[0088] The balance factor of a binary tree is the height of the left subtree of the binary tree minus the height of the right subtree, which can measure the balance of the binary tree. For the isolation forest of any wave number, the smaller the overall balance factor, the more balanced the isolation forest is, indicating that the data distribution is relatively average and the more distinguishable the samples are, and therefore, the greater the possibility that the wave number is a characteristic wave number.
[0089] Figure 2 This is the flowchart of the process for obtaining the possibility provided by the second embodiment of the present invention. The process for obtaining the possibility includes:
[0090] S201. Take the negative of the absolute value of the balance factor of the j-th isolation tree in the isolation forest at the i-th wave number as the input value of the exponential function with base e, and obtain the split absolute value by taking the absolute value after subtracting the minimum split value from the maximum split value of the j-th isolation tree in the isolation forest at the i-th wave number.
[0091] The split absolute value can be expressed by the formula:
[0092] ;
[0093] where, the represents the maximum split value of the j-th isolation tree in the isolation forest at the i-th wave number, the represents the minimum split value of the j-th isolation tree in the isolation forest at the i-th wave number, and the represents the absolute value function.
[0094] S202. Multiply the split absolute value by the output value of the exponential function as the possibility component that the i-th wave number is the characteristic wave number in the j-th isolation tree, and repeat the process of obtaining the possibility component to get the possibility components that the i-th wave number is the characteristic wave number in each isolation tree, where the value range of i is from 1 to the number of wave numbers, and the value range of j is from 1 to the number of isolation trees.
[0095] The output value of the exponential function can be expressed as:
[0096] ;
[0097] where, the represents the exponential function with base e (natural constant), the represents the balance factor of the j-th isolation tree in the isolation forest at the i-th wave number, and the represents the absolute value function.
[0098] The possibility component can be expressed as:
[0099] ;
[0100] S203. Obtain the normalized value of the average of the possibility components as the possibility that the i-th wave number is the characteristic wave number.
[0101] The possibility can be expressed as:
[0102] ;
[0103] where, the represents the normalization function, preferably the range normalization function, and the Represents the number of the isolated trees. The Represents the possibility that the i-th wave number is the characteristic wave number.
[0104] To avoid the influence of the harvesting background and distinguish whether the difference in characteristic values is caused by the background or processing, further analysis is performed on traditional Chinese medicine samples with the same background. For all traditional Chinese medicine samples with any background, the depth of each traditional Chinese medicine sample in any isolated tree is obtained. The greater the difference in depth, the greater the difference between samples with the same background. The greater the difference between all samples with the same background in the isolated tree, the more likely the difference in characteristic values is due to processing rather than the background.
[0105] Figure 3 Is a flowchart of the process for obtaining the final possibility provided by the third embodiment of the present invention. The process for obtaining the final possibility includes:
[0106] S301. In the isolated forest at the i-th wave number, obtain the sum of the absolute values of the differences in tree depth distances between any two traditional Chinese medicine samples with different backgrounds of different isolated trees.
[0107] The sum of the distances can be expressed as:
[0108] ;
[0109] Among them, the Represents the tree depth distance of the u-th sample of the m-th background sample of the j-th isolated tree in the isolated forest at the i-th wave number. The Represents the tree depth distance of the -th sample of the m-th background sample of the j-th isolated tree in the isolated forest at the i-th wave number. The Represents the absolute value function.
[0110] The background sample refers to the division of traditional Chinese medicine samples according to different places of origin, production years, and collection times. The traditional Chinese medicine samples of the same background have the same place of origin, production year, and collection time.
[0111] S302. Multiply the normalized value of the sum of the absolute values by the possibility that the i-th wave number is the characteristic wave number to obtain the final possibility that the i-th wave number is the characteristic wave number.
[0112] The final possibility can be expressed as:
[0113] ;
[0114] Among them, the Represents the possibility that the i-th wave number is the characteristic wave number. The Represents the final possibility that the i-th wave number is the characteristic wave number. The The value range of is from 1 to the number U of the samples, the value range of m is from 1 to the number M of the background samples, and the value range of j is from 1 to the number of the isolated trees .
[0115] Figure 4 FIG. is a flowchart of the process for obtaining the change consistency value provided by the fourth embodiment of the present invention. The process for obtaining the change consistency value includes:
[0116] S401. Obtain a first absolute value of the difference between the differences in reflectance change values of any two of the traditional Chinese medicine samples. The reflectance change value represents a second absolute value of the difference in reflectance between two adjacent wave numbers.
[0117] The first absolute value can be expressed as:
[0118] ;
[0119] wherein, the represents the reflectance change value of the r-th traditional Chinese medicine sample, and the represents the reflectance change value of the s-th traditional Chinese medicine sample.
[0120] The reflectance change value can be expressed as:
[0121] ;
[0122] wherein, the represents the reflectance of one of the two adjacent wave numbers, and the represents the reflectance of the other of the two adjacent wave numbers.
[0123] S402. Add up the first absolute values in sequence to obtain a sum of the first absolute values, and use the opposite of the sum of the first absolute values as the input value of the exponential function with e as the base. The output value of the exponential function is the change consistency value.
[0124] The change consistency value can be expressed as:
[0125] ;
[0126] wherein, the represents the change consistency value, the has a value range from 1 to the number R of the first absolute values, and the represents the exponential function with the natural constant e as the base.
[0127] Figure 5 FIG. is a flowchart of the process for obtaining the probability provided by the fifth embodiment of the present invention. The process for obtaining the probability includes:
[0128] S501. In any of the isolated trees, calculate the sum of the coding ratios, where the coding ratio is the a-th coding divided by the serial number of the a-th coding, and the value range of a is from 1 to the tree depth difference value, and the tree depth difference value is the difference between the depth of the leaf node where the traditional Chinese medicine sample is located and the depth at which the i-th wave number first appears.
[0129] The sum of the coding ratios can be expressed as:
[0130] ;
[0131] where, the represents the a-th coding, the represents the serial number of the a-th coding, and the represents the tree depth difference value of the j-th isolated tree.
[0132] It means that the reciprocal of the coding serial number is used as the weight to weight the coding.
[0133] S502. Calculate the sum value of the sums of the coding ratios corresponding to each of the isolated trees, and use the normalized value after multiplying the sum value by the final possibility that the i-th wave number is the characteristic wave number as the probability that the target characteristic wave number is qualified, where the i-th wave number is the target characteristic wave number.
[0134] The probability can be expressed as:
[0135] ;
[0136] where, the represents the probability that the i-th wave number is qualified, the represents the final possibility that the i-th wave number is the characteristic wave number, and the represents the number of the isolated trees.
[0137] Figure 6 FIG.
[0138] S601. Use the opposite number of the probability that the target characteristic wave number is qualified as the input value of the exponential function with e as the base, and use the output value of the exponential function as the anomaly score component, where the value range of the target characteristic wave number is from 1 to the number of characteristic wave numbers.
[0139] The anomaly score component can be expressed as:
[0140] ;
[0141] Among them, the represents the exponential function with the natural constant e as the base, and the represents the probability that the i-th wave number is qualified, that is, the probability that the target characteristic wave number is qualified.
[0142] S602. Use the normalized value of the sum of the abnormal score components as the abnormal score of the traditional Chinese medicine sample.
[0143] The abnormal score can be expressed as:
[0144] ;
[0145] Among them, the represents the abnormal score of the traditional Chinese medicine sample, and the represents the number of features, that is, the number of the characteristic wave numbers.
[0146] For any traditional Chinese medicine sample, the higher the probability that all features are qualified, the higher the quality of the traditional Chinese medicine sample, and thus the lower the abnormal score.
[0147] The present invention has the following beneficial effects:
[0148] First, establish a first isolation forest based on the wave numbers in the NIR spectrum of the processed traditional Chinese medicine sample, calculate the possibility and the final possibility that the wave number is a characteristic wave number, select the wave number according to the final possibility and remove adjacent repeated wave numbers to obtain the characteristic wave number. The characteristic wave number is regarded as the characteristic of the traditional Chinese medicine sample, and the characteristic can play a role in distinguishing the traditional Chinese medicine sample.
[0149] Second, obtain the reference value of the characteristic wave number according to the HPLC fingerprint of the traditional Chinese medicine sample, select the processed traditional Chinese medicine sample and place it at the root node, use the reference value of the characteristic wave number randomly selected for the first time as the splitting value, and when the characteristic wave number is randomly selected non-first time, set the splitting value as a random number between the maximum value and the minimum value of the sample, and establish a second isolation forest. The second isolation forest is the basis for obtaining the abnormal score subsequently.
[0150] Furthermore, in the second isolation forest, encode the traditional Chinese medicine samples in the right subtree and the left subtree of the isolation tree as the first value and the second value respectively, calculate the probability that the target characteristic wave number is qualified according to the final possibility, the difference in tree depth between the traditional Chinese medicine sample in the isolation tree and the target characteristic wave number, and the encoding information, and calculate the abnormal score of the traditional Chinese medicine sample according to the probability. Each traditional Chinese medicine sample has a corresponding abnormal score.
[0151] Finally, a reference sample of the traditional Chinese medicine sample to be tested is obtained, and the quality of the traditional Chinese medicine sample to be tested is determined according to the anomaly score of the reference sample. The reference sample is the traditional Chinese medicine sample with the smallest difference from the traditional Chinese medicine sample to be tested, and the anomaly score of the reference sample is the anomaly score of the traditional Chinese medicine sample to be tested. The higher the anomaly score, the worse the sample quality.
[0152] The present invention aims at multiple traditional Chinese medicine samples, adopts the isolation forest algorithm, analyzes the correlation and characteristic performance among wavelengths in spectral data, extracts key features for anomaly detection, accurately calculates the anomaly score of the traditional Chinese medicine sample to be tested, and evaluates its quality condition accordingly, thereby realizing the quality detection of the traditional Chinese medicine processing process. The application of the present invention can significantly improve the accuracy of detection and provide strong support for the quality control of traditional Chinese medicine.
[0153] It should be noted that the above sequence of the embodiments of the present invention is only for description and does not represent the advantages and disadvantages of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0154] Each embodiment in this specification is described in a progressive manner, and the same or similar parts among the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.
Claims
1. A method for quality inspection of traditional Chinese medicine processing based on spectral analysis, characterized in that, The method includes: Establish a first isolation forest based on the wave numbers in the NIR spectrum of the processed traditional Chinese medicine sample, calculate the possibility and the final possibility that the wave number is a characteristic wave number, and select the wave number according to the final possibility and remove adjacent repeated wave numbers to obtain the characteristic wave number; Among them, the method for obtaining the possibility is: take the opposite of the absolute value of the balance factor of the j-th isolation tree in the isolation forest of the i-th wave number as the input value of the exponential function with the natural constant e as the base, and subtract the minimum splitting value from the maximum splitting value in the j-th isolation tree in the isolation forest of the i-th wave number and then take the absolute value to obtain the splitting absolute value; multiply the splitting absolute value by the output value of the exponential function as the possibility component that the i-th wave number is the characteristic wave number in the j-th isolation tree, and repeat the process of obtaining the possibility component to obtain the possibility component that the i-th wave number is the characteristic wave number in each isolation tree, where the value range of i is from 1 to the number of wave numbers, and the value range of j is from 1 to the number of isolation trees; obtain the normalized value of the average of the possibility components as the possibility that the i-th wave number is the characteristic wave number; Among them, the method for obtaining the final possibility is: in the isolation forest of the i-th wave number, obtain the sum of the absolute values of the differences in tree depths of any two traditional Chinese medicine samples with different backgrounds in different isolation trees; multiply the normalized value of the sum of the absolute values by the possibility that the i-th wave number is the characteristic wave number to obtain the final possibility that the i-th wave number is the characteristic wave number; Among them, the method for selecting the characteristic wave number is: arrange the final possibilities in descending order, and select the wave numbers in the top preset percentage, and the preset percentage is set independently; Obtain the reference value of the characteristic wave number according to the HPLC fingerprint of the traditional Chinese medicine sample, place the processed traditional Chinese medicine sample at the root node, take the reference value of the characteristic wave number randomly selected for the first time as the splitting value, and when the characteristic wave number is randomly selected non-first time, set the splitting value as a random number between the maximum value and the minimum value of the sample, and establish a second isolation forest; In the second isolation forest, encode the traditional Chinese medicine samples in the right subtree and the left subtree of the isolation tree as the first value and the second value respectively, and obtain the probability that the target characteristic wave number is qualified according to the final possibility, the difference in tree depth between the traditional Chinese medicine sample in the isolation tree and the target characteristic wave number, and the coding information, and obtain the anomaly score of the traditional Chinese medicine sample according to the probability; Obtain the reference sample of the traditional Chinese medicine sample to be tested, and determine the quality of the traditional Chinese medicine sample to be tested according to the anomaly score of the reference sample.
2. The quality detection method for traditional Chinese medicine processing based on spectral analysis according to claim 1, wherein The removal of adjacent repeated wave numbers includes: Obtain the change consistency value of two adjacent wave numbers, and when the change consistency value is greater than the preset change threshold, remove the wave number with the smaller final possibility among the two adjacent wave numbers.
3. The method for detecting the quality of traditional Chinese medicine processing based on spectral analysis according to claim 2, characterized in that, The process for obtaining the change consistency value includes: Obtain the first absolute value of the difference between the difference values of the reflectance changes of any two of the Chinese medicine samples, where the reflectance change difference value represents the second absolute value of the difference in reflectance at two adjacent wave numbers; Successively add up the first absolute values to obtain the sum of the first absolute values, and use the opposite of the sum of the first absolute values as the input value of the exponential function with the natural constant e as the base. The output value of the exponential function is the change consistency value.
4. The method for detecting the quality of traditional Chinese medicine processing based on spectral analysis according to claim 1, characterized in that, The process of obtaining the reference value of the characteristic wave number includes: According to the HPLC fingerprint map, obtain the content of the active ingredients of any of the processed Chinese medicine samples. The average reflectance of the characteristic wave number corresponding to the Chinese medicine sample with the lowest qualified content is used as the reference value of the characteristic wave number.
5. The quality detection method for traditional Chinese medicine processing based on spectral analysis according to claim 1, wherein, The process of obtaining the probability includes: In any of the isolated trees, calculate the sum of the coding ratios. The coding ratio is the a-th coding divided by the serial number of the a-th coding, where the value range of a is from 1 to the tree depth difference value, and the tree depth difference value is the difference between the depth of the leaf node where the Chinese medicine sample is located and the depth at which the i-th wave number first appears; Calculate the sum value of the sum of the coding ratios corresponding to each of the isolated trees. The normalized value after multiplying the sum value by the final possibility that the i-th wave number is the characteristic wave number is used as the probability that the target characteristic wave number is qualified, where the i-th wave number is the target characteristic wave number.
6. The quality detection method for traditional Chinese medicine processing based on spectral analysis according to claim 1, characterized in that, The process of obtaining the anomaly score includes: Use the opposite of the probability that the target characteristic wave number is qualified as the input value of the exponential function with the natural constant e as the base. The output value of the exponential function is used as the anomaly score component, where the value range of the target characteristic wave number is from 1 to the number of characteristic wave numbers; Use the normalized value of the sum of the anomaly score components as the anomaly score of the Chinese medicine sample.
7. The method for detecting the quality of traditional Chinese medicine processing based on spectral analysis according to claim 1, characterized in that, The process of obtaining the reference sample includes: Calculate the minimum value after accumulating and summing the absolute values of the differences in reflectance of the characteristic wave numbers corresponding to the Chinese medicine sample to be tested and the Chinese medicine sample. The Chinese medicine sample corresponding to the minimum value is the reference sample.
8. The quality detection method for traditional Chinese medicine processing based on spectral analysis according to claim 1, characterized in that Determining the quality of the Chinese medicine sample to be tested according to the anomaly score of the reference sample includes: When the anomaly score of the reference sample is greater than the first anomaly threshold, the quality of the Chinese medicine sample to be tested is unqualified. When the anomaly score of the reference sample is greater than the second anomaly threshold and less than or equal to the first anomaly threshold, the quality of the Chinese medicine sample to be tested is passing. When the anomaly score of the reference sample is less than or equal to the second anomaly threshold, the quality of the Chinese medicine sample to be tested is excellent.
Citation Information
Patent Citations
Method for identifying Chinese herbal medicine by using THz-TDS (terahertz-total dissolved solids) in combination with fuzzy rule expert system
CN103411912A
Grain condition data outlier detection method based on isolated forest
CN113327172A