Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to" determining "or" in response to detecting ". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.
Reference throughout this specification to "one embodiment" or "some embodiments," or the like, means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," or the like, in various places throughout this specification are not necessarily all referring to the same embodiment, but rather "one or more but not all embodiments" unless specifically stated otherwise. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless expressly specified otherwise.
In order to explain the technical means of the present invention, the following description will be given by way of specific examples.
Fig. 1 illustrates a substance classification method provided by an embodiment of the present invention. For convenience of explanation, only the portions related to the present embodiment are shown. Referring to fig. 1, a substance classification method includes steps S101-S104.
S101, measuring terahertz time-domain spectral data of the substance to be classified as first time-domain data.
In the embodiment of the invention, the terahertz time-domain spectroscopy of the substance to be classified is measured by the terahertz time-domain spectrometer, a data sequence consisting of terahertz time-domain spectroscopy data of a plurality of time-domain delay points (frequency points) is obtained, and all the data sequences form a data matrix.
S102, calculating an optical parameter matrix of the substance to be classified according to the first time domain data.
In the embodiment of the invention, the optical parameters of each frequency point in the data sequence formed by the terahertz time-domain spectral data are respectively calculated by a Fresnel formula, the optical parameters of all the frequency points are formed into the data sequence, and all the data sequences are formed into the optical parameter matrix.
Optionally, the calculating an optical parameter matrix of the substance to be classified according to the first time domain data includes:
acquiring terahertz time-domain spectral data of a preset reference object as second time-domain data; performing fast Fourier transform on the first time domain data and the second time domain data to obtain first frequency domain data corresponding to the first time domain data and second frequency domain data corresponding to the second time domain data; and calculating an optical parameter matrix of the substances to be classified through a Fresnel formula according to the first frequency domain data and the second frequency domain data.
In this embodiment, the terahertz time-domain spectroscopy of the preset reference object is measured by the terahertz time-domain spectroscopy to obtain second time-domain data.
In one embodiment, the predetermined reference is nitrogen, and the time-domain waveform (second time-domain data) E of nitrogen is usedM(t) as a reference signal, with a time-domain waveform (first time-domain data) E of the substance to be classifiedS(t) as sample signal, by fast Fourier transform, to obtain ES(t) corresponding first frequency domain waveform ES(ω), and EM(t) corresponding second frequency domain waveform EM(ω). Specifically, the method comprises the following steps:
EM(ω)=AM(ω)exp[-iφM(ω)]=∫EM(t)exp(-iωt)dt;
ES(ω)=AS(ω)exp[-iφS(ω)]=∫ES(t)exp(-iωt)dt;
wherein A isM(ω) is the amplitude of the reference signal, AS(ω) is the amplitude of the sample signal, φM(omega) is the phase of the reference signal, phiSAnd (ω) is the phase of the sample signal.
Further, the calculating the optical parameter matrix of the substance to be classified according to the first frequency domain data and the second frequency domain data includes:
calculating the ratio of the first frequency domain data to the second frequency domain data to obtain a complex transmission coefficient; calculating the optical parameters of each frequency point in the substances to be classified according to the complex transmission coefficient; and forming an optical parameter matrix by the optical parameters of all the frequency points.
The complex transmission coefficient is
Wherein rho (omega) is the amplitude ratio of the sample signal (the substance to be classified) to the reference signal (the preset reference), and phi (omega) is the phase difference between the sample signal and the reference signal.
Optionally, the above optical parameters include refractive index n (ω) and absorption coefficient α (ω), specifically,
where ω is the frequency point, c is the speed of light in vacuum, and d is the thickness of the material to be classified.
S103, performing dimensionality reduction on the optical parameter matrix according to a principal component analysis method to obtain a low-dimensional matrix.
The Principal Component Analysis (PCA) is a method of converting a set of high-dimensional variables, which may have correlation, into a set of linearly uncorrelated low-dimensional variables through orthogonal transformation, and the set of converted variables is the principal component. In this embodiment, the optical parameters in the optical parameter matrix are projected to a low-dimensional subspace to achieve dimension reduction. After the PCA is used for reducing the dimension of the optical parameter matrix, the matrix characteristics are concentrated, and therefore the trained neural network model has better performance.
Specifically, the performing the dimensionality reduction on the optical parameter matrix according to the principal component analysis method to obtain the low-dimensional matrix includes:
acquiring optical parameters of a specified frequency interval in the optical parameter matrix and carrying out normalization processing on the optical parameters to obtain an effective matrix; calculating a correlation coefficient matrix of the effective matrix, and calculating an eigenvalue and an eigenvector of the correlation coefficient matrix; calculating the accumulated contribution rate of the principal component according to the characteristic value, and determining the quantity of the characteristic vector according to the accumulated contribution rate; and determining all the feature vectors according to the number of the feature vectors, and forming a low-dimensional matrix by using all the determined feature vectors.
In the embodiment of the invention, the optical parameters are normalized to form an effective matrix, and a correlation coefficient matrix of the effective matrix is calculated as follows:
calculating the eigenvalue and eigenvector of the correlation coefficient matrix:
wherein a is a matrix of correlation coefficients,
is the eigenvector, λ is the eigenvalue.
It should be noted that A does not necessarily exist
And λ, if A is present
And λ, then there is a pair for each dimension of A
And λ. And sorting according to the size of the eigenvalues, wherein the eigenvector corresponding to the largest eigenvalue is the first principal component, the eigenvector corresponding to the second largest eigenvalue is the second principal component, and so on.
Further, sorting the eigenvalues from large to small according to the magnitude of the eigenvalues, and calculating the contribution rate of the ith principal component according to the eigenvalues
And when the accumulated contribution rate reaches a preset threshold (for example, 80%), and the accumulated contribution rate obtained by adding the contribution rates of the plurality of principal components is 80%, determining the number of the corresponding plurality of principal components (namely the number of eigenvectors), and forming a low-dimensional matrix by all the determined eigenvectors.
And S104, inputting the low-dimensional matrix into a feedforward neural network model, and outputting a substance classification result corresponding to the first time domain data.
The feedforward neural network model is a back propagation neural network model (BPNN). The low-dimensional matrix is firstly normalized, and characteristic parameters in the normalization operation are obtained by training samples in the normalization process.
The method can directly test the substance to be tested without complex pretreatment, has the characteristics of high safety, simple operation, high efficiency, no damage and online monitoring, has centralized matrix characteristics after PCA dimension reduction treatment, has simple parameter setting of a BP neural network model, realizes that the classification result has higher accuracy and stronger stability, and solves the problem of poor stability of the substance classification result in the prior art.
On the basis of the embodiment shown in fig. 1, fig. 2 shows a flow chart of another implementation of the substance classification method. As shown in fig. 2, steps S201-S203 are also included before step S104 in the embodiment shown in fig. 1. It should be noted that the steps that are the same as those in the embodiment of fig. 1 are not repeated herein, please refer to the foregoing description.
S201, inputting a training sample into a preset feedforward neural network model, and outputting a prediction output value;
s202, calculating a prediction error corresponding to the preset feedforward neural network model according to the predicted output value and an expected output value, wherein the expected output value is a preset expected value corresponding to the training sample;
s203, adjusting the weight and the threshold of the feedforward neural network model according to the prediction error, wherein the adjusted preset feedforward neural network model is used as the feedforward neural network model.
In the above S201, the output layer outputs the prediction output value
H is the hidden layer output, omega
jkThe output layer weight, b is the output layer threshold, m is the number of output layer nodes, and j is 1,2, …, l.
Specifically, in step S201, inputting a training sample into the feedforward neural network model, and outputting a prediction output value, includes: inputting the training sample into an input layer of the preset feedforward neural network model, and outputting a hidden layer output value through a hidden layer of the feedforward neural network model, wherein the node number of the hidden layer is determined according to the node numbers of the input layer and the output layer of the feedforward neural network model; and taking the hidden layer output value as the input of the output layer, and outputting the prediction output value through the output layer.
The above hidden layer output value
Where f is the excitation function of the hidden layer, l is the number of nodes in the hidden layer, ω
ijAnd b, a is a hidden layer weight, a is a hidden layer threshold, x is an output of the input layer of the BP neural network model, namely an input of the hidden layer, and i is 1,2, …, n is n, and n is the number of nodes of the input layer.
Optionally, the calculation formula of the optimal number of hidden layer nodes is l<n-1,
l=log
2n; wherein a is a constant between 1 and 10.
In S202, the expected output value is an expected value Y set in advance based on a training samplekThen the prediction error is ek=Yk-Qk,k=1,2,…,m。
In S203, an additive momentum method and a gradient correction method may be adopted as the learning algorithm of the weight and the threshold. Adjusting weight omega of hidden layer
ijOutput layer weight omega
jkHidden layer threshold a
jAnd output layer threshold b
kAnd finishing the training of the neural network until the iteration of the neural network algorithm is finished. Specifically, the method comprises the following steps:
ω
jk=ω
jk′+ηH
je
k;
b
k=b′
k+e
kwherein η is a learning rate.
On the basis of the embodiment shown in fig. 2, fig. 3 shows a flow chart of another implementation of the substance classification method. As shown in FIG. 3, steps S301-S303 are also included prior to step S201 in the embodiment shown in FIG. 2. It should be noted that the steps that are the same as those in the embodiment of fig. 2 are not repeated herein, please refer to the foregoing description.
S301, randomly selecting a specified number of data in the low-dimensional matrix, wherein the specified number is greater than or equal to half of the total number in the low-dimensional matrix;
s302, performing normalization operation on the randomly selected data to serve as the training sample;
and S303, normalizing the residual data in the low-dimensional matrix according to the normalization operation, and then taking the normalized data as the low-dimensional matrix input into the feedforward neural network model.
In the embodiment of the invention, data which is more than or equal to half of the total amount is selected as training samples, and the rest data is used as test data, so that the neural network model obtained by real-time training is more consistent with the classification of the corresponding substances to be classified. The test data (namely the low-dimensional matrix of the input feedforward neural network model) and the training sample are normalized separately, and the characteristic parameters of the test data for normalization are obtained when the training sample is normalized, so that the test data is prevented from knowing the spatial characteristics of the dimensionality reduction space in advance, and the classification result is more accurate.
The effect of the present invention will be further described with reference to simulation experiments. It should be noted that the description is only exemplary and should not be construed as limiting the invention.
Specifically, four coffee classifications of different roast levels are exemplified for details. The material 1, the material 2, the material 3 and the material 4 are light-roasted, raw bean, medium-roasted and deep-roasted coffee in sequence. The terahertz time-domain spectroscopy model is THz-TDS, and a transmission-type terahertz light path is adopted to work at room temperature. 120 sets of spectral data were measured for each material, 70 of which were randomly selected as training data and 50 of which were selected as test data.
And acquiring the principal component score (the number of eigenvectors) when the accumulated contribution rate is more than or equal to 99.5 percent to obtain a principal component score matrix. Table 1 shows the principal component scores corresponding to the cumulative contribution rate of 99.5% or more.
Number of major components
|
1
|
2
|
3
|
4
|
5
|
6
|
Rate of contribution
|
0.8508
|
0.1144
|
0.0211
|
0.0055
|
0.0021
|
0.0017
|
Cumulative contribution rate
|
0.8508
|
0.9652
|
0.9863
|
0.9919
|
0.9940
|
0.9957 |
The hidden layer excitation function is selected as:
the BP neural network classification accuracy table is shown in table 2.
Classes of coffee
|
Shallow baking
|
Raw beans
|
Middle drying
|
Deep baking
|
Accuracy of classification
|
0.7818
|
0.8393
|
0.6809
|
1.0000 |
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Fig. 4 shows a substance sorting apparatus provided by an embodiment of the present invention. For convenience of explanation, only the portions related to the present embodiment are shown. Referring to fig. 4, the substance sorting apparatus 400 includes: .
The measuring module 401 is configured to measure terahertz time-domain spectral data of a substance to be classified as first time-domain data;
a calculating module 402, configured to calculate an optical parameter matrix of the substance to be classified according to the first time domain data;
a dimension reduction module 403, configured to perform dimension reduction processing on the optical parameter matrix according to a principal component analysis method to obtain a low-dimensional matrix;
and an output module 404, configured to input the low-dimensional matrix into a feed-forward neural network, and output a substance classification result corresponding to the first time-domain data.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, modules and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
Fig. 5 is a schematic diagram of a terminal device according to an embodiment of the present invention. As shown in fig. 5, the terminal device 5 of this embodiment includes: a processor 50, a memory 51 and a computer program 52 stored in said memory 51 and executable on said processor 50, such as a program for performing a dimension reduction process on a matrix of optical parameters. The processor 50, when executing the computer program 52, implements the steps in the various material classification method embodiments described above, such as the steps 101 to 104 shown in fig. 1. Alternatively, the processor 50, when executing the computer program 52, implements the functions of the modules/units in the above-mentioned device embodiments, such as the functions of the modules 51 to 54 shown in fig. 5.
Illustratively, the computer program 52 may be partitioned into one or more modules/units that are stored in the memory 51 and executed by the processor 50 to implement the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution process of the computer program 52 in the terminal device 5. For example, the computer program 52 may be divided into a measurement module, a calculation module, a dimension reduction module, and an output module (module in a virtual device), and the specific functions of each module are as follows: the measuring module is used for measuring terahertz time-domain spectral data of the substances to be classified as first time-domain data; the calculation module is used for calculating an optical parameter matrix of the substance to be classified according to the first time domain data; the dimensionality reduction module is used for carrying out dimensionality reduction on the optical parameter matrix according to a principal component analysis method to obtain a low-dimensional matrix; and the output module is used for inputting the low-dimensional matrix into the trained feedforward neural network and outputting a substance classification result.
The terminal device 5 may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. The terminal device may include, but is not limited to, a processor 50, a memory 51. Those skilled in the art will appreciate that fig. 5 is merely an example of a terminal device 5 and does not constitute a limitation of terminal device 5 and may include more or fewer components than shown, or some components may be combined, or different components, e.g., the terminal device may also include input-output devices, network access devices, buses, etc.
The Processor 50 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 51 may be an internal storage unit of the terminal device 5, such as a hard disk or a memory of the terminal device 5. The memory 51 may also be an external storage device of the terminal device 5, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the terminal device 5. Further, the memory 51 may also include both an internal storage unit and an external storage device of the terminal device 5. The memory 51 is used for storing the computer program and other programs and data required by the terminal device. The memory 51 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. . Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.