Recently, deep reinforcement learning has enabled neural network policies to achieve state-of-the-art performance on many high-dimensional control tasks, including Atari games (using pixels as inputs) (Mnih et al., 2015; 2016), robot locomotion and manipulation (Schulman et al., 2015; Levine et al., 2016; Lillicrap et al., 2016), and even Go at the human grandmaster level (Silver et al., 2016).
In reinforcement learning (RL), agents learn to act by trial and error, gradually improving their performance at the task as learning progresses. Recent work in deep RL assumes that agents are free to explore any behavior during learning, so long as it leads to performance improvement. In many realistic domains, however, it may be unacceptable to give an agent complete freedom. Consider, for example, an industrial robot arm learning to assemble a new product in a factory. Some behaviors could cause it to damage itself or the plant around it—or worse, take actions that are harmful to people working nearby. In domains like this, safe exploration for RL agents is important (Moldovan & Abbeel, 2012; Amodei et al., 2016). A natural way to incorporate safety is via constraints.
A standard and well-studied formulation for reinforcement learning with constraints is the constrained Markov Decision Process (CMDP) framework (Altman, 1999), where agents must satisfy constraints on expectations of auxilliary costs. Although optimal policies for finite CMDPs with known models can be obtained by linear programming, methods for high-dimensional control are lacking.
Currently, policy search algorithms enjoy state-of-the-art performance on high-dimensional control tasks (Mnih et al., 2016; Duan et al., 2016). Heuristic algorithms for policy search in CMDPs have been proposed (Uchibe & Doya, 2007), and approaches based on primal-dual methods can be shown to converge to constraint-satisfying policies (Chow et al., 2015), but there is currently no approach for policy search in continuous CMDPs that guarantees every policy during learning will satisfy constraints. In this work, we propose the first such algorithm, allowing applications to constrained deep RL.
Driving our approach is a new theoretical result that bounds the difference between the rewards or costs of two different policies. This result, which is of independent interest, tightens known bounds for policy search using trust regions (Kakade & Langford, 2002; Pirotta et al., 2013; Schulman et al., 2015), and provides a tighter connection between the theory and practice of policy search for deep RL. Here, we use this result to derive a policy improvement step that guarantees both an increase in reward and satisfaction of constraints on other costs. This step forms the basis for our algorithm, Constrained Policy Optimization (CPO), which computes an approximation to the theoretically-justified update.
In our experiments, we show that CPO can train neural network policies with thousands of parameters on high-dimensional simulated robot locomotion tasks to maximize rewards while successfully enforcing constraints.
Safety has long been a topic of interest in RL research, and a comprehensive overview of safety in RL was given by (Garc´ıa & Fern´andez, 2015).
Safe policy search methods have been proposed in prior work. Uchibe and Doya (2007) gave a policy gradient algorithm that uses gradient projection to enforce active constraints, but this approach suffers from an inability to prevent a policy from becoming unsafe in the first place. Bou Ammar et al. (2015) propose a theoretically-motivated policy gradient method for lifelong learning with safety constraints, but their method involves an expensive inner loop optimization of a semi-definite program, making it unsuited for the deep RL setting. Their method also assumes that safety constraints are linear in policy parameters, which is limiting. Chow et al. (2015) propose a primal-dual subgradient method for risk-constrained reinforcement learning which takes policy gradient steps on an objective that trades off return with risk, while simultaneously learning the trade-off coefficients (dual variables).
Some approaches specifically focus on application to the deep RL setting. Held et al. (2017) study the problem for robotic manipulation, but the assumptions they make restrict the applicability of their methods. Lipton et al. (2017) use an ‘intrinsic fear’ heuristic, as opposed to constraints, to motivate agents to avoid rare but catastrophic events. Shalev-Shwartz et al. (2016) avoid the problem of enforcing constraints on parametrized policies by decomposing ‘desires’ from trajectory planning; the neural network policy learns desires for behavior, while the trajectory planning algorithm (which is not learned) selects final behavior and enforces safety constraints.
In contrast to prior work, our method is the first policy search algorithm for CMDPs that both 1) guarantees constraint satisfaction throughout training, and 2) works for arbitrary policy classes (including neural networks).
A Markov decision process (MDP) is a tuple, (), where S is the set of states, A is the set of actions,
is the reward function,
is the transition probability function (where
is the probability of transitioning to state
given that the previous state was s and the agent took action a in s), and
is the starting state distribution. A stationary policy
is a map from states to probability distributions over actions, with
denoting the probability of selecting action a in state s. We denote the set of all stationary policies by
.
In reinforcement learning, we aim to select a policy which maximizes a performance measure,
, which is typically taken to be the infinite horizon discounted total return,
. Here
is the discount factor,
denotes a trajectory (
), and
is shorthand for indicating that the distribution over trajectories depends on
:
.
Letting denote the discounted return of a trajectory, we express the on-policy value function as
and the on-policy action-value function as
. The advantage function is
.
Also of interest is the discounted future state distribution, , defined by
. It al- lows us to compactly express the difference in performance between two policies
as
where by , we mean
, with explicit notation dropped to reduce clutter. For proof of (1), see (Kakade & Langford, 2002) or Section 10 in the supplementary material.
A constrained Markov decision process (CMDP) is an MDP augmented with constraints that restrict the set of allowable policies for that MDP. Specifically, we augment the MDP with a set C of auxiliary cost functions, (with each one a function
mapping transition tuples to costs, like the usual reward), and limits
. Let
denote the expected discounted return of policy
with respect to cost function
. The set of feasible stationary policies for a CMDP is then
and the reinforcement learning problem in a CMDP is
The choice of optimizing only over stationary policies is justified: it has been shown that the set of all optimal policies for a CMDP includes stationary policies, under mild technical conditions. For a thorough review of CMDPs and CMDP theory, we refer the reader to (Altman, 1999).
We refer to as a constraint return, or
-return for short. Lastly, we define on-policy value functions, action-value functions, and advantage functions for the auxiliary costs in analogy to
, and
, with
replacing R: respectively, we denote these by
, and
.
For large or continuous MDPs, solving for the exact optimal policy is intractable due to the curse of dimensionality (Sutton & Barto, 1998). Policy search algorithms approach this problem by searching for the optimal policy within a set of parametrized policies with parameters
(for example, neural networks of a fixed architecture). In local policy search (Peters & Schaal, 2008), the policy is iteratively updated by maximizing
over a local neighborhood of the most recent iterate
:
where D is some distance measure, and is a step size. When the objective is estimated by linearizing around
as
is the policy gradient, and the standard policy gradient update is obtained by choosing
(Schulman et al., 2015).
In local policy search for CMDPs, we additionally require policy iterates to be feasible for the CMDP, so instead of optimizing over , we optimize over
:
This update is difficult to implement in practice because it requires evaluation of the constraint functions to determine whether a proposed point is feasible. When using sampling to compute policy updates, as is typically done in high-dimensional control (Duan et al., 2016), this requires off-policy evaluation, which is known to be challenging (Jiang & Li, 2015). In this work, we take a different approach, motivated by recent methods for trust region optimization (Schulman et al., 2015).
We develop a principled approximation to (3) with a particular choice of D, where we replace the objective and constraints with surrogate functions. The surrogates we choose are easy to estimate from samples collected on , and are good local approximations for the objective and constraints. Our theoretical analysis shows that for our choices of surrogates, we can bound our update’s worst-case performance and worst-case constraint violation with values that depend on a hyperparameter of the algorithm.
To prove the performance guarantees associated with our surrogates, we first prove new bounds on the difference in returns (or constraint returns) between two arbitrary stochastic policies in terms of an average divergence between them. We then show how our bounds permit a new analysis of trust region methods in general: specifically, we prove a worst-case performance degradation at each update. We conclude by motivating, presenting, and proving gurantees on our algorithm, Constrained Policy Optimization (CPO), a trust region method for CMDPs.
5.1. Policy Performance Bounds
In this section, we present the theoretical foundation for our approach—a new bound on the difference in returns between two arbitrary policies. This result, which is of independent interest, extends the works of (Kakade & Lang- ford, 2002), (Pirotta et al., 2013), and (Schulman et al., 2015), providing tighter bounds. As we show later, it also relates the theoretical bounds for trust region policy improvement with the actual trust region algorithms that have been demonstrated to be successful in practice (Duan et al., 2016). In the context of constrained policy search, we later use our results to propose policy updates that both improve the expected return and satisfy constraints.
The following theorem connects the difference in returns (or constraint returns) between two arbitrary policies to an average divergence between them.
Theorem 1. For any function and any policies
and
, define
,
where is the total variational divergence between action distributions at s. The following bounds hold:
Furthermore, the bounds are tight (when , all three expressions are identically zero).
Before proceeding, we connect this result to prior work. By bounding the expectation with
, picking
, and bounding
to get a second factor of
, we recover (up to assumption-dependent factors) the bounds given by Pirotta et al. (2013) as Corollary 3.6, and by Schulman et al. (2015) as Theorem 1a.
The choice of allows a useful form of the lower bound, so we give it as a corollary.
Corollary 1. For any policies , with
, the following bound holds:
The bound (5) should be compared with equation (1). The term in (5) is an approximation to
, using the state distribution
instead of
, which is known to equal
to first order in the parameters of
on a neighborhood around
(Kakade & Langford, 2002). The bound can therefore be viewed as describing the worst-case approximation error, and it justifies using the approximation as a surrogate for
.
Equivalent expressions for the auxiliary costs, based on the upper bound, also follow immediately; we will later use them to make guarantees for the safety of CPO.
Corollary 2. For any policies , and any cost function
, with
, the follow- ing bound holds:
The bounds we have given so far are in terms of the TV-divergence between policies, but trust region methods constrain the KL-divergence between policies, so bounds that connect performance to the KL-divergence are desirable. We make the connection through Pinsker’s inequality (Csiszar & K¨orner, 1981): for arbitrary distributions p, q, the TV-divergence and KL-divergence are related by . Combining this with Jensen’s inequality, we obtain
From (7) we immediately obtain the following.
Corollary 3. In bounds (4), (5), and (6), make the substitution
The resulting bounds hold.
5.2. Trust Region Methods
Trust region algorithms for reinforcement learning (Schul- man et al., 2015; 2016) have policy updates of the form
where , and
is the step size. The set
is called the trust region.
The primary motivation for this update is that it is an approximation to optimizing the lower bound on policy performance given in (5), which would guarantee monotonic performance improvements. This is important for optimizing neural network policies, which are known to suffer from performance collapse after bad updates (Duan et al., 2016). Despite the approximation, trust region steps usually give monotonic improvements (Schulman et al., 2015; Duan et al., 2016) and have shown state-of-the-art performance in the deep RL setting (Duan et al., 2016; Gu et al., 2017), making the approach appealing for developing policy search methods for CMDPs.
Until now, the particular choice of trust region for (8) was heuristically motivated; with (5) and Corollary 3, we are able to show that it is principled and comes with a worst-case performance degradation guarantee that depends on . Proposition 1 (Trust Region Update Performance). Suppose
are related by (8), and that
. A lower bound on the policy performance difference between
and
is
Proof. is a feasible point of (8) with objective value 0, so
. The rest follows by (5) and Corollary 3, noting that (8) bounds the average KLdivergence by
.
This result is useful for two reasons: 1) it is of independent interest, as it helps tighten the connection between theory and practice for deep RL, and 2) the choice to develop CPO as a trust region method means that CPO inherits this performance guarantee.
5.3. Trust Region Optimization for Constrained MDPs
Constrained policy optimization (CPO), which we present and justify in this section, is a policy search algorithm for CMDPs with updates that approximately solve (3) with a particular choice of D. First, we describe a policy search update for CMDPs that alleviates the issue of off-policy evaluation, and comes with guarantees of monotonic performance improvement and constraint satisfaction. Then, because the theoretically guaranteed update will take toosmall steps in practice, we propose CPO as a practical approximation based on trust region methods.
By corollaries 1, 2, and 3, for appropriate coefficients ,
the update
is guaranteed to produce policies with monotonically nondecreasing returns that satisfy the original constraints. (Observe that the constraint here is on an upper bound for by (6).) The off-policy evaluation issue is alleviated, because both the objective and constraints involve expectations over state distributions
, which we presume to have samples from. Because the bounds are tight, the problem is always feasible (as long as
is feasible). However, the penalties on policy divergence are quite steep for discount factors close to 1, so steps taken with this update might be small.
Inspired by trust region methods, we propose CPO, which uses a trust region instead of penalties on policy divergence to enable larger step sizes:
Because this is a trust region method, it inherits the performance guarantee of Proposition 1. Furthermore, by corollaries 2 and 3, we have a performance guarantee for approximate satisfaction of constraints:
Proposition 2 (CPO Update Worst-Case Constraint Violation). Suppose are related by (10), and that
in (10) is any set of policies with
. An upper bound on the
-return of
is
In this section, we show how to implement an approximation to the update (10) that can be efficiently computed, even when optimizing policies with thousands of parameters. To address the issue of approximation and sampling errors that arise in practice, as well as the potential violations described by Proposition 2, we also propose to tighten the constraints by constraining upper bounds of the auxilliary costs, instead of the auxilliary costs themselves.
6.1. Approximately Solving the CPO Update
For policies with high-dimensional parameter spaces like neural networks, (10) can be impractical to solve directly because of the computational cost. However, for small step sizes , the objective and cost constraints are well-approximated by linearizing around
, and the KLdivergence constraint is well-approximated by second order expansion (at
, the KL-divergence and its gradient are both zero). Denoting the gradient of the objective as g, the gradient of constraint i as
, the Hessian of the KL-divergence as H, and defining
, the approximation to (10) is:
Because the Fisher information matrix (FIM) H is always positive semi-definite (and we will assume it to be positive-definite in what follows), this optimization problem is convex and, when feasible, can be solved efficiently using duality. (We reserve the case where it is not feasible for the next subsection.) With and
, a dual to (11) can be expressed as
where . This is a convex program in m+1 variables; when the number of constraints is small by comparison to the dimension of
, this is much easier to solve than (11). If
are a solution to the dual, the solution to the primal is
Our algorithm solves the dual for and uses it to propose the policy update (13). For the special case where there is only one constraint, we give an analytical solution in the supplementary material (Theorem 2) which removes the need for an inner-loop optimization. Our experiments
have only a single constraint, and make use of the analytical solution.
Because of approximation error, the proposed update may not satisfy the constraints in (10); a backtracking line search is used to ensure surrogate constraint satisfaction. Also, for high-dimensional policies, it is impractically expensive to invert the FIM. This poses a challenge for computing and
, which appear in the dual. Like (Schulman et al., 2015), we approximately compute them using the conjugate gradient method.
6.2. Feasibility
Due to approximation errors, CPO may take a bad step and produce an infeasible iterate . Sometimes (11) will still be feasible and CPO can automatically recover from its bad step, but for the infeasible case, a recovery method is necessary. In our experiments, where we only have one constraint, we recover by proposing an update to purely decrease the constraint value:
As before, this is followed by a line search. This approach is principled in that it uses the limiting search direction as the intersection of the trust region and the constraint region shrinks to zero. We give the pseudocode for our algorithm (for the single-constraint case) as Algorithm 1.
6.3. Tightening Constraints via Cost Shaping
Because of the various approximations between (3) and our practical algorithm, it is important to build a factor of safety into the algorithm to minimize the chance of constraint violations. To this end, we choose to constrain upper bounds on the original constraints, , instead of the original con- straints themselves. We do this by cost shaping:
where correlates in some useful way with
.
In our experiments, where we have only one constraint, we partition states into safe states and unsafe states, and the agent suffers a safety cost of 1 for being in an unsafe state. We choose to be the probability of entering an unsafe state within a fixed time horizon, according to a learned model that is updated at each iteration. This choice confers the additional benefit of smoothing out sparse constraints.
Our method has similar policy updates to primal-dual methods like those proposed by Chow et al. (2015), but crucially, we differ in computing the dual variables (the Lagrange multipliers for the constraints). In primal-dual optimization (PDO), dual variables are stateful and learned concurrently with the primal variables (Boyd et al., 2003). In a PDO algorithm for solving (3), dual variables would be updated according to
where is a learning rate. In this approach, intermediary policies are not guaranteed to satisfy constraints—only the policy at convergence is. By contrast, CPO computes new dual variables from scratch at each update to exactly enforce constraints.
In our experiments, we aim to answer the following:
• Does CPO succeed at enforcing behavioral constraints when training neural network policies with thousands of parameters?
• How does CPO compare with a baseline that uses primal-dual optimization? Does CPO behave better with respect to constraints?
• How much does it help to constrain a cost upper bound (15), instead of directly constraining the cost?
• What benefits are conferred by using constraints instead of fixed penalties?
We designed experiments that are easy to interpret and motivated by safety. We consider two tasks, and train multiple different agents (robots) for each task:
• Circle: The agent is rewarded for running in a wide circle, but is constrained to stay within a safe region smaller than the radius of the target circle.
Constraint values: (closer to the limit is better)
Figure 1. Average performance for CPO, PDO, and TRPO over several seeds (5 in the Point environments, 10 in all others); the x-axis is training iteration. CPO drives the constraint function almost directly to the limit in all experiments, while PDO frequently suffers from over- or under-correction. TRPO is included to verify that optimal unconstrained behaviors are infeasible for the constrained problem.
• Gather: The agent is rewarded for collecting green apples, and constrained to avoid red bombs.
For the Circle task, the exact geometry is illustrated in Figure 5 in the supplementary material. Note that there are no physical walls: the agent only interacts with boundaries through the constraint costs. The reward and constraint cost functions are described in supplementary material (Section 10.3.1). In each of these tasks, we have only one constraint; we refer to it as C and its upper bound from (15) as .
We experiment with three different agents: a point-mass , a quadruped robot (called an ‘ant’)
, and a simple humanoid
. We train all agent-task combinations except for Humanoid-Gather.
For all experiments, we use neural network policies with two hidden layers of size (64, 32). Our experiments are implemented in rllab (Duan et al., 2016).
8.1. Evaluating CPO and Comparison Analysis
Learning curves for CPO and PDO are compiled in Figure 1. Note that we evaluate algorithm performance based on the return, instead of the C return (except for in PointGather, where we did not use cost shaping due to that environment’s short time horizon), because this is what the algorithm actually constrains in these experiments.
For our comparison, we implement PDO with (16) as the update rule for the dual variables, using a constant learning rate ; details are available in supplementary material (Section 10.3.3). We emphasize that in order for the compari-
Figure 2. The Humanoid-Circle and Point-Gather environments. In Humanoid-Circle, the safe area is between the blue panels.
son to be fair, we give PDO every advantage that is given to CPO, including equivalent trust region policy updates. To benchmark the environments, we also include TRPO (trust region policy optimization) (Schulman et al., 2015), a state-of-the-art unconstrained reinforcement learning algorithm. The TRPO experiments show that optimal unconstrained behaviors for these environments are constraint-violating.
We find that CPO is successful at approximately enforcing constraints in all environments. In the simpler environments (Point-Circle and Point-Gather), CPO tracks the constraint return almost exactly to the limit value.
By contrast, although PDO usually converges to constraint-satisfying policies in the end, it is not consistently constraint-satisfying throughout training (as expected). For example, see the spike in constraint value that it experiences in Ant-Circle. Additionally, PDO is sensitive to the initialization of the dual variable. By default, we initialize , which exploits no prior knowledge about the
Figure 3. Using cost shaping (CS) in the constraint while optimizing generally improves the agent’s adherence to the true constraint on C-return.
environment and makes sense when the initial policies are feasible. However, it may seem appealing to set high, which would make PDO more conservative with respect to the constraint; PDO could then decrease
as necessary after the fact. In the Point environments, we experiment with
and show that although this does assure constraint satisfaction, it also can substantially harm performance with respect to return. Furthermore, we argue that this is not adequate in general: after the dual variable decreases, the agent could learn a new behavior that increases the correct dual variable more quickly than PDO can attain it (as happens in Ant-Circle for PDO; observe that performance is approximately constraint-satisfying until the agent learns how to run at around iteration 350).
We find that CPO generally outperforms PDO on enforcing constraints, without compromising performance with respect to return. CPO quickly stabilizes the constraint return around to the limit value, while PDO is not consistently able to enforce constraints all throughout training.
8.2. Ablation on Cost Shaping
In Figure 3, we compare performance of CPO with and without cost shaping in the constraint. Our metric for comparison is the C-return, the ‘true’ constraint. The cost shaping does help, almost completely accounting for CPO’s inherent approximation errors. However, CPO is nearly constraint-satisfying even without cost shaping.
Figure 4. Comparison between CPO and FPO (fixed penalty optimization) for various values of fixed penalty.
8.3. Constraint vs. Fixed Penalty
In Figure 4, we compare CPO to a fixed penalty method, where policies are learned using TRPO with rewards for
.
We find that fixed penalty methods can be highly sensitive to the choice of penalty coefficient: in Ant-Circle, a penalty coefficient of 1 results in reward-maximizing policies that accumulate massive constraint costs, while a coefficient of 5 (less than an order of magnitude difference) results in cost-minimizing policies that never learn how to acquire any rewards. In contrast, CPO automatically picks penalty coefficients to attain the desired trade-off between reward and constraint cost.
In this article, we showed that a particular optimization problem results in policy updates that are guaranteed to both improve return and satisfy constraints. This enabled the development of CPO, our policy search algorithm for CMDPs, which approximates the theoretically-guaranteed algorithm in a principled way. We demonstrated that CPO can train neural network policies with thousands of parameters on high-dimensional constrained control tasks, simultaneously maximizing reward and approximately satisfying constraints. Our work represents a step towards applying reinforcement learning in the real world, where constraints on agent behavior are sometimes necessary for the sake of safety.
Acknowledgements
The authors would like to acknowledge Peter Chen, who independently and concurrently derived an equivalent policy improvement bound.
Joshua Achiam is supported by TRUST (Team for Research in Ubiquitous Secure Technology) which receives support from NSF (award number CCF-0424422). This project also received support from Berkeley Deep Drive
and from Siemens.
Altman, Eitan. Constrained Markov Decision Processes. pp. 260, 1999. ISSN 01676377. doi: 10.1016/ 0167-6377(96)00003-X.
Amodei, Dario, Olah, Chris, Steinhardt, Jacob, Christiano, Paul, Schulman, John, and Man´e, Dan. Concrete Problems in AI Safety. arXiv, 2016. URL http://arxiv. org/abs/1606.06565.
Bou Ammar, Haitham, Tutunov, Rasul, and Eaton, Eric. Safe Policy Search for Lifelong Reinforcement Learning with Sublinear Regret. International Conference on Machine Learning, 37:19, 2015. URL http://arxiv. org/abs/1505.0579.
Boyd, Stephen, Xiao, Lin, and Mutapcic, Almir. Subgra- dient methods. Lecture Notes of Stanford EE392, 2003. URL http://xxpt.ynjgy.com/resource/ data/20100601/U/stanford201001010/ 02-subgrad{_}method{_}notes.pdf.
Chow, Yinlam, Ghavamzadeh, Mohammad, Janson, Lucas, and Pavone, Marco. Risk-Constrained Reinforcement Learning with Percentile Risk Criteria. Journal of Machine Learning Research, 1(xxxx):1–49, 2015.
Csiszar, I and K¨orner, J. Information Theory: Coding Theorems for Discrete Memoryless Systems. Book, 244:452, 1981. ISSN 0895-4801. doi: 10.2307/ 2529636. URL http://www.getcited.org/ pub/102082957.
Duan, Yan, Chen, Xi, Schulman, John, and Abbeel, Pieter. Benchmarking Deep Reinforcement Learning for Continuous Control. The 33rd International Conference on Machine Learning (ICML 2016) (2016), 48:14, 2016. URL http://arxiv.org/abs/1604.06778.
Garc´ıa, Javier and Fern´andez, Fernando. A Comprehensive Survey on Safe Reinforcement Learning. Journal of Machine Learning Research, 16:1437–1480, 2015. ISSN 15337928.
Gu, Shixiang, Lillicrap, Timothy, Ghahramani, Zoubin, Turner, Richard E., and Levine, Sergey. Q-Prop: Sample-Efficient Policy Gradient with An Off-Policy Critic. In International Conference on Learning Representations, 2017. URL http://arxiv.org/abs/ 1611.02247.
Held, David, Mccarthy, Zoe, Zhang, Michael, Shentu, Fred, and Abbeel, Pieter. Probabilistically Safe Policy Transfer. In Proceedings of the IEEE International Conference on Robotics and Automation (ICRA), 2017.
Jiang, Nan and Li, Lihong. Doubly Robust Off-policy Value Evaluation for Reinforcement Learning. International Conference on Machine Learning, 2015. URL http://arxiv.org/abs/1511.03722.
Kakade, Sham and Langford, John. Approximately Optimal Approximate Reinforcement Learning. Proceedings of the 19th International Conference on Machine Learning, pp. 267–274, 2002. URL http://www.cs.cmu.edu/afs/cs/Web/ People/jcl/papers/aoarl/Final.pdf.
Levine, Sergey, Finn, Chelsea, Darrell, Trevor, and Abbeel, Pieter. End-to-End Training of Deep Visuomotor Policies. Journal of Machine Learning Research, 17:1–40, 2016. ISSN 15337928. doi: 10.1007/ s13398-014-0173-7.2.
Lillicrap, Timothy P., Hunt, Jonathan J., Pritzel, Alexander, Heess, Nicolas, Erez, Tom, Tassa, Yuval, Silver, David, and Wierstra, Daan. Continuous control with deep reinforcement learning. In International Conference on Learning Representations, 2016. ISBN 2200000006. doi: 10.1561/2200000006.
Lipton, Zachary C., Gao, Jianfeng, Li, Lihong, Chen, Jianshu, and Deng, Li. Combating Deep Reinforcement Learning’s Sisyphean Curse with Intrinsic Fear. In arXiv, 2017. ISBN 2004012439. URL http: //arxiv.org/abs/1611.01211.
Mnih, Volodymyr, Kavukcuoglu, Koray, Silver, David, Rusu, Andrei a, Veness, Joel, Bellemare, Marc G, Graves, Alex, Riedmiller, Martin, Fidjeland, Andreas K, Ostrovski, Georg, Petersen, Stig, Beattie, Charles, Sadik, Amir, Antonoglou, Ioannis, King, Helen, Kumaran, Dharshan, Wierstra, Daan, Legg, Shane, and Hassabis, Demis. Human-level control through deep reinforcement learning. Nature, 518(7540):529–533, 2015. ISSN 0028-0836. doi: 10.1038/nature14236. URL http: //dx.doi.org/10.1038/nature14236.
Mnih, Volodymyr, Badia, Adri`a Puigdom`enech, Mirza, Mehdi, Graves, Alex, Lillicrap, Timothy P., Harley, Tim, Silver, David, and Kavukcuoglu, Koray. Asynchronous Methods for Deep Reinforcement Learning. pp. 1– 28, 2016. URL http://arxiv.org/abs/1602. 01783.
Moldovan, Teodor Mihai and Abbeel, Pieter. Safe Explo- ration in Markov Decision Processes. Proceedings of the 29th International Conference on Machine Learning, 2012. URL http://arxiv.org/abs/1205. 4810.
Ng, Andrew Y., Harada, Daishi, and Russell, Stuart. Pol- icy invariance under reward transformations : Theory
and application to reward shaping. Sixteenth International Conference on Machine Learning, 3:278–287, 1999. doi: 10.1.1.48.345.
Peters, Jan and Schaal, Stefan. Reinforcement learning of motor skills with policy gradients. Neural Networks, 21 (4):682–697, 2008. ISSN 08936080. doi: 10.1016/j. neunet.2008.02.003.
Pirotta, Matteo, Restelli, Marcello, and Calandriello, Daniele. Safe Policy Iteration. Proceedings of the 30th International Conference on Machine Learning, 28, 2013.
Schulman, John, Moritz, Philipp, Jordan, Michael, and Abbeel, Pieter. Trust Region Policy Optimization. International Conference on Machine Learning, 2015.
Schulman, John, Moritz, Philipp, Levine, Sergey, Jordan, Michael, and Abbeel, Pieter. High-Dimensional Continuous Control Using Generalized Advantage Estimation. arXiv, 2016.
Shalev-Shwartz, Shai, Shammah, Shaked, and Shashua, Amnon. Safe, Multi-Agent, Reinforcement Learning for Autonomous Driving. arXiv, 2016. URL http: //arxiv.org/abs/1610.03295.
Silver, David, Huang, Aja, Maddison, Chris J., Guez, Arthur, Sifre, Laurent, van den Driessche, George, Schrittwieser, Julian, Antonoglou, Ioannis, Panneershelvam, Veda, Lanctot, Marc, Dieleman, Sander, Grewe, Dominik, Nham, John, Kalchbrenner, Nal, Sutskever, Ilya, Lillicrap, Timothy, Leach, Madeleine, Kavukcuoglu, Koray, Graepel, Thore, and Hassabis, Demis. Mastering the game of Go with deep neural networks and tree search. Nature, 529(7587): 484–489, 2016. ISSN 0028-0836. doi: 10.1038/ nature16961. URL http://dx.doi.org/10. 1038/nature16961.
Sutton, Richard S and Barto, Andrew G. Introduction to Reinforcement Learning. Learning, 4(1996):1–5, 1998. ISSN 10743529. doi: 10.1.1.32.7692. URL http:// dl.acm.org/citation.cfm?id=551283.
Uchibe, Eiji and Doya, Kenji. Constrained reinforcement learning from intrinsic and extrinsic rewards. 2007 IEEE 6th International Conference on Development and Learning, ICDL, (February):163–168, 2007. doi: 10. 1109/DEVLRN.2007.4354030.
10.1. Proof of Policy Performance Bound
10.1.1. PRELIMINARIES
Our analysis will make extensive use of the discounted future state distribution, , which is defined as
It allows us to express the expected discounted total reward compactly as
where by , we mean
, and by
, we mean
. We drop the explicit notation for the sake of reducing clutter, but it should be clear from context that a and
depend on s.
First, we examine some useful properties of that become apparent in vector form for finite state spaces. Let
denote the vector with components
, and let
denote the transition matrix with components
; then
and
This formulation helps us easily obtain the following lemma. Lemma 1. For any function and any policy
,
Proof. Multiply both sides of (18) by and take the inner product with the vector
.
Combining this with (17), we obtain the following, for any function f and any policy :
This identity is nice for two reasons. First: if we pick f to be an approximator of the value function , then (20) relates the true discounted return of the policy (
) to the estimate of the policy return (
) and to the on-policy average TD-error of the approximator; this is aesthetically satisfying. Second: it shows that reward-shaping by
has the effect of translating the total discounted return by
, a fixed constant independent of policy; this illustrates the finding of Ng. et al. (1999) that reward shaping by
does not change the optimal policy.
It is also helpful to introduce an identity for the vector difference of the discounted future state visitation distributions on two different policies, and
. Define the matrices
,
, and
. Then:
left-multiplying by G and right-multiplying by , we obtain
Thus
For simplicity in what follows, we will only consider MDPs with finite state and action spaces, although our attention is on MDPs that are too large for tabular methods.
10.1.2. MAIN RESULTS
In this section, we will derive and present the new policy improvement bound. We will begin with a lemma:
Lemma 2. For any function and any policies
and
, define
and . Then the following bounds hold:
where is the total variational divergence. Furthermore, the bounds are tight (when
, the LHS and RHS are identically zero).
Proof. First, for notational convenience, let . (The choice of
to denote this quantity is intentionally suggestive—this bears a strong resemblance to a TD-error.) By (20), we obtain the identity
Now, we restrict our attention to the first term in this equation. Let denote the vector of components
. Observe that
This term is then straightforwardly bounded by applying H¨older’s inequality; for any such that 1/p+1/q = 1,
we have a
s
The lower bound leads to (23), and the upper bound leads to (24).
We choose p = 1 and ; however, we believe that this step is very interesting, and different choices for dealing with the inner product
may lead to novel and useful bounds.
Withand
, the bounds are almost obtained. The last step is to observe that, by the importance sampling identity,
π(a|s)
After grouping terms, the bounds are obtained.
This lemma makes use of many ideas that have been explored before; for the special case of , this strategy (after bounding
) leads directly to some of the policy improvement bounds previously obtained by Pirotta et al. and Schulman et al. The form given here is slightly more general, however, because it allows for freedom in choosing f.
Remark. It is reasonable to ask if there is a choice of f which maximizes the lower bound here. This turns out to trivially be . Observe that
. For all states,
(by the definition of
), thus
and
. Also,
; from (20) with
, we can
see that this exactly equals . Thus, for
, we recover an exact equality. While this is not practically useful to us (because, when we want to optimize a lower bound with respect to
, it is too expensive to evaluate
for each candidate to be practical), it provides insight: the penalty coefficient on the divergence captures information about the mismatch between f and
.
Next, we are interested in bounding the divergence term, . We give the following lemma; to the best of our knowledge, this is a new result.
Lemma 3. The divergence between discounted future state visitation distributions, , is bounded by an average divergence of the policies
and
:
Proof. First, using (21), we obtain
is bounded by:
To conclude the lemma, we bound .
The new policy improvement bound follows immediately.
Theorem 1. For any function and any policies
and
, define
,
π
δ
s, a, s
, and
Furthermore, the bounds are tight (when , all three expressions are identically zero).
Proof. Begin with the bounds from lemma 2 and bound the divergence by lemma 3.
10.2. Proof of Analytical Solution to LQCLP
Theorem 2 (Optimizing Linear Objective with Linear and Quadratic Constraints). Consider the problem
s.t. bx
(26) x
Hx
δ,
where , and
. When there is at least one strictly feasible point, the optimal point
satisfies
where and
are defined by
.
if λc
r > 0
otherwise,
with q H
g, r
H
b, and s
H
b.
Furthermore, let , and
. The value of
satisfies
with if
and
otherwise, and Proj(a, S) is the projection of a point x on to a set S. Note: the projection of a point
onto a convex segment of R, [a, b], has value Proj(x, [a, b]) = max(a, min(b, x)).
Proof. This is a convex optimization problem. When there is at least one strictly feasible point, strong duality holds by Slater’s theorem. We exploit strong duality to solve the problem analytically.
= max min
2
+ (
12
Strong duality
= max 12
(
) +
12
Plug in
= max Notation: q .
H
g, r .
H
b, s .
H
b.
Optimizing single-variable convex quadratic function over
if λ
λδ
if λ
Notation:
.
r > 0, λ
.
, λ
Observe that when and
; when
and
.
Notes on interpreting the coefficients in the dual problem:
• We are guaranteed to have by the Cauchy-Schwarz inequality. Recall that
,
. The Cauchy-Scwarz inequality gives:
and see if . The solution to this optimization problem is
, thus
. If
, then the plane intersects the trust region; otherwise, it does not.
If and c < 0, then the quadratic trust region lies entirely within the linear constraint-satisfying halfspace, and we can remove the linear constraint without changing the optimization problem. If
and c > 0, the problem is infeasible (the intersection of the quadratic trust region and linear constraint-satisfying halfspace is empty). Otherwise, we follow the procedure below.
Solving the dual for : for any A > 0, B > 0, the problem
has optimal point and optimal value
.
We can use this solution form to obtain the optimal point on each segment of the piecewise continuous dual function for :
objective optimal point (before projection) optimal point (after projection)
The optimization is completed by comparing and
:
otherwise.
10.3. Experimental Parameters
10.3.1. ENVIRONMENTS
In the Circle environments, the reward and cost functions are
where x, y are the coordinates in the plane, v is the velocity, and are environmental parameters. We set these parameters to be
Point-mass Ant Humanoid
In Point-Gather, the agent receives a reward of +10 for collecting an apple, and a cost of 1 for collecting a bomb. Two apples and eight bombs spawn on the map at the start of each episode. In Ant-Gather, the reward and cost structure was the same, except that the agent also receives a reward of for falling over (which results in the episode ending). Eight apples and eight bombs spawn on the map at the start of each episode.
Figure 5. In the Circle task, reward is maximized by moving along the green circle. The agent is not allowed to enter the blue regions, so its optimal constrained path follows the line segments AD and BC.
10.3.2. ALGORITHM PARAMETERS
In all experiments, we use Gaussian policies with mean vectors given as the outputs of neural networks, and with variances that are separate learnable parameters. The policy networks for all experiments have two hidden layers of sizes (64, 32) with tanh activation functions.
We use GAE-(Schulman et al., 2016) to estimate the advantages and constraint advantages, with neural network value functions. The value functions have the same architecture and activation functions as the policy networks. We found that having different
values for the regular advantages and the constraint advantages worked best. We denote the
used for the constraint advantages as .
For the failure prediction networks , we use neural networks with a single hidden layer of size (32), with output of one sigmoid unit. At each iteration, the failure prediction network is updated by some number of gradient descent steps using the Adam update rule to minimize the prediction error. To reiterate, the failure prediction network is a model for the probability that the agent will, at some point in the next T time steps, enter an unsafe state. The cost bonus was weighted by a coefficient
, which was 1 in all experiments except for Ant-Gather, where it was 0.01. Because of the short time horizon, no cost bonus was used for Point-Gather.
For all experiments, we used a discount factor of , a GAE-
for estimating the regular advantages of
0.95, and a KL-divergence step size of
.
Experiment-specific parameters are as follows:
Note that these same parameters were used for all algorithms.
We found that the Point environment was agnostic to , but for the higher-dimensional environments, it was necessary to set
to a value < 1. Failing to discount the constraint advantages led to substantial overestimates of the constraint gradient magnitude, which led the algorithm to take unsafe steps. The choice
was obtained by a hyperparameter search in {0.5, 0.92, 1}, but 0.92 worked nearly as well.
10.3.3. PRIMAL-DUAL OPTIMIZATION IMPLEMENTATION
Our primal-dual implementation is intended to be as close as possible to our CPO implementation. The key difference is that the dual variables for the constraints are stateful, learnable parameters, unlike in CPO where they are solved from scratch at each update.
The update equations for our PDO implementation are
where is from the backtracking line search (
and
, where J is the backtrack budget; this is the same line search as is used in CPO and TRPO), and
is a learning rate for the dual parameters.
is an important hyperparameter of the algorithm: if it is set to be too small, the dual variable won’t update quickly enough to meaningfully enforce the constraint; if it is too high, the algorithm will overcorrect in response to constraint violations and behave too conservatively. We experimented with a relaxed learning rate,
, and an aggressive learning rate,
. The aggressive learning rate performed better in our experiments, so all of our reported results are for
.
Selecting the correct learning rate can be challenging; the need to do this is obviated by CPO.