Trust Region Policy Optimization

John Schulman, Sergey Levine, Philipp Moritz, Michael I. Jordan, Pieter Abbeel

Introduction

Most algorithms for policy optimization can be classified into three broad categories: (1) policy iteration methods, which alternate between estimating the value function under the current policy and improving the policy (Bertsekas, 2005); (2) policy gradient methods, which use an estimator of the gradient of the expected return (total reward) obtained from sample trajectories (Peters & Schaal, 2008a) (and which, as we later discuss, have a close connection to policy iteration); and (3) derivative-free optimization methods, such as the cross-entropy method (CEM) and covariance matrix adaptation (CMA), which treat the return as a black box function to be optimized in terms of the policy parameters (Szita & Lörincz, 2006).

General derivative-free stochastic optimization methods such as CEM and CMA are preferred on many problems, because they achieve good results while being simple to understand and implement. For example, while Tetris is a classic benchmark problem for approximate dynamic programming (ADP) methods, stochastic optimization methods are difficult to beat on this task (Gabillon et al., 2013). For continuous control problems, methods like CMA have been successful at learning control policies for challenging tasks like locomotion when provided with hand-engineered policy classes with low-dimensional parameterizations (Wampler & Popović, 2009). The inability of ADP and gradient-based methods to consistently beat gradient-free random search is unsatisfying, since gradient-based optimization algorithms enjoy much better sample complexity guarantees than gradient-free methods (Nemirovski, 2005). Continuous gradient-based optimization has been very successful at learning function approximators for supervised learning tasks with huge numbers of parameters, and extending their success to reinforcement learning would allow for efficient training of complex and powerful policies.

In this article, we first prove that minimizing a certain surrogate objective function guarantees policy improvement with non-trivial step sizes. Then we make a series of approximations to the theoretically-justified algorithm, yielding a practical algorithm, which we call trust region policy optimization (TRPO). We describe two variants of this algorithm: first, the single-path method, which can be applied in the model-free setting; second, the vine method, which requires the system to be restored to particular states, which is typically only possible in simulation. These algorithms are scalable and can optimize nonlinear policies with tens of thousands of parameters, which have previously posed a major challenge for model-free policy search (Deisenroth et al., 2013). In our experiments, we show that the same TRPO methods can learn complex policies for swimming, hopping, and walking, as well as playing Atari games directly from raw images.

Preliminaries

Consider an infinite-horizon discounted Markov decision process (MDP), defined by the tuple (S,A,P,r,ρ0,γ)(\mathcal{S},\mathcal{A},P,r,\rho_{0},\gamma), where S\mathcal{S} is a finite set of states, A\mathcal{A} is a finite set of actions, P:S×A×SRP:\mathcal{S}\times\mathcal{A}\times\mathcal{S}\rightarrow\mathbb{R} is the transition probability distribution, r:SRr:\mathcal{S}\rightarrow\mathbb{R} is the reward function, ρ0:SR\rho_{0}:\mathcal{S}\rightarrow\mathbb{R} is the distribution of the initial state s0s_{0}, and γ(0,1)\gamma\in(0,1) is the discount factor.

Let π\pi denote a stochastic policy π:S×A\pi:\mathcal{S}\times\mathcal{A}\rightarrow, and let η(π)\eta(\pi) denote its expected discounted reward:

𝑡1𝑃conditionalsubscript𝑠𝑡1subscript𝑠𝑡subscript𝑎𝑡\displaystyle s_{0}\sim\rho_{0}(s_{0}),\ a_{t}\sim\pi(a_{t}|s_{t}),\ s_{t+1}\sim P(s_{t+1}|s_{t},a_{t}). We will use the following standard definitions of the state-action value function QπQ_{\pi}, the value function VπV_{\pi}, and the advantage function AπA_{\pi}:

𝑡1subscript𝑎𝑡1…delimited-[]superscriptsubscript𝑙0superscript𝛾𝑙𝑟subscript𝑠𝑡𝑙\displaystyle Q_{\pi}(s_{t},a_{t})=\mathbb{E}_{s_{t+1},a_{t+1},\dots}\left[\sum_{l=0}^{\infty}\gamma^{l}r(s_{t+l})\right], Vπ(st)= Eat,st+1,[l=0γlr(st+l)],\displaystyle V_{\pi}(s_{t})=\ \mathbb{E}_{a_{t},s_{t+1},\dots}\left[\sum_{l=0}^{\infty}\gamma^{l}r(s_{t+l})\right], Aπ(s,a)= Qπ(s,a)Vπ(s), where\displaystyle A_{\pi}(s,a)=\ Q_{\pi}(s,a)-V_{\pi}(s),\text{ where} \displaystyle\quad a_{t}\sim\pi(a_{t}|s_{t}),s_{t+1}\sim P(s_{t+1}|s_{t},a_{t})\text{\ fort\geq 0}. The following useful identity expresses the expected return of another policy π~\tilde{\pi} in terms of the advantage over π\pi, accumulated over timesteps (see Kakade & Langford (2002) or Appendix A for proof):

𝜂𝜋subscript𝔼similar-tosubscript𝑠0subscript𝑎0⋯~𝜋delimited-[]superscriptsubscript𝑡0superscript𝛾𝑡subscript𝐴𝜋subscript𝑠𝑡subscript𝑎𝑡\displaystyle\eta(\tilde{\pi})=\eta(\pi)+\mathbb{E}_{s_{0},a_{0},\dots\sim\tilde{\pi}}\left[\sum_{t=0}^{\infty}\gamma^{t}A_{\pi}(s_{t},a_{t})\right] (1) where the notation Es0,a0,π~[]\mathbb{E}_{s_{0},a_{0},\dots\sim\tilde{\pi}}\left[\dots\right] indicates that actions are sampled atπ~(st)a_{t}\sim\tilde{\pi}(\cdot|s_{t}). Let ρπ\rho_{\pi} be the (unnormalized) discounted visitation frequencies

𝑃subscript𝑠0𝑠𝛾𝑃subscript𝑠1𝑠superscript𝛾2𝑃subscript𝑠2𝑠…\displaystyle\rho_{\pi}(s)\!=\!P(s_{0}=s)\!+\!\gamma P(s_{1}=s)\!+\!\gamma^{2}P(s_{2}=s)\!+\!\dots, where s0ρ0s_{0}\sim\rho_{0} and the actions are chosen according to π\pi. We can rewrite Equation 1 with a sum over states instead of timesteps:

𝜂𝜋superscriptsubscript𝑡0subscript𝑠𝑃subscript𝑠𝑡conditional𝑠~𝜋subscript𝑎~𝜋conditional𝑎𝑠superscript𝛾𝑡subscript𝐴𝜋𝑠𝑎\displaystyle=\eta(\pi)+\sum_{t=0}^{\infty}\sum_{s}P(s_{t}=s|\tilde{\pi})\sum_{a}\tilde{\pi}(a|s)\gamma^{t}A_{\pi}(s,a) =η(π)+st=0γtP(st=sπ~)aπ~(as)Aπ(s,a)\displaystyle=\eta(\pi)+\sum_{s}\sum_{t=0}^{\infty}\gamma^{t}P(s_{t}=s|\tilde{\pi})\sum_{a}\tilde{\pi}(a|s)A_{\pi}(s,a) =η(π)+sρπ~(s)aπ~(as)Aπ(s,a).\displaystyle=\eta(\pi)+\sum_{s}\rho_{\tilde{\pi}}(s)\sum_{a}\tilde{\pi}(a|s)A_{\pi}(s,a). (2) This equation implies that any policy update ππ~\pi\rightarrow\tilde{\pi} that has a nonnegative expected advantage at every state ss, i.e., aπ~(as)Aπ(s,a)0\sum_{a}\tilde{\pi}(a|s)A_{\pi}(s,a)\geq 0, is guaranteed to increase the policy performance η\eta, or leave it constant in the case that the expected advantage is zero everywhere. This implies the classic result that the update performed by exact policy iteration, which uses the deterministic policy π~(s)=arg maxaAπ(s,a)\tilde{\pi}(s)=\operatorname*{arg\,max}_{a}A_{\pi}(s,a), improves the policy if there is at least one state-action pair with a positive advantage value and nonzero state visitation probability, otherwise the algorithm has converged to the optimal policy. However, in the approximate setting, it will typically be unavoidable, due to estimation and approximation error, that there will be some states ss for which the expected advantage is negative, that is, aπ~(as)Aπ(s,a)<0\sum_{a}\tilde{\pi}(a|s)A_{\pi}(s,a)<0. The complex dependency of ρπ~(s)\rho_{\tilde{\pi}}(s) on π~\tilde{\pi} makes Equation (2) difficult to optimize directly. Instead, we introduce the following local approximation to η\eta:

𝜂𝜋subscript𝑠subscript𝜌𝜋𝑠subscript𝑎~𝜋conditional𝑎𝑠subscript𝐴𝜋𝑠𝑎\displaystyle L_{\pi}(\tilde{\pi})=\eta(\pi)+\sum_{s}\rho_{\pi}(s)\sum_{a}\tilde{\pi}(a|s)A_{\pi}(s,a). (3) Note that LπL_{\pi} uses the visitation frequency ρπ\rho_{\pi} rather than ρπ~\rho_{\tilde{\pi}}, ignoring changes in state visitation density due to changes in the policy. However, if we have a parameterized policy πθ\pi_{\theta}, where πθ(as)\pi_{\theta}(a|s) is a differentiable function of the parameter vector θ\theta, then LπL_{\pi} matches η\eta to first order (see Kakade & Langford (2002)). That is, for any parameter value θ0\theta_{0},

Equation 4 implies that a sufficiently small step πθ0π~\pi_{\theta_{0}}\rightarrow\tilde{\pi} that improves LπθoldL_{\pi_{\theta_{\mathrm{old}}}} will also improve η\eta, but does not give us any guidance on how big of a step to take.

To address this issue, Kakade & Langford (2002) proposed a policy updating scheme called conservative policy iteration, for which they could provide explicit lower bounds on the improvement of η\eta. To define the conservative policy iteration update, let πold\pi_{\mathrm{old}} denote the current policy, and let π=arg maxπLπold(π)\pi^{\prime}=\operatorname*{arg\,max}_{\pi^{\prime}}L_{\pi_{\mathrm{old}}}(\pi^{\prime}). The new policy πnew\pi_{\mathrm{new}} was defined to be the following mixture:

1𝛼subscript𝜋oldconditional𝑎𝑠𝛼superscript𝜋′conditional𝑎𝑠\displaystyle\pi_{\mathrm{new}}(a|s)=(1-\alpha)\pi_{\mathrm{old}}(a|s)+\alpha\pi^{\prime}(a|s). (5) Kakade and Langford derived the following lower bound:

(We have modified it to make it slightly weaker but simpler.) Note, however, that so far this bound only applies to mixture policies generated by Equation (5). This policy class is unwieldy and restrictive in practice, and it is desirable for a practical policy update scheme to be applicable to all general stochastic policy classes.

Monotonic Improvement Guarantee for General Stochastic Policies

Equation 6, which applies to conservative policy iteration, implies that a policy update that improves the right-hand side is guaranteed to improve the true performance η\eta. Our principal theoretical result is that the policy improvement bound in Equation 6 can be extended to general stochastic policies, rather than just mixture polices, by replacing α\alpha with a distance measure between π\pi and π~\tilde{\pi}, and changing the constant ϵ\epsilon appropriately. Since mixture policies are rarely used in practice, this result is crucial for extending the improvement guarantee to practical problems. The particular distance measure we use is the total variation divergence, which is defined by DTV(p  q)=12ipiqiD_{TV}(p\ \|\ q)=\frac{1}{2}\sum_{i}|p_{i}-q_{i}| for discrete probability distributions p,qp,q.111Our result is straightforward to extend to continuous states and actions by replacing the sums with integrals. Define DTVmax(π,π~)D^{\rm max}_{\rm TV}(\pi,\tilde{\pi}) as

Let α=DTVmax(πold,πnew)\alpha=D^{\rm max}_{\rm TV}(\pi_{\mathrm{old}},\pi_{\mathrm{new}}). Then the following bound holds:

We provide two proofs in the appendix. The first proof extends Kakade and Langford’s result using the fact that the random variables from two distributions with total variation divergence less than α\alpha can be coupled, so that they are equal with probability 1α1-\alpha. The second proof uses perturbation theory.

Next, we note the following relationship between the total variation divergence and the KL divergence (Pollard (2000), Ch. 3): DTV(p  q)2DKL(p  q)D_{TV}(p\ \|\ q)^{2}\leq D_{\rm KL}(p\ \|\ q). Let DKLmax(π,π~)=maxsDKL(π(s)  π~(s)){D^{\rm max}_{\rm KL}}(\pi,\tilde{\pi})=\max_{s}D_{\rm KL}(\pi(\cdot|s)\ \|\ \tilde{\pi}(\cdot|s)). The following bound then follows directly from 1:

Algorithm 1 describes an approximate policy iteration scheme based on the policy improvement bound in Equation (9). Note that for now, we assume exact evaluation of the advantage values AπA_{\pi}.

𝑖1\displaystyle\qquad\pi_{i+1} =arg maxπ[Lπi(π)CDKLmax(πi,π)]\displaystyle=\operatorname*{arg\,max}_{\pi}\left[L_{\pi_{i}}(\pi)-C{D^{\rm max}_{\rm KL}}(\pi_{i},\pi)\right] where C=4ϵγ/(1γ)2C=4\epsilon\gamma/(1-\gamma)^{2}  ⁣ ⁣ ⁣ ⁣ ⁣ and Lπi(π) ⁣= ⁣η(πi) ⁣+ ⁣sρπi ⁣(s) ⁣a ⁣π(as)Aπi(s,a)\displaystyle\!\!\!\!\!\text{ and }L_{\pi_{i}}(\pi)\!=\!\eta(\pi_{i})\!+\!\sum_{s}\rho_{\pi_{i}}\!(s)\!\sum_{a}\!\pi(a|s)A_{\pi_{i}}(s,a) \State \For \State \State \EndFor Algorithm 1 Policy iteration algorithm guaranteeing non-decreasing expected return η\eta It follows from Equation 9 that Algorithm 1 is guaranteed to generate a monotonically improving sequence of policies η(π0)η(π1)η(π2)\eta(\pi_{0})\leq\eta(\pi_{1})\leq\eta(\pi_{2})\leq\dots. To see this, let Mi(π)=Lπi(π)CDKLmax(πi,π)M_{i}(\pi)=L_{\pi_{i}}(\pi)-C{D^{\rm max}_{\rm KL}}(\pi_{i},\pi). Then

𝑖1subscript𝑀𝑖subscript𝜋𝑖1 by Equation (9)\displaystyle\eta(\pi_{i+1})\geq M_{i}(\pi_{i+1})\text{ by Equation~{}\eqref{eq:klminorizer}} η(πi)=Mi(πi), therefore,\displaystyle\eta(\pi_{i})=M_{i}(\pi_{i}),\text{ therefore,} η(πi+1)η(πi)Mi(πi+1)M(πi).\displaystyle\eta(\pi_{i+1})-\eta(\pi_{i})\geq M_{i}(\pi_{i+1})-M(\pi_{i}). (10) Thus, by maximizing MiM_{i} at each iteration, we guarantee that the true objective η\eta is non-decreasing. This algorithm is a type of minorization-maximization (MM) algorithm (Hunter & Lange, 2004), which is a class of methods that also includes expectation maximization. In the terminology of MM algorithms, MiM_{i} is the surrogate function that minorizes η\eta with equality at πi\pi_{i}. This algorithm is also reminiscent of proximal gradient methods and mirror descent.

Trust region policy optimization, which we propose in the following section, is an approximation to Algorithm 1, which uses a constraint on the KL divergence rather than a penalty to robustly allow large updates.

Optimization of Parameterized Policies

In the previous section, we considered the policy optimization problem independently of the parameterization of π\pi and under the assumption that the policy can be evaluated at all states. We now describe how to derive a practical algorithm from these theoretical foundations, under finite sample counts and arbitrary parameterizations.

Since we consider parameterized policies πθ(as)\pi_{\theta}(a|s) with parameter vector θ\theta, we will overload our previous notation to use functions of θ\theta rather than π\pi, e.g. η(θ):=η(πθ)\eta(\theta)\vcentcolon=\eta(\pi_{\theta}), Lθ(θ~):=Lπθ(πθ~)L_{\theta}(\tilde{\theta})\vcentcolon=L_{\pi_{\theta}}(\pi_{\tilde{\theta}}), and DKL(θ  θ~):=DKL(πθ  πθ~)D_{\rm KL}(\theta\ \|\ \tilde{\theta})\vcentcolon=D_{\rm KL}(\pi_{\theta}\ \|\ \pi_{\tilde{\theta}}). We will use θold\theta_{\mathrm{old}} to denote the previous policy parameters that we want to improve upon.

The preceding section showed that η(θ)Lθold(θ)CDKLmax(θold,θ)\eta(\theta)\geq L_{\theta_{\mathrm{old}}}(\theta)-C{D^{\rm max}_{\rm KL}}(\theta_{\mathrm{old}},\theta), with equality at θ=θold\theta=\theta_{\mathrm{old}}. Thus, by performing the following maximization, we are guaranteed to improve the true objective η\eta:

In practice, if we used the penalty coefficient CC recommended by the theory above, the step sizes would be very small. One way to take larger steps in a robust way is to use a constraint on the KL divergence between the new policy and the old policy, i.e., a trust region constraint:

This problem imposes a constraint that the KL divergence is bounded at every point in the state space. While it is motivated by the theory, this problem is impractical to solve due to the large number of constraints. Instead, we can use a heuristic approximation which considers the average KL divergence:

We therefore propose solving the following optimization problem to generate a policy update:

Similar policy updates have been proposed in prior work (Bagnell & Schneider, 2003; Peters & Schaal, 2008b; Peters et al., 2010), and we compare our approach to prior methods in Section 7 and in the experiments in Section 8. Our experiments also show that this type of constrained update has similar empirical performance to the maximum KL divergence constraint in Equation (11).

Sample-Based Estimation of the Objective and Constraint

The previous section proposed a constrained optimization problem on the policy parameters (Equation (12)), which optimizes an estimate of the expected total reward η\eta subject to a constraint on the change in the policy at each update. This section describes how the objective and constraint functions can be approximated using Monte Carlo simulation.

We seek to solve the following optimization problem, obtained by expanding LθoldL_{\theta_{\mathrm{old}}} in Equation (12):

We first replace sρθold(s)[]\sum_{s}\rho_{\theta_{\mathrm{old}}}(s)\left[\dots\right] in the objective by the expectation 11γEsρθold[]\frac{1}{1-\gamma}\mathbb{E}_{s\sim\rho_{\theta_{\mathrm{old}}}}\left[\dots\right]. Next, we replace the advantage values AθoldA_{\theta_{\mathrm{old}}} by the QQ-values QθoldQ_{\theta_{\mathrm{old}}} in Equation (13), which only changes the objective by a constant. Last, we replace the sum over the actions by an importance sampling estimator. Using qq to denote the sampling distribution, the contribution of a single sns_{n} to the loss function is

Our optimization problem in Equation 13 is exactly equivalent to the following one, written in terms of expectations:

All that remains is to replace the expectations by sample averages and replace the QQ value by an empirical estimate. The following sections describe two different schemes for performing this estimation.

The first sampling scheme, which we call single path, is the one that is typically used for policy gradient estimation (Bartlett & Baxter, 2011), and is based on sampling individual trajectories. The second scheme, which we call vine, involves constructing a rollout set and then performing multiple actions from each state in the rollout set. This method has mostly been explored in the context of policy iteration methods (Lagoudakis & Parr, 2003; Gabillon et al., 2013).

In this estimation procedure, we collect a sequence of states by sampling s0ρ0s_{0}\sim\rho_{0} and then simulating the policy πθold\pi_{\theta_{\mathrm{old}}} for some number of timesteps to generate a trajectory s0,a0,s1,a1,,sT1,aT1,sTs_{0},a_{0},s_{1},a_{1},\dots,s_{T-1},a_{T-1},s_{T}. Hence, q(as)=πθold(as)q(a|s)=\pi_{\theta_{\mathrm{old}}}(a|s). Qθold(s,a)Q_{\theta_{\mathrm{old}}}(s,a) is computed at each state-action pair (st,at)(s_{t},a_{t}) by taking the discounted sum of future rewards along the trajectory.

2 Vine

In this estimation procedure, we first sample s0ρ0s_{0}\sim\rho_{0} and simulate the policy πθi\pi_{\theta_{i}} to generate a number of trajectories. We then choose a subset of NN states along these trajectories, denoted s1,s2,,sNs_{1},s_{2},\dots,s_{N}, which we call the “rollout set”. For each state sns_{n} in the rollout set, we sample KK actions according to an,kq(sn)a_{n,k}\sim q(\cdot|s_{n}). Any choice of q(sn)q(\cdot|s_{n}) with a support that includes the support of πθi(sn)\pi_{\theta_{i}}(\cdot|s_{n}) will produce a consistent estimator. In practice, we found that q(sn)=πθi(sn)q(\cdot|s_{n})=\pi_{\theta_{i}}(\cdot|s_{n}) works well on continuous problems, such as robotic locomotion, while the uniform distribution works well on discrete tasks, such as the Atari games, where it can sometimes achieve better exploration.

For each action an,ka_{n,k} sampled at each state sns_{n}, we estimate Q^θi(sn,an,k)\hat{Q}_{\theta_{i}}(s_{n},a_{n,k}) by performing a rollout (i.e., a short trajectory) starting with state sns_{n} and action an,ka_{n,k}. We can greatly reduce the variance of the QQ-value differences between rollouts by using the same random number sequence for the noise in each of the KK rollouts, i.e., common random numbers. See (Bertsekas, 2005) for additional discussion on Monte Carlo estimation of QQ-values and (Ng & Jordan, 2000) for a discussion of common random numbers in reinforcement learning.

In small, finite action spaces, we can generate a rollout for every possible action from a given state. The contribution to LθoldL_{\theta_{\mathrm{old}}} from a single state sns_{n} is as follows:

where the action space is A={a1,a2,,aK}\mathcal{A}=\left\{a_{1},a_{2},\dots,a_{K}\right\}. In large or continuous state spaces, we can construct an estimator of the surrogate objective using importance sampling. The self-normalized estimator (Owen (2013), Chapter 9) of LθoldL_{\theta_{\mathrm{old}}} obtained at a single state sns_{n} is

assuming that we performed KK actions an,1,an,2,,an,Ka_{n,1},a_{n,2},\dots,a_{n,K} from state sns_{n}. This self-normalized estimator removes the need to use a baseline for the QQ-values (note that the gradient is unchanged by adding a constant to the QQ-values). Averaging over snρ(π)s_{n}\sim\rho(\pi), we obtain an estimator for LθoldL_{\theta_{\mathrm{old}}}, as well as its gradient.

The vine and single path methods are illustrated in Figure 1. We use the term vine, since the trajectories used for sampling can be likened to the stems of vines, which branch at various points (the rollout set) into several short offshoots (the rollout trajectories).

The benefit of the vine method over the single path method that is our local estimate of the objective has much lower variance given the same number of QQ-value samples in the surrogate objective. That is, the vine method gives much better estimates of the advantage values. The downside of the vine method is that we must perform far more calls to the simulator for each of these advantage estimates. Furthermore, the vine method requires us to generate multiple trajectories from each state in the rollout set, which limits this algorithm to settings where the system can be reset to an arbitrary state. In contrast, the single path algorithm requires no state resets and can be directly implemented on a physical system (Peters & Schaal, 2008b).

Practical Algorithm

Here we present two practical policy optimization algorithm based on the ideas above, which use either the single path or vine sampling scheme from the preceding section. The algorithms repeatedly perform the following steps:

Use the single path or vine procedures to collect a set of state-action pairs along with Monte Carlo estimates of their QQ-values.

By averaging over samples, construct the estimated objective and constraint in Equation 14.

Approximately solve this constrained optimization problem to update the policy’s parameter vector θ\theta. We use the conjugate gradient algorithm followed by a line search, which is altogether only slightly more expensive than computing the gradient itself. See Appendix C for details.

With regard to (3), we construct the Fisher information matrix (FIM) by analytically computing the Hessian of the KL divergence, rather than using the covariance matrix of the gradients. That is, we estimate AijA_{ij} as 1Nn=1N2θiθjDKL(πθold(sn)  πθ(sn))\frac{1}{N}\sum_{n=1}^{N}\frac{\partial^{2}}{\partial\theta_{i}\partial\theta_{j}}D_{\rm KL}(\pi_{\theta_{\mathrm{old}}}(\cdot|s_{n})\ \|\ \pi_{\theta}(\cdot|s_{n})), rather than 1Nn=1Nθilogπθ(ansn)θjlogπθ(ansn)\frac{1}{N}\sum_{n=1}^{N}\frac{\partial}{\partial\theta_{i}}\log\pi_{\theta}(a_{n}|s_{n})\frac{\partial}{\partial\theta_{j}}\log\pi_{\theta}(a_{n}|s_{n}). The analytic estimator integrates over the action at each state sns_{n}, and does not depend on the action ana_{n} that was sampled. As described in Appendix C, this analytic estimator has computational benefits in the large-scale setting, since it removes the need to store a dense Hessian or all policy gradients from a batch of trajectories. The rate of improvement in the policy is similar to the empirical FIM, as shown in the experiments.

Let us briefly summarize the relationship between the theory from Section 3 and the practical algorithm we have described:

The theory justifies optimizing a surrogate objective with a penalty on KL divergence. However, the large penalty coefficient CC leads to prohibitively small steps, so we would like to decrease this coefficient. Empirically, it is hard to robustly choose the penalty coefficient, so we use a hard constraint instead of a penalty, with parameter δ\delta (the bound on KL divergence).

The constraint on DKLmax(θold,θ){D^{\rm max}_{\rm KL}}(\theta_{\mathrm{old}},\theta) is hard for numerical optimization and estimation, so instead we constrain DKL(θold,θ){\overline{D}_{\rm KL}}(\theta_{\mathrm{old}},\theta).

Our theory ignores estimation error for the advantage function. Kakade & Langford (2002) consider this error in their derivation, and the same arguments would hold in the setting of this paper, but we omit them for simplicity.

Connections with Prior Work

As mentioned in Section 4, our derivation results in a policy update that is related to several prior methods, providing a unifying perspective on a number of policy update schemes. The natural policy gradient (Kakade, 2002) can be obtained as a special case of the update in Equation (12) by using a linear approximation to LL and a quadratic approximation to the DKL{\overline{D}_{\rm KL}} constraint, resulting in the following problem:

The update is \theta_{\mathrm{new}}=\theta_{\mathrm{old}}+\frac{1}{\lambda}A(\theta_{\mathrm{old}})^{-1}\nabla_{\theta}L(\theta)\big{\rvert}_{\theta=\theta_{\mathrm{old}}}, where the stepsize 1λ\frac{1}{\lambda} is typically treated as an algorithm parameter. This differs from our approach, which enforces the constraint at each update. Though this difference might seem subtle, our experiments demonstrate that it significantly improves the algorithm’s performance on larger problems.

We can also obtain the standard policy gradient update by using an 2\ell_{2} constraint or penalty:

The policy iteration update can also be obtained by solving the unconstrained problem maximizeπLπold(π)\operatorname*{maximize}_{\pi}L_{\pi_{\mathrm{old}}}(\pi), using LL as defined in Equation 3.

Several other methods employ an update similar to Equation (12). Relative entropy policy search (REPS) (Peters et al., 2010) constrains the state-action marginals p(s,a)p(s,a), while TRPO constrains the conditionals p(as)p(a|s). Unlike REPS, our approach does not require a costly nonlinear optimization in the inner loop. Levine and Abbeel (2014) also use a KL divergence constraint, but its purpose is to encourage the policy not to stray from regions where the estimated dynamics model is valid, while we do not attempt to estimate the system dynamics explicitly. Pirotta et al. (2013) also build on and generalize Kakade and Langford’s results, and they derive different algorithms from the ones here.

Experiments

We designed our experiments to investigate the following questions:

What are the performance characteristics of the single path and vine sampling procedures?

TRPO is related to prior methods (e.g. natural policy gradient) but makes several changes, most notably by using a fixed KL divergence rather than a fixed penalty coefficient. How does this affect the performance of the algorithm?

Can TRPO be used to solve challenging large-scale problems? How does TRPO compare with other methods when applied to large-scale problems, with regard to final performance, computation time, and sample complexity?

To answer (1) and (2), we compare the performance of the single path and vine variants of TRPO, several ablated variants, and a number of prior policy optimization algorithms. With regard to (3), we show that both the single path and vine algorithm can obtain high-quality locomotion controllers from scratch, which is considered to be a hard problem. We also show that these algorithms produce competitive results when learning policies for playing Atari games from images using convolutional neural networks with tens of thousands of parameters.

We conducted the robotic locomotion experiments using the MuJoCo simulator (Todorov et al., 2012). The three simulated robots are shown in Figure 2. The states of the robots are their generalized positions and velocities, and the controls are joint torques. Underactuation, high dimensionality, and non-smooth dynamics due to contacts make these tasks very challenging. The following models are included in our evaluation:

Swimmer. 1010-dimensional state space, linear reward for forward progress and a quadratic penalty on joint effort to produce the reward r(x,u)=vx105u2r(x,u)=v_{x}-10^{-5}\|u\|^{2}. The swimmer can propel itself forward by making an undulating motion.

Hopper. 1212-dimensional state space, same reward as the swimmer, with a bonus of +1+1 for being in a non-terminal state. We ended the episodes when the hopper fell over, which was defined by thresholds on the torso height and angle.

Walker. 1818-dimensional state space. For the walker, we added a penalty for strong impacts of the feet against the ground to encourage a smooth walk rather than a hopping gait.

We used δ=0.01\delta=0.01 for all experiments. See Table 2 in the Appendix for more details on the experimental setup and parameters used. We used neural networks to represent the policy, with the architecture shown in Figure 3, and further details provided in Appendix D. To establish a standard baseline, we also included the classic cart-pole balancing problem, based on the formulation from Barto et al. (1983), using a linear policy with six parameters that is easy to optimize with derivative-free black-box optimization methods.

The following algorithms were considered in the comparison: single path TRPO; vine TRPO; cross-entropy method (CEM), a gradient-free method (Szita & Lörincz, 2006); covariance matrix adaption (CMA), another gradient-free method (Hansen & Ostermeier, 1996); natural gradient, the classic natural policy gradient algorithm (Kakade, 2002), which differs from single path by the use of a fixed penalty coefficient (Lagrange multiplier) instead of the KL divergence constraint; empirical FIM, identical to single path, except that the FIM is estimated using the covariance matrix of the gradients rather than the analytic estimate; max KL, which was only tractable on the cart-pole problem, and uses the maximum KL divergence in Equation (11), rather than the average divergence, allowing us to evaluate the quality of this approximation. The parameters used in the experiments are provided in Appendix E. For the natural gradient method, we swept through the possible values of the stepsize in factors of three, and took the best value according to the final performance.

Learning curves showing the total reward averaged across five runs of each algorithm are shown in Figure 4. Single path and vine TRPO solved all of the problems, yielding the best solutions. Natural gradient performed well on the two easier problems, but was unable to generate hopping and walking gaits that made forward progress. These results provide empirical evidence that constraining the KL divergence is a more robust way to choose step sizes and make fast, consistent progress, compared to using a fixed penalty. CEM and CMA are derivative-free algorithms, hence their sample complexity scales unfavorably with the number of parameters, and they performed poorly on the larger problems. The max KL method learned somewhat more slowly than our final method, due to the more restrictive form of the constraint, but overall the result suggests that the average KL divergence constraint has a similar effect as the theorecally justified maximum KL divergence. Videos of the policies learned by TRPO may be viewed on the project website: http://sites.google.com/site/trpopaper/.

Note that TRPO learned all of the gaits with general-purpose policies and simple reward functions, using minimal prior knowledge. This is in contrast with most prior methods for learning locomotion, which typically rely on hand-architected policy classes that explicitly encode notions of balance and stepping (Tedrake et al., 2004; Geng et al., 2006; Wampler & Popović, 2009).

2 Playing Games from Images

To evaluate TRPO on a partially observed task with complex observations, we trained policies for playing Atari games, using raw images as input. The games require learning a variety of behaviors, such as dodging bullets and hitting balls with paddles. Aside from the high dimensionality, challenging elements of these games include delayed rewards (no immediate penalty is incurred when a life is lost in Breakout or Space Invaders); complex sequences of behavior (Q*bert requires a character to hop on 2121 different platforms); and non-stationary image statistics (Enduro involves a changing and flickering background).

We tested our algorithms on the same seven games reported on in (Mnih et al., 2013) and (Guo et al., 2014), which are made available through the Arcade Learning Environment (Bellemare et al., 2013) The images were preprocessed following the protocol in Mnih et al (2013), and the policy was represented by the convolutional neural network shown in Figure 3, with two convolutional layers with 1616 channels and stride 22, followed by one fully-connected layer with 2020 units, yielding 33,500 parameters.

The results of the vine and single path algorithms are summarized in Table 1, which also includes an expert human performance and two recent methods: deep QQ-learning (Mnih et al., 2013), and a combination of Monte-Carlo Tree Search with supervised training (Guo et al., 2014), called UCC-I. The 500 iterations of our algorithm took about 30 hours (with slight variation between games) on a 16-core computer. While our method only outperformed the prior methods on some of the games, it consistently achieved reasonable scores. Unlike the prior methods, our approach was not designed specifically for this task. The ability to apply the same policy search method to methods as diverse as robotic locomotion and image-based game playing demonstrates the generality of TRPO.

Discussion

We proposed and analyzed trust region methods for optimizing stochastic control policies. We proved monotonic improvement for an algorithm that repeatedly optimizes a local approximation to the expected return of the policy with a KL divergence penalty, and we showed that an approximation to this method that incorporates a KL divergence constraint achieves good empirical results on a range of challenging policy learning tasks, outperforming prior methods. Our analysis also provides a perspective that unifies policy gradient and policy iteration methods, and shows them to be special limiting cases of an algorithm that optimizes a certain objective subject to a trust region constraint.

In the domain of robotic locomotion, we successfully learned controllers for swimming, walking and hopping in a physics simulator, using general purpose neural networks and minimally informative rewards. To our knowledge, no prior work has learned controllers from scratch for all of these tasks, using a generic policy search method and non-engineered, general-purpose policy representations. In the game-playing domain, we learned convolutional neural network policies that used raw images as inputs. This requires optimizing extremely high-dimensional policies, and only two prior methods report successful results on this task.

Since the method we proposed is scalable and has strong theoretical foundations, we hope that it will serve as a jumping-off point for future work on training large, rich function approximators for a range of challenging problems. At the intersection of the two experimental domains we explored, there is the possibility of learning robotic control policies that use vision and raw sensory data as input, providing a unified scheme for training robotic controllers that perform both perception and control. The use of more sophisticated policies, including recurrent policies with hidden state, could further make it possible to roll state estimation and control into the same policy in the partially-observed setting. By combining our method with model learning, it would also be possible to substantially reduce its sample complexity, making it applicable to real-world settings where samples are expensive.

Acknowledgements

We thank Emo Todorov and Yuval Tassa for providing the MuJoCo simulator; Bruno Scherrer, Tom Erez, Greg Wayne, and the anonymous ICML reviewers for insightful comments, and Vitchyr Pong and Shane Gu for pointing our errors in a previous version of the manuscript. This research was funded in part by the Office of Naval Research through a Young Investigator Award and under grant number N00014-11-1-0688, DARPA through a Young Faculty Award, by the Army Research Office through the MAST program.

References

Appendix A Proof of Policy Improvement Bound

This proof (of 1) uses techniques from the proof of Theorem 4.1 in (Kakade & Langford, 2002), adapting them to the more general setting considered in this paper. An informal overview is as follows. Our proof relies on the notion of coupling, where we jointly define the policies π\pi and π\pi^{\prime} so that they choose the same action with high probability =(1α)=(1-\alpha). Surrogate loss Lπ(π~)L_{\pi}(\tilde{\pi}) accounts for the the advantage of π~\tilde{\pi} the first time that it disagrees with π\pi, but not subsequent disagreements. Hence, the error in LπL_{\pi} is due to two or more disagreements between π\pi and π~\tilde{\pi}, hence, we get an O(α2)O(\alpha^{2}) correction term, where α\alpha is the probability of disagreement.

We start out with a lemma from Kakade & Langford (2002) that shows that the difference in policy performance η(π~)η(π)\eta(\tilde{\pi})-\eta(\pi) can be decomposed as a sum of per-timestep advantages.

\displaystyle\eta(\tilde{\pi})=\eta(\pi)+ Eτπ~[t=0γtAπ(st,at)]\displaystyle\mathbb{E}_{\tau\sim\tilde{\pi}}\left[\sum_{t=0}^{\infty}\gamma^{t}A_{\pi}(s_{t},a_{t})\right] This expectation is taken over trajectories τ:=(s0,a0,s1,a0,)\tau\vcentcolon=(s_{0},a_{0},s_{1},a_{0},\dots), and the notation Eτπ~[]\mathbb{E}_{\tau\sim\tilde{\pi}}\left[\dots\right] indicates that actions are sampled from π~\tilde{\pi} to generate τ\tau.

First note that Aπ(s,a)=EsP(ss,a)[r(s)+γVπ(s)Vπ(s)]A_{\pi}(s,a)=\mathbb{E}_{s^{\prime}\sim P(s^{\prime}|s,a)}\left[r(s)+\gamma V_{\pi}(s^{\prime})-V_{\pi}(s)\right]. Therefore,

𝑟subscript𝑠𝑡𝛾subscript𝑉𝜋subscript𝑠𝑡1subscript𝑉𝜋subscript𝑠𝑡\displaystyle=\mathbb{E}_{\tau|\tilde{\pi}}\left[\sum_{t=0}^{\infty}\gamma^{t}(r(s_{t})+\gamma V_{\pi}(s_{t+1})-V_{\pi}(s_{t}))\right] (21) =Eτπ~[Vπ(s0)+t=0γtr(st)]\displaystyle=\mathbb{E}_{\tau|\tilde{\pi}}\left[-V_{\pi}(s_{0})+\sum_{t=0}^{\infty}\gamma^{t}r(s_{t})\right] (22) =Es0[Vπ(s0)]+Eτπ~[t=0γtr(st)]\displaystyle=-\mathbb{E}_{s_{0}}\left[V_{\pi}(s_{0})\right]+\mathbb{E}_{\tau|\tilde{\pi}}\left[\sum_{t=0}^{\infty}\gamma^{t}r(s_{t})\right] (23) =η(π)+η(π~)\displaystyle=-\eta(\pi)+\eta(\tilde{\pi}) (24) Rearranging, the result follows. ∎

Define Aˉ(s)\bar{A}(s) to be the expected advantage of π~\tilde{\pi} over π\pi at state ss:

𝜂𝜋subscript𝔼similar-to𝜏~𝜋delimited-[]superscriptsubscript𝑡0superscript𝛾𝑡¯𝐴subscript𝑠𝑡\displaystyle\eta(\tilde{\pi})=\eta(\pi)+\mathbb{E}_{\tau\sim\tilde{\pi}}\left[\sum_{t=0}^{\infty}\gamma^{t}\bar{A}(s_{t})\right] (26) Note that LπL_{\pi} can be written as

𝜂𝜋subscript𝔼similar-to𝜏𝜋delimited-[]superscriptsubscript𝑡0superscript𝛾𝑡¯𝐴subscript𝑠𝑡\displaystyle L_{\pi}(\tilde{\pi})=\eta(\pi)+\mathbb{E}_{\tau\sim\pi}\left[\sum_{t=0}^{\infty}\gamma^{t}\bar{A}(s_{t})\right] (27) The difference in these equations is whether the states are sampled using π\pi or π~\tilde{\pi}. To bound the difference between η(π~)\eta(\tilde{\pi}) and Lπ(π~)L_{\pi}(\tilde{\pi}), we will bound the difference arising from each timestep. To do this, we first need to introduce a measure of how much π\pi and π~\tilde{\pi} agree. Specifically, we’ll couple the policies, so that they define a joint distribution over pairs of actions.

(π,π~)(\pi,\tilde{\pi}) is an α\alpha-coupled policy pair if it defines a joint distribution (a,a~)s(a,\tilde{a})|s, such that P(aa~s)αP(a\neq\tilde{a}|s)\leq\alpha for all ss. π\pi and π~\tilde{\pi} will denote the marginal distributions of aa and a~\tilde{a}, respectively.

Computationally, α\alpha-coupling means that if we randomly choose a seed for our random number generator, and then we sample from each of π\pi and π~\tilde{\pi} after setting that seed, the results will agree for at least fraction 1α1-\alpha of seeds.

Given that π,π~\pi,\tilde{\pi} are α\alpha-coupled policies, for all ss,

Let (π,π~)(\pi,\tilde{\pi}) be an α\alpha-coupled policy pair. Then

Given the coupled policy pair (π,π~)(\pi,\tilde{\pi}), we can also obtain a coupling over the trajectory distributions produced by π\pi and π~\tilde{\pi}, respectively. Namely, we have pairs of trajectories τ,τ~\tau,\tilde{\tau}, where τ\tau is obtained by taking actions from π\pi, and τ~\tilde{\tau} is obtained by taking actions from π~\tilde{\pi}, where the same random seed is used to generate both trajectories. We will consider the advantage of π~\tilde{\pi} over π\pi at timestep tt, and decompose this expectation based on whether π\pi agrees with π~\tilde{\pi} at all timesteps i<ti<t.

Let ntn_{t} denote the number of times that aia~ia_{i}\neq\tilde{a}_{i} for i<ti<t, i.e., the number of times that π\pi and π~\tilde{\pi} disagree before timestep tt.

𝑃subscript𝑛𝑡0subscript𝔼similar-tosubscript𝑠𝑡conditional~𝜋subscript𝑛𝑡0delimited-[]¯𝐴subscript𝑠𝑡𝑃subscript𝑛𝑡0subscript𝔼similar-tosubscript𝑠𝑡~𝜋ketsubscript𝑛𝑡0delimited-[]¯𝐴subscript𝑠𝑡\displaystyle\mathbb{E}_{s_{t}\sim\tilde{\pi}}\left[\bar{A}(s_{t})\right]=P(n_{t}=0)\mathbb{E}_{s_{t}\sim\tilde{\pi}|n_{t}=0}\left[\bar{A}(s_{t})\right]+P(n_{t}>0)\mathbb{E}_{s_{t}\sim\tilde{\pi}|n_{t}>0}\left[\bar{A}(s_{t})\right] (33) The expectation decomposes similarly for actions are sampled using π\pi:

𝑃subscript𝑛𝑡0subscript𝔼similar-tosubscript𝑠𝑡conditional𝜋subscript𝑛𝑡0delimited-[]¯𝐴subscript𝑠𝑡𝑃subscript𝑛𝑡0subscript𝔼similar-tosubscript𝑠𝑡𝜋ketsubscript𝑛𝑡0delimited-[]¯𝐴subscript𝑠𝑡\displaystyle\mathbb{E}_{s_{t}\sim\pi}\left[\bar{A}(s_{t})\right]=P(n_{t}=0)\mathbb{E}_{s_{t}\sim\pi|n_{t}=0}\left[\bar{A}(s_{t})\right]+P(n_{t}>0)\mathbb{E}_{s_{t}\sim\pi|n_{t}>0}\left[\bar{A}(s_{t})\right] (34) Note that the nt=0n_{t}=0 terms are equal:

because nt=0n_{t}=0 indicates that π\pi and π~\tilde{\pi} agreed on all timesteps less than tt. Subtracting Equations 33 and 34, we get

By definition of α\alpha, P(\pi,\tilde{\pi}\text{ agree at timestepi})\geq 1-\alpha, so P(nt=0)(1α)tP(n_{t}=0)\geq(1-\alpha)^{t}, and

subscript𝔼similar-tosubscript𝑠𝑡~𝜋ketsubscript𝑛𝑡0delimited-[]¯𝐴subscript𝑠𝑡subscript𝔼similar-tosubscript𝑠𝑡𝜋ketsubscript𝑛𝑡0delimited-[]¯𝐴subscript𝑠𝑡\displaystyle\leq\left|\mathbb{E}_{s_{t}\sim\tilde{\pi}|n_{t}>0}\left[\bar{A}(s_{t})\right]\right|+\left|\mathbb{E}_{s_{t}\sim\pi|n_{t}>0}\left[\bar{A}(s_{t})\right]\right| (38) 4αmaxs,aAπ(s,a)\displaystyle\leq 4\alpha\max_{s,a}{\left|A_{\pi}(s,a)\right|} (39) Where the second inequality follows from Lemma 3.

Plugging Equation 37 and Equation 39 into Equation 36, we get

The preceding Lemma bounds the difference in expected advantage at each timestep tt. We can sum over time to bound the difference between η(π~)\eta(\tilde{\pi}) and Lπ(π~)L_{\pi}(\tilde{\pi}). Subtracting Equation 26 and Equation 27, and defining ϵ=maxs,aAπ(s,a)\epsilon=\max_{s,a}{\left|A_{\pi}(s,a)\right|},

Last, to replace α\alpha by the total variation divergence, we need to use the correspondence between TV divergence and coupled random variables:

Suppose pXp_{X} and pYp_{Y} are distributions with DTV(pX  pY)=αD_{TV}(p_{X}\ \|\ p_{Y})=\alpha. Then there exists a joint distribution (X,Y)(X,Y) whose marginals are pX,pYp_{X},p_{Y}, for which X=YX=Y with probability 1α1-\alpha.

See (Levin et al., 2009), Proposition 4.7.

It follows that if we have two policies π\pi and π~\tilde{\pi} such that maxsDTV(π(s)  π~(s))α\max_{s}D_{TV}(\pi(\cdot|s)\ \|\ \tilde{\pi}(\cdot|s))\leq\alpha, then we can define an α\alpha-coupled policy pair (π,π~)(\pi,\tilde{\pi}) with appropriate marginals. Taking α=maxsDTV(π(s)  π~(s))α\alpha=\max_{s}D_{TV}(\pi(\cdot|s)\ \|\ \tilde{\pi}(\cdot|s))\leq\alpha in Equation 45, 1 follows.

Appendix B Perturbation Theory Proof of Policy Improvement Bound

We also provide an alternative proof of 1 using perturbation theory.

Let G=(1+γPπ+(γPπ)2+)=(1γPπ)1G=(1+\gamma P_{\pi}+(\gamma P_{\pi})^{2}+\dots)=(1-\gamma P_{\pi})^{-1}, and similarly Let G~=(1+γPπ~+(γPπ~)2+)=(1γPπ~)1\tilde{G}=(1+\gamma P_{\tilde{\pi}}+(\gamma P_{\tilde{\pi}})^{2}+\dots)=(1-\gamma P_{\tilde{\pi}})^{-1}. We will use the convention that ρ\rho (a density on state space) is a vector and rr (a reward function on state space) is a dual vector (i.e., linear functional on vectors), thus rρr\rho is a scalar meaning the expected reward under density ρ\rho. Note that η(π)=rGρ0\eta(\pi)=rG\rho_{0}, and η(π~)=cG~ρ0\eta(\tilde{\pi})=c\tilde{G}\rho_{0}. Let Δ=Pπ~Pπ\Delta=P_{\tilde{\pi}}-P_{\pi}. We want to bound η(π~)η(π)=r(G~G)ρ0\eta(\tilde{\pi})-\eta(\pi)=r(\tilde{G}-G)\rho_{0}. We start with some standard perturbation theory manipulations.

Left multiply by GG and right multiply by G~\tilde{G}.

𝐺𝛾𝐺Δ~𝐺\displaystyle=G+\gamma G\Delta\tilde{G} (47) Substituting the right-hand side into G~\tilde{G} gives

𝐺𝛾𝐺Δ𝐺superscript𝛾2𝐺Δ𝐺Δ~𝐺\displaystyle=G+\gamma G\Delta G+\gamma^{2}G\Delta G\Delta\tilde{G} (48) So we have

𝛾𝑟𝐺Δ𝐺subscript𝜌0superscript𝛾2𝑟𝐺Δ𝐺Δ~𝐺subscript𝜌0\displaystyle\eta(\tilde{\pi})-\eta(\pi)=r(\tilde{G}-G)\rho=\gamma rG\Delta G\rho_{0}+\gamma^{2}rG\Delta G\Delta\tilde{G}\rho_{0} (49) Let us first consider the leading term γrGΔGρ0\gamma rG\Delta G\rho_{0}. Note that rG=vrG=v, i.e., the infinite-horizon state-value function. Also note that Gρ0=ρπG\rho_{0}=\rho_{\pi}. Thus we can write γcGΔGρ0=γvΔρπ\gamma cG\Delta G\rho_{0}=\gamma v\Delta\rho_{\pi}. We will show that this expression equals the expected advantage Lπ(π~)Lπ(π)L_{\pi}(\tilde{\pi})-L_{\pi}(\pi).

𝑟𝑠subscriptsuperscript𝑠′𝑝conditionalsuperscript𝑠′𝑠𝑎𝛾𝑣superscript𝑠′𝑣𝑠\displaystyle=\sum_{s}\rho_{\pi}(s)\sum_{a}\left(\pi_{\theta}(a|s)-\pi_{\tilde{\theta}}(a|s)\right)\left[r(s)+\sum_{s^{\prime}}p(s^{\prime}|s,a)\gamma v(s^{\prime})-v(s)\right] =sρπ(s)sa(π(as)π~(as))p(ss,a)γv(s)\displaystyle=\sum_{s}\rho_{\pi}(s)\sum_{s^{\prime}}\sum_{a}\left(\pi(a|s)-\tilde{\pi}(a|s)\right)p(s^{\prime}|s,a)\gamma v(s^{\prime}) =sρπ(s)s(pπ(ss)pπ~(ss))γv(s)\displaystyle=\sum_{s}\rho_{\pi}(s)\sum_{s^{\prime}}(p_{\pi}(s^{\prime}|s)-p_{\tilde{\pi}}(s^{\prime}|s))\gamma v(s^{\prime}) =γvΔρπ\displaystyle=\gamma v\Delta\rho_{\pi} (50) Next let us bound the O(Δ2)O(\Delta^{2}) term γ2rGΔGΔG~ρ\gamma^{2}rG\Delta G\Delta\tilde{G}\rho. First we consider the product γrGΔ=γvΔ\gamma rG\Delta=\gamma v\Delta. Consider the component ss of this dual vector.

where the last line used the definition of the total-variation divergence, and the definition of ϵ=maxs,aAπ(s,a)\epsilon=\max_{s,a}{\left|A_{\pi}(s,a)\right|}. We bound the other portion GΔG~ρG\Delta\tilde{G}\rho using the 1\ell_{1} operator norm

where we have that G1=G~1=1/(1γ)\|G\|_{1}=\|\tilde{G}\|_{1}=1/(1-\gamma) and Δ1=2α\|\Delta\|_{1}=2\alpha. That gives

Appendix C Efficiently Solving the Trust-Region Constrained Optimization Problem

This section describes how to efficiently approximately solve the following constrained optimization problem, which we must solve at each iteration of TRPO:

The method we will describe involves two steps: (1) compute a search direction, using a linear approximation to objective and quadratic approximation to the constraint; and (2) perform a line search in that direction, ensuring that we improve the nonlinear objective while satisfying the nonlinear constraint.

The search direction is computed by approximately solving the equation Ax=gAx=g, where AA is the Fisher information matrix, i.e., the quadratic approximation to the KL divergence constraint: DKL(θold,θ)12(θθold)TA(θθold){\overline{D}_{\rm KL}}(\theta_{\mathrm{old}},\theta)\approx\frac{1}{2}(\theta-\theta_{\mathrm{old}})^{T}A(\theta-\theta_{\mathrm{old}}), where Aij=θiθjDKL(θold,θ)A_{ij}=\frac{\partial}{\partial\theta_{i}}\frac{\partial}{\partial\theta_{j}}{\overline{D}_{\rm KL}}(\theta_{\mathrm{old}},\theta). In large-scale problems, it is prohibitively costly (with respect to computation and memory) to form the full matrix AA (or A1A^{-1}). However, the conjugate gradient algorithm allows us to approximately solve the equation Ax=bAx=b without forming this full matrix, when we merely have access to a function that computes matrix-vector products yAyy\rightarrow Ay. Section C.1 describes the most efficient way to compute matrix-vector products with the Fisher information matrix. For additional exposition on the use of Hessian-vector products for optimizing neural network objectives, see (Martens & Sutskever, 2012) and (Pascanu & Bengio, 2013).

Having computed the search direction sA1gs\approx A^{-1}g, we next need to compute the maximal step length β\beta such that θ+βs\theta+\beta s will satisfy the KL divergence constraint. To do this, let δ=DKL12(βs)TA(βs)=12β2sTAs\delta={\overline{D}_{\rm KL}}\approx\frac{1}{2}(\beta s)^{T}A(\beta s)=\frac{1}{2}\beta^{2}s^{T}As. From this, we obtain β=2δ/sTAs\beta=\sqrt{2\delta/s^{T}As}, where δ\delta is the desired KL divergence. The term sTAss^{T}As can be computed through a single Hessian vector product, and it is also an intermediate result produced by the conjugate gradient algorithm.

Last, we use a line search to ensure improvement of the surrogate objective and satisfaction of the KL divergence constraint, both of which are nonlinear in the parameter vector θ\theta (and thus depart from the linear and quadratic approximations used to compute the step). We perform the line search on the objective Lθold(θ)X[DKL(θold,θ)δ]L_{\theta_{\mathrm{old}}}(\theta)-\mathcal{X}[{\overline{D}_{\rm KL}}(\theta_{\mathrm{old}},\theta)\leq\delta], where X[]\mathcal{X}[\dots] equals zero when its argument is true and ++\infty when it is false. Starting with the maximal value of the step length β\beta computed in the previous paragraph, we shrink β\beta exponentially until the objective improves. Without this line search, the algorithm occasionally computes large steps that cause a catastrophic degradation of performance.

Here we will describe how to compute the matrix-vector product between the averaged Fisher information matrix and arbitrary vectors. This matrix-vector product enables us to perform the conjugate gradient algorithm. Suppose that the parameterized policy maps from the input xx to “distribution parameter” vector μθ(x)\mu_{\theta}(x), which parameterizes the distribution π(ux)\pi(u|x). Now the KL divergence for a given input xx can be written as follows:

where kl\operatorname{kl} is the KL divergence between the distributions corresponding to the two mean parameter vectors. Differentiating kl\operatorname{kl} twice with respect to θ\theta, we obtain

subscript𝜇𝑎𝑥subscript𝜃𝑖subscript𝜇𝑏𝑥subscript𝜃𝑗subscriptsuperscriptkl′′𝑎𝑏subscript𝜇𝜃𝑥subscript𝜇oldsuperscript2subscript𝜇𝑎𝑥subscript𝜃𝑖subscript𝜃𝑗subscriptsuperscriptkl′𝑎subscript𝜇𝜃𝑥subscript𝜇old\displaystyle\frac{\partial\mu_{a}(x)}{\partial\theta_{i}}\frac{\partial\mu_{b}(x)}{\partial\theta_{j}}\operatorname{kl}^{\prime\prime}_{ab}(\mu_{\theta}(x),\mu_{\mathrm{old}})+\frac{\partial^{2}\mu_{a}(x)}{\partial\theta_{i}\partial\theta_{j}}\operatorname{kl}^{\prime}_{a}(\mu_{\theta}(x),\mu_{\mathrm{old}}) (57) where the primes (′) indicate differentiation with respect to the first argument, and there is an implied summation over indices a,ba,b. The second term vanishes, leaving just the first term. Let J:=μa(x)θiJ\vcentcolon=\frac{\partial\mu_{a}(x)}{\partial\theta_{i}} (the Jacobian), then the Fisher information matrix can be written in matrix form as JTMJJ^{T}MJ, where M=klab(μθ(x),μold)M=kl^{\prime\prime}_{ab}(\mu_{\theta}(x),\mu_{\mathrm{old}}) is the Fisher information matrix of the distribution in terms of the mean parameter μ\mu (as opposed to the parameter θ\theta). This has a simple form for most parameterized distributions of interest.

The Fisher-vector product can now be written as a function yJTMJyy\rightarrow J^{T}MJy. Multiplication by JTJ^{T} and JJ can be performed by most automatic differentiation and neural network packages (multiplication by JTJ^{T} is the well-known backprop operation), and the operation for multiplication by MM can be derived for the distribution of interest. Note that this Fisher-vector product is straightforward to average over a set of datapoints, i.e., inputs xx to μ\mu.

One could alternatively use a generic method for calculating Hessian-vector products using reverse mode automatic differentiation ((Wright & Nocedal, 1999), chapter 8), computing the Hessian of DKL{\overline{D}_{\rm KL}} with respect to θ\theta. This method would be slightly less efficient as it does not exploit the fact that the second derivatives of μ(x)\mu(x) (i.e., the second term in Equation 57) can be ignored, but may be substantially easier to implement.

We have described a procedure for computing the Fisher-vector product yAyy\rightarrow Ay, where the Fisher information matrix is averaged over a set of inputs to the function μ\mu. Computing the Fisher-vector product is typically about as expensive as computing the gradient of an objective that depends on μ(x)\mu(x) (Wright & Nocedal, 1999). Furthermore, we need to compute kk of these Fisher-vector products per gradient, where kk is the number of iterations of the conjugate gradient algorithm we perform. We found k=10k=10 to be quite effective, and using higher kk did not result in faster policy improvement. Hence, a naïve implementation would spend more than 90%90\% of the computational effort on these Fisher-vector products. However, we can greatly reduce this burden by subsampling the data for the computation of Fisher-vector product. Since the Fisher information matrix merely acts as a metric, it can be computed on a subset of the data without severely degrading the quality of the final step. Hence, we can compute it on 10%10\% of the data, and the total cost of Hessian-vector products will be about the same as computing the gradient. With this optimization, the computation of a natural gradient step A1gA^{-1}g does not incur a significant extra computational cost beyond computing the gradient gg.

Appendix D Approximating Factored Policies with Neural Networks

The policy, which is a conditional probability distribution πθ(as)\pi_{\theta}(a|s), can be parameterized with a neural network. This neural network maps (deterministically) from the state vector ss to a vector μ\mu, which specifies a distribution over action space. Then we can compute the likelihood p(aμ)p(a|\mu) and sample ap(aμ)a\sim p(a|\mu).

For our experiments with continuous state and action spaces, we used a Gaussian distribution, where the covariance matrix was diagonal and independent of the state. A neural network with several fully-connected (dense) layers maps from the input features to the mean of a Gaussian distribution. A separate set of parameters specifies the log standard deviation of each element. More concretely, the parameters include a set of weights and biases for the neural network computing the mean, {Wi,bi}i=1L\left\{W_{i},b_{i}\right\}_{i=1}^{L}, and a vector rr (log standard deviation) with the same dimension as aa. Then, the policy is defined by the normal distribution N(mean=NeuralNet(s;{Wi,bi}i=1L),stdev=exp(r))\mathcal{N}\left(\operatorname{mean}=\operatorname{NeuralNet}\left(s;\left\{W_{i},b_{i}\right\}_{i=1}^{L}\right),\operatorname{stdev}=\exp(r)\right). Here, μ=[mean,stdev]\mu=\left[\operatorname{mean},\operatorname{stdev}\right].

For the experiments with discrete actions (Atari), we use a factored discrete action space, where each factor is parameterized as a categorical distribution. That is, the action consists of a tuple (a1,a2,,aK)(a_{1},a_{2},\dots,a_{K}) of integers ak{1,2,,Nk}a_{k}\in\left\{1,2,\dots,N_{k}\right\}, and each of these components is assumed to have a categorical distribution, which is specified by a vector μk=[p1,p2,,pNk]\mu_{k}=[p_{1},p_{2},\dots,p_{N_{k}}]. Hence, μ\mu is defined to be the concatenation of the factors’ parameters: μ=[μ1,μ2,,μK]\mu=[\mu_{1},\mu_{2},\dots,\mu_{K}] and has dimension dimμ=k=1KNk\dim\mu=\sum_{k=1}^{K}N_{k}. The components of μ\mu are computed by taking applying a neural network to the input ss and then applying the softmax operator to each slice, yielding normalized probabilities for each factor.

Appendix E Experiment Parameters

Appendix F Learning Curves for the Atari Domain