# Concept Drift Detection Based on Deep Neural Networks and Autoencoders
## 3 Methodology
### Processing Stream Data  
The data stream processing flow is shown in Figure 4, and the algorithm is detailed in Algorithm 3. Model2 uses the same network structure as Model1. The difference lies in the model initialization, which is carried out as follows: the connection weights and biases, \(W,b\), of all the hidden neurons in the trained Model1 are copied to Model2, and the parameters \(W^{(F)},W^{(S)},b^{(F)},b^{(S)}\) (highlighted in the blue box in Figure 4) of all hidden layers, except for the last hidden layer, are frozen (see step 2 in Algorithm 2).This approach is based on the following considerations: first, neural networks have feature representation capabilities, and using pretrained model weights helps reduce the time required for retraining. Secondly, assuming that the hidden layer parameters of the trained model can represent data belonging to the old concept distribution, we copy and freeze the connection weights and biases of the earlier hidden layers to assist the model in recognizing data from the old concept distribution in the data stream. The last hidden layer is kept in an updatable state, allowing the model to adjust its parameters promptly when new concept distributions emerge in the data stream.  
After the model initialization is completed, Model2 is used to process the data stream \(S\) (refer to steps 3-6 in Algorithm 3), and the output from the last hidden layer, \(o^{(L)}\), is collected as the test data for Model3.To demonstrate that the weights of the last hidden layer in Model2 exhibit significant differences before and after the drift in Figure 4, detailed analysis is provided in Appendix A. This test data are represented by the deep pink neurons within the green box in Figure 4. In contrast to the hidden layer output of Model1, the hidden layer output of Model2 corresponds to the output in the online learning scenario. Since the data stream requires the model to learn from one data point at a time and produce a corresponding output, the weights displayed in the figure reflect the data stream format, indicating that the processing of the data stream is conducted in an online setting.  
Figure 4: Processing stream data.  
Figure 3: Pretrain process.  
```
0: Stream data \(S=\{(x_{1},y_{1}),(x_{2},y_{2}),(x_{3},y_{3}),\ldots,(x_{t},y_{t}),\ldots\}\), \(x_{i}\) represent the feature of sample, \(y_{i}\) represent the label, weights and bias associated with all hidden layers \(W\), \(b\) obtained from pretrain, learning rate \(\eta_{2}\), the loss function \(\mathcal{L}_{\mathcal{P}}\), the optimizer \(optim_{1}\), the delay rate \(\gamma_{2}\), the learning rate update step size \(s_{2}\).
0: Last hidden layer's output stream \(o^{(L)}=[o_{1}^{(L)},o_{2}^{(L)},\ldots,o_{t}^{(L)},\ldots]\).
1: Normalize the stream data \(S\) with StandardScaler.
2: Initialize the DNN network with \(W\), \(b\) and frozen the first two hidden layers neurons' parameters \(W^{(F)},W^{(S)},b^{(F)}\), \(b^{(S)}\), keep the last hidden layer neuron's weights \(W_{F}^{(L)}\) and bias \(b_{F}^{(L)}\) active.
3:for\((x_{k},y_{k})\) in \(S\)do
4: Calculate the prediction value \(\hat{y_{k}}\).
5: Calculate the loss \(\mathcal{L}_{\mathcal{P}}(y_{k},\hat{y_{k}})\) between prediction \(\hat{y_{k}}\) and true label \(y_{k}\).
6: Loss backward and only update the parameters \(W_{F}^{(L)},b_{F}^{(L)}\) of the active layer.
7:endfor
```  
**Algorithm 3** Process stream data