# Real-Time, Model-Agnostic and User-Driven Counterfactual Explanations Using Autoencoders
## 4 Experimental Framework
### Employed Models
#### 4.2.2. Gearbox  
Black-box model.  
The proposed black-box model \(f(\cdot)\) for the classification stage is illustrated in Figure 6. This model is based on the anomaly detection model proposed by [PERSON] et al. [21], which is a combination of 1-Dimensional Convolutional Neural Networks (1D-CNN) with Recurrent Neural Networks (RNNs). The architecture is designed to be valid for both multivariate and univariate time series. The classifier \(f(\cdot)\) is composed of three parts: the CNN backbone, the RNN head, and the classification head.  
The CNN backbone, as shown in Figure 7, is composed of three convolutional blocks, each containing 1D-CNNs with a ReLU activation function, Batch Normalization, and Dropout regularization layers. The 1D-CNNs in the convolutional blocks are composed of 128, 64, and 32 filters, respectively, with a kernel length of 5 and a stride of 1. The proposed architecture processes the data in a window-based manner, whereby the input data \(\mathbf{x}\in\mathbb{R}^{L}\) are divided into a sequence of \(T\) windows \(\mathbf{x}=(\mathbf{x}_{1},\ldots,\mathbf{x}_{T})\) and the convolutional blocks are applied to each window separately, resulting in a vector of features \(\mathbf{F}_{t}\) for each time window \(\mathbf{x}_{t}\). These extracted features are the inputs of the RNN head, which is composed of a Bi-LSTM layer that processes the features in chronological order in both directions, allowing for the identification of hidden temporal patterns within the extracted features. Finally, the last hidden state is input into a fully connected layer with a sigmoid activation function, and the final output is computed as  
\[\mathbf{y}^{\prime}=\text{sigmoid}(\mathbf{W}_{c}\mathbf{h}_{T}+b_{c}) \tag{6}\]  
where \(\mathbf{W}_{c}\) and \(b_{c}\) are the weights and bias of the fully connected layer, respectively.  
Figure 6: Proposed black-box model.  
Autoencoder.  
The proposed Autoencoder (AE) is composed of a Bi-directional Long Short-Term Memory (Bi-LSTM) network with 128 hidden units for both the encoder and the decoder. The forward and backward hidden states of the encoder are concatenated to obtain the hidden state representation \(\mathbf{h}_{t}^{t}=[\overline{\mathbf{h}^{t}}_{t},\overline{\mathbf{h}^{t}}_{t}]\), which contains the context information around time step \(t=1,\dots,T\). The last hidden state \(\mathbf{h}_{t}^{t}\) is used as the vector representation \(\mathbf{z}\in\mathbb{R}^{d_{z}}\), which contains the compressed information of the input sequence.  
In a traditional sequence-to-sequence learning framework, the vector \(\mathbf{z}\) is used by the decoder to transform it back into a sequence \(\mathbf{x}^{\prime}=(\mathbf{x}_{1}^{\prime},\dots,\mathbf{x}^{\prime}_{T})\) as close as possible to the encoder input \(\mathbf{x}=(\mathbf{x}_{1},\dots,\mathbf{x}_{T})\). However, when dealing with long sequences, the latent representation \(\mathbf{z}\) may not accurately capture all the information present in the input. To address this issue, attention mechanisms have been introduced to allow the decoder to focus on the most relevant encoder hidden states at each time step. In this work, an attention mechanism is used, whereby the attention weights are computed with an alignment score function. The attention weights at time-step \(t\) are calculated as:  
\[\boldsymbol{\alpha}_{t,i}=\frac{\exp\Bigl{(}\text{score}\Bigl{(} \mathbf{h}_{t}^{d},\mathbf{h}_{t}^{e}\Bigr{)}\Bigr{)}}{\sum_{j=1}^{T}\exp( \text{score}\Bigl{(}\mathbf{h}_{t}^{d},\mathbf{h}_{j}^{e}\Bigr{)})}, \tag{7}\] \[\text{s.t}\quad\text{score}\Bigl{(}\mathbf{h}_{t}^{d},\mathbf{h} _{t}^{e}\Bigr{)}=(\mathbf{h}_{t}^{d})^{\top}\mathbf{W}_{a}\mathbf{h}_{t}^{e},\] (8) \[\boldsymbol{c}_{t}=\sum_{i=1}^{T}\boldsymbol{\alpha}_{i,t}\mathbf{ h}_{t}^{e} \tag{9}\]  
where \(\boldsymbol{\alpha}_{