









\section{Introduction}
The design of reliable perception systems is a key challenge in the development of safety-critical autonomous systems~\cite{rosique2019systematic, van2018autonomous}. Modern perception systems are often required to predict state information from complex, high-dimensional inputs such as images or LiDAR data \cite{jung2018perception, li2020lidar, opromolla2021visual}. This information is then passed to a controller, which uses the state estimate to make safety-critical decisions. For example, vision-based perception systems have been proposed for detect and avoid applications in aviation~\cite{opromolla2021visual}.
It is important that perception systems produce accurate estimates, and these systems are typically trained to minimize overall perceptual error using a regression loss on a set of training data. This training method, however, fails to account for the effect of perceptual errors on the performance of the fully-integrated, closed-loop control system. In particular, not all errors will have an equal effect on overall performance. While some errors pose minimal risk, others may lead to catastrophic outcomes \cite{Julian2020, Corso2019itsc}. 

\textbf{Contribution} \ \ In this work, we develop a technique to design perception systems that are sensitive to the overall risk of the closed-loop system in which they operate. We formulate a risk function that quantifies the downstream effect on safety of making a given perceptual error in a given state. We then show how the risk function can be used to design safer perception systems by incorporating it into the loss function during training and using it to focus data collection efforts on the most risk-sensitive regions of the state space. Finally, we analyze the impact of our risk-driven design approach on the safety of a realistic vision-based aircraft detect and avoid system. We show that our approach is able to reduce collision risk by up to \SI{37}{\percent} over a baseline perception system.

\section{Background}\label{sec:background}
This work uses a notion of conditional value at risk (CVaR) and a Markov decision process (MDP) formulation to estimate the effect of perceptual errors on the safety of a closed-loop system. This section details the necessary background on these topics.

\textbf{Conditional Value at Risk (CVaR)} \ \ Let $X$ be a bounded random variable and $F(x) = P(X \leq x)$ be its cumulative distribution function. The value at risk (VaR) is the highest value that $X$ is guaranteed not to exceed with probability $\alpha$ written as
\begin{equation}
    \text{VaR}_\alpha(X) = \min \{x \mid F(x) \geq \alpha\}
\end{equation}
Using the VaR, we can derive the CVaR for a given $\alpha \in (0, 1)$, which represents the expected value of the top $1 - \alpha$ quantile of the probability distribution over $X$. More formally,
\begin{equation}\label{eq:CVaR}
    \text{CVaR}_\alpha(X) = \mathbb{E}[X \mid X \geq \text{VaR}_\alpha(X)]
\end{equation}
If $X$ is random variable that represents cost, $\text{CVaR}_\alpha(X)$ will correspond to the expected value of the worst $\alpha$-fraction of costs. As $\alpha$ approaches \num{1}, $\text{CVaR}_\alpha(X)$ approaches the cost of the worst-case outcome. As $\alpha$ approaches \num{0}, $\text{CVaR}_\alpha(X)$ approaches the expected value of $X$. CVaR has some desirable mathematical properties~\cite{majumdar2020should} that have often made it the preferred risk metric in risk-sensitive domains such as finance \cite{pflug2000some, chow2015risk, keramati2020being} and robotics~\cite{majumdar2020should}.

\textbf{Markov Decision Process (MDP)} \ \ An MDP is a way of encoding a sequential decision making problem in which an agent's action at each time step depends only on its current state \cite{DMU}. An MDP is defined by the tuple $(S, A, T, C, \gamma)$, where $S$ is the state space, $A$ is the action space, $T(s' \mid s, a)$ is the probability of transitioning to state $s'$ given that we are in state $s$ and take action $a$, $C(s,a)$ is the cost of taking action $a$ in state $s$, and $\gamma$ is the discount factor. A stochastic policy for an MDP, written as $\pi(a \mid s)$, denotes the likelihood of taking action $a$ in state $s$ and induces a distribution over future costs. We define the cost distribution function $Z^\pi(s,a)$ to represent the distribution of the sum of discounted future costs obtained by taking action $a$ from state $s$ and subsequently following policy $\pi$ as follows
\begin{equation}
    Z^\pi(s_t,a_t) = C(s_t, a_t) + \sum_{t^\prime = t+1}^\infty \gamma^{t^\prime} C(s_{t^\prime}, a_{t^\prime})
\end{equation}
where $s_{t^\prime+1} \sim T(\cdot \mid s_{t^\prime}, a_{t^\prime})$ and $a_{t^\prime} \sim \pi(\cdot \mid s_{t^\prime})$. To evaluate a given policy $\pi$, we calculate a state-action value function, denoted $Q^\pi(s, a)$, as the expected sum of discounted future costs
\begin{equation} \label{eq:expected_return}
    Q^\pi(s,a) = \mathbb{E}\left[ Z^\pi(s,a) \right]
\end{equation}
In traditional reinforcement learning, $Q^\pi$ is the optimization objective~\cite{DMU}; however, in safety-critical domains we may wish evaluate a policy based on an upper quantile of the worst-case outcomes.
In this case, rather than calculating the expectation of future costs, we define a new state-action value function $Q^\pi_\alpha(s, a)$ that represents the CVaR of the distribution of future costs as
\begin{equation}\label{eq:cvar_return}
Q^\pi_\alpha(s, a) = \text{CVaR}_\alpha[Z^\pi(s, a)]
\end{equation}
Intuitively, $Q^\pi_\alpha(s, a)$ is the expected value of the $\alpha$-percentile of worst-case outcomes. We note that when $\alpha=0$, \cref{eq:cvar_return} reduces to \cref{eq:expected_return}. One way to solve for $Q^\pi_\alpha(s, a)$ is to first solve for the cost distribution function $Z^\pi(s,a)$, which can be done using techniques from distributional reinforcement learning \cite{bdr2022}. The CVaR can then be computed using this distribution. Other techniques that do not require explicitly solving for the distribution over costs may also be applied~\cite{chow2015risk, haskell2015convex}.

\section{Approach}
\begin{figure}[t]
    \centering
    \begin{subfigure}{0.45\textwidth}
        \input{system}
        \caption{System Architecture \label{fig:system}}
    \end{subfigure}
    \begin{subfigure}{0.45\textwidth}
        \input{adversarial}
        \caption{Abstracted Perception MDP \label{fig:adversarial}}
    \end{subfigure}
    \caption{Problem formulation. \label{fig:formulation}}
\end{figure}
We consider the setting shown in \cref{fig:system}, in which a system is composed of a perception module $f$ and a controller $g$. Given an observation $o \in \mathcal O$ of the true state $s \in \mathcal S$, the perception system produces an estimate of the state $\hat s = f(o)$. The controller produces a control input $u = g(\hat s)$ and the system transitions to state $s'$ with probability $T(s' \mid s, u)$. We assume that the controller $g$ is given, and we wish to design a perception module $f$ such that the overall system satisfies a safety property. 

\textbf{Pendulum example} \ \ We will use a vision-based inverted pendulum problem as a running example to describe our approach (see \Cref{fig:pendulum_overview}). We assume that a camera produces noisy image observations of the pendulum's current state $s = [\theta, \omega]$ where $\theta$ is its angle from the vertical and $\omega$ is its angular velocity. To estimate both position and velocity information from the images, we use two consecutive image frames for each observation. The perception system is a multi-layer perceptron (MLP) that takes in the image observations and produces an estimate of the state. Using the state estimate, the controller selects a torque to keep the pendulum upright. We specify a safety property that requires that $|\theta| < \pi/4$ at all time steps. We use a rule-based controller that satisfies the safety property under perfect perception; however, image noise, image downsampling, and the finite capacity of the MLP make perception errors inevitable, and the goal is to design a perception system that limits the occurrence of high risk errors. \Cref{app:pend_controller} summarizes the inverted pendulum model.

\begin{figure}[t]
    \centering
    \input{pendulum_overview}
    \caption{Overview of the inverted pendulum example system. \label{fig:pendulum_overview}}
\end{figure}

\subsection{Overview} 

The key insight in our approach is to abstract the perception system using a notional model of perception errors and analyze the effect of specific perception errors on the performance of the closed-loop system. As shown in 
\cref{fig:adversarial}, we model the errors $\epsilon \in \mathcal E$ of the abstracted perception system as a stochastic policy $\pi_e(\epsilon \mid s)$ in an MDP. The cost function of the MDP is chosen to reflect the risk of a being in a state with respect to a safety property. By formulating the problem in this way, we can use the policy evaluation techniques outlined in \cref{sec:background} to evaluate the risk of making perception error $\epsilon$ in state $s$.
Given that $\pi_e$ is an abstraction of the perception system, it will not exactly reflect the true distribution of perception errors. To account for this mismatch, we are conservative in our risk estimate by evaluating the policy according to \cref{eq:cvar_return}. Once computed, the risk function represents the downstream impact of making a given perception error in the current state. This function can therefore be used in a supervised learning setting to encourage a model to avoid making high-risk errors. We also show that the risk function can be used to identify error-sensitive regions of the state space, from which additional training data can be collected.





\subsection{Risk Function} \label{sec:risk_func}
Our goal is to define a risk function $\rho(s, \epsilon)$ that quantifies the risk of making perception error $\epsilon$ in state $s$ when using a controller $g$. We model the perception error as a stochastic policy $\pi_e(\epsilon \mid s)$ that reflects a notional distribution over errors in state $s$. The controller produces an action based on the perceived state $\hat s$, which is computed from $s$ and $\epsilon$. For additive noise, the resulting transition function for the abstracted perception MDP is
\begin{equation}
    T_\pi(s' \mid s, \epsilon) = T(s^\prime \mid s, g(s + \epsilon))
\end{equation}


The error model $\pi_e$ can be designed to match the performance of a previously trained baseline perception system or using domain knowledge. If we are confident that our choice closely matches the errors we will see when designing the perception system, we can set our risk function to match the state action-value function in \cref{eq:expected_return}. However, if we have not yet designed the perception system, there will be a mismatch between our estimate of $\pi_e$ and the true distribution of perception errors.

In these scenarios, we may want a more conservative risk function in which we consider the CVaR of the distribution over future costs when making perception error $\epsilon$ in state $s$ given that all future perception errors are distributed according to $\pi_e$. Therefore, we select our risk function as follows
\begin{equation}
    \rho^{\pi_e}_\alpha(s, \epsilon) = Q^{\pi_e}_\alpha(s, \epsilon)
\end{equation}
where $Q^{\pi_e}_\alpha(s, \epsilon)$ refers to the CVaR state-action value function defined in \cref{eq:cvar_return} for the abstracted perception MDP. The parameter $\alpha$ smoothly controls the degree of conservatism. When $\alpha = 0$, the risk function is equivalent to the expected cost when following the notional perception model. When $\alpha=1$, we consider only the worst-case sequence of possible perception errors.

To solve for the CVaR state-action value function we apply distributional dynamic programming to compute the distribution over costs. 
Distributional dynamic programming (alg. 5.3 in \citet{bdr2022}) resembles value iteration where the Bellman operator is replaced with a distributional version to update a parameterized distribution. In this work, we approximate the distribution over costs using a categorical distribution with a fixed number of discrete costs. Additionally, we discretize the states and actions and use a linear weighting function for local approximation. To extend our method to problems with larger state and action spaces, we could apply function approximation techniques developed in prior work~ \cite{bellemare2017distributional, dabney2018distributional, dabney2018implicit}, but we leave this as future work. Once we solve for the cost distributions, we can calculate $\rho^{\pi_e}_\alpha(s, \epsilon)$ for any value of $\alpha$ using \cref{eq:CVaR} with minimal additional computation.


\textbf{Pendulum example} \ \ For the inverted pendulum system, we model the perception errors $\epsilon = [\epsilon_\theta, \epsilon_\omega]$ as additive noise on the true state ($\hat{s} = s + \epsilon$) distributed according to a multivariate Gaussian distribution with zero mean and diagonal covariance. The cost function penalizes the absolute deviation from the vertical $|\theta|$. See \cref{app:pend_risk_func} for more detail.
\Cref{fig:pend_cvar_slices} shows the values of the pendulum risk function at the state $s = [0.2, 0.0]$ over the set of errors for multiple values of $\alpha$. A higher value of $\alpha$ will put more weight on worst-case perception errors in the future, so as $\alpha$ increases, the overall risk values increase. The risk function also provides a notion of \textit{which} perception errors are most risky in a given state. For example, the optimal action when $s = [0.2, 0.0]$ is to apply a negative torque to move the pendulum closer to upright, but if perception errors are negative, the resulting $\hat s$ may indicate that the pendulum is at a smaller angle and already moving in the negative direction as shown in the leftmost image on \cref{fig:pend_cvar_slices}. This estimate may cause the controller to produce a smaller torque or even a torque in the positive direction, leading to high risk of falling over.



\begin{figure}[t]
    \centering
    \input{pend_cvar_slices_alpha}
    \caption{Values of $\rho^{\pi_e}_\alpha([0.2, 0.0], \epsilon)$ for different values of $\alpha$. The state and an example error are depicted on the left. \label{fig:pend_cvar_slices}}
\end{figure}





\subsection{Risk-Sensitive Loss Function}\label{sec:risk_loss}
Perceptual errors are inevitable whenever there is sensor noise, occlusions, limited training data, or limited model capacity. Our goal is to ensure that the errors that are made by the perception system are in the direction of lower, rather than higher, risk.
We incorporate this notion into our design by formulating a risk-sensitive loss function. Let $\mathcal L(s, \hat s)$ be the standard loss function for the baseline perception system such as mean squared error for regression tasks or cross entropy for classification tasks. We define a risk-sensitive loss function for a single datapoint with additive noise as follows
\begin{equation}\label{eq:risk_loss}
    \mathcal L_R(s, \hat s) = \mathcal L(s, \hat s) + \lambda \rho^{\pi_e}_\alpha (s, \hat s - s)
\end{equation}
where $\lambda$ is a hyperparameter that controls the relative weighting of each term. The first term in the loss function pushes all perception errors toward zero, while the second term seeks to minimize the risk of the current errors that the model makes. We note that this is different from simply minimizing perception errors in states with high risk values. If the risk function outputs the same value for a given state regardless of perception error, the gradient of the risk term in the loss function will be zero.

\textbf{Pendulum example} \ \ For the inverted pendulum problem, we use a mean squared error baseline loss function, which penalizes positive and negative errors equally. However, a positive and negative error of the same magnitude do not necessarily have an equal effect on the overall risk of the closed-loop system. For example, consider the results shown in \cref{fig:pend_cvar_slices} where the pendulum is positioned at an angle of \num{0.2} from the vertical. The risk function shows that a perception error of $\epsilon_\theta = 0.2$ ($\hat\theta = 0.4$) is less risky than a perception error of $\epsilon_\theta = -0.2$ ($\hat\theta = 0.0$). Intuitively, predicting that the pendulum is tipped further in the positive direction will still result in a negative torque to move the pendulum closer to upright. In contrast, predicting that the pendulum is perfectly upright will cause the controller to output zero torque. The second term in \cref{eq:risk_loss} accounts for this effect.

\subsection{Risk-Driven Data Generation}\label{sec:risk_data}
In addition to considering the directionality of the errors, we can use the risk function we formulated in \cref{sec:risk_func} to identify states that are especially sensitive to perception errors and generate more training data in those regions. In effect, this process gives higher weight to risky states during training. Since training with a regression loss will push all errors toward zero, we define risky states as states in which making a nonzero perception error will result in a high risk value compared to the risk of zero error. We use a weighting function $w_\alpha(s)$ to capture this notion as follows
\begin{equation}\label{eq:risk_weight}
    w_\alpha(s) = \max_{\epsilon \in \mathcal E} \rho^{\pi_e}_\alpha(s, \epsilon) - \rho^{\pi_e}_\alpha(s, 0)
\end{equation}
We note that $w_\alpha(s)$ is not the same as (and not necessarily correlated with) the risk of being in state $s$. Instead, $w_\alpha(s)$ represents the risk of making a nonzero perception error in state $s$. For instance, states in which failure is inevitable regardless of perception error will have high risk values but low weight assigned to them according to $w_\alpha(s)$. To sample data, we use rejection sampling with $w_\alpha(s)$ as the likelihood function.

\textbf{Pendulum example} \ \ \Cref{fig:pend_risk_weights} illustrates each term in \cref{eq:risk_weight} for the inverted pendulum example problem. The lower left and upper right regions of the state space represent states in which the pendulum is at a high angle and moving in a direction away from the vertical. Due to underactuation of the pendulum system, the states at these extremes are guaranteed to lead to failure regardless of perception error. States in the central band of each plot, on the other hand, constitute states in which the pendulum is likely to remain upright as long as proper control is applied. This band widens when we consider the effect of having zero perception error compared to the worst-case perception error. By subtracting these quantities, we can understand in which states having zero perception error is most critical. Given a limited data budget, we can focus our data collection on these states by sampling data according to $w_\alpha(s)$.

\begin{figure}[t]
    \centering
    \input{pend_rw}
    \caption{Illustration of \cref{eq:risk_weight}. \label{fig:pend_risk_weights}}
\end{figure}

\subsection{Hypotheses}
We design the experiments in this work to test the following two hypotheses:
\begin{itemize}
    \item \textbf{H1}: A perception module trained using the risk-sensitive loss function proposed in \cref{sec:risk_loss} will result in a safer closed-loop system than one trained using the baseline loss on the same dataset.
    \item \textbf{H2}: A perception system trained on data sampled according to the risk-driven data generation technique proposed in \cref{sec:risk_data} will result in a safer closed-loop system than one trained on data uniformly sampled throughout the state space.
    
\end{itemize}

\textbf{Pendulum example} \ \ We evaluate the inverted pendulum  by measuring the mean time to failure over \num{100} trajectories each with \num{500} time steps from random initial states. We report the mean and standard error of this metric over \num{5} trials with \num{500} being the maximum attainable value. To test \textbf{H1}, we train a baseline perception system using a mean squared error loss function and a risk-driven perception system using the loss function described in \cref{sec:risk_loss} on \num{10000} uniformly sampled data points. To make the perception problem more challenging, we add noise to the images. The risk sensitive loss function improved the mean time to failure from the baseline of $234 \pm 62$ to $492 \pm 6$. To test \textbf{H2} on the inverted pendulum system, we limit the perception system to a data budget of \num{50} training examples. We train a baseline perception system on data sampled uniformly throughout the state space and a risk-driven perception system on data sampled according to the weighting function shown in \cref{fig:pend_risk_weights}. The mean time to failure for the baseline system is $152 \pm 89$, while the time to failure for the system trained of the risk-driven data was \num{500} for all trials. See \cref{app:pend_results} for full results.


\section{Vision-Based Detect and Avoid Application}
Aircraft collision avoidance systems use information gathered from sensors to detect intruding aircraft and issue advisories for safe collision avoidance maneuvers \cite{kochenderfer2012next}. Traditional sensors used for surveillance and tracking include ADS-B, onboard radar, and transponders \cite{owen2019acas}; however, autonomous aircraft require additional sensors both for redundancy and to replace the visual acquisition typically performed by the pilot. For this reason, vision-based traffic detection systems have been proposed, in which intruding aircraft are detected from images taken by a camera sensor mounted on the aircraft \cite{opromolla2021visual, james2018learning}. In this section, we will apply our risk-driven design techniques to improve the safety of a vision-based detect and avoid (DAA) system. The code for this work can be found at \href{https://github.com/sisl/RiskDrivenPerception}{https://github.com/sisl/RiskDrivenPerception}.

\begin{figure}[htb]
    \centering
    \input{daa_overview}
    \caption{Overview of the vision-based detect and avoid system application. \label{fig:daa_overview}}
\end{figure}

\subsection{Problem Setup}
\Cref{fig:daa_overview} outlines the components of a vision-based DAA system. A camera mounted on the aircraft (which we refer to as the ownship) produces image observations of its surroundings. These images are then passed through a perception system to produce an estimate of the state for the controller. The collision avoidance controller $g$, which is loosely based on the ACAS X family of collision avoidance systems \cite{kochenderfer2012next}, commands vertical maneuvers based on an estimate of the relative position and velocity of an intruder aircraft. Specifically, the state is defined as $s = [p, h, \dot h, a_\text{prev}, \tau]$ where $p$ is a binary variable describing whether an intruder is present, $h$ is the relative altitude of the intruder, $\dot h$ is the relative vertical rate of the intruder, $a_\text{prev}$ is the previous action, and $\tau$ is the time to loss of horizontal separation. The controller selects an action $u \in \{\textsc{coc}, \textsc{climb}, \textsc{descend}\}$ where \textsc{coc} represents clear of conflict. If $p=0$, the action is always \textsc{coc}.

We assume that the state estimate for the controller is produced using two steps. First, the image is passed through a perception network that is responsible for detecting other aircraft (which we refer to as intruders) and producing a bounding box. Once an intruder has been detected, the ownship interrogates it to determine the rest of the state. We focus our risk-driven design efforts on the detection component of the perception system. We train a baseline network using the YOLOv5 algorithm \cite{Redmon_2016_CVPR, glenn_jocher_2022_6222936} on \num{10000} images in which the intruder location is sampled uniformly within the ownship field of view. For additional details on the controller, network architecture, computational resources, and training, see \cref{app:daa}.


\subsection{Risk-Driven Design}
An object detector can make two types of errors: false positives and false negatives. While false positives have an effect on the efficiency of the system, they do not affect the risk of a collision. We therefore focus on quantifying the risk of of false negatives in the presence of an intruder. We define the perception error $\epsilon$ as zero when an intruder is properly detected and one when it is missed, leading to a perceived state
\begin{equation}
\hat{s} = [1 - \epsilon, h, \dot h, a_\text{prev}, \tau]
\end{equation}
The notional error model $\pi_e(\epsilon \mid s)$ is a Bernoulli distribution with a success probability based on the detection performance of the baseline model (see \cref{app:daa} for more detail). To solve for $Q^{\pi_e}_\alpha(s, \epsilon)$, we discretize the state space and apply approximate dynamic programming. 



\textbf{Risk-sensitive loss function} \ \ In addition to outputting the bounding box coordinates, the detection network outputs an objectness score $\hat p$ representing the model's confidence that an aircraft is present in the frame.
The model detects an aircraft after checking if $\hat p$ exceeds a threshold;
however, this check poses a numerical challenge when differentiating 
\begin{wrapfigure}[]{r}{0.4\textwidth}
    \centering
   
    \input{daa_rw}
    \caption{DAA weighting function. \label{fig:daa_rw}}
   
\end{wrapfigure}
the risk sensitive loss since the gradient is undefined at the decision threshold and is zero everywhere else. 
To avoid this problem we evaluate the risk of $\hat p$ directly by interpolating between the risk of not detecting and detecting the intruder
\begin{equation}\label{eq:daa_risk_func}
    \rho_\alpha^{\pi_e}(s, \hat p) = (\hat p) Q_\alpha^{\pi_e}(s, 0) + (1 - \hat p) Q_\alpha^{\pi_e}(s, 1)
\end{equation}
The gradient of risk function in \cref{eq:daa_risk_func} with respect to $\epsilon$ is equal to the risk weight, so the model will be incentivized to be more confident in states where a detection has a significant effect on overall risk.

\textbf{Risk-driven data generation} \ \ \Cref{fig:daa_rw} shows the weighting function when $\alpha=0$ and an intruder is present. States with high weights correspond to states where not detecting the intruder is significantly more risky than detecting the intruder. While a collision is imminent in states with low values of $\tau$ and $|h|$, these states have low weights since a collision will occur regardless of whether the intruder is detected. The states with the highest risk weights are states in which there is just enough time to resolve an impending collision as long as the intruder is detected.




\subsection{Evaluation}
The safety of aircraft collision avoidance systems is often assessed using Monte Carlo analysis on airspace encounter models \cite{TCASMonteCarlo,ACASXMonteCarlo}. Encounter models are probabilistic representations of typical aircraft behavior during a close encounter with another aircraft. To analyze the safety of a particular collision avoidance system, we can simulate the system on a set of encounters and count the number of times a near mid-air collision (NMAC) occurs. We define an NMAC as a simultaneous loss of aircraft separation to within \SI{50}{\meter} vertically and \SI{100}{\meter} horizontally. For the evaluation in this work, we use model consisting of \num{1000} pairwise encounters in which the ownship and intruder follow straight line trajectories with various relative geometries. All encounters result in an NMAC if no collision avoidance actions are taken (see \cref{app:enc_model}).

\begin{figure}[t]
    \centering
    \input{daa_results_v2}
    \caption{Number of NMACs and cumulative risk for each perception system. \label{fig:daa_results}}
\end{figure}

We trained perception networks using four perception design techniques: no risk awareness (baseline), risk-sensitive loss function, risk-driven data generation, and both a risk-sensitive loss function and risk-driven data generation. We performed three trials for each perception design method. The first section of \cref{fig:daa_results} shows the number of encounters that result in an NMAC for each technique. In support of \textbf{H1}, training with the risk-sensitive loss function (blue) results in a slight increase in safety. In support of \textbf{H2}, training on data generated using the weighting function (red) results in a \SI{33}{\percent} decrease in the number of NMACs over the baseline.  With a \SI{37}{\percent} decrease in the number of NMACs compared to the baseline, the perception systems that were developed using both risk-driven techniques (purple) are slightly safer than using either technique individually.
\Cref{fig:daa_results} also shows the cumulative distribution over the risks of the errors made by each perception system on the encounter set. This result implies that even small shifts in overall risk can have significant impacts on safety.

\Cref{fig:daa_ex} shows an example encounter that resulted in NMAC for the baseline system but was resolved by the risk-sensitive systems. The risk-sensitive system (purple) detects the intruder aircraft sooner and more often than the baseline. Moreover, the plot at the bottom of the figure shows that the risks of the perceptual errors made by the baseline system are much higher than the risks of the errors made by the risk-sensitive system.

\begin{figure}[t]
    \centering
    \input{daa_example}
    \caption{Example encounter that was resolved by the risk-sensitive systems but resulted in an NMAC for the baseline system. The red line denotes the intruder trajectory, while the gray and purple lines denote the ownship trajectory when using the baseline and risk-sensitive perception systems respectively. Left: overhead view of the encounter. Bottom right: altitude of each aircraft over time along with the risk of each perception error. The dotted markings indicate time steps in which the intruder was detected. Top right: perception outputs of each system at four snapshots in time. \label{fig:daa_ex}}
\end{figure}

\section{Related Work}
We discuss prior work in perception system evaluation, risk-aware control, and task-aware prediction.

\textbf{Perception system evaluation} \ \ The high-dimensional, complex nature of perception inputs makes closed-loop safety evaluation of perception systems especially challenging. For this reason, a number of recent works have focused on finding adversarial perturbations that will cause misclassification of single input images \cite{machado2021adversarial}. 
\citet{Julian2020}, in contrast, use adaptive stress testing (AST) \cite{Corso2021survey} to find sequences of adversarial perturbations that will lead a vision-based aircraft taxi system to failure rather than focusing on single images in isolation. However, this approach is only able to find failures and cannot guarantee safety if no failures are found. \citet{Katz2021dasc} provide approximate formal guarantees of closed-loop safety properties by using a generative model to approximate the set of plausible inputs to a perception system. \citet{dreossi2019compositional} address the complexity of analyzing the closed-loop system by analyzing the controller and perception system separately before combining the results to find failures in the overall system. This work draws inspiration from this decoupled approach.

\textbf{Risk-aware control} \ \ In safety-critical domains, it is desirable to design controllers that perform well even in worst-case conditions. This problem has been addressed through safety-constrained MDPs \cite{wachi2018safe} and shielding techniques in reinforcement learning \cite{alshiekh2018safe}.
Other risk-aware control approaches use a notion of CVaR to design controllers. CVaR MDPs, for instance, have been used to produce control policies that are robust to modeling errors and worst-case outcomes \cite{chow2015risk, haskell2015convex}. Distributional reinforcement learning approaches estimate the distribution of returns~\cite{bellemare2017distributional}.  Using the estimate of the return distribution, it is possible to compute risk-related metrics such as CVaR and produce risk-aware reinforcement learning policies \cite{chow2014algorithms, dabney2018distributional, dabney2018implicit, keramati2020being}. In this work, rather than using a notion of risk to design control policies, we use it to design safe perception systems.

\textbf{Task-aware prediction} \ \ Recent work has explored the benefit of using task-aware metrics to inform the design of predictive models. 
For example, \citet{lambert2020objective} note that more accurate dynamics models in reinforcement learning do not necessarily correlate with higher rewards, and \citet{bansal2017goal} show improved performance when learning a dynamics model that achieves the best control rather than learning the most accurate model. Multiple techniques have been proposed to augment traditional training loss functions with task-specific metrics to design models that are not only accurate but also satisfy domain constraints \cite{innes2020elaborating, pmlr-v97-fischer19a, leung2020back}.
In the context of trajectory prediction, \citet{mcallister2022control} propose control-aware prediction objectives, which take into account the downstream effects of the predictions on controller performance. These works motivate the need for task-aware objectives but are not used with image-based perception.  In the context of perception, \citet{philion2020learning} develop planner-centric metrics for an object detection system and show their benefit over traditional metrics used to evaluate object detectors. However, they focus only on the evaluation of perception systems, while this work focuses on their design.

\section{Conclusion}
\label{sec:conclusion}
In this work, we presented a methodology for risk-driven design of safety-critical perception systems. We formulated a risk function that measures the effect of perception errors on the closed-loop performance of the fully-integrated perception and control system. We then showed how to use that risk function during the design process by incorporating it into the loss function and developing a risk-driven data generation technique. We demonstrated our approach on a realistic vision-based aircraft detect and avoid system and showed that our techniques could increase safety by \SI{37}{\percent} over a baseline system. We note that while the methods presented here focus on designing safe perception systems, they do not represent safety guarantees. Therefore, perception systems designed in this manner should still be put through additional testing and safety validation before deployment. A limitation of this work is that we assume that the perception system is Markov, which limits the applicability of our technique to perception systems that use filtering to produce state estimates. Future work will address this limitation.


\begin{ack}
The NASA University Leadership Initiative (grant \#80NSSC20M0163) provided funds to assist the authors with their research. This research was also supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE–1656518. Any opinion, findings, and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of any NASA entity or the National Science Foundation. This work was also supported by a grant from the UKRI Strategic Priorities Fund to the UKRI Research Node on Trustworthy Autonomous Systems Governance and Regulation (EP/V026607/1, 2020-2024).
\end{ack}













\typeout{}
\printbibliography




























