Near-infrared spectroscopy method, system, medium and device for qualitative discrimination of oil varieties
Through neural network and Bayesian regularization-optimized near-infrared spectral qualitative discriminant model, the problem of low accuracy in fuel grade recognition is solved, and the accurate identification of multiple fuels is achieved.
Patent Information
- Application Number
- CN202410696586.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2044-05-31
AI Technical Summary
The prior art is difficult to accurately identify the grades of multiple fuels through near-infrared spectroscopy, and is interfered with spectral information between different types of fuels, resulting in a decrease in the recognition accuracy.
A qualitative discriminant model is constructed using neural networks, and the hyperparameters of the neural network are optimized through Bayesian regularization to establish a near-infrared spectral qualitative discriminant model that can effectively utilize the nonlinear relationship information between spectral data.
When identifying multiple fuels with the same model, the accuracy of oil varieties and brand identification is improved, and the risk of merchants taking inferior products as good products is reduced.
Smart Images

Figure CN118603930B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of oil product detection, and particularly to a near-infrared spectroscopy method, system, medium and device for qualitatively discriminating oil product types. Background Art
[0002] At present, the fuel market is chaotic, and the phenomenon of passing off inferior goods as good ones is common. The types and grades of oil products sold do not match the actual ones, which has a serious impact on vehicle use and so on. In the national standard regulations, the Pensky-Martens closed cup, the freezing point tester and the full-size spark-ignition engine can be used to indirectly realize the index determination and discriminate the grades, but the laboratory methods are cumbersome and the portability is poor, which is not conducive to on-site analysis. Among the methods suitable for rapid detection, most are near-infrared spectroscopy methods. However, due to the similar chemical compositions among fuels, it is difficult to directly use near-infrared spectroscopy to achieve accurate qualitative discrimination. Moreover, most of the current oil product grade identification functions are for single types and mostly use linear modeling methods. When using the same model to identify the grades of multiple fuels, affected by the spectral information interference between different types of fuels, the grade identification accuracy rate decreases. Summary of the Invention
[0003] The present invention provides a near-infrared spectroscopy method for qualitatively discriminating oil product types, including:
[0004] Obtaining the near-infrared spectra of multiple fuel samples to be tested, so as to obtain near-infrared spectral data;
[0005] Constructing a qualitative discrimination model through a neural network, where the input of the qualitative discrimination model is the near-infrared spectral data, and the output of the qualitative discrimination model is the probability of belonging to each oil product type and / or the probability of belonging to each grade;
[0006] Inputting the near-infrared spectral data of multiple fuel samples to be tested into the qualitative discrimination model to discriminate the probability of each fuel sample to be tested belonging to each oil product type and / or the probability of belonging to each grade, and taking the highest probability of the fuel sample to be tested belonging to the oil product type and / or belonging to each grade as the oil product type and / or the grade to which the fuel sample to be tested belongs;
[0007] Among them, the step of constructing the qualitative discrimination model through a neural network includes:
[0008] Selecting multiple training samples of multiple oil product types;
[0009] Obtaining the true labels of multiple training samples, where the true labels are the oil product types and / or grades to which the training samples belong, setting the true probability of the oil product type and / or grade corresponding to the true label to 1, and setting the probabilities of other oil product types and / or grades to 0, so as to obtain a true probability matrix composed of the true probabilities of multiple training samples belonging to each oil product type and / or belonging to each grade;
[0010] Construct a training set, where the training set includes the near-infrared spectral data of training samples and the true probability matrix;
[0011] Use Bayesian regularization on the training set to introduce prior knowledge to set the range of hyperparameters, optimize the hyperparameters, and construct a Bayesian-regularized optimized backpropagation neural network to establish a qualitative discrimination model;
[0012] The step of using Bayesian regularization on the training set to introduce prior knowledge to set the range of hyperparameters includes:
[0013] Select a prior distribution, where the prior distribution is a Gaussian distribution or a uniform distribution;
[0014] Obtain the confidence interval of the hyperparameters whose prior distribution satisfies the normal distribution based on the near-infrared spectral data and the true probability matrix of the training samples in the training set;
[0015] Set the confidence interval of a certain proportion of the hyperparameters as the range of the hyperparameters.
[0016] According to one aspect of the present invention, the set proportion is 90%-100%.
[0017] According to one aspect of the present invention, the set proportion is 95%.
[0018] According to one aspect of the present invention, the step of optimizing the hyperparameters includes:
[0019] Construct an objective function through the following formula (1):
[0020] L totul =L + λΩ (θ) (1)
[0021] where L totul is the total loss function and also the objective function; L is the original loss function, N is the number of training samples, y j is the true probability matrix corresponding to the true label of the i-th training sample, o i is the predicted probability matrix of the i-th training sample, o i (l) =f (l) (w (l) X i +b (l) ),X i is the near-infrared spectral data of the i-th training sample, o i (i) is the output of the l-th layer corresponding to the i-th training sample and is also X i belongs to the predicted probability matrix composed of the predicted probabilities of each oil variety or / and each license plate number, w (l) is the weight matrix of the l-th layer, b(l) is the bias vector of the l-th layer, and f (l) is the activation function of the l-th layer; Ω (θ) is the regularization term, and Ω (θ) = kL(θ||θprior), where kL() is the KL divergence, θ is the hyperparameter of the neural network, the hyperparameter includes the weight matrix and the bias vector, θprior is the prior probability; λ is the regularization coefficient;
[0022] Initialize the search space and initialize the search space to the range of hyperparameters;
[0023] Initialize the prior distribution and initialize the probability of each configuration of hyperparameters being selected within the range of hyperparameters according to the prior distribution;
[0024] Sampling, randomly sample a configuration of hyperparameters;
[0025] Evaluation, obtain the objective function corresponding to the configuration of the hyperparameters;
[0026] Update, update the prior distribution according to the objective function corresponding to the configuration of the hyperparameters, including: calculating the likelihood function of the objective function corresponding to the configuration of the hyperparameters and the likelihood function of the prior distribution, and then using Bayes' theorem to update the prior distribution;
[0027] Iterate the processes of sampling, evaluation and update until the iteration termination condition is satisfied, and obtain the optimal hyperparameters. The iteration termination condition includes: reaching the preset number of iterations or / and reaching the number of evaluations.
[0028] According to one aspect of the present invention, the step of using Bayes' theorem to update the prior distribution includes:
[0029] Update the prior distribution according to the near-infrared spectral data and probability of the training samples in the training set through the following formula (2):
[0030]
[0031] where D is the observed data, the observed data is the near-infrared spectral data and probability of the training samples in the training set, p(θ|D) is the updated prior distribution, p(D|θ) is the likelihood function of the objective function corresponding to the configuration of the hyperparameters, p(θ) is the prior distribution before update, and p(D) is the total probability of the observed data, which is obtained by adding the probabilities of each observed data and dividing by the total number of observed data.
[0032] According to one aspect of the present invention, the step of optimizing the hyperparameters further includes:
[0033] Perform gradient descent processing on the hyperparameters.
[0034] According to one aspect of the present invention, the steps of constructing a qualitative discrimination model by building a Bayesian regularization optimized backpropagation neural network include:
[0035] Establish a qualitative discrimination model through the following formula (3):
[0036]
[0037] Where, O c = softmax(W0X + b0), X is the near-infrared spectral data of the fuel sample to be measured, W0 and b0 are respectively the weight matrix and bias vector of the output layer after training with the training set, O c is the prediction probability on the c-th oil product category of the fuel sample to be measured, is the predicted label of the oil product type of the fuel sample to be measured.
[0038] According to one aspect of the present invention, the steps of constructing the training set include:
[0039] Eliminate abnormal training samples in the training set.
[0040] According to one aspect of the present invention, the steps of eliminating abnormal training samples in the training set include:
[0041] Randomly select multiple training samples from the training set to form an abnormal training set for elimination;
[0042] Obtain the mean value of the spectral values at each wavelength of the spectral matrix of the abnormal training set for elimination through formula (4), obtain the standard deviation of the spectral values at each wavelength of the spectral matrix of the abnormal training set for elimination through formula (5), and perform standardization processing on the spectral values of the spectral matrix by using the mean value and standard deviation of the spectral values at each wavelength of the spectral matrix of the abnormal training set for elimination through formula (6) to obtain a standard spectral matrix
[0043]
[0044] Where, μ lsj is the mean value of the spectral values at the j-th wavelength, i is the training sample index, j is the wavelength index, σ lsj is the standard deviation of the spectral values at the j-th wavelength, ls ij is the spectral value of the i-th training sample at the j-th wavelength, ls' ij is the standard spectral value of the i-th training sample at the j-th wavelength after standardization processing, LS' is the standard spectral matrix, LS' = [ls' ij I×J , I is the total number of training samples, J is the total number of wavelengths;
[0045] Obtain the covariance matrix of the standard spectral matrix through formula (7):
[0046]
[0047] The covariance matrix is eigen-decomposed by formula (8) to obtain the eigenvalues and eigenvectors of each training sample:
[0048] ∑CM = V * DM (8)
[0049] where DM is a diagonal matrix containing the eigenvalues of the covariance matrix, V is the eigenmatrix, and the columns of V are the corresponding eigenvectors;
[0050] Select the corresponding number of eigenvectors in descending order of eigenvalues to form a projection matrix:
[0051] PM = [v1, v2, …, v k (9)
[0052] where PM is the projection matrix and K is the number of dimensions to be achieved for dimensionality reduction;
[0053] The standard spectral matrix is transformed into a dimensionality-reduced spectral matrix through the projection matrix by formula (10):
[0054] DR = LS′ * PM (10)
[0055] where DR is the dimensionality-reduced spectral matrix, DR = [dr ik I×K ; [dr ik is the matrix calculation for the k-dimensionality of the i-th training sample; I is the total number of training samples;
[0056] Obtain the Mahalanobis distance of the vector corresponding to each training sample in the dimensionality-reduced spectral matrix, and use the Mahalanobis distance as the T statistic to obtain a T statistic matrix;
[0057] The first degree of freedom is K, and the second degree of freedom is I - K - 1. Look up the T statistic critical value in the T distribution critical table according to the first and second degrees of freedom, and use the training samples corresponding to the T statistics with a difference greater than the first difference range from the T statistic critical value as abnormal training samples;
[0058] Input the standard index matrix and the dimensionality-reduced spectral matrix after removing the abnormal training set into the qualitative discrimination model for training, input the dimensionality-reduced spectral matrix after removing the abnormal training set into the trained qualitative discrimination model, obtain a prediction probability matrix composed of the prediction probabilities after removing the abnormal training set, obtain a residual index matrix composed of the residuals of the true probabilities and the prediction probabilities through the true probability matrix corresponding to the true labels after removing the abnormal training set and the prediction probability matrix, and construct an F statistic matrix of the residual index matrix through the F statistic;
[0059] The first degree of freedom is K, and the second degree of freedom is I - K - 1. According to the first and second degrees of freedom, the second critical value is found in the F-test critical value table, and the training samples corresponding to the F-statistic whose difference from the second critical value is greater than the second difference range are used as abnormal training samples.
[0060] According to one aspect of the present invention, after the step of removing abnormal training samples from the training set, the following steps are further included:
[0061] Perform baseline correction on the near-infrared spectra of the normal training samples after removing the abnormal training samples.
[0062] According to one aspect of the present invention, the step of performing baseline correction on the near-infrared spectra of the normal training samples after removing the abnormal training samples from the training set includes:
[0063] Perform derivative processing on the spectral matrix of the normal training samples to obtain a derivative matrix composed of derivative values. The derivative processing is first-order derivative processing or higher-order derivative processing;
[0064] Among them, the training set after baseline correction includes a derivative matrix composed of derivative values of the spectral values of the normal training samples and the true probability matrix of the normal training samples.
[0065] The step of constructing the training set includes:
[0066] Perform baseline correction on the near-infrared spectra of multiple training samples.
[0067] According to one aspect of the present invention, the step of performing baseline correction on the near-infrared spectra of multiple training samples includes:
[0068] Perform derivative processing on the spectral matrix of multiple training samples to obtain a derivative matrix composed of derivative values. The derivative processing is first-order derivative processing or higher-order derivative processing;
[0069] Among them, the training set after baseline correction includes a derivative matrix composed of derivative values of the spectral values of the training samples and the true probability matrix of the training samples.
[0070] According to one aspect of the present invention, the derivative processing is second-order derivative processing.
[0071] According to the second aspect of the present invention, a near-infrared spectroscopy system for qualitative discrimination of oil types is provided, including:
[0072] A spectral acquisition module that acquires the near-infrared spectra of multiple fuel samples to be measured, thereby obtaining near-infrared spectral data;
[0073] A model construction module constructs a qualitative discrimination model through a neural network. The input of the qualitative discrimination model is near-infrared spectrum data, and the output of the qualitative discrimination model is the probability of belonging to each oil variety or / and the probability of belonging to each grade.
[0074] A qualitative discrimination module inputs the near-infrared spectrum data of multiple fuel samples to be measured collected by the spectrum acquisition module into the qualitative discrimination model to discriminate the probability of each fuel sample to be measured belonging to each oil variety or / and the probability of belonging to each grade, and takes the highest probability of the fuel sample to be measured belonging to the oil variety or / and belonging to each grade as the oil variety of the fuel sample to be measured or / and belonging to the grade.
[0075] Among them, the model construction module includes:
[0076] A training sample collection sub-module collects multiple training samples of multiple oil varieties.
[0077] A true label collection sub-module obtains the true labels of the multiple training samples collected by the training sample collection sub-module. The true label is the oil variety to which the training sample belongs or / and the grade to which it belongs. Set the true probability of the oil variety or / and grade corresponding to the true label to 1, and set the probabilities of other oil varieties or / and grades to 0, so as to obtain a true probability matrix composed of the true probabilities of multiple training samples belonging to each oil variety or / and belonging to each grade.
[0078] A training set construction sub-module constructs a training set, and the training set includes the near-infrared spectrum data of the training samples and the true probability matrix.
[0079] A qualitative discrimination model establishment sub-module uses Bayesian regularization for the training set constructed by the training set construction sub-module to introduce prior knowledge to set the range of hyperparameters, optimize the hyperparameters, and construct a Bayesian regularization optimized backpropagation neural network to establish a qualitative discrimination model.
[0080] The steps of using Bayesian regularization for the training set to introduce prior knowledge to set the range of hyperparameters include:
[0081] Select a prior distribution, and the prior distribution is a Gaussian distribution or a uniform distribution.
[0082] Obtain the confidence interval of the hyperparameters whose prior distribution satisfies the normal distribution according to the near-infrared spectrum data and the true probability matrix of the training samples in the training set.
[0083] Set the confidence interval of the hyperparameter setting ratio as the range of the hyperparameters.
[0084] According to a third aspect of the present invention, there is provided a computer-readable storage medium, which includes a near-infrared spectroscopy program for qualitative discrimination of fuel types. When the near-infrared spectroscopy program for qualitative discrimination of fuel types is executed by a processor, the steps of the above-mentioned near-infrared spectroscopy method for qualitative discrimination of fuel types are implemented.
[0085] According to a fourth aspect of the present invention, there is provided an electronic device, including a memory and a processor. The memory includes a near-infrared spectroscopy program for qualitative discrimination of fuel types. When the near-infrared spectroscopy program for qualitative discrimination of fuel types is executed by the processor, the steps of the above-mentioned near-infrared spectroscopy method for qualitative discrimination of fuel types are implemented.
[0086] The present invention optimizes the hyperparameters of a neural network by combining Bayesian regularization with posterior distribution to establish a qualitative discrimination model of near-infrared spectroscopy that can effectively utilize the non-linear relationship information between spectral data. When using the same model to identify the types and / or grades of multiple fuels, it is not affected by the spectral information interference between different types of fuels, and improves the accuracy of fuel type and / or grade identification.
[0087] In order to reduce the phenomena of serious environmental pollution and safety accidents caused by merchants passing off inferior products as good ones, resulting in incorrect use of fuel types and grades, and to improve the accuracy rate in the process of fuel type and its grade identification, so as to quickly, conveniently and efficiently obtain fuel type and grade information. The present invention establishes and screens a qualitative discrimination model for fuels, selects a modeling method that can simultaneously achieve type discrimination and grade identification, and establishes a rapid identification model for simultaneous discrimination of fuel types and grades.
[0088] The present invention analyzes the near-infrared spectral data of training samples by combining Mahalanobis distance, T statistic and F statistic, and eliminates abnormal training models, making the established model more stable and reliable. The present invention adds the calculation of the Euclidean distance in the y-vector direction (i.e., the data reference value dimension direction) of different samples on the basis of SPXY, and combines the distances in the x and y directions through regularization to more comprehensively evaluate and divide the data set. The present invention uses derivative processing to further reduce the influence of baseline drift and wide peaks, and helps to resolve overlapping peaks. The introduction of Bayesian regularization improves the precision of the modeling fitting process and reduces the risk of overfitting. Using the backpropagation neural network optimized by Bayesian regularization to establish a qualitative discrimination model can effectively utilize the non-linear information between spectral data. The qualitative discrimination model of the present invention shows high accuracy and stability in both fuel type and grade identification.
[0089] The present invention applies the Bayesian regularization method to a backpropagation artificial neural network to optimize model parameters and achieve accurate identification of the grades and types of oil products. Traditional gradient descent and its variant parameter optimization methods are prone to falling into local optimal solutions and are greatly affected by the setting of initial parameters. Bayesian regularization not only optimizes the parameters but also improves the adjustment mechanism of the learning rate, making it more flexible and adaptive. This breaks through the limitations of traditional backpropagation artificial neural networks in parameter optimization, making the model more stable and efficient in processing complex data. Bayesian regularization introduces prior knowledge into the model, enabling the model to not only adapt to the training data during the training process but also take into account the model complexity, thereby effectively preventing overfitting and improving the generalization ability. Moreover, it can automatically adjust parameters according to the characteristics of the data. This self-adaptability enables the model to maintain good performance on different data sets without the need to manually adjust too many hyperparameters, providing a new and efficient solution for the identification of oil product grades and types. Description of the Drawings
[0090] Figure 1 is a schematic flowchart of an embodiment of the near-infrared spectroscopy method for qualitative discrimination of oil product types according to the present invention;
[0091] Figure 2 is a schematic flowchart of a preferred embodiment of the method for constructing a qualitative discrimination model through a neural network according to the present invention;
[0092] Figure 3 is a coordinate diagram of eliminating training samples of the near-infrared spectroscopy method for qualitative discrimination of oil product types according to the present invention;
[0093] Figure 4 is a schematic block diagram of an embodiment of the near-infrared spectroscopy system for qualitative discrimination of oil product types according to the present invention;
[0094] Figure 5 is a schematic block diagram of an embodiment of the electronic device according to the present invention;
[0095] Figure 6 is a coordinate diagram of the confusion matrix of the validation set in a specific embodiment of the near-infrared spectroscopy method for qualitative discrimination of oil product types according to the present invention;
[0096] Figure 7 is a coordinate diagram of the ROC curve in a specific embodiment of the near-infrared spectroscopy method for qualitative discrimination of oil product types according to the present invention;
[0097] Figure 8(a) is a coordinate diagram of grade identification of a comparative example of establishing a qualitative discrimination model without Bayesian regularization according to the present invention;
[0098] Figure 8(b) is a coordinate diagram of brand identification in a specific embodiment of the near-infrared spectroscopy method for qualitative discrimination of oil types according to the present invention;
[0099] The realization, functional features, and advantages of the object of the present invention will be further described in conjunction with embodiments with reference to the accompanying drawings. Detailed Embodiments
[0100] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0101] Figure 1 is a schematic flowchart of an embodiment of the near-infrared spectroscopy method for qualitative discrimination of oil types according to the present invention. As Figure 1 shown, the near-infrared spectroscopy method for qualitative discrimination of oil types includes:
[0102] Step S1, obtaining the near-infrared spectra of a plurality of fuel samples to be tested, thereby obtaining near-infrared spectral data;
[0103] Step S2, constructing a qualitative discrimination model through a neural network. The input of the qualitative discrimination model is the near-infrared spectral data, and the output of the qualitative discrimination model is the probability of belonging to each oil type and / or the probability of belonging to each brand;
[0104] Step S3, inputting the near-infrared spectral data of a plurality of fuel samples to be tested into the qualitative discrimination model to discriminate the probability of each fuel sample to be tested belonging to each oil type and / or the probability of belonging to each brand, and taking the highest probability of the fuel sample to be tested belonging to the oil type and / or belonging to each brand as the oil type and / or belonging brand of the fuel sample to be tested.
[0105] In some embodiments of the present invention, the step S2 includes:
[0106] Step S21, selecting a plurality of training samples of a plurality of oil types;
[0107] Step S22, obtaining the true labels of the plurality of training samples. The true labels are the oil types and / or brands to which the training samples belong. Setting the true probability of the oil type and / or brand corresponding to the true label to 1 and the probabilities of other oil types and / or brands to 0, thereby obtaining a true probability matrix composed of the true probabilities of the plurality of training samples belonging to each oil type and / or belonging to each brand;
[0108] Step S23, constructing a training set, where the training set includes the near-infrared spectral data of the training samples and the true probability matrix;
[0109] Step S24: Use Bayesian regularization on the training set to introduce prior knowledge to set the range of hyperparameters, optimize the hyperparameters, and construct a Bayesian-regularized optimized backpropagation neural network to establish a qualitative discrimination model.
[0110] The present invention establishes a qualitative discrimination model for near-infrared spectroscopy that can effectively utilize the non-linear relationship information between spectral data. When using the same model to identify the types and / or grades of various fuels, it is not interfered by the spectral information between different types of fuels, improving the accuracy of fuel type and / or grade identification.
[0111] In some embodiments of the present invention, the step of using Bayesian regularization on the training set to introduce prior knowledge to set the range of hyperparameters in step S24 includes:
[0112] Select a prior distribution, where the prior distribution includes a Gaussian distribution and / or a uniform distribution;
[0113] Obtain the confidence interval of the hyperparameters whose prior distribution satisfies a normal distribution based on the near-infrared spectral data and the true probability matrix of the training samples in the training set;
[0114] Set the confidence interval of a certain proportion of the hyperparameters as the range of the hyperparameters. Preferably, the set proportion is 90%-100%, and more preferably, the set proportion is 95%.
[0115] In some embodiments of the present invention, the step of optimizing the hyperparameters in step S24 includes:
[0116] Construct an objective function through the following formula (1):
[0117] L totul =L + λΩ (θ) (1)
[0118] where L totul is both the total loss function and the objective function; L is the original loss function, measures the difference between the model prediction and the true label, N is the number of training samples, y j is the true probability matrix corresponding to the true label of the i-th training sample, o i is the predicted probability matrix of the i-th training sample, o i (l) =f (l) (w (l) X i +b (l) ),X i is the near-infrared spectral data of the i-th training sample, o i (l) is the output of the l-th layer corresponding to the i-th training sample and is also X iThe prediction probability matrix composed of the prediction probabilities of each oil variety or / and each license plate number, w (l) is the weight matrix of the l-th layer, b (l) is the bias vector of the l-th layer, f (l) is the activation function of the l-th layer. This forward propagation model represents how the input spectral data is processed through a multi-layer neural network. The neurons in each layer transform the input data through weights and biases, and the activation function introduces non-linearity, enabling the model to learn complex patterns in the data; Ω (θ) is the regularization term, Ω (θ) = kL(θ||θprior), where kL() is the KL divergence, θ is the hyperparameter of the neural network, and the hyperparameters include the weight matrix and the bias vector, θprior is the prior probability; λ is the regularization coefficient; the objective function uses regularization to prevent the model from overfitting. Regularization can help the model better generalize to unseen data and improve the classification accuracy;
[0119] Initialize the search space and initialize the search space to the range of hyperparameters;
[0120] Initialize the prior distribution and initialize the probability of each configuration of hyperparameters being selected within the range of hyperparameters according to the prior distribution. For example, the prior distribution describes the prior knowledge of the possibility of hyperparameter configurations. The initial prior distribution is uniform, which means that the probability of each configuration being selected is equal;
[0121] Sampling, randomly sample a configuration of hyperparameters;
[0122] Evaluation, obtain the objective function corresponding to the configuration of the hyperparameters;
[0123] Update, update the prior distribution according to the objective function corresponding to the configuration of the hyperparameters, including: calculating the likelihood function of the objective function corresponding to the configuration of the hyperparameters and the likelihood function of the prior distribution, and then using Bayes' theorem to update the prior distribution; the updated prior distribution reflects the influence of new data points on the possibility of hyperparameter configurations; if a hyperparameter configuration performs well on the objective function, then its probability in the posterior distribution will increase; if it performs poorly, the probability will decrease, and the prior distribution gradually changes from a uniform distribution to a distribution more concentrated on those hyperparameter configurations that perform well on the objective function;
[0124] Iterate the process of sampling, evaluation, and update until the iteration termination condition is met to obtain the optimal hyperparameters. The iteration termination conditions include: reaching the preset number of iterations or / and reaching the number of evaluations; as the number of iterations increases, the prior distribution will gradually become more concentrated, which means that the selection of hyperparameter configurations will get closer and closer to those configurations that perform well on the objective function; select the hyperparameter configuration with the best performance as the final result.
[0125] The present invention regards the objective function as a probability distribution, and updates this distribution by collecting the evaluation results of the objective function, and then predicts the best position for the next evaluation.
[0126] In some embodiments of the present invention, the step of using Bayes' theorem to update the prior distribution includes:
[0127] Update the prior distribution according to the near-infrared spectral data and probability of the training samples in the training set through the following formula (2):
[0128]
[0129] Where D is the observed data, the observed data is the near-infrared spectral data and probability of the training samples in the training set, p(θ|D) is the updated prior distribution, p(D|θ) is the likelihood function of the objective function corresponding to the configuration of the hyperparameters, p(θ) is the prior distribution before update, and p(D) is the total probability of the observed data, which is obtained by adding the probabilities of each observed data and dividing by the total number of observed data.
[0130] If a hyperparameter configuration performs well on the objective function, then its value in the likelihood function will be high. Bayes' theorem combines this information to give the probability distribution of the hyperparameter configuration after observing the data, enabling the qualitative discriminant model to adjust the hyperparameters according to the performance of the data, so as to find the best hyperparameter configuration.
[0131] In some embodiments of the present invention, the hyperparameters further include one or more of the learning rate, batch size, number of layers, and number of neurons per layer. Among them, the learning rate determines the speed of model parameter update; batch size: the number of samples used to train the model in each iteration; number of layers: the number of hidden layers included in the neural network; number of neurons per layer: the number of neurons included in each hidden layer.
[0132] In some embodiments of the present invention, the step of optimizing the hyperparameters in step S24 further includes:
[0133] Perform gradient descent on the hyperparameters:
[0134]
[0135] Where ΔW and Δb are the gradients of the weights and biases respectively, and α is the learning rate, and are the gradients of the weights and biases respectively.
[0136] The present invention updates the model parameters through the gradient descent algorithm. The gradient provides the direction and magnitude of the parameter update, and the learning rate determines the speed of the parameter update. By iteratively updating the parameters, the model can gradually reduce the value of the loss function.
[0137] In some embodiments of the present invention, the steps of constructing a Bayesian regularization optimized backpropagation neural network to establish a qualitative discrimination model in step S24 include:
[0138] Establish a qualitative discrimination model through the following formula (3):
[0139]
[0140] where, O c = soft max(W0X + b0), X is the near-infrared spectral data of the fuel sample to be measured, W0 and b0 are the weight matrix and bias vector of the output layer after training through the training set respectively, O c is the prediction probability on the c-th oil product category of the fuel sample to be measured, is the prediction label of the oil product type of the fuel sample to be measured.
[0141] In some embodiments of the present invention, step S23 includes:
[0142] Eliminate abnormal training samples in the training set;
[0143] In some embodiments of the present invention, the steps of eliminating abnormal training samples in the training set include:
[0144] Randomly select multiple training samples from the training set to form an abnormal training set for elimination;
[0145] Obtain the mean value of the spectral values at each wavelength of the spectral matrix of the abnormal training set for elimination through formula (4), obtain the standard deviation of the spectral values at each wavelength of the spectral matrix of the abnormal training set for elimination through formula (5), and perform standardization processing on the spectral values of the spectral matrix by using the mean value and standard deviation of the spectral values at each wavelength of the spectral matrix of the abnormal training set for elimination through formula (6) to obtain a standard spectral matrix
[0146]
[0147] where, μ lsj is the mean value of the spectral values at the j-th wavelength, i is the training sample index, j is the wavelength index, σ lsj is the standard deviation of the spectral values at the j-th wavelength, ls uj is the spectral value of the i-th training sample at the j-th wavelength, ls′ ijls' ij I×J , where I is the total number of training samples and J is the total number of wavelengths;
[0148] The covariance matrix of the standard spectral matrix is obtained through Equation (7):
[0149]
[0150] The covariance matrix is eigen-decomposed through Equation (8) to obtain the eigenvalues and eigenvectors of each training sample:
[0151] ∑CM = V * DM (8)
[0152] where DM is a diagonal matrix containing the eigenvalues of the covariance matrix, and V is the eigenmatrix, and the columns of V are the corresponding eigenvectors;
[0153] Select the eigenvectors corresponding to the number of dimensions to be reduced according to the order of eigenvalues from large to small to form a projection matrix:
[0154] PM = [v1, v2,..., v k (9)
[0155] where PM is the projection matrix and K is the number of dimensions to be reduced;
[0156] The standard spectral matrix is transformed into a dimensionality-reduced spectral matrix through the projection matrix by Equation (10):
[0157] DR = LS' * PM (10)
[0158] where DR is the dimensionality-reduced spectral matrix, DR = [dr ik I×K ; [dr ik is the matrix calculation for the k-th dimension of the i-th training sample; I is the total number of training samples;
[0159] The Mahalanobis distance of the vector corresponding to each training sample in the dimensionality-reduced spectral matrix is obtained, and the Mahalanobis distance is used as the T statistic to obtain the T statistic matrix;
[0160] The first degree of freedom is K, and the second degree of freedom is I - K - 1. The critical value of the T statistic is found in the T distribution critical table according to the first and second degrees of freedom, and the training samples corresponding to the T statistics with a difference greater than the first difference range from the critical value of the T statistic are used as abnormal training samples;
[0161] Input the standard index matrix after removing the abnormal training set and the dimensionality-reduced spectral matrix into the qualitative discrimination model for training. Input the dimensionality-reduced spectral matrix after removing the abnormal training set into the trained qualitative discrimination model to obtain a prediction probability matrix composed of the prediction probabilities of the abnormal training set removed. Obtain a residual index matrix composed of the residuals of the true probabilities and the prediction probabilities through the true probability matrix corresponding to the true labels of the abnormal training set removed and the prediction probability matrix. Construct an F-statistic matrix of the residual index matrix through F-statistics;
[0162] The first degree of freedom is K, and the second degree of freedom is I - K - 1. Look up the second critical value in the F-test critical value table according to the first degree of freedom and the second degree of freedom. Take the training samples corresponding to the F-statistics whose difference from the second critical value is greater than the second difference range as abnormal training samples.
[0163] In the method for removing abnormal training samples of the present invention, the spectral data is sampled to generate training samples, and the spectral data of the training samples is mapped from a high-dimensional space to a low-dimensional space, so that the main features of the spectral data are retained. Then, through the Mahalanobis distance in the low-dimensional space. Using the T-statistic critical value as the threshold, mark the data points whose distance exceeds the threshold as outliers and exclude them from consideration, screening out the samples abnormal on the X-axis, and screening out the abnormal samples with large deviations between the predicted values and the true values on the Y-axis through the F-statistic. Moreover, a scheme combining the degrees of freedom of the T-statistic and the F-statistic is adopted, reducing the complexity while ensuring the accuracy and comprehensiveness of removing abnormal samples.
[0164] In some embodiments of the present invention, after the step of removing abnormal training samples in the training set in step S23, the following steps are further included:
[0165] Perform baseline correction on the near-infrared spectra of the normal training samples after removing the abnormal training samples;
[0166] Preferably, the step of performing baseline correction on the near-infrared spectra of the normal training samples after removing the abnormal training samples in the training set includes:
[0167] Perform derivative processing on the spectral matrix of the normal training samples to obtain a derivative matrix composed of derivative values. The derivative processing is first-order derivative processing or high-order derivative processing. Preferably, the derivative processing is second-order derivative processing;
[0168] Among them, the training set after baseline correction includes a derivative matrix composed of the derivative values of the spectral values of the normal training samples and the true probability matrix of the normal training samples.
[0169] In some embodiments of the present invention, step S23 includes: performing baseline correction on the near-infrared spectra of multiple training samples;
[0170] In some embodiments of the present invention, the step of performing baseline correction on the near-infrared spectra of a plurality of training samples includes:
[0171] Performing derivative processing on the spectral matrix of a plurality of training samples to obtain a derivative matrix composed of derivative values. The derivative processing is first-order derivative processing or higher-order derivative processing. Preferably, the derivative processing is second-order derivative processing;
[0172] Among them, the training set after baseline correction includes a derivative matrix composed of derivative values of the spectral values of the training samples and a true probability matrix of the training samples.
[0173] Figure 2 is a schematic flowchart of a preferred embodiment of the method for constructing a qualitative discrimination model by a neural network according to the present invention. As Figure 2 shown, the method for constructing a qualitative discrimination model by a neural network includes:
[0174] Step S210, analyzing the near-infrared spectral data (spectral matrix) of a plurality of training samples and removing abnormal training samples, including:
[0175] Step 211, randomly selecting a plurality of training samples from the training sample set to form a set of training samples for removing abnormal samples. Obtain the mean value of the spectral values at each wavelength of the spectral matrix of the set of training samples for removing abnormal samples through formula (4), obtain the standard deviation of the spectral values at each wavelength of the spectral matrix of the set of training samples for removing abnormal samples through formula (5), and perform standardization processing on the spectral values of the spectral matrix by using the mean value and standard deviation of the spectral values at each wavelength of the spectral matrix of the set of training samples for removing abnormal samples through formula (6) to obtain a standard spectral matrix LS′. LS is the spectral matrix of the set of training samples for removing abnormal samples, I is the number of training samples in the set of training samples for removing abnormal samples, J is the number of wavelengths, and ls IJ is the spectral value of the I-th training sample at the J-th wavelength. The spectral value is a spectral value such as reflectance or absorptance;
[0176] Step S212, obtaining the covariance matrix of the standard spectral matrix through formula (7);
[0177] Step S213, performing eigenvalue decomposition on the covariance matrix through formula (8) to obtain the eigenvalues and eigenvectors of each training sample;
[0178] Step S214, selecting the corresponding number of eigenvectors corresponding to the number of dimensions to be reduced in descending order of eigenvalues to form a projection matrix;
[0179] Step S215, transforming the standard spectral matrix into a reduced-dimensional spectral matrix through the projection matrix through formula (10);
[0180] Step S216: Obtain the Mahalanobis distance of the vector corresponding to each training sample in the dimensionality-reduced spectral matrix, and use the Mahalanobis distance as the T statistic, so as to obtain a T statistic matrix;
[0181] Step S217: The first degree of freedom is K, and the second degree of freedom is I - K - 1. Look up the critical value of the T statistic in the T distribution critical value table according to the first degree of freedom and the second degree of freedom, and use the training samples corresponding to the T statistic whose difference from the critical value of the T statistic is greater than the first difference range as abnormal training samples. As Figure 3 shown, the abscissa is the T statistic, the critical value of the T statistic is 8.06240, and the points to the right of the vertical line corresponding to the critical value of the T statistic are abnormal training samples;
[0182] Step S218: Input the standard index matrix and the dimensionality-reduced spectral matrix after removing the abnormal training set into the qualitative discrimination model for training, input the dimensionality-reduced spectral matrix after removing the abnormal training set into the trained qualitative discrimination model, obtain a prediction probability matrix composed of the prediction probabilities after removing the abnormal training set, obtain a residual index matrix composed of the residuals of the true probabilities and the prediction probabilities through the true probability matrix corresponding to the true labels after removing the abnormal training set and the prediction probability matrix, and construct an F statistic matrix of the residual index matrix through the F statistic;
[0183] Step S219: The first degree of freedom is K, and the second degree of freedom is I - K - 1. Look up the second critical value in the F test critical value table according to the first degree of freedom and the second degree of freedom, and use the training samples corresponding to the F statistic whose difference from the second critical value is greater than the second difference range as abnormal training samples. As Figure 3 shown, the ordinate is the F statistic, the critical value of the F statistic is 0.00594, and the points above the horizontal line corresponding to the critical value of the F statistic are abnormal training samples;
[0184] Step S220: Spectral preprocessing: Perform baseline correction on the near-infrared spectral data of multiple normal training samples after removing abnormal training samples to eliminate the spectral baseline offset phenomenon caused by factors such as instruments and the background of training samples, and at the same time make the information differences between training samples more obvious, including:
[0185] Perform derivative processing on the normal training sample spectral matrix. The derivative processing is first-order derivative processing or high-order derivative processing, and the derivative spectral matrix after derivative processing is Z is the number of normal training samples after excluding abnormal training samples. Preferably, the derivative processing is second-order derivative processing. If the spectral image is represented by a function, taking the derivative can eliminate the numerical remainder in the function formula. The remainder can be reflected as an upward or downward translation in the graph. Therefore, using the second-order derivative can eliminate the baseline shift. At the same time, the second-order derivative represents the curvature of the data, and the convex and concave information of the data curve can be obtained, thereby amplifying the convex and concave information in the curve that is not obvious itself.
[0186] Step S230: Divide the normal training samples after baseline correction into a calibration set and a validation set. The calibration set is used to establish a qualitative discrimination model, and the validation set is used to verify the discrimination ability of the qualitative discrimination model. Preferably, the SPXY algorithm is used to divide the normal training samples after spectral preprocessing into a calibration set and a validation set.
[0187] Step S240: Use the calibration set to introduce prior knowledge through Bayesian Regularization (BR) to set the range of hyperparameters, construct a probability model, calculate the posterior distribution, so as to optimize the hyperparameters and construct a Bayesian Regularization Optimized Back Propagation Artificial Neural Network (BR-BP-ANN) to establish a qualitative discrimination model for oil product types and grades.
[0188] Step S250: Evaluate the performance of the qualitative discrimination model through the validation set according to the performance evaluation indicators. The performance evaluation indicators include one or more of accuracy (Acc), precision (PPV), recall rate (TPR), and Receiver Operating Characteristic curve (ROC curve).
[0189] TPR = TP / (TP + FN)
[0190] PPV = TP / (TP + FP)
[0191] Acc = (TP + TN) / (TP + FP + TN + FN)
[0192] Wherein: TP, FP, TN, and FN are respectively the number of positive training samples correctly predicted, the number of negative training samples mispredicted as positive training samples, the number of negative training samples correctly predicted, and the number of positive training samples mispredicted; TPR: sensitivity, which describes the proportion of correctly identified positive training samples among all positive training samples; PPV: precision, which describes the proportion of correctly identified positive training samples among the predicted positive training samples; Acc: Accuracy, which describes the classification accuracy of the classifier; The recall rate represents the recognition ability of the model for positive training samples. The higher the recall rate, the lower the probability of recognition omission. The precision rate represents the differential features between positive training samples and negative training samples. The higher the precision rate, the higher the probability of correctly judging positive training samples. The ROC curve visualizes the performance of the classification model through the relationship between the True Positive Rate (TPR) and the False Positive Rate (FPR) under different threshold conditions. The area under the ROC curve is AUC (Area under ROC Curve). The value of AUC generally ranges between 0 and 1. The closer the value of AUC is to 1, the better the model's discrimination ability. The closer the value of AUC is to 0, the worse the model's discrimination ability. When the value of AUC is equal to 0.5, it means the model's discrimination ability is random.
[0193] In some embodiments of the present invention, the method for constructing a qualitative discrimination model through a neural network further includes:
[0194] Step S260, if the result of the performance evaluation of the qualitative discrimination model in step S250 meets the performance requirements, where the performance requirements are the required range of the index values of the performance evaluation indicators, then the discrimination model established in step S240 is established; if the result of the performance evaluation of the qualitative discrimination model in step S250 does not meet the performance requirements, then return to step S230 to re-partition the calibration set and the validation set, and repeat steps S240 and S250 until the performance requirements are met.
[0195] Figure 4 It is a schematic block diagram of an embodiment of the near-infrared spectroscopy system for qualitative discrimination of oil types according to the present invention, as Figure 4 shown, the near-infrared spectroscopy system for qualitative discrimination of oil types includes:
[0196] A spectral acquisition module 100 that acquires the near-infrared spectra of a plurality of fuel samples to be measured, thereby obtaining near-infrared spectral data;
[0197] The model construction module 200 constructs a qualitative discrimination model through a neural network. The input of the qualitative discrimination model is near-infrared spectral data, and the output of the qualitative discrimination model is the probability belonging to each oil type and / or the probability belonging to each grade.
[0198] The qualitative discrimination module 300 inputs the near-infrared spectral data of multiple fuel samples to be measured collected by the spectral acquisition module into the qualitative discrimination model to determine the probability belonging to each oil type and / or the probability belonging to each grade of each fuel sample to be measured, and takes the highest probability that the fuel sample to be measured belongs to the oil type and / or belongs to each grade as the oil type and / or the grade to which the fuel sample to be measured belongs.
[0199] In some embodiments of the present invention, the model construction module 200 includes:
[0200] The training sample acquisition sub-module 210 acquires multiple training samples of multiple oil types.
[0201] The true label acquisition sub-module 220 obtains the true labels of the multiple training samples acquired by the training sample acquisition sub-module. The true labels are the oil types and / or grades to which the training samples belong. Set the true probability of the oil type and / or grade corresponding to the true label to 1, and set the probabilities of other oil types and / or grades to 0, so as to obtain a true probability matrix composed of the true probabilities that multiple training samples belong to each oil type and / or belong to each grade.
[0202] The training set construction sub-module 230 constructs a training set, and the training set includes the near-infrared spectral data of the training samples and the true probability matrix.
[0203] The qualitative discrimination model establishment sub-module 240 uses Bayesian regularization to introduce prior knowledge to set the range of hyperparameters for the training set constructed by the training set construction sub-module, optimizes the hyperparameters, and constructs a Bayesian regularization optimized backpropagation neural network to establish a qualitative discrimination model.
[0204] In some embodiments of the present invention, the qualitative discrimination model establishment sub-module 240 includes:
[0205] The hyperparameter range acquisition unit 241 uses Bayesian regularization to introduce prior knowledge to obtain the range of hyperparameters for the training set.
[0206] The hyperparameter optimization unit 242 optimizes the hyperparameters.
[0207] The model establishment unit 243 constructs a Bayesian regularization optimized backpropagation neural network to establish a qualitative discrimination model.
[0208] In some embodiments of the present invention, the hyperparameter range acquisition unit includes:
[0209] A prior distribution selection subunit selects a prior distribution, and the prior distribution includes a Gaussian distribution and / or a uniform distribution;
[0210] A confidence interval analysis subunit obtains a confidence interval of hyperparameters for which the prior distribution satisfies a normal distribution based on the near-infrared spectral data and the true probability matrix of the training samples in the training set;
[0211] A hyperparameter range analysis subunit sets the confidence interval of a hyperparameter ratio as the range of the hyperparameter. Preferably, the set ratio is 90%-100%, and further preferably, the set ratio is 95%.
[0212] In some embodiments of the present invention, the hyperparameter optimization unit includes:
[0213] A target function construction subunit constructs a target function through formula (1);
[0214] An initialization subunit initializes the search space as the range of the hyperparameter and initializes the probability of each configuration of the hyperparameter being selected within the range of the hyperparameter according to the prior distribution;
[0215] A sampling subunit randomly samples a configuration of the hyperparameter;
[0216] An evaluation subunit obtains the target function corresponding to the configuration of the hyperparameter;
[0217] An update subunit updates the prior distribution according to the target function corresponding to the configuration of the hyperparameter.
[0218] In some embodiments of the present invention, the above-mentioned training set construction sub-module 230 may include one or more of the following units:
[0219] An abnormal rejection unit 231 analyzes the spectral matrix of multiple training samples and rejects abnormal training samples;
[0220] A baseline correction unit 232 performs baseline correction on the near-infrared spectral data of multiple training samples;
[0221] A training set division subunit 233 divides the training samples into a calibration set and a validation set.
[0222] The above-mentioned near-infrared spectral method for qualitative discrimination of various oil types in the present invention can be applied to the electronic device 1. Refer to Figure 5 As shown, it is a schematic diagram of the application environment of the preferred embodiment of the near-infrared spectral method for qualitative discrimination of various oil types in the present invention.
[0223] In this embodiment, the electronic device 1 may be a terminal device with computing functions such as a server, a smart phone, a tablet computer, a portable computer, a desktop computer, etc.
[0224] The electronic device 1 includes: a processor 12 and a memory 11, and may also include a network interface 13, a communication bus 14, etc.
[0225] The memory 11 includes at least one type of readable storage medium. The at least one type of readable storage medium may be a non-volatile storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory, etc. In some embodiments, the readable storage medium may be an internal storage unit of the electronic device 1, such as the hard disk of the electronic device 1. In other embodiments, the readable storage medium may also be an external memory of the electronic device 1, such as a plug-in hard disk equipped on the electronic device 1, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc.
[0226] In this embodiment, the readable storage medium of the memory 11 is generally used to store the near-infrared spectroscopy program 10 for qualitative discrimination of oil types installed in the electronic device 1, training samples, and data sets of training samples, etc. The memory 11 can also be used to temporarily store data that has been output or will be output.
[0227] In some embodiments, the processor 12 may be a central processing unit (CPU), a microprocessor, or other data processing chips, and is used to run the program code stored in the memory 11 or process data, such as executing the near-infrared spectroscopy program 10 for qualitative discrimination of oil types, etc.
[0228] The network interface 13 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), and is generally used to establish a communication connection between the electronic device 1 and other electronic devices.
[0229] The communication bus 14 is used to realize the connection and communication between these components.
[0230] Figure 5 Only the electronic device 1 with components 11 - 14 is shown, but it should be understood that it is not required to implement all the shown components, and more or fewer components can be alternatively implemented.
[0231] Optionally, the electronic device 1 may further include a user interface. The user interface may include an input unit such as a keyboard, a voice input device such as a microphone and other devices with voice recognition functions, a voice output device such as a speaker, headphones, etc. Optionally, the user interface may also include a standard wired interface, a wireless interface.
[0232] Optionally, the electronic device 1 may further include a display, which may also be referred to as a display screen or a display unit. In some embodiments, it may be an LED display, a liquid crystal display, a touch liquid crystal display, an organic light-emitting diode (OLED) touch device, etc. The display is used to display the information processed in the electronic device 1 and to display a visual user interface.
[0233] Optionally, the electronic device 1 further includes a touch sensor. The area provided by the touch sensor for the user to perform a touch operation is called a touch area. In addition, the touch sensor described herein may be a resistive touch sensor, a capacitive touch sensor, etc. Moreover, the touch sensor includes not only a contact type touch sensor, but also a proximity type touch sensor, etc. In addition, the touch sensor may be a single sensor or multiple sensors arranged in an array, for example.
[0234] In addition, the area of the display of the electronic device 1 may be the same as or different from the area of the touch sensor. Optionally, the display and the touch sensor are stacked to form a touch display screen. The device detects a touch operation triggered by the user based on the touch display screen.
[0235] Optionally, the electronic device 1 may further include a radio frequency (RF) circuit, sensors, an audio circuit, etc., which will not be elaborated here.
[0236] In addition, an embodiment of the present invention further provides a computer-readable storage medium, which includes a near-infrared spectroscopy program for qualitative discrimination of oil types. When the near-infrared spectroscopy program for qualitative discrimination of oil types is executed by a processor, the steps of the near-infrared spectroscopy method for qualitative discrimination of oil types in the above embodiments are implemented.
[0237] The specific implementation manner of the computer-readable storage medium of the present invention is substantially the same as the specific implementation manners of the above near-infrared spectroscopy method for qualitative discrimination of oil types and the electronic device, and will not be elaborated here.
[0238] In order to verify the application effect of the near-infrared spectroscopy method for qualitative discrimination of oil types of the present invention in actual samples, the following specific embodiments are carried out:
[0239] A total of 80 samples of different grades of jet fuel, diesel, and gasoline were randomly selected from the Beijing area as training samples;
[0240] The true labels of the training samples were obtained through the factory inspection reports of the training samples, and the true labels are the true oil types and grades;
[0241] Eliminate abnormal training samples by combining the T statistic and the F statistic, such as Figure 3 as shown;
[0242] Perform spectral preprocessing of the second derivative on the spectral data of normal training samples;
[0243] Divide the normal training samples to obtain a calibration set and a validation set. For example, select 11 training samples as the validation set;
[0244] Use Bayesian regularization for the calibration set to introduce prior knowledge to set the range of hyperparameters, optimize the hyperparameters, and construct a Bayesian regularization optimized backpropagation neural network to establish a qualitative discrimination model;
[0245] Use the validation set as the fuel sample to be tested and input it into the above qualitative discrimination model for verification, including:
[0246] Preheat the spectrometer for 30 min, set the wavelength resolution of 12 nm and the wavelength range of 800 nm to 1700 nm for spectral acquisition. Detect with air as the background. Each sample is scanned 7 times, and the mean value is taken as the spectral scan result for that time. To reduce the influence of factors such as instrument status and environment, each sample is tested 5 times repeatedly, and the average value is taken as the input spectral variable for modeling. The prediction results are shown in Table 1:
[0247] Table 1
[0248]
[0249]
[0250] As shown in the above table, there is no significant difference between the actual classification results and the prediction results of 11 groups of fuels. The correct rate of type identification is 100%, and the correct rate of brand identification is 100%. It shows that the qualitative discrimination model of the present invention has an accurate identification ability for a total of 9 brands of three types of oils, namely jet fuel, diesel, and gasoline, and can meet the requirements of on-site rapid detection and analysis.
[0251] Evaluate the performance of the qualitative discrimination model through the validation set. It can be seen from Figure 6 that when the qualitative discrimination model of the present invention is used to identify the types of oils in the validation set, the PPV value, TPR value, and Acc value are all 100.0%. Draw the ROC curve for it ( Figure 7)The AUC values of jet fuel, diesel, and gasoline are 0.9993, 0.9973, and 0.9973 respectively. From the data calculation in Figure 8(b), it can be seen that the PPV value, TPR value, and Acc value of oil brand identification all exceed 90.0%, and the brand discrimination accuracy rate is close to 95.0%. In practical applications (Table 1), the correct rate of type identification and the correct rate of brand identification are both 100%. Compared with the model without Bayesian regularization optimization (as shown in Figure 8(a)), its PPV value, TPR value, and Acc value are increased by 10.51%, 9.14%, and 9.10% respectively. It is a reliable oil type and brand identification model. Therefore, the present invention can effectively mine the information with high correlation with the type in the spectrum, and improve the accuracy and reliability of model identification and classification.
[0252] In order to reduce the phenomena of serious environmental pollution and safety accidents caused by merchants substituting inferior products for good ones, resulting in incorrect use of fuel types and brands, and to improve the accuracy rate in the process of fuel type and its brand identification, so as to quickly, conveniently, and efficiently obtain fuel type and brand information. The present invention establishes and screens a qualitative discrimination model for three most widely used fuels, namely diesel, gasoline, and jet fuel, selects a modeling method that can simultaneously realize type discrimination and brand identification, and establishes a rapid identification model for simultaneous discrimination of fuel type and brand.
[0253] The present invention applies the Bayesian regularization method to the backpropagation neural network to optimize the model parameters and achieve accurate identification of the brands and types of three oil products, namely diesel, gasoline, and jet fuel. The traditional gradient descent and its variant parameter optimization methods are prone to falling into local optimal solutions and are greatly affected by the initial parameter settings. Bayesian regularization not only optimizes the parameters but also improves the adjustment mechanism of the learning rate, making it more flexible and adaptive. This breaks through the limitations of the traditional backpropagation neural network in parameter optimization, making the model more stable and efficient in processing complex data. Bayesian regularization introduces prior knowledge into the model, enabling the model to not only adapt to the training data during the training process but also take into account the model complexity, thereby effectively preventing overfitting and improving the generalization ability. And it can automatically adjust the parameters according to the characteristics of the data. This self-adaptability enables the model to maintain good performance on different data sets without the need to manually adjust too many hyperparameters, providing a new and efficient solution for the identification of oil brands and types.
[0254] It should be noted that in this document, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article or method comprising a series of elements not only includes those elements but also other elements not expressly listed, or further includes elements inherent to such process, apparatus, article or method. Without further limitation, an element defined by the phrase "comprising an..." does not exclude the presence of additional identical elements in the process, apparatus, article or method comprising that element.
[0255] The serial numbers of the above-described embodiments of the present invention are merely for description and do not represent the superiority or inferiority of the embodiments. Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation. Based on such understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product is stored in a storage medium as described above (such as ROM / RAM, magnetic disk, optical disc) and includes several instructions for causing a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0256] The above are only the preferred embodiments of the present invention and do not limit the patent scope of the present invention accordingly. Any equivalent structural or equivalent process transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present invention.
Claims
1. A near infrared spectroscopy method for qualitative identification of oil types, characterized in that: include: Obtaining near infrared spectra of a plurality of fuel samples to be tested, thereby obtaining near infrared spectrum data; A qualitative discrimination model is constructed by a neural network, wherein the input of the qualitative discrimination model is near infrared spectral data, and the output of the qualitative discrimination model is the probability of belonging to each oil type and / or the probability of belonging to each brand; Inputting the near infrared spectrum data of multiple fuel samples to be tested into the qualitative discrimination model to discriminate the probability of each fuel sample to be tested belonging to each fuel type and / or each brand, and taking the highest probability of the fuel sample to be tested belonging to each fuel type and / or each brand as the fuel type and / or brand of the fuel sample to be tested; The step of constructing a qualitative discrimination model through a neural network includes: Select multiple training samples of multiple oil types; Obtaining true labels of multiple training samples, wherein the true labels are the oil types and / or brands to which the training samples belong, setting the true probability of the oil types and / or brands corresponding to the true labels to 1, and setting the probabilities of other oil types and / or brands to 0, thereby obtaining a true probability matrix consisting of the true probabilities of the multiple training samples belonging to each oil type and / or brand; Constructing a training set, wherein the training set includes near-infrared spectral data of training samples and a true probability matrix; Use Bayesian regularization to introduce prior knowledge into the training set to set the range of hyperparameters, optimize the hyperparameters, and construct a Bayesian regularization optimized back propagation neural network to establish a qualitative discrimination model; The step of using Bayesian regularization to introduce prior knowledge to set the range of hyperparameters in the training set includes: Select a prior distribution, wherein the prior distribution is a Gaussian distribution or a uniform distribution; According to the near infrared spectral data of the training samples in the training set and the true probability matrix, the confidence interval of the hyperparameter whose prior distribution satisfies the normal distribution is obtained; Set the confidence interval for the hyperparameter setting ratio to the range of the hyperparameter.
2. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 1 is characterized in that: The setting ratio is 90%-100%.
3. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 1 is characterized in that: The set ratio is 95%.
4. The near infrared spectroscopy method for qualitative identification of oil types according to claim 1 is characterized in that: The step of optimizing the hyperparameters comprises: The objective function is constructed by the following formula (1): L totul =L+λΩ (θ) (1) Among them, L totul is the total loss function and the objective function; L is the original loss function, N is the number of training samples, y j is the true probability matrix corresponding to the true label of the i-th training sample, o i is the prediction probability matrix of the i-th training sample, o i (l) =f (l) (w (l) X i +b (l) ), X i is the near infrared spectrum data of the i-th training sample, o i (l) The output of the lth layer corresponding to the i-th training sample is also X i The prediction probability matrix consisting of the prediction probabilities of each oil type and / or each license plate, w (l) is the weight matrix of the lth layer, b (l) is the bias vector of the lth layer, f (l) is the activation function of the lth layer; Ω (θ) is the regularization term, Ω (θ) =kL(θ||θprior), kL( ) is the KL divergence, θ is the hyperparameter of the neural network, the hyperparameter includes the weight matrix and the bias vector, θprior is the prior probability; λ is the regularization coefficient; Initialize the search space, initialize the search space to the range of the hyperparameters; Initialize the prior distribution, and initialize the probability of each configuration of the hyperparameters being selected within the range of the hyperparameters according to the prior distribution; Sampling, randomly sampling a hyperparameter configuration; Evaluate and obtain the objective function corresponding to the configuration of the hyperparameters; Updating, updating the prior distribution according to the objective function corresponding to the configuration of the hyperparameter, including: calculating the likelihood function of the objective function corresponding to the configuration of the hyperparameter and the likelihood function of the prior distribution, and then using Bayes' theorem to update the prior distribution; The process of iterative sampling, evaluation and updating is continued until the iteration termination condition is met to obtain the optimal hyperparameters. The iteration termination condition includes: reaching a preset number of iterations and / or reaching the number of evaluations.
5. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 4 is characterized in that: The steps of using Bayes' theorem to update the prior distribution include: According to the near infrared spectral data and probability of the training samples in the training set, the prior distribution is updated by the following formula (2): Where D is the observed data, which is the near-infrared spectral data and probability of the training samples in the training set, p(θ|D) is the updated prior distribution, p(D|θ) is the likelihood function of the objective function corresponding to the configuration of the hyperparameters, p(θ) is the prior distribution before updating, and p(D) is the total probability of the observed data, which is the sum of the probabilities of each observed data and divided by the total number of observed data.
6. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 4 is characterized in that: The step of optimizing the hyperparameters further comprises: Perform gradient descent on the hyperparameters.
7. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 1 is characterized in that: The steps of constructing a Bayesian regularized optimized back propagation neural network to establish a qualitative discrimination model include: The qualitative discrimination model is established by the following formula (3): Among them, O c =softmax(W0X+b0), X is the near infrared spectrum data of the fuel sample to be tested, W0 and b0 are the weight matrix and bias vector of the output layer after training with the training set, respectively. c is the predicted probability of the cth fuel category of the fuel sample to be tested, is the predicted label of the fuel type of the fuel sample to be tested.
8. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 1 is characterized in that: The step of constructing a training set includes: Remove abnormal training samples from the training set.
9. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 8 is characterized in that: The step of removing abnormal training samples in the training set includes: Randomly select multiple training samples from the training set to form an abnormal elimination training set; The mean spectral value at each wavelength of the spectral matrix of the training set with abnormalities removed is obtained by formula (4), the standard deviation of the spectral value at each wavelength of the spectral matrix of the training set with abnormalities removed is obtained by formula (5), and the spectral value of the spectral matrix is standardized by using the mean spectral value and the standard deviation of the spectral value at each wavelength of the spectral matrix of the training set with abnormalities removed by formula (6) to obtain the standard spectral matrix Among them, μ lsj is the mean spectral value at the jth wavelength, i is the training sample index, j is the wavelength index, σ lsj is the standard deviation of the spectral value at the jth wavelength, ls ij is the spectral value of the i-th training sample at the j-th wavelength, ls′ ij is the standard spectrum value of the i-th training sample at the j-th wavelength after standardization, LS′ is the standard spectrum matrix, LS′=[ls′ ij ] I×J , I is the total number of training samples, J is the total number of wavelengths; The covariance matrix of the standard spectral matrix is obtained by formula (7): The covariance matrix is decomposed by formula (8) to obtain the eigenvalue and eigenvector of each training sample: ΣCM=V*DM (8) Where DM is the diagonal matrix containing the eigenvalues of the covariance matrix, V is the characteristic matrix, and the columns of V are the corresponding eigenvectors; Select the eigenvectors corresponding to the number of dimensions to be achieved by dimensionality reduction in descending order of eigenvalues to form a projection matrix: PM=[v1,v2,…,v K ](9) Among them, PM is the projection matrix, K is the number of dimensions to be achieved by dimensionality reduction; The standard spectral matrix is transformed into a reduced-dimensional spectral matrix through the projection matrix using formula (10): DR=LS′*PM (10) Among them, DR is the dimension-reduced spectrum matrix, DR = [dr ik ] I×K ; [dr ik ] is the matrix calculation for the k-th latitude of the i-th training sample; I is the total number of training samples; Obtaining the Mahalanobis distance of the vector corresponding to each training sample in the dimension-reduced spectrum matrix, and using the Mahalanobis distance as the T statistic, thereby obtaining a T statistic matrix; The first degree of freedom is K, the second degree of freedom is IK-1, the critical value of the T statistic is searched in the T distribution critical table according to the first degree of freedom and the second degree of freedom, and the training samples corresponding to the T statistic whose difference with the critical value of the T statistic is greater than the first difference range are taken as abnormal training samples; The standard indicator matrix and the reduced-dimensional spectrum matrix of the training set with abnormalities removed are input into the qualitative discriminant model for training, and the reduced-dimensional spectrum matrix of the training set with abnormalities removed is input into the trained qualitative discriminant model to obtain a predicted probability matrix composed of the predicted probabilities of the training set with abnormalities removed, and a residual indicator matrix composed of the residuals of the true probability and the predicted probability is obtained through the true probability matrix and the predicted probability matrix corresponding to the true labels of the training set with abnormalities removed, and an F statistic matrix of the residual indicator matrix is constructed through the F statistic; The first degree of freedom is K, the second degree of freedom is IK-1, and the second critical value is searched in the F test critical value table according to the first degree of freedom and the second degree of freedom. The training samples corresponding to the F statistic whose difference with the second critical value is greater than the second difference range are taken as abnormal training samples.
10. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 8, characterized in that: The step of removing abnormal training samples from the training set also includes: The near-infrared spectra of normal training samples after removing abnormal training samples are baseline corrected.
11. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 10, characterized in that: The step of performing baseline correction on the near infrared spectra of normal training samples after removing abnormal training samples in the training set comprises: Performing derivative processing on the spectral matrix of the normal training sample to obtain a derivative matrix composed of derivative values, wherein the derivative processing is first-order derivative processing or high-order derivative processing; The baseline-corrected training set includes a derivative matrix formed by derivative values of spectral values of normal training samples and a true probability matrix of normal training samples.
12. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 1, characterized in that: The step of constructing a training set includes: Baseline correction was performed on the near-infrared spectra of multiple training samples.
13. The near infrared spectroscopy method for qualitatively distinguishing oil types according to claim 12, characterized in that: The step of performing baseline correction on the near infrared spectra of a plurality of training samples comprises: Performing derivative processing on the spectral matrices of the plurality of training samples to obtain a derivative matrix composed of derivative values, wherein the derivative processing is first-order derivative processing or high-order derivative processing; The baseline-corrected training set includes a derivative matrix formed by derivative values of the spectral values of the training samples and a true probability matrix of the training samples.
14. The near infrared spectroscopy method for qualitatively distinguishing oil types according to any one of claims 11 or 13, characterized in that: The derivative processing is a second-order derivative processing.
15. A near infrared spectroscopy system for qualitative identification of oil types, characterized in that: include: A spectrum acquisition module collects near-infrared spectra of multiple fuel samples to be tested, thereby obtaining near-infrared spectrum data; A model building module, which builds a qualitative discrimination model through a neural network, wherein the input of the qualitative discrimination model is near infrared spectral data, and the output of the qualitative discrimination model is the probability of belonging to each oil type and / or the probability of belonging to each brand; The qualitative discrimination module inputs the near infrared spectrum data of the multiple fuel samples to be tested collected by the spectrum collection module into the qualitative discrimination model to discriminate the probability of each fuel sample to be tested belonging to each fuel type and / or each brand, and takes the highest probability of the fuel sample to be tested belonging to each fuel type and / or each brand as the fuel type and / or brand of the fuel sample to be tested; Wherein, the model building module includes: A training sample collection submodule collects multiple training samples of multiple oil types; A real label collection submodule obtains the real labels of multiple training samples collected by the training sample collection submodule, wherein the real labels are the oil type and / or brand to which the training samples belong, and the real probability of the oil type and / or brand corresponding to the real labels is set to 1, and the probabilities of other oil types and / or brands are set to 0, thereby obtaining a real probability matrix consisting of the real probabilities of the multiple training samples belonging to each oil type and / or brand; A training set construction submodule is used to construct a training set, wherein the training set includes near infrared spectrum data of training samples and a true probability matrix; The qualitative discriminant model is established in a submodule. The training set constructed by the training set construction submodule uses Bayesian regularization to introduce prior knowledge to set the range of hyperparameters, optimize hyperparameters, and construct a Bayesian regularization optimized back propagation neural network to establish a qualitative discriminant model. The step of using Bayesian regularization to introduce prior knowledge to set the range of hyperparameters in the training set includes: Select a prior distribution, wherein the prior distribution is a Gaussian distribution or a uniform distribution; According to the near infrared spectral data of the training samples in the training set and the true probability matrix, the confidence interval of the hyperparameter whose prior distribution satisfies the normal distribution is obtained; Set the confidence interval for the hyperparameter setting ratio to the range of the hyperparameter.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a near-infrared spectroscopy program for qualitatively distinguishing oil types. When the near-infrared spectroscopy program for qualitatively distinguishing oil types is executed by a processor, the steps of the near-infrared spectroscopy method for qualitatively distinguishing oil types as described in any one of claims 1-14 are implemented.
17. An electronic device, characterized in that: It comprises a memory and a processor, wherein the memory comprises a near-infrared spectroscopy program for qualitatively distinguishing the type of oil, and when the near-infrared spectroscopy program for qualitatively distinguishing the type of oil is executed by the processor, the steps of the near-infrared spectroscopy method for qualitatively distinguishing the type of oil as described in any one of claims 1-14 are implemented.
Citation Information
Patent Citations
Near-infrared spectrum diesel vehicle license plate identification method based on SMOTE and deep learning
CN112613536A
Soil heavy metal quantitative analysis method based on Bayesian regularization
CN113866204A