Enriching Neural Network Training Dataset to Improve Worst-Case
  Performance Guarantees
Machine learning algorithms, especially Neural Networks (NNs), are a valuable
tool used to approximate non-linear relationships, like the AC-Optimal Power
Flow (AC-OPF), with considerable accuracy -- and achieving a speedup of several
orders of magnitude when deployed for use. Often in power systems literature,
the NNs are trained with a fixed dataset generated prior to the training
process. In this paper, we show that adapting the NN training dataset during
training can improve the NN performance and substantially reduce its worst-case
violations. This paper proposes an algorithm that identifies and enriches the
training dataset with critical datapoints that reduce the worst-case violations
and deliver a neural network with improved worst-case performance guarantees.
We demonstrate the performance of our algorithm in four test power systems,
ranging from 39-buses to 162-buses.
Rahul Nellikkath, Spyros Chatzivasileiadis
# Enriching Neural Network Training Dataset to Improve Worst-Case Performance Guarantees

###### Abstract

Machine learning algorithms, especially Neural Networks (NNs), are a valuable tool used to approximate non-linear relationships, like the AC-Optimal Power Flow (AC-OPF), with considerable accuracy - and achieving a speedup of several orders of magnitude when deployed for use. Often in power systems literature, the NNs are trained with a fixed dataset generated prior to the training process. In this paper, we show that adapting the NN training dataset _during training_ can improve the NN performance and substantially reduce its worst-case violations. This paper proposes an algorithm that identifies and enriches the training dataset with critical datapoints that reduce the worst-case violations and deliver a neural network with improved worst-case performance guarantees. We demonstrate the performance of our algorithm in four test power systems, ranging from 39-buses to 162-buses.

 AC-OPF, Worst-Case Guarantees, Trustworthy Machine Learning, Explainable AI.

## I Introduction

Machine learning algorithms, especially Neural Networks (NNs), are a valuable tool widely used to approximate non-linear relationships with considerable accuracy. An adequately sized NN with sufficient training data can be used to estimate complex non-nonlinear and non-convex power flow problems like the AC-Optimal Power Flow (AC-OPF) [1] in a fraction of the time it would take to solve the exact problem. Considering AC-OPF is a valuable tool that the power system operators have to use numerous times to evaluate multiple uncertain scenarios and to prepare contingency plans for the daily safe operation of the power system, a well-trained NN would be a valuable tool that can save computational time and help the power system operators run orders of magnitude more scenarios. Moreover, these well-trained NNs could be used to either replace the existing convex approximations or relaxations of these non-convex non-linear problems [2, 3], to warm start the actual problem [4], or as a surrogate function in challenging optimization algorithms [5].

However, for the widespread adoption of the NN algorithms in power systems, it is essential to build an accurate approximation of the non-linear problems that do not violate the constraints of the power system. In the case of approximating AC-OPF algorithms, a few researchers have shown that incorporating power flow constraint violations into the training process [6, 7, 8, 9] can improve the accuracy of the predictions drastically. Previously, we had proposed a Physics-Informed Neural Network (PINN) [10], which combined the KKT conditions of AC-OPF along with the power flow constraints to improve the performance of the NN [11]. Moreover, exciting research is happening on how the NN predictions could be altered to satisfy the power system constraints [12]. These works have helped improve the accuracy and build trust in the NN predictions for AC-OPF predictions.

Regardless, the performance of all these NN algorithms depends highly on the ability of the training data set to capture adverse points to the NN. Yet, a traditional NN training algorithm usually relies on a fixed training dataset, either randomly generated from the input domain or collected from a previously existing dataset, throughout the training process to generalize the problem. In a sizable system with multiple parameters to consider, one might require more than this traditional way of compiling training datasets to capture challenging adverse inputs to the NN that could lead to massive power system constraint violations once deployed. One of our previous works has shown the importance of enriching the training dataset with challenging input data points during training to improve its accuracy when predicting the N-1 small-signal stability margin of a wind farm [13].

Ultimately, to build trust in the NN's performance for a safety-critical application, such as power systems operation, some form of worst-case performance guarantees is required. Our previous work has shown how we can determine worst-case guarantees for AC [11] and DC-OPF [14] problems; and demonstrated how one could use the worst-case guarantees to select appropriate hyperparameters [11, 15] for the NN training which improve the worst-case performance. Still, as we show in this paper, we can substantially further improve the NN worst-case performance by enriching the training dataset.

In this paper, we illustrate how we can use the worst-case guarantees of the NN for AC-OPF to enrich the NN training data set with critical data points that improve the worst-case performance of the NN. Our contributions are as follows:

1. We demonstrate how to use the worst-case guarantees of NN predictions, proposed in [11], to enrich the NN training dataset during training to minimize the worst-case generation constraint violations of the NN.
2. We demonstrate how we can use a simplified MILP problem to identify the region around the point that caused worst-case constraint violations to sample effectively multiple data points to the training dataset.

This paper is structured as follows: Section II discusses AC-OPF and how we can use a power flow-informed NN
to approximate the AC-OPF solutions. Section III explains the proposed NN dataset enrichment algorithm.Section IV presents results from case studies, and Section V concludes.

## II Optimal Power Flow Algorithm and Power Flow Informed Neural Network

This section describes the AC -OPF problem we used as a guiding application, presents the standard neural network architecture, and the power-flow-informed NN that will be used as a building block for the proposed NN training dataset enrichment algorithm.

### _AC-Optimal Power Flow_

The objective function for reducing the cost of active power generation in a power system with \(N_{g}\) number of generators, \(N_{b}\) number of buses, and \(N_{d}\) number of loads can be formulated as follows:

\[\min_{\mathbf{P}_{g},\mathbf{Q}_{g},\mathbf{v}}\quad\mathbf{c}_{p}^{T}\mathbf{ P}_{g} \tag{1}\]

where the vector \(\mathbf{P}_{g}\) denotes the active power setpoints of the generators in the system, and \(\mathbf{c}_{p}^{T}\) denotes the costs vector for the active power production at each generator. \(\mathbf{Q}_{g}\) and \(\mathbf{v}\) denote the reactive power setpoints of the generators and the complex bus voltages, respectively. The active and reactive power injection at each node \(n\in N_{b}\), denoted by \(p_{n}\) and \(q_{n}\) respectively, can be calculated as follows:

\[p_{n} =p_{n}^{g}-p_{n}^{d} \forall n\in N_{b}, \tag{2}\] \[q_{n} =q_{n}^{g}-q_{n}^{d} \forall n\in N_{b}, \tag{3}\]

where \(p_{n}^{g}\) and \(q_{n}^{g}\) are the active and reactive power generation, and \(p_{n}^{d}\) and \(q_{n}^{d}\) are the active reactive power demand at node \(n\). The power flow equations in the network in cartesian coordinates can be written as follows:

\[p_{n} =\sum_{k=1}^{N_{b}}v_{n}^{r}(v_{k}^{r}G_{nk}-v_{k}^{i}B_{nk})+v_{n }^{i}(v_{k}^{i}G_{nk}+v_{k}^{r}B_{nk}) \tag{4}\] \[q_{n} =\sum_{k=1}^{N_{b}}v_{n}^{i}(v_{k}^{r}G_{nk}-v_{k}^{i}B_{nk})-v_{n }^{r}(v_{k}^{i}G_{nk}+v_{k}^{r}B_{nk}) \tag{5}\]

where \(v_{n}^{r}\) and \(v_{n}^{i}\) denote the real and imaginary part of the voltage at node \(n\). The conductance and susceptance of the line \(nk\) connecting node \(n\) and \(k\) is denoted by \(G_{nk}\) and \(B_{nk}\) respectively. The power flow equations can be written in a more compact form by combining the real and imaginary parts of voltage into a vector of size \(2N_{b}\times 1\) as \(\mathbf{v}=[(\mathbf{v}^{r})^{T},(\mathbf{v}^{i})^{T}]^{T}\) as follows [6]:

\[\mathbf{v}^{T}\mathbf{M}_{p}^{n}\mathbf{v}= p_{n} \forall n\in N_{b} \tag{6}\] \[\mathbf{v}^{T}\mathbf{M}_{q}^{n}\mathbf{v}= q_{n} \forall n\in N_{b} \tag{7}\]

where \(\mathbf{M}_{p}^{n}\) and \(\mathbf{M}_{q}^{n}\) are symmetric real valued matrices [16].

The active and reactive power generation limits can be formulated as follows:

\[p_{n}^{g}\leq p_{n}^{g}\leq\overline{p}_{n}^{g} \forall n\in N_{g} \tag{8}\] \[q_{n}^{g}\leq q_{n}^{g}\leq\overline{q}_{n}^{g} \forall n\in N_{g} \tag{9}\]

Similarly, the voltage and line current flow constraints for the power system can be represented as follows:

\[\mathbf{V}^{n}\leq\mathbf{v}^{T}\mathbf{M}_{v}^{n}\mathbf{v}\leq \overline{\mathbf{V}}^{n} \forall n\in N_{b} \tag{10}\] \[\ell_{mn} =\mathbf{v}^{T}\mathbf{M}_{i_{mn}}\mathbf{v}\leq\overline{\ell}_{ mn} \forall mn\in N_{l} \tag{11}\]

where \(\mathbf{M}_{v}^{n}:=e_{n}e_{n}^{T}+e_{N_{b}+n}e_{N_{b}+n}^{T}\) and \(e_{n}\) is a \(2N_{b}\times 1\) unit vector with zeros at all the locations except \(n\). The squared magnitude of upper and lower voltage limit is denoted by \(\overline{\mathbf{V}}^{n}\) and \(\underline{\mathbf{V}}^{n}\) respectively. The squared magnitude of line current flow in line \(mn\) is represented by \(\ell_{mn}\) and matrix \(\mathbf{M}_{i}^{mn}=|y_{mn}|^{2}(e_{m}-e_{n})(e_{m}-e_{n})^{T}+|y_{mn}|^{2}(e_ {N_{b}+m}-e_{N_{b}+n})(e_{N_{b}+m}-e_{N_{b}+n})^{T}\), where \(y_{mn}\) is the line admittance of branch \(mn\). Assuming the slack bus \(N_{sb}\) acts as an angle reference for the voltage, we will have:

\[v_{N_{sb}}^{i}=\mathbf{v}^{T}\mathbf{e}_{N_{b}+N_{sb}}\mathbf{e}_{N_{b}+N_{sb} }^{T}\mathbf{v}=0 \tag{12}\]

The constraints (2)-(3),(6)-(12) and the objective function for the AC-OPF problem (1) can be written in a more compact form as follows (for more details, see [6]):

\[\min_{\mathbf{v},\mathbf{G}}\quad\mathbf{c}^{T}\mathbf{G} \tag{13a}\] \[s.t\ \mathbf{v}^{T}\mathbf{L}_{l}\mathbf{v} =a_{l}^{T}\mathbf{G}+b_{l}^{T}\mathbf{D}, l=1:L\] (13b) \[\mathbf{v}^{T}\mathbf{M}_{m}\mathbf{v} \leq d_{m}^{T}\mathbf{D}+f_{m}, m=1:M \tag{13c}\]

where \(\mathbf{G}=[\mathbf{P}_{g}^{T},\mathbf{Q}_{g}^{T}]^{T}\), \(\mathbf{c}^{T}\) is the combined linear cost terms for the active power and, if necessary, reactive power generation. \(\mathbf{D}=[\mathbf{P}_{d}^{T},\mathbf{Q}_{d}^{T}]^{T}\) denotes the active and reactive power demand in the system. Following that, the equality constraints (6)-(7) and (12) can be represented by the \(\mathbf{L}=2N_{b}+1\) constraints in (13b). Similarly, the inequality constraints (8)-(11) can be represented by the \(\mathbf{M}=4N_{g}+2N_{b}+N_{l}\) constraints in (13c).

### _Neural Network for Optimal Power Flow Predictions_

Neural Networks (NNs) are considered global approximators and can estimate the AC-OPF solution with significant accuracy when trained appropriately, and with sufficient training data. To achieve this, NN uses a group of interconnected hidden layers with multiple neurons to learn the relationship between the input and output layers. In the case of AC-OPF for generation cost minimization, the input layer will be the active and reactive power demand in the power system, and the output layer will be the optimal active and reactive power generation setpoints.

Each neuron in a hidden layer will be connected with neurons in the neighboring layers through a set of edges. The information exiting one neuron goes through a linear transformation before reaching the neuron in the subsequent layer. Activation functions are used in every neuron to introduce nonlinear relationships into the approximator. In this paper, we use the ReLU activation function in the hidden layers, as they have shown to accelare convergence during training [17].

A standard NN, with \(K\) number of hidden layers and \(N_{k}\) number of neurons in hidden layer \(k\), is shown in Fig. 1.

The information arriving at layer \(k\) can be formulated as follows:

\[\hat{\mathbf{Z}}_{k}=\mathbf{w}_{k}\mathbf{Z}_{k-1}+\mathbf{b}_{k} \tag{14}\]
where \(\mathbf{Z}_{k-1}\) is the output of the neurons in layer \(k-1\), \(\hat{\mathbf{Z}}_{k}\) is the information received at layer \(k\), \(\mathbf{w_{k}}\) and \(\mathbf{b_{k}}\) are the weights and biases connecting layer \(k-1\) and \(k\).

As mentioned, each neuron in the neural network uses the nonlinear ReLU activation function to accurately approximate the nonlinear relationships between the input and output layer. So, the output of each hidden layer in the NN can be represented as follows:

\[\mathbf{Z}_{k}=\max(\hat{\mathbf{Z}}_{k},0) \tag{15}\]

The weights \(\mathbf{w_{k}}\) and biases \(\mathbf{b_{k}}\) in the NN are optimized to minimize the average error in predicting the optimal generation setpoints in the training data set, denoted by \(\mathcal{L}_{0}\), which will be measured as follows:

\[\mathcal{L}_{0}=\frac{1}{N}\sum_{i=1}^{N}|\mathbf{G}_{i}-\hat{\mathbf{G}}_{i}| \tag{16}\]

where \(N\) is the number of data points in the training set, \(\mathbf{G}_{i}\) is the generation setpoint determined by the OPF, and \(\hat{\mathbf{G}}_{i}\) is the predicted NN generation setpoint. The back-propagation algorithm will be used to modify the weights and biases to minimize the average prediction error (\(\mathcal{L}_{0}\)), as shown in Fig. 1, during each iteration of the NN training. A learning rate of \(\lambda\) controls the step size of the optimizer.

### _Power-Flow-Informed Neural Network_

A standard NN training procedure relies solely on the average error between its predictions and the data in the training dataset to achieve adequately accurate AC-OPF predictions. However, since these NN predictions should satisfy the power flow constraints given in Eq. (13), we can use a power-flow-informed NN (PFNN) similar to the ones proposed in [6], and our previous work [11] to improve the generalization capability of the NN.

The structure of the power-flow-informed NN (PFNN) used in this work is given in Fig. 2. Here an additional NN, denoted by \(NN_{v}\), is used to approximate the real and imaginary part of the voltages in the system. Subsequently, both the predicted optimal generation setpoints and voltages in the system were analyzed to compute the power flow constraint violation, denoted by \(\mathcal{L}_{PF}\), as follows:

\[\mathcal{L}_{PF}=\frac{1}{N}\sum_{i=1}^{N}|\sigma_{eq}+\sigma_{incq}|\] (17a) where, \[\sigma_{eq} =|\mathbf{v}^{T}\mathbf{L}_{l}\mathbf{v}-a_{l}^{T}\mathbf{G}-b_{l }^{T}\mathbf{D}|, l=1:L \tag{17b}\] \[\sigma_{incq} =\max(\mathbf{v}^{T}\mathbf{M}_{m}\mathbf{v}-d_{m}^{T}\mathbf{D} -f_{m},0), m=1:M \tag{17c}\]

Thus the loss function for training the PFNN is formulated as follows:

\[\mathcal{L}_{PFNN}=\Lambda_{0}\mathcal{L}_{0}+\Lambda_{PF}\mathcal{L}_{PF} \tag{18}\]

where \(\Lambda_{0}\) and \(\Lambda_{PF}\) are the weights given to the two loss functions \(\mathcal{L}_{0}\) and \(\mathcal{L}_{PF}\), respectively.

In our investigations, this configuration of NN with power flow constraint check has been shown to improve the average and worst-case performance of the NN without introducing a substantial computational burden. Still, the performance of the trained PFNN depends highly on the ability of the training dataset to capture adverse points to the PFNN.

## III Neural Network Data Enriching Using Worst-Case Constraint Violations

The following section describes a NN dataset-enriching algorithm that uses worst-case generation constraint violations in regular intervals during training to identify the input regions causing the largest generation constraint violations and then enrich the training dataset with new training points from those regions. This shall help minimize the probability a NN prediction to lead to significant generation constraint violations.

Fig. 1: Illustration of the NN training architecture to predict the optimal active and reactive power generation setpoints (\(\hat{\mathbf{G}}\)) using the active and reactive power demand (\(\mathbf{D}\)) in the system as input: There are K hidden layers with \(N_{k}\) neurons each. During training the weights \(\mathbf{w_{k}}\) and biases \(\mathbf{b_{k}}\) in the NN are optimized to minimize the average error (\(\mathcal{L}_{0}\)) in predicting the optimal generation setpoints (\(\mathbf{G}\)), calculated using Eq. (16).A learning rate of \(\alpha\) controls the step size of the optimizer.

Fig. 2: Illustration of the power-flow-informed NN (PFNN) training architecture to predict the optimal active and reactive power generation setpoints (\(\hat{\mathbf{G}}\)) using the active and reactive power demand (\(\mathbf{D}\)) in the system as input. There are two NNs, one for predicting \(\hat{\mathbf{G}}\), denoted by \(NN_{G}\), and the other for predicting the voltage in the system, denoted by \(NN_{v}\). During training, the weights \(\mathbf{w_{k}}\) and biases \(\mathbf{b_{k}}\) in the NN are optimized to minimize the average error (\(\mathcal{L}_{0}\)) in predicting the optimal generation (\(\mathbf{G}\)) and voltage setpoints (\(\mathbf{v}\)), and the power flow constraint violation(\(\mathcal{L}_{PF}\)). See (17) for the calculations.
### _Worst-Case Violations of the Neural Networks to Identify Adverse Examples_

As mentioned earlier, we determine the input data with which we enrich our NN training dataset by identifying which are the NN inputs that cause the worst violations. The optimization problem to identify worst-case generation constraint violation is presented in (19) [11]:

\[\max_{\mathbf{D}} v_{g}\] (19a) \[v_{g}=\max_{\mathbf{D}} (\mathbf{\hat{G}}-\mathbf{\overline{G}},\mathbf{\underline{G}}- \mathbf{\hat{G}},0)\] (19b) s.t. ( 14 ) ( 15 )

where \(\mathbf{\overline{G}}\) and \(\mathbf{\underline{G}}\) are the maximum and minimum active and reactive power generation bounds. However, the formulation for the ReLU activation function in (15) is nonlinear. So, the ReLU activation function is reformulated into a set of mixed-integer linear inequality constraints, as follows, to simplify the optimization problem [14]:

\[\mathbf{Z}_{k}=\max(\mathbf{\hat{Z}}_{k},0)\Rightarrow\left\{\begin{aligned} \mathbf{Z}_{k}&\leq\mathbf{\hat{Z}}_{k}-\mathbf{Z}_{k}(1- \mathbf{y}_{k})\end{aligned}\right. \tag{20a}\] \[\mathbf{Z}_{k}\geq\mathbf{\hat{Z}}_{k}\] (20b) \[\mathbf{Z}_{k}\leq\mathbf{\overline{Z}}_{k}\mathbf{y}_{k}\] (20c) \[\mathbf{Z}_{k}\geq\mathbf{0}\] (20d) \[\mathbf{y}_{k}\in\{0,1\}^{N_{k}}. \tag{20e}\]

where \(\mathbf{Z}_{k}\) and \(\mathbf{\hat{Z}}_{k}\) are the outputs and inputs of the ReLU activation function, \(y_{k}^{i}\) is a binary variable, and \(\mathbf{\underline{Z}}_{k}\) and \(\mathbf{\overline{Z}}_{k}\) are the upper and lower limits of the input to ReLU. These limits should be sufficiently large to ensure they are not binding and small enough so the constraints are not unbounded. We used interval arithmetic to ensure a tighter bound (ref [18] and [14] for more information). If \(\mathbf{\hat{Z}}_{k}\) is less than zero, then \(y_{k}^{i}\) will be zero because of (20c), and \(Z_{k}^{i}\) will be constrained to zero. Else, \(y_{k}^{i}\) will be equal to one, and \(Z_{k}^{i}\) will be equal to \(\mathbf{\hat{Z}}_{k}\) due to (20a) and (20b).

The MILP optimization problem for identifying the specific input combination that could lead to a large generation constraint violation (will be denoted by \(D_{WC}\) from now on) can be formulated as follows:

\[\max_{\mathbf{D}} v_{g}\Rightarrow v_{g}^{max}\] (21a) \[v_{g}=\max(\mathbf{\hat{G}}-\mathbf{\overline{G}},\mathbf{ \underline{G}}-\mathbf{\hat{G}},0)\] (21b) s.t. ( 14 ) ( 20 )

where \(v_{g}^{max}\) is the worst-case generation constraint violation obtained after solving the optimization.

By solving the optimization problem mentioned above for all the generators in the system, we can identify the specific \(D_{WC}\) that caused the largest constraint violations. However, simply adding these \(D_{WC}\) to the dataset might not be adequate; instead, to properly enrich the dataset, it is also essential to identify the size of a region around \(D_{WC}\) that could lead to equally large constraint violations. Thus, we can collect multiple points from this region to enrich the dataset.

The optimization problem below is used to fit a hypercube to the space around \(D_{WC}\) that could cause significant constraint violations.

\[\max_{\mathbf{D}} d \tag{22a}\] \[d=\left\|D_{0}-D_{WC}\right\|_{\infty}\] (22b) s.t. \[v_{g}\geq\alpha\cdot v_{g}^{max}\] (22c) \[\eqref{eq:DWC} \tag{22d}\]

Here, the distance \(d\) defines a hypercube around \(D_{WC}\) that causes constraint violations more than \(\alpha\cdot v_{g}\). We can choose a smaller or larger value of \(\alpha\) to get a wider or tighter region around \(D_{WC}\).

In the optimization problem (22), for \(\alpha\) close to 1, we can assume the hypercube around \(D_{WC}\) will be small. Thus we can consider a significant positive or negative \(\mathbf{\hat{Z}}\) value will not change signs for any of the input data points inside the hypercube. Therefore, we can set those ReLU statuses, denoted by \(\mathbf{y}_{k}\) in (20), to always be active or inactive in the hypercube. This reduces the number of binary variables in the optimization problem and thereby reduces the computational complexity of the optimization problem. A threshold of 10 % with respect to the \(\mathbf{\overline{Z}}\) or \(\mathbf{\underline{Z}}\) was used to decide whether to fix \(\mathbf{y}_{k}\) or not. That is, if the \(\mathbf{\hat{Z}}\) value for NN input \(D_{WC}\) was more than \(0.1\cdot\mathbf{\overline{Z}}\) or less than of \(0.1\cdot\mathbf{\underline{Z}}\), then those binary variables are set to active or inactive respectively in the hypercube.

After obtaining the size of the hypercube, a random gaussian sampling, centered at \(D_{WC}\), is used to sample new training data points from the hypercube. Unlike the original training dataset, we did not compute the optimal generation setpoints (i.e., G) for these additional data points to avoid using extra computational power to solve the AC-OPF problem. Instead, we used the power flow constraint violations in \(\mathcal{L}_{PF}\) to train the neural network.

The proposed NN dataset enrichment algorithm is given in Algorithm 1.

```

[MISSING_PAGE_POST]
dataset, 20% were assigned to the validation set, and the remaining 30% were assigned to the unseen test dataset. The AC-OPF solver in MATPOWER [21] was used to obtain the optimal generation setpoints and the voltages at each bus.

A NN with three hidden layers and 20 nodes in each layer is used to predict the AC-OPF solutions. The ML algorithms were implemented using PyTorch [22] and the Adam optimizer [23]; a learning rate of 0.001 was used for training. WandB [24] was used for monitoring and tuning the hyperparameters. The MILP problem for obtaining the worst-case violations and identifying the region was programmed in Pyomo [25] and solved using the Gurobi solver [26]. The NNs were trained in a High-Performance Computing (HPC) server with an Intel Xeon E5-2650v4 processor and 256 GB RAM. The code and datasets to reproduce the results are available online [27].

### _Comparing the Average and the Worst-Case Performance_

Both the PFNN and WC-PFNN algorithms, in all cases, achieved convergence in 600 iterations. After every 200 iterations during training, we evaluated the worst-case constraint violations, and in the case of WC-PFNN, a new 1000 data points were added to the training dataset. To compensate, 2000 random data points were added to the PFNN training dataset before starting the training process to have a comparable training dataset.

For WC-PFNN and PFNN, we selected the weight \(\Lambda_{0}\) and \(\Lambda_{PF}\) for the loss functions \(L_{0}\) and \(L_{PF}\) that offered the lowest worst-case generation constraint violation using WandB.

While comparing the worst-case performance over the training process, we can see in Fig. 3 that in all cases, the proposed NN dataset enriching algorithms (WC-PFNN) result in a steep reduction in worst-case guarantees. At the same time, the PFNN was only able to achieve a slight decline or, in case162 and case 57, even an increase in worst-case generation constraint violation during training. This highlights the importance of monitoring and enriching the NN dataset using worst-case constraint violations.

The mean absolute error (MAE) in an unseen test dataset, the worst-case generation constraint violation (\(v_{g}\)), and the width of the hypercube around \(D_{WC}\), denoted by \(d\) (as a fraction of the nominal loading at each node), caused by PFNN and WC-PFNN after training are given in Table II.

From Table II, we see that WC-PFNN can reduce worst-case generation constraint violations by more than 30% in all test systems. As a matter of fact, in case57, it achieves an up to 80% reduction compared to PFNN with a fixed dataset. Moreover, it was observed that the hypercube around \(D_{WC}\), which collects points that could cause significant constraint violations (see (22)), was also shrinking as we were including new points in the training set. So, the proposed method also made the NN safer in more regions in the input domain.

Fig. 3: Change in worst case generation constraint violation with respect to the worst-case generation constraint violation at training iteration 200
## V Conclusion

The objective of this paper is to demonstrate the importance of enriching the NN training dataset with critical datapoints in order to improve the NN worst-case performance. To determine these datapoints we use algorithms that accurately quantify the worst-case violations of the NN. This helps significantly improve the NN performance and enhances the trust in NN for safety-critical applications. In this paper, we show that by enriching the NN training dataset using the worst-case generation constraint violations of an AC-OPF problem during training, we can improve the worst-case performance of the NN drastically. We test the proposed algorithm on four different power systems, ranging from 39-buses to 162-buses and we show that we can achieve up to 80% reduction in worst-case performance. In future work, we plan to integrate this approach with our recent work on designing a neural network training procedure that achieves best average performance and minimizes the worst case violations at the same time [28].
