b

DiscoverSearch
About
My stuff
Constrained Policy Optimization
2017·arXiv
Abstract
Abstract

For many applications of reinforcement learning it can be more convenient to specify both a reward function and constraints, rather than trying to design behavior through the reward function. For example, systems that physically interact with or around humans should satisfy safety constraints. Recent advances in policy search algorithms (Mnih et al., 2016; Schulman et al., 2015; Lillicrap et al., 2016; Levine et al., 2016) have enabled new capabilities in high-dimensional control, but do not consider the constrained setting.

We propose Constrained Policy Optimization (CPO), the first general-purpose policy search algorithm for constrained reinforcement learning with guarantees for near-constraint satisfaction at each iteration. Our method allows us to train neural network policies for high-dimensional control while making guarantees about policy behavior all throughout training. Our guarantees are based on a new theoretical result, which is of independent interest: we prove a bound relating the expected returns of two policies to an average divergence between them. We demonstrate the effectiveness of our approach on simulated robot locomotion tasks where the agent must satisfy constraints motivated by safety.

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, (S, A, R, P, µ), where S is the set of states, A is the set of actions,  R : S × A × S → Ris the reward function, P : S×A×S → [0, 1]is the transition probability function (where  P(s′|s, a)is the probability of transitioning to state s′given that the previous state was s and the agent took action a in s), and  µ : S → [0, 1]is the starting state distribution. A stationary policy  π : S → P(A)is a map from states to probability distributions over actions, with π(a|s)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,  J(π), which is typically taken to be the infinite horizon discounted total return,  J(π) .= Eτ∼π [�∞t=0 γtR(st, at, st+1)]. Here γ ∈ [0, 1)is the discount factor,  τdenotes a trajectory (τ = (s0, a0, s1, ...)), and  τ ∼ πis shorthand for indicating that the distribution over trajectories depends on  π: s0 ∼ µ, at ∼ π(·|st), st+1 ∼ P(·|st, at).

Letting  R(τ)denote the discounted return of a trajectory, we express the on-policy value function as  V π(s) .=Eτ∼π[R(τ)|s0 = s]and the on-policy action-value function as  Qπ(s, a) .= Eτ∼π[R(τ)|s0 = s, a0 = a]. The advantage function is  Aπ(s, a) .= Qπ(s, a) − V π(s).

Also of interest is the discounted future state distribution, dπ, defined by  dπ(s) = (1−γ) �∞t=0 γtP(st = s|π). It al- lows us to compactly express the difference in performance between two policies  π′, πas

image

where by  a ∼ π′, we mean  a ∼ π′(·|s), 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,  C1, ..., Cm(with each one a function  Ci : S × A × S → Rmapping transition tuples to costs, like the usual reward), and limits  d1, ..., dm. Let  JCi(π)denote the expected discounted return of policy  πwith respect to cost function Ci: JCi(π) = Eτ∼π [�∞t=0 γtCi(st, at, st+1)]. The set of feasible stationary policies for a CMDP is then

image

and the reinforcement learning problem in a CMDP is

image

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  JCias a constraint return, or  Ci-return for short. Lastly, we define on-policy value functions, action-value functions, and advantage functions for the auxiliary costs in analogy to  V π, Qπ, and  Aπ, with  Cireplacing R: respectively, we denote these by  V πCi, QπCi, and  AπCi.

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  J(π)over a local neighborhood of the most recent iterate  πk:

image

where D is some distance measure, and  δ > 0is a step size. When the objective is estimated by linearizing around πkas  J(πk) + gT (θ − θk), gis the policy gradient, and the standard policy gradient update is obtained by choosing D(π, πk) = ∥θ − θk∥2(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  Πθ ∩ ΠC:

image

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  πk, 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  f : S → Rand any policies π′and  π, define  δf(s, a, s′) .= R(s, a, s′) + γf(s′) − f(s),

image

where  DT V (π′||π)[s] = (1/2) �a |π′(a|s) − π(a|s)|is the total variational divergence between action distributions at s. The following bounds hold:

image

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  Es∼dπ [DT V (π′||π)[s]]with maxs DT V (π′||π)[s], picking  f = V π, and bounding  ϵπ′V πto get a second factor of  maxs DT V (π′||π)[s], 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  f = V πallows a useful form of the lower bound, so we give it as a corollary.

Corollary 1. For any policies  π′, π, with  ϵπ′ .=maxs |Ea∼π′[Aπ(s, a)]|, the following bound holds:

image

The bound (5) should be compared with equation (1). The term  (1 − γ)−1Es∼dπ,a∼π′[Aπ(s, a)]in (5) is an approximation to  J(π′) − J(π), using the state distribution  dπinstead of  dπ′, which is known to equal  J(π′) − J(π)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 J(π′) − J(π).

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  Ci, with  ϵπ′Ci .= maxs |Ea∼π′[AπCi(s, a)]|, the follow- ing bound holds:

image

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  DT V (p||q) ≤ �DKL(p||q)/2. Combining this with Jensen’s inequality, we obtain

image

From (7) we immediately obtain the following.

Corollary 3. In bounds (4), (5), and (6), make the substitution

image

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

image

where ¯DKL(π||πk) = Es∼πk [DKL(π||πk)[s]], and  δ > 0is the step size. The set  {πθ ∈ Πθ : ¯DKL(π||πk) ≤ δ}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  πk, πk+1are related by (8), and that  πk ∈ Πθ. A lower bound on the policy performance difference between πkand  πk+1is

image

Proof.  πkis a feasible point of (8) with objective value 0, so  Es∼dπk ,a∼πk+1 [Aπk(s, a)] ≥ 0. 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  αk, βikthe update

image

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 JCi(π)by (6).) The off-policy evaluation issue is alleviated, because both the objective and constraints involve expectations over state distributions  dπk, which we presume to have samples from. Because the bounds are tight, the problem is always feasible (as long as  π0is 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:

image

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  πk, πk+1are related by (10), and that  Πθin (10) is any set of policies with  πk ∈ Πθ. An upper bound on the  Ci-return of  πk+1is

image

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  πk, and the KLdivergence constraint is well-approximated by second order expansion (at  πk = π, the KL-divergence and its gradient are both zero). Denoting the gradient of the objective as g, the gradient of constraint i as  bi, the Hessian of the KL-divergence as H, and defining  ci .= JCi(πk) − di, the approximation to (10) is:

image

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  B .= [b1, ..., bm]and c .= [c1, ..., cm]T, a dual to (11) can be expressed as

image

where  r .= gT H−1B, S .= BT H−1B. 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

image

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

image

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  H−1gand  H−1bi, 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  πk. 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:

image

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,  C+i, instead of the original con- straints themselves. We do this by cost shaping:

image

where  ∆i : S × A × S → R+correlates in some useful way with  Ci.

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

image

where  αkis 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.

image

Constraint values: (closer to the limit is better)

image

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  C+.

We experiment with three different agents: a point-mass (S ⊆ R9, A ⊆ R2), a quadruped robot (called an ‘ant’) (S ⊆ R32, A ⊆ R8), and a simple humanoid  (S ⊆R102, A ⊆ R10). 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  C+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-

image

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  ν0 = 0, which exploits no prior knowledge about the

image

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  ν0high, 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  ν0 = 1000and 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.

image

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 R(s, a, s′) + λC+(s, a, s′)for  λ ∈ {1, 5, 50}.

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,  dπ, which is defined as

image

It allows us to express the expected discounted total reward compactly as

image

where by  a ∼ π, we mean  a ∼ π(·|s), and by  s′ ∼ P, we mean  s′ ∼ P(·|s, a). We drop the explicit notation for the sake of reducing clutter, but it should be clear from context that a and  s′depend on s.

First, we examine some useful properties of  dπthat become apparent in vector form for finite state spaces. Let  ptπ ∈ R|S|denote the vector with components  ptπ(s) = P(st = s|π), and let  Pπ ∈ R|S|×|S|denote the transition matrix with components  Pπ(s′|s) =�daP(s′|s, a)π(a|s); then  ptπ = Pπpt−1π = P tπµand

image

This formulation helps us easily obtain the following lemma. Lemma 1. For any function  f : S → Rand any policy  π,

Proof. Multiply both sides of (18) by  (I − γPπ)and take the inner product with the vector  f ∈ R|S|.

Combining this with (17), we obtain the following, for any function f and any policy  π:

image

This identity is nice for two reasons. First: if we pick f to be an approximator of the value function  V π, then (20) relates the true discounted return of the policy (J(π)) to the estimate of the policy return (Es∼µ[f(s)]) and to the on-policy average TD-error of the approximator; this is aesthetically satisfying. Second: it shows that reward-shaping by  γf(s′) − f(s)has the effect of translating the total discounted return by  Es∼µ[f(s)], a fixed constant independent of policy; this illustrates the finding of Ng. et al. (1999) that reward shaping by  γf(s′) + f(s)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  G .= (I − γPπ)−1, ¯G .= (I − γPπ′)−1, and  ∆ = Pπ′ − Pπ. Then:

image

left-multiplying by G and right-multiplying by ¯G, we obtain

image

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  f : S → Rand any policies  π′and  π, define

image

and  ϵπ′f .= maxs |Ea∼π′,s′∼P [R(s, a, s′) + γf(s′) − f(s)]|. Then the following bounds hold:

image

where  DT Vis the total variational divergence. Furthermore, the bounds are tight (when  π′ = π, the LHS and RHS are identically zero).

Proof. First, for notational convenience, let  δf(s, a, s′) .= R(s, a, s′) + γf(s′) − f(s). (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

image

Now, we restrict our attention to the first term in this equation. Let ¯δπ′f ∈ R|S|denote the vector of components  ¯δπ′f (s) =Ea∼π′,s′∼P [δf(s, a, s′)|s]. Observe that

image

This term is then straightforwardly bounded by applying H¨older’s inequality; for any  p, q ∈ [1, ∞]such that 1/p+1/q = 1,

we have �dπ, ¯δπ′f�+���dπ′ − dπ���p���¯δπ′f���q ≥ Es∼dπ′a∼π′s′∼P

The lower bound leads to (23), and the upper bound leads to (24).

We choose p = 1 and  q = ∞; however, we believe that this step is very interesting, and different choices for dealing with the inner product�dπ′ − dπ, ¯δπ′f�may lead to novel and useful bounds.

With���dπ′ − dπ���1 = 2DT V (dπ′||dπ)and���¯δπ′f���∞ = ϵπ′f, 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  f = V π, this strategy (after bounding  DT V (dπ′||dπ)) 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  f = V π′. Observe that  Es′∼P [δV π′ (s, a, s′)|s, a] = Aπ′(s, a). For all states,  Ea∼π′[Aπ′(s, a)] = 0(by the definition of  Aπ′), thus ¯δπ′V π′ = 0and  ϵπ′V π′ = 0. Also,  Lπ,V π′ (π′) = −Es∼dπ,a∼π�Aπ′(s, a)�; from (20) with  f = V π′, we can

see that this exactly equals  J(π′) − J(π). Thus, for  f = V π′, 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  V π′for each candidate to be practical), it provides insight: the penalty coefficient on the divergence captures information about the mismatch between f and  V π′.

Next, we are interested in bounding the divergence term,  ∥dπ′ − dπ∥1. 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,  ∥dπ′ −dπ∥1, is bounded by an average divergence of the policies  π′and  π:

image

Proof. First, using (21), we obtain

image

∥ ¯G∥1is bounded by:

image

To conclude the lemma, we bound  ∥∆dπ∥1.

image

The new policy improvement bound follows immediately.

Theorem 1. For any function  f : S → Rand any policies  π′and  π, define  δf(s, a, s′) .= R(s, a, s′) + γf(s′) − f(s),

image

��π′(a|s)π(a|s) − 1�δf(s, a, s′)�, and

image

Furthermore, the bounds are tight (when  π′ = π, all three expressions are identically zero).

Proof. Begin with the bounds from lemma 2 and bound the divergence  DT V (dπ′||dπ)by lemma 3.

10.2. Proof of Analytical Solution to LQCLP

Theorem 2 (Optimizing Linear Objective with Linear and Quadratic Constraints). Consider the problem

image

s.t. bTx  + c ≤ 0(26) xTHx  ≤δ,

where  g, b, x ∈ Rn, c, δ ∈ R, δ > 0, H ∈ Sn, and  H ≻ 0. When there is at least one strictly feasible point, the optimal point  x∗satisfies

image

where  λ∗and  ν∗are defined by

�fa(λ).= 12λ�r2s − q�+ λ2�c2s − δ�− rcsif λc  −r > 0

fb(λ) .= − 12� qλ + λδ�otherwise,

with q  = gTH−1g, r  = gTH−1b, and s  = bTH−1b.

Furthermore, let  Λa .= {λ|λc − r > 0, λ ≥ 0}, and  Λb .= {λ|λc − r ≤ 0, λ ≥ 0}. The value of  λ∗satisfies

image

with  λ∗ = λ∗aif  fa(λ∗a) > fb(λ∗b)and  λ∗ = λ∗botherwise, and Proj(a, S) is the projection of a point x on to a set S. Note: the projection of a point  x ∈ Ronto 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.

image

= max λ≥0ν≥0min xλ2 xT Hx+ (g + νb)T x +�νc −12λδ�Strong duality

image

= max λ≥0ν≥0−12λ(g + νb)T H−1 (g + νb) +�νc −12λδ�Plug in  x∗

= max λ≥0ν≥0− 12λ�q + 2νr + ν2s�+�νc − 12λδ�Notation: q .= gTH−1g, r .= gTH−1b, s .= bTH−1b.

image

�+Optimizing single-variable convex quadratic function over  R+

� 12λ�r2s − q�+ λ2�c2s − δ�− rcsif λ  ∈ Λa− 12� qλ +λδ�if λ  ∈ ΛbNotation: Λa.= {λ|λc −r > 0, λ  ≥ 0},Λb.= {λ|λc − r ≤ 0, λ  ≥ 0}

Observe that when  c < 0, Λa = [0, r/c)and  Λb = [r/c, ∞); when  c > 0, Λa = [r/c, ∞)and  Λb = [0, r/c).

Notes on interpreting the coefficients in the dual problem:

We are guaranteed to have  r2/s − q ≤ 0by the Cauchy-Schwarz inequality. Recall that  q = gT H−1g, r = gT H−1b, s = bT H−1b. The Cauchy-Scwarz inequality gives:

image

image

and see if  x∗T Hx∗ ≤ δ. The solution to this optimization problem is  x∗ = cH−1b/s, thus  x∗T Hx∗ = c2/s. If c2/s − δ ≤ 0, then the plane intersects the trust region; otherwise, it does not.

If  c2/s − δ > 0and 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  c2/s − δ > 0and 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  λ∗ =�A/Band optimal value  f(λ∗) = −√AB.

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)

image

The optimization is completed by comparing  fa(λ∗a)and  fb(λ∗b): λ∗ =� λ∗a fa(λ∗a) ≥ fb(λ∗b)λ∗botherwise.

image

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  d, xlimare environmental parameters. We set these parameters to be

Point-mass Ant Humanoid

image

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  −10for falling over (which results in the episode ending). Eight apples and eight bombs spawn on the map at the start of each episode.

image

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  λGAEvalues for the regular advantages and the constraint advantages worked best. We denote the  λGAE

used for the constraint advantages as  λGAEC.

For the failure prediction networks  Pφ(s → U), 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  γ = 0.995, a GAE-λfor estimating the regular advantages of  λGAE =0.95, and a KL-divergence step size of  δKL = 0.01.

Experiment-specific parameters are as follows:

image

Note that these same parameters were used for all algorithms.

We found that the Point environment was agnostic to  λGAEC, but for the higher-dimensional environments, it was necessary to set  λGAECto 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  λGAEC = 0.5was 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  sjis from the backtracking line search (s ∈ (0, 1)and  j ∈ {0, 1, ..., J}, 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,  α = 0.001, and an aggressive learning rate,  α = 0.01. The aggressive learning rate performed better in our experiments, so all of our reported results are for  α = 0.01.

Selecting the correct learning rate can be challenging; the need to do this is obviated by CPO.


Designed for Accessibility and to further Open Science