{'fraction_non_alphanumeric': 0.036739624786810685, 'fraction_numerical': 0.015539132082622703, 'mean_word_length': 4.557793575566087, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Safe Option-Critic: Learning Safety in the Option-Critic Architecture

Designing hierarchical reinforcement learning algorithms that exhibit safe behaviour is not only vital for practical applications but also, facilitates a better understanding of an agent's decisions. We tackle this problem in the options framework, a particular way to specify temporally abstract actions which allow an agent to use sub-policies with start and end conditions. We consider a behaviour as safe that avoids regions of state-space with high uncertainty in the outcomes of actions. We propose an optimization objective that learns safe options by encouraging the agent to visit states with higher behavioural consistency. The proposed objective results in a trade-off between maximizing the standard expected return and minimizing the effect of model uncertainty in the return. We propose a policy gradient algorithm to optimize the constrained objective function. We examine the quantitative and qualitative behaviour of the proposed approach in a tabular grid-world, continuous-state puddle-world, and three games from the Arcade Learning Environment: Ms.Pacman, Amidar, and Q*Bert. Our approach achieves a reduction in the variance of return, boosts performance in environments with intrinsic variability in the reward structure, and compares favorably both with primitive actions as well as with risk-neutral options.


INTRODUCTION
Safety in Artificial Intelligence (AI) has become an important focus of research as AI methods make rapid advancements (Amodei et al., 2016). The 23 Asilomar AI principles (Future of Life Institute, 2017) discuss a variety of safety aspects such as risk-aversion, transparency, robustness, fairness, and also legal and ethical values that an agent must hold. In this work, we mainly focus on safety from the perspective of preventing undesirable behaviour, in particular, reducing visits to undesirable or risky states during the learning process of a reinforcement learning (RL) system. RL algorithms optimize the expected value of cumulative rewards (return) obtained over time (Sutton and Barto, 1998). For safety-critical applications such as finance, medicine, or industrial automation, optimizing the expected return alone is often not sufficient. An agent might exhibit undesirable behaviour over certain trajectories or for a certain period. In general, safety requires measuring some notion of risk or uncertainty in addition to maximizing the mean return thus ensuring that the learning algorithm also minimizes risk.
An additional challenge in RL is that agents need to explore during which an agent might be unaware of the states prone to noise or potentially leading to catastrophic consequences. Risk-awareness in RL has been formulated in several ways, for example by directed exploration that avoids the high entropy states (Law et al., 2005), optimizing the worst-case performance instead of the expected performance of an agent (Tamar et al., 2013), measuring and bounding the probabilities of visiting the erroneous states (Geibel and Wysotzki, 2005) and several other approaches. Garcıa and Fernández (2015) present a comprehensive survey covering a broad range of techniques aimed at achieving safety in RL. In the context of Markov Decision Processes (MDPs), the source of uncertainty or variability in a sequential decision making task can arise mainly from two sources -inherent stochastic uncertainty in the reward and the transition model (aleatoric uncertainty), and imperfect knowledge regarding the model (epistemic uncertainty). The former uncertainty is usually To appear at The Knowledge Engineering Review (KER), 2021. A previous draft appeared in Adaptive Learning Agents (ALA) 2018 workshop held at ICML, AAMAS in Stockholm. clustered under risk-sensitive MDPs (Howard and Matheson, 1972;White, 1994;Heger, 1994;Borkar and Meyn, 2002), whereas the latter is covered under robust MDPs (Nilim and El Ghaoui, 2005;Iyengar, 2005;Lim et al., 2013). In this work, we focus on risk-sensitive MDPs and address the former source of variability via mean-variance optimization.
The natural question that follows is how can we measure variance in RL? Several works focus on estimating the variance in return using temporal difference (TD) style learning methods (Tamar et al., 2012(Tamar et al., , 2016Gehring and Precup, 2013;Sherstan et al., 2018;Jain et al., 2021). Our work is based on the specific approach proposed by Gehring and Precup (2013), which suggests using the absolute value of the TD error to define controllability of a state. Intuitively, for an agent to exhibit safe behaviour, it will prefer taking the actions whose effects are more predictable on a state. Such states are referred as controllable. We re-define controllability slightly to provide an estimator which calculates the uncertainty in the value function, and then show how to "encourage" an agent to focus on controllable states.
All approaches discussed so far define safety in the primitive action space (one step action). Inspired by how humans think and plan, temporally abstract actions also provide a path to learn and plan efficiently. Temporal abstractions have been a crucial part of AI research since the 1970s (Fikes et al., 1972(Fikes et al., , 1981Iba, 1989;Korf, 1983;Parr and Russell, 1998;Sutton et al., 1999;Precup, 2000;Dietterich, 2000;McGovern and Barto, 2001;Menache et al., 2002;Barto and Mahadevan, 2003;Konidaris and Barto, 2007;Bacon et al., 2017;Barreto et al., 2019). Prior research has shown that the temporal abstractions can improve exploration, reduce the complexity of deliberation and enhance robustness. More importantly, from the safety perspective, temporal abstractions lead to composition of behaviour and predictions. To simplify, if every subpart of the abstraction hierarchy can be derived respecting the safety conditions, the entire hierarchy would automatically be safe in behaviour. In this paper, we take the first step in this direction by showing how to construct temporally safe extended actions by reducing the variability or uncertainty as discussed above.
We approach this problem in the options framework (Sutton et al., 1999;Precup, 2000), which provides an intuitive way to plan, reason, and act at multiple timescales. We are especially interested in learning options end-to-end from the data obtained by the agent's interaction with the environment. The options framework has received a lot of attention over time, for example, Stolle and Precup (2002); Daniel et al. (2016); Konidaris and Barto (2007); Konidaris et al. (2011);Kulkarni et al. (2016); Vezhnevets et al. (2016); Mankowitz et al. (2016); Jain and Precup (2018); Riemer et al. (2018); Barreto et al. (2019). Bacon et al. (2017) introduced the option-critic framework by adapting to the actor-critic model. The option-critic model facilitates an end-to-end learning of options without the need to specify sub-goals. We modify the option-critic objective to include the negation of controllability (Gehring and Precup, 2013) (estimates the variability in the performance) as a regularizer in the optimization objective. Consequently, the key contributions of this work can be summarised as follows: 1. We propose a new objective function which uses the effect of the uncertainty in the return as a regularizer for the classical optimization problem of maximizing the expected return. We then use this objective to derive a policy gradient algorithm for automatically learning safe options.
2. We empirically demonstrate the effectiveness of our approach in the tabular setup.
3. We also show that our method is scalable to both linear and non-linear function approximation settings using the puddle-world and ALE games: Ms.Pacman, Amidar, and Q*Bert.
The paper is structured as follows. After presenting definitions and notations in Sec. 2, we introduce the safe option-critic algorithm in Sec. 3. Next, we present tabular, continuous and ALE experiments in Sec. 4. Finally, we conclude with discussion and future work in Sec. 5.

PRELIMINARIES
In RL, an agent interacts with the environment at discrete time steps t ∈ {1, 2, ...}. At each step, the agent observes a state s ∈ S and chooses an action a ∈ A according to a policy which defines a probability distribution of actions over the state space π : S × A → [0, 1]. Afterwards, the agent transitions from S t to S t+1 state according to the transition probability distribution P : S × A × S → [0, 1]. After transitioning to a next state, an agent receives a reward R t+1 ∈ R, where the expected reward function is r(s, a) = r∈R r s P (s , r|s, a), and r : S × A → R. The Markov Decision Process (MDP) is defined as a tuple of (S, A, r, P, γ), where γ ∈ [0, 1] is the discount factor, which de-values rewards received farther into the future. A Markov Decision Process with a defined optimality criteria is known as a Markov Decision Problem. In this work, we focus on MDP with an optimality criteria as the expected total discounted reward. According to this optimality criteria, we define the state-action value function as Q(s, a) = E π [ ∞ t=0 γ t R t+1 |S t = s, A t = a]. An estimate of Q can be learned in an incremental fashion using temporal-difference (TD) learning methods (Sutton, 1988). For example, in T D(0), the agent computes a temporal difference error, which captures the difference in the agent's value estimate at two consecutive time steps: The state-action value function is then updated as: where α ∈ [0, 1] is the step size.
The policy gradient theorem (Sutton et al., 2000) provides a way to update a parameterized policy in the direction of the gradient of the expected return. Here, return is the total discounted rewards received in a trajectory. The performance of a policy π is measured by the expected return as where, the initial state is denoted by s 0 . The gradient of the performance with respect to the policy parameter θ is given by: where, d π (s|s 0 ) = ∞ t=0 γ t P (S t = s|s 0 , π) is the discounted weighting of the states.

OPTIONS
The options framework (Sutton et al., 1999;Precup, 2000) facilitates the incorporation of temporally abstract knowledge into RL. An option w ∈ W, is defined as a tuple of (I w , π w , β w ). I w is an initiation set containing initial states from which an option w can start. π w denotes an option policy that defines a distribution over actions given a state during the execution of option w. The termination condition of w option, β w , defines a probability of termination in each state. If the option policies are Markovian, the intra-option Bellman equation (Sutton et al., 1999) provides an off-policy method for updating the value of a state-option pair as where, the same option w continues with 1 − β w probability, or, terminates with β w probability and selects the next best option.

OPTION-CRITIC ARCHITECTURE
The above described intra-option value learning (Sutton et al., 1999) also lays the foundation for how the options are learnt in the Option-Critic architecture (Bacon et al., 2017). The option-critic method is a policy gradient based method for learning intra-options policies and option's termination conditions. Bacon et al. (2017) considers the call-and-return option execution model, where an option w is chosen according to a policy over options π W , and an intra-option policy π w is followed until the termination condition β w is met. Once the current option terminates, another option is selected using π W and the process continues. Let π w,θ denotes intra-option policy parameterized by θ, and β w,ν represents the option termination parameterized by ν. The value of executing an action a at a particular state-option pair is given by Q U : S × W × A → R which is defined as Q U (s, w, a) = r(s, a) + γ s P (s |s, a)U (s , w), where, U (s , w) represents the value of arriving through an option w at a state s . Here, either the option w could terminate with β w,ν probability and select the other options, or could continue with the same option with (1 − β w,ν ) probability, Here, Q W represents the value function over options, which is given by- V W represents the value function of executing policy over options π W , given by- . Bacon et al. (2017) derived the gradient of the discounted return from an initial condition (s 0 , w 0 ) ∈ (S × W) with respect to θ (intra-option policy parameter) as: where, µ(s, w|s 0 , w 0 ) = ∞ t=0 γ t P (S t = s, W t = w|s 0 , w 0 ) is the discounted weighting of a state-option pair. The gradient of the expected discounted return with respect to the option termination parameter ν and the initial condition (s 1 , w 0 ) is given by: where, A W is the advantage function A W (s, w) = Q W (s, w)−V W (s). In (5), the initial condition changed from (s 0 , w 0 ) to (s 1 , w 0 ) because given an initial state-option (s 0 , w 0 ), the first action is selected according to π w0 policy, and then the agent transitions to the next state s 1 . The updates to the termination parameter ν are made thereafter based on the advantage of switching to the next option in state s .

SAFE OPTION-CRITIC MODEL
In this work, we introduce a notion of learning safe hierarchical policies using a penalty based on the variance in TD error. Previous works in the literature had focused on the measures derived from the TDbased methods for quantifying uncertainty in the value of a state or a state-action pair. As mentioned earlier, here, we focus on addressing uncertainty arising due to inherent stochasticity present in the model (aleatoric uncertainty). The uncertainty present in the model is reflected in the form of variability in the value function. One such feasible approach to capture the uncertainty/variability in the value function would be to estimate the variance in TD error. After the policy has converged, the expected TD error would approach zero value. The variance in the TD error results from the stochasticity in the environment's reward function and the transition dynamics. We define "safety" as constraining the uncertainty in the value function. Therefore, we modify the objective function of maximizing the mean return by adding a regularizer on uncertainty in the value function.
Inspired by Gehring and Precup (2013), we define controllability as a negation of the variance in TD error of a state-option action pair. We use the aforementioned definition of controllability to introduce the concept of safety in the option-critic architecture, which aids in measuring the uncertainty in the value of a state-option pair. The key idea is -the higher the variance in TD error of a state-option pair, the higher would be the uncertainty in the value function.
In safety-critical applications, the agent must learn to avoid such state-option pairs as they induce variability in return eventually. We optimize for obtaining the maximum expected discounted return and controllability value of the initial state-option pair. Depending on the nature of the application, one can limit or encourage the agent's visit to a state-option pair based on the degree of controllability. Introducing controllability via the TD error facilitates the linear scalability of the proposed approach with the number of state-option pairs.
Analogous to the notations used in Bacon et al. (2017), we introduce a parameter vector described by Θ = [θ, ν], where, θ is an intra-option policy parameter, and ν is an option termination parameter. We 4 assume that all options can be initialized from any state such that I w = S, ∀w ∈ W. Uncertainty in the value of a state-option pair is measured using controllability C, which is given by the negation of the variance in the TD error (δ). The TD error is - where, Q U,Θ (s, w, a) and U Θ (s, w) are defined in (2) and (3) respectively. For the ease of notation, we will use δ t to denote δ(S t , W t , A t ). Whenever it is not clear from the context, we will use the full notation for the TD error. The expected value of the TD error would converge to zero. Therefore, the variance in TD error can be simplified to denote controllability as: The aim here is to maximize both the expected discounted return and the controllability value from an initial state-option pair. We want to maximize the objective function J, ψ ∈ R is a regularizer on the controllability value, and κ denotes the initial state-option pair distribution. The value of a state-option pair is defined as Q Θ (s, w) = a π w,θ (a|s) Q U,Θ (s, w, a). Another interpretation is to view the above objective as a constrained optimization problem, where, the constraints are imposed on the controllability function. One could bound the controllability value, but, it would require specific assumptions about the environment or one needs to rely on an input value from the user. In this paper, we opted to keep the method general without the need to rely on certain assumptions regarding the environment. We will now derive the gradient of the performance evaluator J with respect to the intra-option policy parameter θ, assuming they are differentiable.
First, we calculate the gradient of the δ t with θ using (6): The above equation follows through (2). Next, we take the gradient of C with respect to θ. Following from (7), The last term in the above equation vanishes because the gradient of TD error with respect to the policy parameter θ is zero (using (9)). The 1-step state-option transition is denoted by P (1) γ (s , w |s, w) = γ a π w,θ (a|s)P (s |s, a) (1 − β w,ν (s ))1 w=w + β w,ν (s )π W (w |s ) .
Using the above 1-step transition, similarly, the k-step state-option transition is expressed as Using the Intra-Option Policy Gradient Theorem (Bacon et al., 2017), the gradient of Q Θ (s, w) with θ is: Following the objective function (8), combining the gradient of Q Θ (s 0 , w 0 ) (11) and C Θ (s 0 , w 0 ) (10), the gradient of J with θ is: In (12), (s 0 , w 0 ) corresponds to the initial state-option pair. In the above equation, one can simply replace Q U,Θ (s, w, a) with the advantage term The gradient update of J here describes that each option aims to maximize its own reward, along with, maintaining a high controllability value pertaining to that option policy only. Now, we will compute the gradient of J(Θ|κ) with respect to the option termination function parameter ν. First, we would calculate the gradient of TD error with ν.
The last equation follows through (2). The gradient of controllability C with ν using (7) and (14) can be expressed as: Therefore, the gradient of J with ν remains same as the gradient of the state-option value. On using the Termination Gradient Theorem (Bacon et al., 2017), the gradient of J with ν results as follows: Our interpretation of the above derivation follows the notion of safety; each option is responsible for making its intra-option policy safe by incorporating the controllability function. Due to the assumption that each option takes care of its own safety through the intra-option policy (the objective function implicitly does not bring changes at the policy over options level), one is only concerned about choosing an option that maximizes the expected discounted return from the next state-option pair while terminating an option. As a result, introduction of controllability does not impact the termination function update. Algorithm 1 shows a prototype implementation details of controllability in the option-critic architecture in the look-up table setting. We now provide some intuition behind using the variance of TD error to learn the controllable states. The variance in the TD error of the initial state-option-action δ(s 0 , w 0 , a 0 ) uses the difference in the current

Algorithm 1 Safe Option-Critic with look-up table intra-option Q learning
Here α c , α θ , α ν stands for the step size of critic, intra-option policy and termination respectively. ψ is controllability regularization parameter. s ← s 0 Take w ∼ π W (w|s 0 )) Let initial w be w 0 repeat Take a ∼ π w,θ (.|s) Let initial a taken at (s 0 , w 0 ) be a 0 Maintain (s 0 , w 0 , a 0 ) at the beginning of the episode Choose new w ∼ π W (w|s ) end if s ← s until s is a terminal state state-option value Q U,Θ (S t , W t , A t ), and the next expected state-option value E[U Θ (s , W t )|S t = s]. With the increase in the time steps, the estimate of the Q value function changes (on seeing the new reward samples along a trajectory, the Q function estimate changes). Therefore, the square of the TD error would capture the variations in the return (sum of rewards) from the initial state-option pair on wards, thus yielding the uncertainty in the value function estimates.

Grid World
First, we consider a simple navigation task in a two-dimensional grid environment using a variant of the four-rooms domain as described in Sutton et al. (1999). As shown in Fig. 1, similar to Gehring and Precup (2013), we define some slippery frozen states in the environment which are unsafe to visit. We accomplish this by introducing variability in the rewards of these frozen states. The states labeled as F and G indicate the frozen and the goal states respectively.
An agent can be initialized with any random start state in the environment apart from the goal state. The action space consists of four stochastic actions, namely, up, down, left, and right. Upon choosing an action, with 0.2 probability, the agent can transition into any of the four directions (irrespective of the selected action). Whereas, with 0.8 probability, an agent takes the intended action deterministically. The task is to navigate through the rooms to a fixed goal state as depicted in Fig. 1. The dark states in Fig. 1 depict the walls. The agent remains in the same state with a reward of 0 if the agent hits the wall. A reward of 0 and 50 is given to the agent on transitioning into the normal and the goal state respectively. Rewards for the unsafe states are drawn from N (µ = 0, σ = 15) distribution when the agent transitions to a slippery state. The expected value of the reward for the normal and the slippery states is the same.
Here we are using a look-up table representation to learn the policy. In the safe option-critic framework, we represent both policy over options and intra-option policies with the Boltzmann distribution. Sigmoid activation is used for learning the termination function. We ran the experiments with different controllability factor ψ for learning 4 options. One could choose a different number of options as well. We optimize for the hyperparameters: temperature and step size for both the baseline Option-Critic (OC) with ψ = 0 and Safe-OC. The discount factor γ is set to 0.99. Hyperparameters for the experiment are mentioned in Table  1. We ran the experiments for a total of 500 episodes averaged over 50 trials, where, the training in each trial starts from scratch. In each episode, the agent is allowed to take a maximum of only 500 steps, wherein if the agent fails to reach the goal state within those steps, then the episode terminates.
To evaluate these experiments, we consider the following metrics: compared the expectation and the variance in the performance over multiple trials (to comment on the stability of the introduced algorithm); sum of the absolute TD error over episodes; density of the state visits. We also show sampled trajectories from both the baseline and the proposed method to qualitatively express the differences between the two after learning has been completed.
It can be observed from Fig. 2a that the options with the controllability (Safe-OC) have a lower standard deviation in the return of an episode as compared to the baseline i.e. options without any notion of safety (OC). Fig. 2b represents a lower standard deviation in the absolute sum of the TD error with safety. This highlights the fact that the controllability helps the agent to avoid the unsafe states (variable reward), thus resulting into a smaller variance in the sum of absolute TD error over multiple trials. The Fig. 3 shows how the performance (expectation and variance in the return) varies with the change in the controllability regularizer ψ. We chose the optimal value of ψ which maximizes the mean, but also, minimizes the variance in return. From the figure, it can be easily seen that ψ = 0.1 leads to maximum expectation but also significant reduction in the variance of return. We also visualize the state frequency graph depicted in the Fig. 4. It is observed that the options with the controllability function have lower frequency of visit to the frozen states (risky) as opposed to the vanilla options.
Learning of safe options induces transparency in the behaviour of an agent. This is most explicitly demonstrated through the trajectory taken by the agent without controllability regularizer (baseline OC) Figure 3: Performance with varying variance regularizer in FR domain. The plot shows the mean and the standard deviation of the score in the Four Rooms Domain with varying controllability regularizer value ψ, while keeping all other parameters fixed. The best hyper-parameters are chosen such that they minimize the standard deviation, but also, maximize the mean performance, which in this case is achieved by ψ = 0.1. and with controllability regularizer (Safe-OC) as shown in the Fig. 5. Regardless of the start state, Safe-OC agent navigates to the goal state by avoiding the states with a high variance in the reward, as opposed to the OC agent, which finds a shortest route to the goal state being unaware of the risky states.
To capture how each option is behaving, we plotted the converged policy for all the options in Fig. 6. It can be observed that each option does not capture the safety for the entire state space, but rather a subset of state space. The switches among the options for the safety are similar to the baseline (last image in both the rows). The overall trend observed from the individual option policy of safe algorithm is to avoid the unsafe frozen patch whereas, the vanilla option policies do not differentiate between the two hallways.

Continuous State Space Environment
In this section, we examine the performance in the puddle-world Open AI gym environment with the linear function approximation. It is a continuous 2-dimensional state-space environment in [0, 1] 2 . The action space consists of four actions that change the position by a value of 0.05 in any one of the coordinates. In each transition, noise is drawn from the Uniform[−0.025, 0.025] distribution, which is added to both the coordinates. For introducing the notion of unsafe regions, similar to the four rooms environment, we added a square puddle region with a center at (0.5, 0.5) and 0.4 height. An agent can be randomly initialized from any state and the goal is located at (1, 1). When the agent is within 0.1 L1 distance from the goal state, the agent receives a reward of 50. Whenever the agent transitions from a puddle region, it receives a reward from a normal distribution of N (µ = 0, σ = 8), and 0 reward otherwise. On expectation, the reward received from both regions is the same. The penalty makes the puddle locations 'unsafe' due to the variability in the rewards. For these experiments, we use 2 options. One could choose to have more number of options, but given the complexity of the task, we decide to use only 2 options. We use intra-option Q-learning in the critic to learn policy over options. Boltzmann distribution is used to represent both intra-option policies and policy over options with a temperature value of 0.1. To learn the termination function, we use sigmoid activation. The agent can take a maximum of 5000 steps in an episode. The standard tile coding (Sutton and Barto, 1998) is used for discretizing the state-space. We use 5 tilings, each of 5 × 5 over the joint space of two features which is hashed to a vector of 1024 dimension. The discount factor γ is set to 0.99. The optimized parameters are shown in the Table 1. The code for both the discrete four-rooms and the continuous puddleworld is available at Github 1 . Fig. 7 shows the return observed in the puddle-world domain with different values of ψ averaged over 50 trials. The best performance in terms of stability was observed by ψ = 0.015 Safe-OC which exhibits a reduction in the standard deviation of the return across multiple runs as compared to the baseline (ψ = 0). This highlights that the agent following the safe policy learns to avoid the variance inducing puddle region. Fig. 8 shows the sampled trajectories from both the baseline OC and the Safe-OC. To further validate, the frequency of visits is shown in Fig. 9a & Fig. 9b. They describe the average number of visits across multiple runs for an episode, depicting a decrease in the number of visits to the unsafe puddle region in the safe policy learning option-critic framework as compared to the baseline. It demonstrates that the safe policy learning agent avoids the erratically behaving unsafe puddle region placed at the centre of the state space.

Arcade Learning Environment
We now analyze our method in the ALE domain (Bellemare et al., 2013). Harb et al. (2018) introduced deliberation cost in the options framework to learn temporally extended options by adding a penalty cost on switching options too frequently. We use the asynchronous advantage option-critic (A2OC) (Harb et al., 2018) as our baseline for learning 'safe' options with non-linear function approximation. A2OC provides an extension of the asynchronous advantage actor-critic (A3C) algorithm  in the optioncritic architecture. Introducing the controllability function in the A2OC algorithm results in an additional regularizer term in the intra-option policy gradient (see Equation (12)). The update rule for the intra-option policy gradient in the A2OC with controllability is given as follows: Here, similar to the A2OC algorithm, G is a mixture of n-step return, with a slight modification that the n-step return is only considered until the current option terminates or number of steps are more than n. Without any loss in generality, the 1-step TD error in the definition of controllability can be extended to the n-step TD error if the current option persists until the n th step. Similarly, as discussed in the Equation (16), there is no change in the termination gradient and we use the same update rule as derived in the A2OC algorithm. In the below equation, η represents the deliberation cost (Harb et al., 2018) which penalizes the frequent switching of the options, We evaluate the performance in three games, namely, MsPacman, Amidar, and Q*Bert from the ATARI 2600 suite. We introduce Safe-A2OC 2 which uses a similar deep network architecture as A2OC but with an additional safety criteria added to it. We use -greedy for learning policy over options. Intra-option policies follows the linear Boltzmann distribution. Termination functions use sigmoid activation along will linear function approximation for the Q values. For hyperparameters, we learn 4 options, with a fixed deliberation cost of 0.02, margin cost of 0.99, step size of 0.0007, and entropy regularization of 0.01 for varying degrees of controllability (ψ) and . The training used 16 parallel threads for all our experiments. We also optimize for parameter for the baseline case (ψ = 0). For fair analysis, we compare the best performance of A2OC with varying ψ regularizer for controllability function in the Safe-A2OC. Results and Evaluation: To evaluate the agents, we investigate the averaged performance over 100 games after the training has been completed over 80M frames (Machado et al., 2017). Table 2 depicts the averaged performance over 5 different runs, where, each run contains the averaged score obtained over 100 testing games. It is observed that the Safe-A2OC with a controllability value of ψ = 0.10 in MsPacman not only outperforms the score achieved by the baseline A2OC (ψ = 0), but also, results in a smaller variance in the scores (values are shown in the braces). We observe a similar pattern in Q*Bert, wherein, the Safe-A2OC (ψ = 0.05) shows an improved robust performance over the A2OC (ψ = 0), achieving almost half of the variance of A2OC across multiple games.
In the game of Amidar, we note that Safe-A2OC outperforms the score achieved by A2OC, and the other state-of-the-art approaches Nair et al., 2015;Van Hasselt et al., 2016;Wang et al., 2015) using the primitive actions. Empirically, we observe that on adding an optimal amount of controllability value in options, an agent optimizing for low variance in the TD error learns better than the one optimizing only for the cumulative reward. Intuitively, minimizing the variance in the TD error as a measure of safety helps the agents avoid states with high intrinsic variability in the reward. Depending on the nature of the game itself, we observe different degrees of response to different levels of controllability in Q*bert, Amidar, and MsPacman. Based on the amount of variability in the reward structure, each game benefits differently in the performance. Overall, a consistent boost in the performance is demonstrated with the proposed approach once the training is completed.
We also inspect the learning curves during the training phase for all three Atari games. Fig. 10 depicts the learning curves over 80M frames with varying controllability parameter. The results are averaged across 5 runs per game. In Amidar we observe that with a specific degrees of controllability (ψ = 0.15), options learned with our notion of safety (Safe-A2OC) outperforms the baseline option-critic (A2OC). An improvement in the training performance also translates well to the testing phase as seen in the Table 2. Interestingly, we observe that the performance of Safe-A2OC improves only marginally during the training  Table 2: ALE Final Scores: The performance is averaged over 100 games once the training is completed. The scores are averaged over 5 independent seeds. Scores in the boxes highlight the performance without controllability function (baseline), whereas, aqua highlighted cells indicate the benefits of introducing our notion of safety in learning end-to-end options. Introducing controllability in options outperforms best performances of primitive actions (gray) in 2 out of 3 games analyzed here. Learning options with our notion of safety outperforms the baseline A2OC in all 3 games. A3C scores have been taken from Mnih et al. (2016), DQN from Nair et al. (2015), Double DQN from Van Hasselt et al. (2016), and Dueling from Wang et al. (2015). ψ represents the degree of controllability. Values in the brackets indicate the standard deviation across 100 games for 5 independent runs. phase in Ms-Pacman and is at-par with A2OC in Q*Bert. However, it is noteworthy that while we do not see much improvement in the training curves for both MsPacman and Q*Bert, during the testing phase, both these games show robust and improved performance. According to our interpretation, explicitly optimizing for the variance in TD error might not always result in a performance boost. Nevertheless, the proposed objective function makes the agent aware of intrinsic variability in the rewards. In the subsequent section, we will qualitatively analyze the behaviour of the trained agents. Qualitative Observations: We are now interested in better understanding the behaviour of the trained agents. We observe that different values of ψ control the degree to which an agent tends to be risk averse. A grid search over the different degrees of the controllability hyper parameter ψ resulted in a narrow range of 0 to 0.15. For a very high value of ψ > 0.3, we observe that the agents become extremely risk-averse resulting in a poor performance. An optimum value of ψ for all three games is obtained around 0.05 − 0.15. For a qualitative analysis, we also present the videos of the trained agents 3 .
Upon visual inspection, we observe improvements in game playing strategies for Safe-OC agent as compared to its counterpart OC. The Safe-A2OC agents demonstrate relatively better understanding of the source of intrinsic variability in the reward structure. For instance, consider the game of MsPacman. The agent is tasked with eating all of the pellets in an enclosed maze while avoiding the four colored ghosts. Figure 10: Learning curves in Atari games during training: demonstrate that options with a controllability factor of ψ = 0.10 learn better than the best performing A2OC baseline (ψ = 0, = 0.2). Higher value of ψ results in a poor performance. Performance is averaged across 5 independent seeds for each game.  Figure 11: Qualitative analysis in MsPacman: Our interpretation is that the Safe-A2OC agent understands the source of intrinsic variability in the reward due to explicitly optimizing for the variance in TD error. This results in Safe-A2OC agent to adopt the strategy of eating the large flashing power pellets, causing the ghosts to flee. The Safe-A2OC agent is able to survive longer and ends up accumulating more cumulative reward as opposed to the baseline A2OC agent. Here, we depict a sampled trajectory of the Safe-A2OC agent in comparison with the baseline A2OC agent.
On consuming the power pellets in the environment, the ghosts turns blue and flee, resulting in bonus points. Frame-by-frame analysis shows that the Safe-A2OC agent is able to escape from the ghosts and stay alive longer when these ghosts are harmful in the context of a terminal state. Figure 11 depicts this observation, where, the A2OC agent loses its first life relatively quickly as compared to the Safe-A2OC agent. These insights demonstrate that explicitly optimizing for the variance in TD error results in avoiding the visits to states with intrinsic variability in the rewards. Particularly, in MsPacman, the additional cost in the objective function helps the agent to understand the intrinsic variability in reward structure such as the behaviour observed upon the acquisition of the power pellets. Furthermore, on close analysis of the behaviour of the Safe-OC agents, we observe agents with extremely high value of ψ are relatively more risk-averse but less exploratory in nature, thereby resulting in a poor performance (see Appendix 0.1). This corroborates with the findings in the learning curves as shown in the Fig. 10. For an optimal value of controllability regularizer (ψ), we observe a balanced amount of risk-aversion, and therefore, the agent adopts a behaviour which demonstrates a better understanding of intrinsic variability in the rewards structure. We perform a similar analysis for the game of Amidar and report similar insights in the Appendix 0.2.
14 In this work, we introduced Safe Option-Critic, a general framework that extends the idea of controllability from the primitive action space to the option-critic architecture. The key idea is to discourage the agent from visiting the state space with high uncertainty in their behavioural outcomes by constraining the variance in TD error. Recently, Sherstan et al. (2018) proposed a direct method to estimate the variance of λ return. The authors proposed a Bellman operator for the variance that uses the square of the TD error. This work further supports our approach to estimating the risk using the squared TD error.
Our experiments in the tabular case empirically demonstrate the reduced variance in the return. Moreover, we observe a boost in the overall performance for both the tabular and the linear function approximation. Experiments in the ALE domain demonstrate that the agent can learn about the intrinsic variability in a large and complicated state-space using non-linear function approximation. Qualitative insights from ALE also demonstrate that the options with a notion of safety are more cautious in their behaviour, and therefore, result in improved overall performance.
Limitations and Future Work: In this work, we limit the return calculation until an option terminates. Using the n-step returns at the SMDP level is of potential interest for future work. Additionally, in this work we assume that all the options are available in every state. In the context of safety, it would be of interest to understand the setting where options initiation sets are limited to a subset of the entire state space (Khetarpal et al., 2020). One could also add a scheduler on the controllability regularizer ψ over time. For instance, ψ could be initiated with a small value to encourage exploration in the initial stages of learning, and gradually the value of ψ could be increased to limit the exploration in the unsafe states.
Besides, a more formal analysis of the agent behaviour in ALE can provide a rigorous understanding of the interplay between learning the dynamics and the controllability parameter. For instance, studying the training and policy traces by human subjects is scope for future work.
In the proposed algorithm, we consider the notion of safety by accounting for the controllability of only the initial state-option pair. However, one can instead account for the variability due to the entire state-space by means of bootstrapping the target value function, aliasing due to the function approximation, and random resets to starting state. A potential direction for future work is to extend the controllability from the initial state-option pair to all the state-option pairs in the trajectory. This extension could potentially enhance the effects of the risk mitigation and speed up learning. The proposed notion of safety can also be extended to different levels of hierarchy, e.g. a mixture of options with varying degrees of controllability can be learned. Figure 2: Qualitative analysis in Amidar: We here demonstrate the final frames from randomly sampled 3 games played by the trained agents. Safe-A2OC agent learns to paint relatively more rectangles as compared to the A2OC agent as painting all sides of a rectangle results in making the ghosts ineffective, and thus increases the cumulative return. Amidar offers intrinsic variability in the reward structure and our approach empowers the agents to understand it better.