{'fraction_non_alphanumeric': 0.025636553889082665, 'fraction_numerical': 0.0056243460062783395, 'mean_word_length': 4.630093274423172, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Trusted Confidence Bounds for Learning Enabled Cyber-Physical Systems

Cyber-physical systems (CPS) can benefit by the use of learning enabled components (LECs) such as deep neural networks (DNNs) for perception and decision making tasks. However, DNNs are typically non-transparent making reasoning about their predictions very difficult, and hence their application to safety-critical systems is very challenging. LECs could be integrated easier into CPS if their predictions could be complemented with a confidence measure that quantifies how much we trust their output. The paper presents an approach for computing confidence bounds based on Inductive Conformal Prediction (ICP). We train a Triplet Network architecture to learn representations of the input data that can be used to estimate the similarity between test examples and examples in the training data set. Then, these representations are used to estimate the confidence of set predictions from a classifier that is based on the neural network architecture used in the triplet. The approach is evaluated using a robotic navigation benchmark and the results show that we can computed trusted confidence bounds efficiently in real-time.


I. INTRODUCTION
Machine learning components are being used by many cyber-physical system (CPS) applications because of their ability to handle dynamic and uncertain environments. Deep neural networks (DNNs), for example, are used for perception and decision making tasks in autonomous vehicles. Although such components offer many advantages for representing knowledge in high-dimensional spaces and approximating complex functions, they introduce significant challenges when they are integrated into the system. Typical DNNs are non-transparent and it is not clear how to rationalize their predictions. Modern architectures are parameterized using million of values which makes reasoning about their predictions very challenging.
Complementing the predictions of DNNs with a confidence measure can be very useful for improving the trustworthiness of such models and allow their application to safety critical systems. Several approaches have been proposed for confidence estimation. Neural networks for classification, in particular, typically provide probability-like outputs using a softmax layer. However, these probabilities are typically overconfident even for inputs coming from the same distribution as the training data [5]. The reason is that the softmax probabilities are not well-calibrated meaning they do not provide a good estimate of the error rates. Several methods are proposed to compute well-calibrated confidence values. A class of methods aims to estimate scaling factors from the training data and use them to scale the softmax probabilities in order to compute well-calibrated confidence values and include temperature scaling [5], Platt scaling [10], and isotonic regression [15]. Although such methods can compute wellcalibrated confidence values, using them in CPS requires selecting an appropriate confidence bound which ensures a very small error rate and at the same time limiting the number of inputs for which a confidence prediction cannot be made.
The approach presented in this paper is based on conformal prediction (CP) [1]. For classification, CP associates reliable confidence values with set predictions that may include multiple labels. The confidence measures are well-calibrated and can be computed in an online setting which is suitable for CPS applications. The online application of the approach is based on the inductive conformal prediction (ICP) for computational efficiency [8]. ICP leverages a calibration data set that is used to compute the confidence values of new previously unseen inputs efficiently. The confidence values rely on nonconformity functions computed using techniques such as k-Nearest Neighbors and Kernel Density Estimation. However, such approaches do not scale for high-dimensional inputs.
In our previous work, we used the ICP framework for assurance monitoring of CPS with machine learning components [3]. In order to handle high-dimensional inputs in real-time, the approach computes the nonconformity scores using the embedding representations produced by trained DNN models in lower dimensional spaces than the input space. The main contribution of this paper is a significant improvement in computing confidence bounds by employing a triplet network architecture to learn representations of the input data that can be used to estimate the similarity between test examples and examples in the training data set. Then, these representations are used to estimate the confidence of set predictions from a classifier that is based on the neural network architecture used in the triplet. In order to achieve the desired confidence, the LEC may need to generate more than one possible prediction. Sets with multiple predictions can be useful especially when the alternatives are provided to a human operator. However, in this paper, we focus on autonomous CPS and compute the optimal confidence bounds required for the LEC to generate single predictions.
Another contribution of the paper is the evaluation of the approach using the SCITOS-G5 robotic navigation benchmark. Our results show that we can compute trusted confidence bounds efficiently in real-time. We also compare the proposed approach with the approach presented in [3] which relies on applying ICP using representations learned by the model used to generate the predictions. The comparison shows for a chosen confidence bound, ICP using triplet produces fewer sets with multiple candidate labels, or equivalently there is a higher confidence bound that eliminate all the sets with multiple predictions.
The paper is organized a follows. Section II describes the problem. Section III reviews the Triplet Network architecture and the associated training algorithms. Section IV presents the methods for ICP using the Triplet. We evaluate the performance of the proposed approach in Section V and we discuss the conclusions in Section VI.

II. PROBLEM
Learning-enabled components in CPS are used for taking decisions based on the state of the system and the environment. For a mobile robot, for example, an LEC can be used to navigate through a room while avoiding collisions with obstacles. A commonly used approach involves learning a model using training data and using the learned model for operation. We expect the system to perform better in scenarios similar to those used during the training phase. The problem we consider is the computation of a significance level along with each decision by the LEC. The significance level must be well-calibrated which means that it must be consistent with the expected error and ideally the expected error rate must be bounded. Moreover, CPS applications require minimizing the number of incorrect decisions while limiting the number of false alarms to enable efficient monitoring. Another requirement for CPS is that such monitoring must be performed in real-time often with limited computional resources.

III. TRIPLET NETWORK
The ICP framework requires a way to estimate the similarity between the training data and a test input. The main idea in our approach is that we can do this efficiently by learning representations of the inputs for which the Euclidean distance is a suitable measure of similarity. The triplet network is a Deep Neural Network (DNN) architecture that is trained to compute appropriate representations for metric or distance learning [6].
A Triplet Network is composed using three copies of the same neural network with shared parameters as shown in where α is the margin between positive and negative pairs.
The triplet network can be trained by randomly sampling anchor data from the training set and augmenting them with one training sample with the same label as the anchor's and one sample with a different label, randomly chosen. However, this method leads to slow training and low performance as The training can be improved by carefully mining the training data [14]. For each training iteration, first, the anchor training data are randomly chosen. For each anchor, the hardest positive sample is chosen, meaning a sample from the same class as the anchor that is located the furthest away from the anchor. Then, the triplets are formed by mining all the hard negative samples, meaning the samples that satisfy Comparator Figure 1: Triplet network structure [6] A trained triplet network maps the raw data inputs to a lower dimensional space called embedding space. The distance between the representations N et(x) of the inputs is a useful measure of similarity and can be used for classification by training a k-NN classifier on the embedding space of the training data. This distance can also be used by the ICP framework as described in the next section.

IV. TRIPLET-BASED ICP
In this section, we briefly explain the Inductive Conformal Prediction (ICP) approach based on the Triplet Network We also consider a test input x l+1 which we wish to classify. ICP assumes that all the examples z 1 , . . . , z l+1 are independent and identically distributed (IID) generated from the same but usually unknown probability distribution. For a chosen significance level ∈ [0, 1], the objective is to generate a set of possible labels Γ for the input x l+1 , such that the probability of the correct label y l+1 / ∈ Γ does not exceed . ICP is based on a nonconformity measure (NCM) which is a dissimilarity metric between an example z l+1 and the examples of the training set z 1 , . . . , z l . There are many different possible NCMs that can be used [3], [1], [13], [12], [7]. The proposed approach uses the Triplet Network to estimate similarities by encoding the inputs to an embedding space where the Euclidean distance between two samples is a direct measure of similarity. NCMs defined in the embedding space include (1) the k-Nearest Neighbors (k-NN) [9], (2) the one Nearest Neighbor (1-NN) [13] and (3) the Nearest Centroid [1].
The k-NN NCM finds the k most similar examples in the training data and counts how many of those are labeled different than the candidate label y of a test input x. We denote f : X → V the mapping from the input space X to the embedding space V defined by the Triplet's last layer. After the training of the Triplet is complete, we compute and store the encodings v i = f (x i ) for the training data x i . Given a test example x with encoding v = f (x), we compute the knearest neighbors in V and store their labels in a multi-set Ω. The k-NN nonconformity of the test example x with a candidate label y is defined as: α(x, y) = |i ∈ Ω : i = y|.
The 1-NN NCM requires to find the most similar example in the training set that has the same label as the candidate label y of a test input x as well as the most similar example that belong to any other class other than y. It is defined as: where , and d is the euclidean distance metric in the V space. The Nearest Centroid NCM simplifies the task of computing individual training examples that are similar to a test example when there is a large amount of training data. We expect examples that belong to a particular class to be similar to each other so for each class y i we compute its centroid where v i j is the embedding representation of the j th training example from class y i and n i is the number of training examples in class y i . The nonconformity function is defined as: where v = f (x). It should be noted that for computing the nearest centroid NCM, we need to store only the centroid for each class.
The NCM a(x, y) is a measure of dissimilarity between a test input x with candidate label y and the training data z 1 . . . z l as larger values would indicate higher "dissimilarity". However, this measure does not provide useful information by itself but it can be used by comparing it with NCM values computed using a calibration set of known labeled data. Consider the training set (z 1 . . . z l ). This set is split into two parts, the proper training set (z 1 . . . z m ) of size m < l that will also be used for the training of the Triplet Network and the calibration set (z m+1 . . . z l ) of size l − m. The method first computes the NCMs a(x i , y i ), i = m + 1 . . . l for the examples in the calibration set. Given a test example x with an unknown label y, the method forms a set |Γ | of possible labelsỹ so that P (y / ∈ |Γ |) < . For all the candidate labels y, ICP is based on the empirical p-value defined as that computes the fraction of nonconformity scores of the calibration data that are equal or larger than the nonconformity score of a test input. A candidate label is added to Γ if p j (x) > . Depending on the desired significance level , there may be more than one possible label. Although these multiple labels can provide useful information, we assume we do not have a way to process more than one possible label and we want to minimize these cases. The objective of the monitoring algorithm is after receiving each input to compute a valid prediction that ensures a predefined error rate (based on ) and limits the number of input examples for which a confident prediction cannot be made. The output of the monitor is defined as: Depending on the size of the set Γ , the monitor outputs out = 1 to indicate there is a single prediction with bounded confidence by . If the set Γ is either empty or have multiple labels, the monitor raises alarms to indicate that no decision can be made. However, we distinguish between multiple and no predictions, because they may lead to different action in the system. An empty Γ may be an indication that the input is out-of-distribution while multiple possible labels indicates that the accuracy of the underlying model is lower than the chosen .

Algorithm 1 -Monitoring Algorithm.
Input: training data (X, Y ), calibration data (X c , Y c ) Input: trained neural network f with l layers Input: Nonconformity function α Input: test input z Input: significance level threshold 1: // Compute the nonconformity scores for the calibration data offline 2: A = {α(x, y) : (x, y) ∈ (X c , Y c )} Calibration 3: // Generate prediction sets for each test data online 4: for each label j ∈ 1..n do 5: Compute the nonconformity score α(z, j) In this section, we evaluate how the triplet network improves the computation of significance levels using ICP. For the comparison, we use metrics that include how well inputs for different classes are clustered in the embedding represenation learned by the Triplet, the validity and efficiency of the produced prediction sets |Γ |, the execution time of the monitoring algorithm, and the required memory.

A. Experimental Setup
We apply the proposed method to the SCITOS-G5 wall following robot navigation dataset [4]. The robot has the task of navigating around the room counter-clockwise in close proximity to the walls. It is equipped with 24 ultrasound sensors that are sampled at a rate of 9 samples per second. The possible actions are "Move-Forward", "Sharp-Right-Turn", "Slight-Left-Turn", and "Slight-Right-Turn". The SCITOS-G5 dataset contains 5456 raw values of the ultrasound sensor measurements as well as the decision it took in each sample.
10% of the samples is used for testing. From the remaining 90% of the data, 80% is used for training and 20% for calibration and/or validation.
The triplet network is formed using three identical DNNs with shared weights as shown in Fig. 1. Since the inputs in the SCITOS-G5 dataset come from 24 sensors, we treat them as vectors and use a fully connected neural network. The parameters of the network architecture are shown in Table I. For the baseline approach the DNN of Table I is trained using the dedicated training data. The output of the hidden layer FC4, without taking into account the ReLu activation, is used to produce the representations for the baseline ICP. The FC5 is used as the baseline DNN classifier. The Triplet is trained using three copies of the same base DNN with hidden layers FC1-FC4. After training, only one of the three copies is used to generate the embeddings on the output of FC4 without any activation.

B. Triplet Performance
We first look at how well the triplet clusters the data on a 16-dimensional space. For comparison, we use the embedding space produced by the FC4 hidden layer of the DNN classifier. A commonly used metric of the separation between classes is the Silhouette [11]. For each sample, we first compute the mean distance between i and all other data points in the same cluster in the embedding space .
Then we compute the smallest mean distance from i to all the data points in any other cluster The silhouette value is defined as . Each sample i in the embedding space is assigned a silhouette value −1 ≤ s(i) ≤ 1 depending on how close and how far it is to samples belonging to the same and different classes respectively. The closer s(i) is to 1, the closer the sample is to samples of the same class and further from samples belonging to other classes. To compare the representations learned using the Triplet with the representations learned using the FC4 hidden layer of the fully connected DNN, we compute the mean silhouette over the training data and the validation data separately. In Table II, we see that the representations learned by the Triplet form better-defined clusters.  Another way to evaluate the performance of the triplet network is to combine it with a k-Nearest Neighbors classifier as shown in Figure 2a, and compute the classification accuracy. A test input is converted to an embedding representation using the triplet and then the k-NN classifier with k=15 is used to make a prediction. The baseline DNN uses a softmax activation (Figure 2b) for the classification. The Table III shows the accuracy of the triplet combined with a k-NN compared to the softmax classifier both using the same base neural network architecture shown in Table I

C. ICP and Assurance Monitoring
The SCITOS-G5 robot is a safety-critical CPS for which the controller needs to take decisions with a well-calibrated and valid predefined significance level. As a baseline, we consider a NCM defined based on the penultimate layer of a DNN to generate a representations that allow real-time monitoring [3]. We evaluate the performance of the triplet when used with the nonconformity functions presented in IV. In particular, we compare the calibration and validity of the predicted candidate label sets as well as we compute the bound that eliminates the sets Γ with |Γ | > 1, that is the sets with multiple predictions.
First, we verify that the error rates of the monitoring algorithm are bounded by the significance level . We compute the percentage of incorrect predictions and we plot the cumulative error for different values of . In Figure 3, we plot the cumulative error for three different values of for the SCITOS-G5 dataset using the Nearest Centroid nonconformity function. We see that the three different significance levels bound the cumulative error rate well. Similar behavior is observed using the other two nonconformity functions.
In order to see how well-calibrated the confidence bounds are as well as how many sets with multiple candidate predictions are generated when ∈ [0.001, 0.4], we plot the calibration and performance curves in   Table IV reports the average execution time for each test input and the required memory using different nonconformity functions. The memory needed for the ICP application with each NC function is the memory required to store the DNN weights and the memory required to store the training data used by each NC function. In the k-NN and 1-NN case, the encodings of the training data are stored in a k − d tree [2] that is used to compute efficiently the nearest neighbors. In the 1-NN case, it is required to find the nearest neighbor in the training data for each possible class which is  The nearest centroid nonconformity function requires storing only the centroids for each class so the additional memory required is minimal. Both the triplet network architecture and the FC DNN we use as a baseline have the same network architecture and generate the same embedding size so the memory requirements are exactly the same between the two. The evaluation results demonstrate that both the baseline FC DNN based ICP confidence monitor and the Triplet based ICP confidence monitor have well-calibrated error rates. The approach allows selecting the significance level to tradeoff errors and alarms. When our objective is to minimize the number of alarms raised because of multiple candidate predictions, the Triplet with k-NN or Nearest Centroid NC functions satisfies it while keeping a higher significance level. When the significance level is selected, the Triplet based algorithm produces less sets of multiple candidate predictions. Finally, the memory requirements and the execution times for both approaches show that this monitoring system can be used for real-time CPS applications.

VI. CONCLUSION
DNN components are being used in Cyber-physical systems (CPS) to perform tasks like perception and control. However, their decision making process cannot be interpreted in a straightforward way and they cannot provide well-calibrated probabilities on the correctness of their predictions. This paper considers the problem of complementing the prediction of DNNs with a computation of confidence for real-time monitoring of CPS. We used the Inductive Conformal Prediction framework for classification tasks to produce sets of predictions with an error rate bounded by a chosen significance level. The evaluation results demonstrate that the addition of Triplet to the ICP framework produces well-calibrated probabilities as well as less prediction sets with more than one candidate decisions for a given significance level. The Triplet networks have been used on applications with higher dimensional input space such as images. Thus our future work is to scale our suggested assurance monitoring approach to be used on ICP applications that deal with images, like the camera outputs on self driving vehicles. Moreover, since there are many NC functions that can be used it is natural to see if we can combine the prediction sets produced by each of them on a test input using ensemble methods with voting to produce a narrower prediction set.

ACKNOWLEDGMENT
The material presented in this paper is based upon work supported by the Defense Advanced Research Projects Agency (DARPA) through contract number FA8750-18-C-0089 and the Air Force Office of Scientific Research (AFOSR) DDDAS through contract number FA9550-18-1-0126. The views and conclusions contained herein are those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of DARPA or AFOSR