Sensor drift compensation method and device based on domain self-adaption
Through a domain adaptive method, the domain divider and classifier are used to compensate for the drift of the gas sensor, which solves the high cost and time cost problems caused by sensor drift, and achieves the accuracy and efficiency of gas classification.
Patent Information
- Application Number
- CN202311245787.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2025-03-25
AI Technical Summary
The prior art cannot effectively solve the problem of gas sensor drift, resulting in high cost and time costs.
The domain adaptive sensor drift compensation method is adopted to obtain historical gas sample data for each period of the gas sensor, perform feature extraction, and use domain divider and classifier for training to predict gas classification to achieve compensation for sensor drift.
The domain adaptive algorithm maximizes the difference between the measured values of the drift-free sensor and the measured values of the drift-free sensor, reducing the cost of sensor hardware optimization and the time cost of data processing, and achieving accurate gas classification.
Smart Images

Figure CN119688914A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of sensors, and in particular to a sensor drift compensation method and device based on domain adaptation. Background Art
[0002] Gas sensors are commonly used devices for detecting and measuring gas concentrations in the environment. However, during long-term use, gas sensors may experience drift problems. The sensitivity of the sensor may be affected by environmental factors, self-aging, and poisoning, resulting in different responses when the same gas is passed into the sensor at different times, which is called sensor drift.
[0003] Current technical means cannot completely solve the problem of sensor drift, so drift can be regarded as an inherent characteristic of the sensor. Among the existing technical means, on the one hand, the performance of the sensor is optimized at the hardware level to reduce the impact of drift factors, but the cost is high; another method is to collect different sensor data at the data level at the same time to complement each other, and extract invariant features that are not affected by drift through data methods. However, sensor drift is a long process, and collecting a large amount of training data from different sensors will bring high time costs.
[0004] Therefore, in order to balance cost and benefit, the present invention adopts a method of constructing an algorithm model to achieve the mitigation of sensor drift. Summary of the invention
[0005] The object of the present invention is to provide a sensor drift compensation method and device based on domain adaptation to solve the problem of high cost and time cost caused by sensor drift in the prior art.
[0006] To achieve one of the above-mentioned purposes of the invention, an embodiment of the present invention provides a sensor drift compensation method based on domain adaptation, the method comprising:
[0007] Obtain historical gas sample data of the gas sensor in each period and perform feature extraction on the sample data;
[0008] Input the sample features into the domain distinguisher for training and predicting the domain and time period corresponding to the sample data, obtaining source domain data without drift and target domain data with drift, and applying the source domain corresponding to the drift information to the target domain based on domain adaptation;
[0009] A classifier is trained based on the source domain data, and the target domain data is input into the classifier for training to predict the gas classification corresponding to the sample data.
[0010] As a further improvement of an embodiment of the present invention, the method further includes: defining the data representation of each time period as
[0011] Where d∈{0,1,2,3…} represents the period of data collection, X d Represents all sensor measurement data in the dth period, which collected n d data, each data consists of Features and Label composition;
[0012] The data in the period d=0 is defined as the source domain sample data without drift, and the data in the period d∈{1,2,3…} is the target domain sample data with drift. The larger d is, the more serious the sensor drift is.
[0013] As a further improvement of an embodiment of the present invention, the method further includes: inputting the sample data into a feature extractor to obtain a high-dimensional feature x of the sample ed , expressed as:
[0014]
[0015] Among them, θ e Represents the parameters of the feature extractor neural network.
[0016] As a further improvement of an embodiment of the present invention, the method further includes: inputting the high-dimensional features of the sample into a domain distinguisher to obtain a predicted value p of the domain to which the sample belongs fd , expressed as:
[0017]
[0018] Among them, θ f represents the domain discriminator neural network parameters, p fd Indicates the degree of drift of the data in period d relative to the drift-free data.
[0019] As a further improvement of an embodiment of the present invention, the method further includes: using mini batch to train the domain distinguisher, including:
[0020] For all the predicted values in a batch, according to p fd Sort from small to large, and get
[0021] in, j is the sorting number, B is the size of the mini batch used during training;
[0022] Based on the sorted Construct a loss function of the domain classifier, which is expressed as:
[0023]
[0024] Among them, the more the sorting sequence number j is in the d period, the f The smaller it is, the higher the prediction accuracy is. The optimization goal of the domain distinguisher is
[0025] As a further improvement of an embodiment of the present invention, the method further includes: training a classifier based on the source domain data, and the prediction value of the classifier is expressed as:
[0026]
[0027] Among them, θ c are the classifier neural network parameters, It means that the sample passes through the feature extractor and classifier in turn to obtain the prediction result of the category to which the sample belongs.
[0028] As a further improvement of an embodiment of the present invention, the method further includes: inputting the target domain data into the classifier for training, and the loss function of the output of the classifier is expressed as:
[0029]
[0030] Among them, the predicted value and the true value y i The closer you get, the c The smaller is, the optimization goal of the classifier is
[0031] To achieve one of the above-mentioned purposes of the invention, an embodiment of the present invention provides a gas sensor drift compensation device based on domain adaptation, including a feature extraction module, a domain classifier module, and a classifier module.
[0032] The feature extraction module is used to obtain historical gas sample data of the gas sensor in each period and perform feature extraction on the sample data;
[0033] The domain classifier module is used to input the feature into the domain classifier for training and predicting the domain and time period corresponding to the sample data, so as to obtain source domain data without drift and target domain data with drift;
[0034] The classifier module is used to train a classifier based on the source domain data, and input the target domain data into the classifier training to predict the gas classification corresponding to the sample data.
[0035] To achieve one of the above-mentioned purposes of the invention, one embodiment of the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the program is executed on the processor, the steps in the gas sensor drift compensation method based on domain adaptation as described above are implemented.
[0036] To achieve one of the above-mentioned purposes of the invention, an embodiment of the present invention provides a storage medium, wherein the storage medium stores a computer program, and wherein the computer program, when executed by a processor, implements the steps in the gas sensor drift compensation method based on domain adaptation as described above.
[0037] Compared with the prior art, the sensor drift compensation method and device based on domain adaptation provided by the present invention maximizes the difference between the measurement value of the drift-free sensor and the measurement value of the drifted sensor by using the domain adaptation algorithm, and makes full use of the characteristics of linear drift of the sensor in different time periods, so that there are also differences between different drift states of the sensor. The present invention also compensates for the measurement value of the drifted sensor by establishing an algorithm model and designing a loss function to obtain accurate gas classification, reducing the cost of sensor hardware optimization and the time cost of data processing, and has good practicality. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is an overall flow chart of the sensor drift compensation method based on domain adaptation described in the present invention.
[0039] Figure 2 It is a structural schematic diagram of the sensor drift compensation device based on domain adaptation described in the present invention. DETAILED DESCRIPTION
[0040] The present invention will be described in detail below in conjunction with the specific embodiments shown in the accompanying drawings. However, these embodiments do not limit the present invention, and any structural, methodological, or functional changes made by a person skilled in the art based on these embodiments are all within the scope of protection of the present invention.
[0041] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0042] In terms of hardware, the present invention uses a sensor module to collect data. A module is equipped with multiple sensors, and each sensor collects a gas feature. When applied, all the features of this module are put into the model for application.
[0043] In data collection, the application cycle of the sensor is divided into multiple time periods, and food identification data is collected in each time period.
[0044] In the first embodiment of the present invention, the present invention provides a sensor drift compensation method based on domain adaptation, such as Figure 1 As shown, the method includes:
[0045] S1: Obtain historical gas sample data of the gas sensor in each period and perform feature extraction on the sample data;
[0046] S2: Input the sample features into the domain distinguisher for training and predicting the domain and time period corresponding to the sample data, obtaining source domain data without drift and target domain data with drift, and applying the source domain corresponding to the drift information to the target domain based on domain adaptation;
[0047] S3: training a classifier based on the source domain data, and inputting the target domain data into the classifier for training, to predict the gas classification corresponding to the sample data.
[0048] In a specific embodiment of the present invention, food identification training data is collected in each time period, and the data of each time period is defined as Where d∈{0,1,2,3…} represents the period of data collection, X d Represents all sensor measurement data in the dth period, which collected n d data, each data consists of Features and Label composition;
[0049] The first of all measurement periods is selected as the benchmark, i.e., the source domain. The source domain is the sensor data without drift, at which point s = d = 0. Then, all batches except the first period are data with drift, i.e., the target domain, at which point t = d∈{1,2,3…}. The larger d is, the more serious the corresponding sensor drift is.
[0050] It should be noted that if the sensor data for food identification is not cleaned (such as ozone sterilization), the drift of the sensor is monotonous.
[0051] In a specific embodiment of the present invention, the sample data is input into a feature extractor to obtain a high-dimensional feature x of the sample. ed , expressed as:
[0052]
[0053] Among them, θ eRepresents the parameters of the feature extractor neural network.
[0054] In a specific embodiment of the present invention, the high-dimensional features of the sample are input into a domain distinguisher to obtain a predicted value p of the domain to which the sample belongs. fd , expressed as:
[0055]
[0056] Among them, θ f represents the domain discriminator neural network parameters, p fd Indicates the degree of drift of the data in period d relative to the drift-free data.
[0057] Specifically, the feature extractor outputs the high-dimensional features x of the sample ed The domain classifier is used to obtain the predicted value of the domain of the corresponding sample. As mentioned above, the training data set is collected at multiple different time periods of sensor attenuation, that is, d∈{0,1,2,3…} in the above text. The output p of the domain classifier is fd What is predicted is the measurement period from which the sample comes, that is, the value of d.
[0058] In a specific embodiment of the present invention, a domain classifier is trained using mini batch, specifically,
[0059] For all the predicted values in a batch, according to p fd Sort from small to large, and get
[0060] in, j is the sorting number, B is the size of the mini batch used during training;
[0061] Based on the sorted Construct the loss function of the domain discriminator. Based on the linear attenuation characteristics of the gas sensor, the loss function of the domain discriminator is optimized as follows:
[0062]
[0063] Among them, the more the sorting sequence number j is in the d period, the f The smaller it is, the higher the prediction accuracy is. The optimization goal of the domain distinguisher is
[0064] Specifically, L fIt is a function of the domain order j and the domain time period number d to which the sample belongs. This function not only maximizes the difference between the target domain and the source domain, that is, the difference between the measurement value of the drift-free sensor and the measurement value of the drift sensor, but also makes full use of the characteristics of the linear drift of the sensor in different time periods, so that there are differences between different drift states of the sensor.
[0065] Furthermore, suppose a batch has 6 data points, and these 6 data points happen to come from different measurement periods, that is, d is different. The predicted value p of these 6 data points is calculated according to the predicted value of the domain classifier. fd Sort from small to large, if the corresponding d j It is exactly [5, 4, 3, 2, 1, 0], as shown in the following table:
[0066]
[0067] At this time, the loss of the domain distinguisher output is L f =10.27183294.
[0068] If the corresponding d j It is exactly [0, 1, 2, 3, 4, 5], as shown in the following table:
[0069]
[0070] At this time, the loss of the domain distinguisher output is L f =6.251554.
[0071] From the above table, we can see that when the domain distinguisher output p fd After sorting from small to large, if the number of samples of the corresponding d that can be sorted from small to large is larger, the corresponding L f The smaller the value, the larger the value. The optimization goal of the domain distinguisher is to make L f Therefore, L can only be minimized when the ranking of the domain distinguisher prediction value has a relative size relationship with the data measurement period d. f Minimize, that is, make the sensor have differences between different drift states.
[0072] Specifically, the domain adaptive algorithm is used to extract features related to the data and the target task (stone classification) during the domain classifier training. During the neural network training phase, when the gradient is back-propagated from the domain classifier to the feature extractor, all gradients are multiplied by -1, which is the optimization target.
[0073] In a specific embodiment of the present invention, a classifier is trained based on the source domain data, and the prediction value of the classifier is expressed as:
[0074]
[0075] Among them, θ c are the classifier neural network parameters, Indicates that the sample passes through the feature extractor and classifier in turn to obtain the prediction result of the category to which the sample belongs. The corresponding data set and The y in i , predicted value and the true value y i The closer they are, the better the model prediction effect is.
[0076] In a specific embodiment of the present invention, the target domain data is input into the classifier for training, and the loss function of the output of the classifier is expressed as:
[0077]
[0078] Among them, the predicted value and the true value y i The closer you get, the c The smaller is, the optimization goal of the classifier is
[0079] Specifically, the present invention evaluates the similarity of two values by using cross entropy, L c The smaller the value, the more accurate the classifier's prediction.
[0080] Furthermore, by combining the optimization objectives of the domain distinguisher and the classifier, we obtain the objective function:
[0081]
[0082] Among them, λ is a hyperparameter, which is adjusted according to the specific problem.
[0083] In the second embodiment of the present invention, the present invention provides a gas sensor drift compensation device based on domain adaptation, such as Figure 2 The shown module includes a feature extraction module, a domain distinguisher module, and a classifier module.
[0084] Feature extraction module 1, used to obtain historical gas sample data of the gas sensor in each period and perform feature extraction on the sample data;
[0085] A domain classifier module 2 is used to input the features into a domain classifier for training and predicting the domain and time period corresponding to the sample data to obtain source domain data without drift and target domain data with drift;
[0086] The classifier module 3 is used to train a classifier based on the source domain data, and input the target domain data into the classifier training to predict the gas classification corresponding to the sample data.
[0087] In a third embodiment of the present invention, the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the program is executed on the processor, the steps of the gas sensor drift compensation method based on domain adaptation as described above are implemented.
[0088] In a fourth embodiment of the present invention, the present invention provides a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the gas sensor drift compensation method based on domain adaptation as described above.
[0089] In summary, the sensor drift compensation method and device based on domain adaptation provided by the present invention maximizes the difference between the measurement value of the drift-free sensor and the measurement value of the drift sensor by using the domain adaptation algorithm, and makes full use of the characteristics of linear drift of the sensor in different time periods, so that there are also differences between different drift states of the sensor. The present invention also compensates for the measurement value of the drifted sensor by establishing an algorithm model and designing a loss function to obtain accurate gas classification, thereby reducing the cost of sensor hardware optimization and the time cost of data processing, and has good practicality.
[0090] It should be understood that although this specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each implementation mode may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
[0091] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the modules described above can refer to the corresponding process in the aforementioned method implementation, and will not be repeated here.
[0092] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present implementation scheme.
[0093] In addition, each functional module in each embodiment of the present application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0094] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for a computer system (which can be a personal computer, a server, or a network system, etc.) or a processor to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.
[0095] Finally, it should be noted that the above implementation modes are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned implementation modes, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned implementation modes, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various implementation modes of the present application.
Claims
1. A gas sensor drift compensation method based on domain adaptation, characterized in that: include: Obtain historical gas sample data of the gas sensor in each period and perform feature extraction on the sample data; Input the sample features into the domain distinguisher for training and predicting the domain and time period corresponding to the sample data, obtaining source domain data without drift and target domain data with drift, and applying the source domain corresponding to the drift information to the target domain based on domain adaptation; A classifier is trained based on the source domain data, and the target domain data is input into the classifier for training to predict the gas classification corresponding to the sample data.
2. The sensor drift compensation method based on domain adaptation according to claim 1, characterized in that: The data for each period is defined as Where d∈{0,1,2,3…} represents the period of data collection, X d Represents all sensor measurement data in the dth period, which collects n d data, each data consists of Features and Label composition; The data in the period d=0 is defined as the source domain sample data without drift, and the data in the period d∈{1,2,3…} is the target domain sample data with drift. The larger d is, the more serious the sensor drift is.
3. The sensor drift compensation method based on domain adaptation according to claim 2, characterized in that: The sample data is input into the feature extractor to obtain the high-dimensional features x of the sample ed , expressed as: Among them, θ e Represents the parameters of the feature extractor neural network.
4. The sensor drift compensation method based on domain adaptation according to claim 3 is characterized in that: The high-dimensional features of the sample are input into the domain distinguisher to obtain the predicted value p of the domain to which the sample belongs fd , expressed as: Among them, θ f represents the domain discriminator neural network parameters, p fd Indicates the degree of drift of the data in period d relative to the drift-free data.
5. The sensor drift compensation method based on domain adaptation according to claim 4, characterized in that: The domain discriminator is trained using minibatch, including: For all the predicted values in a batch, according to p fd Sort from small to large, and get in, j is the sorting number, B is the size of the minibatch used during training; Based on the sorted Construct a loss function of the domain classifier, which is expressed as: Among them, the more the sorting sequence number j is in the d period, the f The smaller it is, the higher the prediction accuracy is. The optimization goal of the domain distinguisher is 6. The sensor drift compensation method based on domain adaptation according to claim 2, characterized in that: A classifier is trained based on the source domain data, and the predicted value of the classifier is expressed as: Among them, θ c are the classifier neural network parameters, It means that the sample passes through the feature extractor and classifier in turn to obtain the prediction result of the category to which the sample belongs.
7. The sensor drift compensation method based on domain adaptation according to claim 6, characterized in that: The target domain data is input into the classifier for training, and the loss function of the output of the classifier is expressed as: Among them, the predicted value and the true value y i The closer you get, the c The smaller is, the optimization goal of the classifier is 8. A gas sensor drift compensation device based on domain adaptation, comprising a feature extraction module, a domain classifier module, and a classifier module, characterized in that: The feature extraction module is used to obtain historical gas sample data of the gas sensor in each period and perform feature extraction on the sample data; The domain classifier module is used to input the feature into the domain classifier for training and predicting the domain and time period corresponding to the sample data, so as to obtain source domain data without drift and target domain data with drift; The classifier module is used to train a classifier based on the source domain data, and input the target domain data into the classifier training to predict the gas classification corresponding to the sample data.
9. An electronic device, comprising a memory and a processor, characterized in that: The memory stores a computer program that can be run on the processor, and when the program is executed on the processor, the steps in the gas sensor drift compensation method based on domain adaptation as described in any one of claims 1 to 7 are implemented.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps in the gas sensor drift compensation method based on domain adaptation according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Electronic nose signal drift compensation method based on integrated neural network learning
CN111103325A
Air conditioner control method and device, air conditioner and storage medium
CN114543294A
Computer-implemented system and method for analyzing mixtures of gases
US20060155486A1
Systems and methods for processing analyte sensor data
US20130245401A1
Gas sensor MEMS structures and methods of fabrication thereof
US20190360924A1