# An Improved Algorithm of Drift Compensation for Olfactory Sensors
## 3 Materials and Methods
### Sensor Drift Compensation Algorithm  
This section proposes the DTSWKELM algorithm, which transforms the source domain data and the target domain data so that the two sets of data distributions are close. The semi-supervised classification problem of different domain data is converted into a semi-supervised classification problem of the same domain, and then the semi-supervised classification task is carried out through the SWKELM algorithm. The algorithm has the \begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline
**Batch ID** & **Month** & **Acetone** & **Acetaldehyde** & **Ethanol** & **Ethylene** & **Ammonia** & **Toluene** & **Total** \\ \hline Batch 1 & 1–2 & 90 & 98 & 83 & 30 & 70 & 74 & 445 \\ Batch 2 & 3–10 & 164 & 334 & 100 & 109 & 532 & 5 & 1244 \\ Batch 3 & 11–13 & 365 & 490 & 216 & 240 & 275 & 0 & 1586 \\ Batch 4 & 14,15 & 64 & 43 & 12 & 30 & 12 & 0 & 161 \\ Batch 5 & 16 & 28 & 40 & 20 & 46 & 63 & 0 & 197 \\ Batch 6 & 17–20 & 514 & 574 & 110 & 29 & 606 & 467 & 2300 \\ Batch 7 & 21 & 649 & 662 & 360 & 744 & 630 & 568 & 3613 \\ Batch 8 & 22,23 & 30 & 30 & 40 & 33 & 143 & 18 & 294 \\ Batch 9 & 24,30 & 61 & 55 & 100 & 75 & 78 & 101 & 470 \\ Batch10 & 36 & 600 & 600 & 600 & 600 & 600 & 600 & 3600 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Data volume for different sample gases in 10 batches. advantages of a good classification effect, strong generalization ability, and no need for labeled target domain data. In the dataset, labeled source domain data are accessible, so only unlabeled target domain data and labeled source domain data can be used to build data reconstruction models. Through data transformation, it is desirable to keep the source domain data unchanged as much as possible, while making the distribution of the drifting target data close to the distribution of the source data. Figure 1 is a flow chart of the DTSWKELM algorithm:  
As can be seen from Figure 1, the source domain data and the target domain data are obtained through kernel mapping to obtain the hidden layer. Under the constraints of two conditions, two sets of new domain data are obtained, which are sent to the SWKELM classifier for model training, and finally the new target domain data are predicted. The calculation flow of the specific algorithm is given below. The algorithm in this paper can be defined as the following optimization problem, as shown in Equation (3):  
\[\underset{f\in\mathcal{F}}{min}\ DD(\varnothing(X_{S}),\varnothing(X_{T}))+L(X _{S},\varnothing(X_{S}))+\|f\|_{H}^{2} \tag{3}\]  
The first term in the formula is used to represent the distribution difference between the source domain data and the target domain data, and \(\varnothing(\cdot)\) represents the correlation mapping. The second term is the loss function, which is used to prevent the loss of useful information in the source domain data in the process of data transformation. The third normal form is the regularization term used to avoid overfitting. This paper chooses the maximum average difference to describe the distribution difference between the source domain and the target domain, as shown in Equation (4):  
\[DD(\varnothing(X_{S}),\varnothing(X_{T}))=MMD^{2}(X_{S},X_{T}) \tag{4}\]  
The second loss function can be expressed as Equation (5):  
\[L(X_{S},\varnothing(X_{S}))=\sum_{i=1}^{N_{S}}\|\varnothing(x_{Si})-x_{si}\|^{2} \tag{5}\]  
The domain transformation algorithm can be defined as Equation (6):  
Figure 1: DTSWKELM algorithm flow chart. \[ \begin{array}{c}min_{\beta}\frac{\lambda}{2}MMD^{2}(X_{S},X_{T})+\frac{C}{2}\sum \limits_{i=1}^{N_{S}}\xi_{Si}{}^{2}+\frac{1}{2}\|\beta\|^{2}\\ \text{s.t.}\ h(x_{Si})\beta=x_{Si}^{T}-\xi_{Si}^{T},\ i=1,\cdots,N_{S}\\ h(x_{Si})\beta=\varnothing(x_{Si}),\ i=1,\cdots,N_{S}\\ h(x_{Ti})\beta=\varnothing(x_{Ti}),\ j=1,\cdots,N_{T}\end{array}  \tag{6}\]  
where \(\beta\) represents the output layer matrix, \(C\) and \(\lambda\) are the trade-off parameters for adjusting the model, and \(h(x_{Si})\) is the \(i-\) th point obtained by the source data through a single hidden layer neuron.