# High-impedance Fault Detection in DC Microgrid Lines Using Open-Set Recognition
## 3 Fault Detection
### Classification with Neural Networks  
The aim of the classification is to assign an input sample to one of the predefined classes based on its features. The importance of the features is determined during the training phase of the classifier, where the most salient features will have a greater impact on the classification decision. In supervised learning, the dataset contains samples with corresponding class labels. The training procedure minimizes the loss between the output of the classifier and label by shifting the parameters of the classifier. In the case of neural networks, these are the weights and biases of individual layers. The basic feed-forward neural network (FFNN) defines a mapping \(\mathbf{z}=g(\mathbf{x};\boldsymbol{\theta})\), where \(\mathbf{x}\) is an input, \(\mathbf{z}_{k},k\in K\) is a predicted score (logit) for each of \(K\) classes, and \(\boldsymbol{\theta}\) are parameters learned during the training. The logits vector \(\mathbf{z}\) is normalized by the softmax function to obtain the probabilities for each class:  
\[\boldsymbol{\hat{y}}_{k}=\frac{\exp(\mathbf{z}_{k})}{\sum_{j}^{K}\exp( \mathbf{z}_{j})}. \tag{3}\]  
Each element \(\boldsymbol{\hat{y}}_{k}\) is greater than 0, and the sum of elements of vector \(\boldsymbol{\hat{y}}\) is equal to 1.  
The training procedure minimizes the loss function \(\mathcal{L}(\boldsymbol{\hat{y}},\mathbf{y};\boldsymbol{\theta})\), which measures the loss between the output \(\boldsymbol{\hat{y}}\) and the ground truth labels \(\mathbf{y}\). To find the optimal parameters, the following optimization problem is solved:  
\[\underset{\boldsymbol{\theta}}{\text{argmin}}\ \mathcal{L}(\boldsymbol{\hat{y}},\mathbf{y};\boldsymbol{\theta})=\underset{\boldsymbol{\theta}}{\text{argmin}} \ \sum_{i}^{n}\ell(\boldsymbol{\hat{y}},\mathbf{y}_{i};\boldsymbol{\theta}), \tag{4}\]  
where \(n\) is the number of samples. This optimization problem is nonlinear, so its solution requires the use of a gradient descent optimizer. The optimizer searches for the minimum of the loss function and the performance of the classifier is tested on the test dataset. If it appears that the classifier is starting to overfit, the process is stopped to preserve the generalization ability [46]. A standard choice for classification tasks is the cross-entropy loss:  
\[\ell(\boldsymbol{\hat{y}},\mathbf{y})=-\sum_{i=1}^{K}\boldsymbol{\hat{y}}_{i} \log\mathbf{y}_{i} \tag{5}\]  
The function is constructed to significantly increase the loss value when the predicted value is far from the ground truth.  
The NN's performance depends on its architecture, as the capability of a model increases with the number of layers and neurons per layer. However, there are NN architectures that are adapted to the data type.  
Convolutional NNs are commonly used for image classification and signal processing. The convolutional layers of a CNN act as filters to extract features from the input, with each layer consisting of multiple kernels representing different feature maps. The second type of layer in CNNs is the pooling layer, which is usually placed between adjacent convolutional layers to reduce their output size. Finally, the fully connected layer produces the output [47].  
On the other hand, RNNs are used for sequential data because they have an additional recurrent layer that has a memory effect. That is, the hidden state \(\mathbf{h}\) of the previous step(s) of the RNN is taken into account when generating the output. Formally, the output \(\boldsymbol{\hat{y}}=g(\mathbf{x},\mathbf{h}^{t-1};\boldsymbol{\theta})\) depends not only on the current input but also on the previously seen inputs. Therefore, RNN models are best suited for working with time series, either for prediction or classification tasks [48].