Learning Continuous Control Policies by Stochastic Value Gradients
Nicolas Heess, Greg Wayne, David Silver, Timothy Lillicrap, Yuval Tassa, Tom Erez
Introduction
Policy gradient algorithms maximize the expectation of cumulative reward by following the gradient of this expectation with respect to the policy parameters. Most existing algorithms estimate this gradient in a model-free manner by sampling returns from the real environment and rely on a likelihood ratio estimator . Such estimates tend to have high variance and require large numbers of samples or, conversely, low-dimensional policy parameterizations.
A second approach to estimate a policy gradient relies on backpropagation instead of likelihood ratio methods. If a differentiable environment model is available, one can link together the policy, model, and reward function to compute an analytic policy gradient by backpropagation of reward along a trajectory . Instead of using entire trajectories, one can estimate future rewards using a learned value function (a critic) and compute policy gradients from subsequences of trajectories. It is also possible to backpropagate analytic action derivatives from a Q-function to compute the policy gradient without a model . Following Fairbank , we refer to methods that compute the policy gradient through backpropagation as value gradient methods.
In this paper, we address two limitations of prior value gradient algorithms. The first is that, in contrast to likelihood ratio methods, value gradient algorithms are only suitable for training deterministic policies. Stochastic policies have several advantages: for example, they can be beneficial for partially observed problems ; they permit on-policy exploration; and because stochastic policies can assign probability mass to off-policy trajectories, we can train a stochastic policy on samples from an experience database in a principled manner. When an environment model is used, value gradient algorithms have also been critically limited to operation in deterministic environments. By exploiting a mathematical tool known as “re-parameterization” that has found recent use for generative models , we extend the scope of value gradient algorithms to include the optimization of stochastic policies in stochastic environments. We thus describe our framework as Stochastic Value Gradient (SVG) methods. Secondly, we show that an environment dynamics model, value function, and policy can be learned jointly with neural networks based only on environment interaction. Learned dynamics models are often inaccurate, which we mitigate by computing value gradients along real system trajectories instead of planned ones, a feature shared by model-free methods . This substantially reduces the impact of model error because we only use models to compute policy gradients, not for prediction, combining advantages of model-based and model-free methods with fewer of their drawbacks.
We present several algorithms that range from model-based to model-free methods, flexibly combining models of environment dynamics with value functions to optimize policies in stochastic or deterministic environments. Experimentally, we demonstrate that SVG methods can be applied using generic neural networks with tens of thousands of parameters while making minimal assumptions about plants or environments. By examining a simple stochastic control problem, we show that SVG algorithms can optimize policies where model-based planning and likelihood ratio methods cannot. We provide evidence that value function approximation can compensate for degraded models, demonstrating the increased robustness of SVG methods over model-based planning. Finally, we use SVG algorithms to solve a variety of challenging, under-actuated, physical control problems, including swimming of snakes, reaching, tracking, and grabbing with a robot arm, fall-recovery for a monoped, and locomotion for a planar cheetah and biped.
Background
In what follows, we make extensive use of the state-action-value Q-function and state-value V-function.
For finite-horizon problems, the value functions are time-dependent, e.g., , and for infinite-horizon problems the value functions are stationary, . The relevant meaning should be clear from the context. The state-value function can be expressed recursively using the stochastic Bellman equation
Deterministic value gradients
The deterministic Bellman equation takes the form for a deterministic model and deterministic policy . Differentiating the equation with respect to the state and policy yields an expression for the value gradient
In eq. 4, the term arises because the total derivative includes policy gradient contributions from subsequent time steps (full derivation in Appendix A). For a purely model-based formalism, these equations are used as a pair of coupled recursions that, starting from the termination of a trajectory, proceed backward in time to compute the gradient of the value function with respect to the state and policy parameters. returns the total policy gradient. When a state-value function is used after one step in the recursion, directly expresses the contribution of the current time step to the policy gradient. Summing these gradients over the trajectory gives the total policy gradient. When a Q-function is used, the per-time step contribution to the policy gradient takes the form .
Stochastic value gradients
One limitation of the gradient computation in eqs. 3 and 4 is that the model and policy must be deterministic. Additionally, the accuracy of the policy gradient is highly sensitive to modeling errors. We introduce two critical changes: First, in section 4.1, we transform the stochastic Bellman equation (eq. 2) to permit backpropagating value information in a stochastic setting. This also enables us to compute gradients along real trajectories, not ones sampled from a model, making the approach robust to model error, leading to our first algorithm “SVG(),” described in section 4.2. Second, in section 4.3, we show how value function critics can be integrated into this framework, leading to the algorithms “SVG()” and “SVG()”, which expand the Bellman recursion for 1 and 0 steps, respectively. Value functions further increase robustness to model error and extend our framework to infinite-horizon control.
The advantage of working with re-parameterized distributions is that we can now obtain a simple Monte-Carlo estimator of the derivative of an expectation with respect to :
In contrast to likelihood ratio-based Monte Carlo estimators, , this formula makes direct use of the Jacobian of .
Re-parameterization of the Bellman equation
We now re-parameterize the Bellman equation. When re-parameterized, the stochastic policy takes the form , and the stochastic environment the form for noise variables and , respectively. Inserting these functions into eq. (2) yields
Differentiating eq. 6 with respect to the current state and policy parameters gives
We are interested in controlling systems with a priori unknown dynamics. Consequently, in the following, we replace instances of or its derivatives with a learned model .
Gradient evaluation by planning
A planning method to compute a gradient estimate is to compute a trajectory by running the policy in loop with a model while sampling the associated noise variables, yielding a trajectory . On this sampled trajectory, a Monte-Carlo estimate of the policy gradient can be computed by the backward recursions:
where have written lower-case to emphasize that the quantities are one-sample estimatesIn the finite-horizon formulation, the gradient calculation starts at the end of the trajectory for which the only terms remaining in eq. (9) are . After the recursion, the total derivative of the value function with respect to the policy parameters is given by , which is a one-sample estimate of ., and “\big{|}_{x}” means “evaluated at ”.
Gradient evaluation on real trajectories
An important advantage of stochastic over deterministic models is that they can assign probability mass to observations produced by the real environment. In a deterministic formulation, there is no principled way to account for mismatch between model predictions and observed trajectories. In this case, the policy and environment noise that produced the observed trajectory are considered unknown. By an application of Bayes’ rule, which we explain in Appendix B, we can rewrite the expectations in equations 7 and 8 given the observations as
where we can now replace the two outer expectations with samples derived from interaction with the real environment. In the special case of additive noise, , it is possible to use a deterministic model to compute the derivatives . The noise’s influence is restricted to the gradient of the value of the next state, , and does not affect the model Jacobian. If we consider it desirable to capture more complicated environment noise, we can use a re-parameterized generative model and infer the missing noise variables, possibly by sampling from .
2 SVG(∞\infty)
SVG() computes value gradients by backward recursions on finite-horizon trajectories. After every episode, we train the model, , followed by the policy, . We provide pseudocode for this in Algorithm 1 but discuss further implementation details in section 5 and in the experiments.
3 SVG(1) and SVG(0)
In our framework, we may learn a parametric estimate of the expected value (critic) with parameters . The derivative of the critic value with respect to the state, , can be used in place of the sample gradient estimate given in eq. (9). The critic can reduce the variance of the gradient estimates because approximates the expectation of future rewards while eq. (9) provides only a single-trajectory estimate. Additionally, the value function can be used at the end of an episode to approximate the infinite-horizon policy gradient. Finally, eq. (9) involves the repeated multiplication of Jacobians of the approximate model , . Just as model error can compound in forward planning, model gradient error can compound during backpropagation. Furthermore, SVG() is on-policy. That is, after each episode, a single gradient-based update is made to the policy, and the policy optimization does not revisit those trajectory data again. To increase data-efficiency, we construct an off-policy, experience replay algorithm that uses models and value functions, SVG(1) with Experience Replay (SVG(1)-ER). This algorithm also has the advantage that it can perform an infinite-horizon computation.
To construct an off-policy estimator, we perform importance-weighting of the current policy distribution with respect to a proposal distribution, :
Specifically, we maintain a database with tuples of past state transitions . Each proposal drawn from is a sample of a tuple from the database. At time , the importance-weight , where comprise the policy parameters in use at the historical time step . We do not importance-weight the marginal distribution over states generated by a policy; this is widely considered to be intractable.
Similarly, we use experience replay for value function learning. Details can be found in Appendix C. Pseudocode for the SVG() algorithm with Experience Replay is in Algorithm 2.
Model and value learning
We can use almost any kind of differentiable, generative model. In our work, we have parameterized the models as neural networks. Our framework supports nonlinear state- and action-dependent noise, notable properties of biological actuators. For example, this can be described by the parametric form . Model learning amounts to a purely supervised problem based on observed state transitions. Our model and policy training occur jointly. There is no “motor-babbling” period used to identify the model. As new transitions are observed, the model is trained first, followed by the value function (for SVG()), followed by the policy. To ensure that the model does not forget information about state transitions, we maintain an experience database and cull batches of examples from the database for every model update. Additionally, we model the state-change by and have found that constructing models as separate sub-networks per predicted state dimension improved model quality significantly.
Our framework also permits a variety of means to learn the value function models. We can use temporal difference learning or regression to empirical episode returns. Since SVG() is model-based, we can also use Bellman residual minimization . In practice, we used a version of “fitted” policy evaluation. Pseudocode is available in Appendix C, Algorithm 4.
Experiments
We tested the SVG algorithms in two sets of experiments. In the first set of experiments (section 6.1), we test whether evaluating gradients on real environment trajectories and value function approximation can reduce the impact of model error. In our second set (section 6.2), we show that SVG(1) can be applied to several complicated, multidimensional physics environments involving contact dynamics (Figure 1) in the MuJoCo simulator . Below we only briefly summarize the main properties of each environment: further details of the simulations can be found in Appendix D and supplement. In all cases, we use generic, 2 hidden-layer neural networks with tanh activation functions to represent models, value functions, and policies. A video montage is available at https://youtu.be/PYdL7bcn_cM.
To demonstrate the difficulty of planning with a stochastic model, we first present a very simple control problem for which SVG() easily learns a control policy but for which an otherwise identical planner fails entirely. Our example is based on a problem due to . The policy directly controls the velocity of a point-mass “hand” on a 2D plane. By means of a spring-coupling, the hand exerts a force on a ball mass; the ball additionally experiences a gravitational force and random forces (Gaussian noise). The goal is to bring hand and ball into one of two randomly chosen target configurations with a relevant reward being provided only at the final time step.
With simulation time step , this demands controlling and backpropagating the distal reward along a trajectory of steps. Because this experiment has a non-stationary, time-dependent value function, this problem also favors model-based value gradients over methods using value functions. SVG() easily learns this task, but the planner, which uses trajectories from the model, shows little improvement. The planner simulates trajectories using the learned stochastic model and backpropagates along those simulated trajectories (eqs. 9 and 10) . The extremely long time-horizon lets prediction error accumulate and thus renders roll-outs highly inaccurate, leading to much worse final performance (c.f. Fig. 2, left).We also tested REINFORCE on this problem but achieved very poor results due to the long horizon.
Robustness to degraded models and value functions
We investigated the sensitivity of SVG() and SVG(1) to the quality of the learned model on Swimmer. Swimmer is a chain body with multiple links immersed in a fluid environment with drag forces that allow the body to propel itself . We build chains of 3, 5, or 7 links, corresponding to 10, 14, or 18-dimensional state spaces with 2, 4, or 6-dimensional action spaces. The body is initialized in random configurations with respect to a central goal location. Thus, to solve the task, the body must turn to re-orient and then produce an undulation to move to the goal.
To assess the impact of model quality, we learned to control a link-3 swimmer with SVG() and SVG(1) while varying the capacity of the network used to model the environment (5, 10, or 20 hidden units for each state dimension subnetwork (Appendix D); i.e., in this task we intentionally shrink the neural network model to investigate the sensitivity of our methods to model inaccuracy. While with a high capacity model (20 hidden units per state dimension), both SVG() and SVG(1) successfully learn to solve the task, the performance of SVG() drops significantly as model capacity is reduced (c.f. Fig. 3, middle). SVG(1) still works well for models with only 5 hidden units, and it also scales up to 5 and 7-link versions of the swimmer (Figs. 3, right and 4, left). To compare SVG(1) to conventional model-free approaches, we also tested a state-of-the-art actor-critic algorithm that learns a -function and updates the policy using the TD-error as an estimate of the advantage, yielding the policy gradient . (SVG(1) and the AC algorithm used the same code for learning .) SVG(1) outperformed the model-free approach in the 3-, 5-, and 7-link swimmer tasks (c.f. Fig. 3, left, right; Fig. 4, top left). In figure panels 2, middle, 3, right, and 4, left column, we show that experience replay for the policy can improve the data efficiency and performance of SVG(1).
Similarly, we tested the impact of varying the capacity of the value function approximator (Fig. 2, right) on a cart-pole. The V-function-based SVG(1) degrades less severely than the Q-function-based DPG presumably because it computes the policy gradient with the aid of the dynamics model.
2 SVG in complex environments
In a second set of experiments we demonstrated that SVG(1)-ER can be applied to several challenging physical control problems with stochastic, non-linear, and discontinuous dynamics due to contacts. Reacher is an arm stationed within a walled box with 6 state dimensions and 3 action dimensions and the coordinates of a target site, giving 8 state dimensions in total. In 4-Target Reacher, the site was randomly placed at one of the four corners of the box, and the arm in a random configuration at the beginning of each trial. In Moving-Target Reacher, the site moved at a randomized speed and heading in the box with reflections at the walls. Solving this latter problem implies that the policy has generalized over the entire work space. Gripper augments the reacher arm with a manipulator that can grab a ball in a randomized position and return it to a specified site. Monoped has 14 state dimensions, 4 action dimensions, and ground contact dynamics. The monoped begins falling from a height and must remain standing. Additionally, we apply Gaussian random noise to the torques controlling the joints with a standard deviation of of the total possible actuator strength at all points in time, reducing the stability of upright postures. Half-Cheetah is a planar cat robot designed to run based on with 18 state dimensions and 6 action dimensions. Half-Cheetah has a version with springs to aid balanced standing and a version without them. Walker is a planar biped, based on the environment from .
Figure 4 shows learning curves for several repeats for each of the tasks. We found that in all cases SVG(1) solved the problem well; we provide videos of the learned policies in the supplemental material. The 4-target reacher reliably finished at the target site, and in the tracking task followed the moving target successfully. SVG(1)-ER has a clear advantage on this task as also borne out in the cart-pole and swimmer experiments. The cheetah gaits varied slightly from experiment to experiment but in all cases made good forward progress. For the monoped, the policies were able to balance well beyond the 200 time steps of training episodes and were able to resist significantly higher adversarial noise levels than used during training (up to noise). We were able to learn gripping and walking behavior, although walking policies that achieved similar reward levels did not always exhibit equally good walking phenotypes.
Related work
Writing the noise variables as exogenous inputs to the system to allow direct differentiation with respect to the system state (equation 7) is a known device in control theory where the model is given analytically. The idea of using a model to optimize a parametric policy around real trajectories is presented heuristically in and for deterministic policies and models. Also in the limit of deterministic policies and models, the recursions we have derived in Algorithm 1 reduce to those of . Werbos defines an actor-critic algorithm called Heuristic Dynamic Programming that uses a deterministic model to roll-forward one step to produce a state prediction that is evaluated by a value function . Deisenroth et al. have used Gaussian process models to compute policy gradients that are sensitive to model-uncertainty , and Levine et al. have optimized impressive policies with the aid of a non-parametric trajectory optimizer and locally-linear models . Our work in contrast has focused on using global, neural network models conjoined to value function approximators.
Discussion
We have shown that two potential problems with value gradient methods, their reliance on planning and restriction to deterministic models, can be exorcised, broadening their relevance to reinforcement learning. We have shown experimentally that the SVG framework can train neural network policies in a robust manner to solve interesting continuous control problems. The framework includes algorithm variants beyond the ones tested in this paper, for example, ones that combine a value function with steps of back-propagation through a model (SVG(k)). Augmenting SVG(1) with experience replay led to the best results, and a similar extension could be applied to any SVG(k). Furthermore, we did not harness sophisticated generative models of stochastic dynamics, but one could readily do so, presenting great room for growth.
We thank Arthur Guez, Danilo Rezende, Hado van Hasselt, John Schulman, Jonathan Hunt, Nando de Freitas, Martin Riedmiller, Remi Munos, Shakir Mohamed, and Theophane Weber for helpful discussions and John Schulman for sharing his walker model.
References
Appendix A Derivation of recursive gradient of the deterministic value function
The use of derivatives in equation 4 is subtle, so we expand on the logic here. We first note that a change to the policy parameters affects the immediate action as well as each future state and action. Thus, the total derivative can be expanded to
Let us define the operator \nabla_{\theta}^{t}\triangleq\bigg{[}\sum_{t^{\prime}\geq t}\frac{d\mathbf{a}^{t^{\prime}}}{d\theta}\frac{\partial}{\partial\mathbf{a}^{t^{\prime}}}+\sum_{t^{\prime}>t}\frac{d\mathbf{s}^{t^{\prime}}}{d\theta}\frac{\partial}{\partial\mathbf{s}^{t^{\prime}}}\bigg{]}. The operator obeys the recursive formula
The value function depends on the policy parameters . The deterministic Bellman equation can be specified as . Now, we can apply the operator :
In the “tick” notation of the main text, this is equation 4.
Appendix B Gradient calculation for noise models
Evaluating the Jacobian terms in equations in equations 9 and 10) may require knowledge of the noise variables and . This poses no difficulty when we obtain trajectory samples by forward-sampling and computing using the policy and learned system model.
However, the same is not true when we sample trajectories from the real environment. Here, the noise variables are unobserved and may need to be “filled in” to evaluate the Jacobians around the right arguments.
Equations 11 and 12 arise from an application of Bayes’ rule. We formally invert the forward sampling process that generates samples from the joint distribution . Instead of sampling and then , , we first sample and using our policy and the real environment. Given these data and a function of them, we sample to produce
For example, in eq. 11, we plug in .
Appendix C Model and value learning
We found that the models exhibited the lowest per-step prediction error when the and vector components were computed by parallel subnetworks, producing one pair for each state dimension, i.e., . (This was due to varied scaling of the dynamic range of the state dimensions.) In the experiments in this paper, the components were parametrized as constant biases per dimension. (As remarked in the main text, this implies that they do not contribute to the gradient calculation. However, in the Hand environment, the planner agent forward-samples based on the learned standard deviations.)
Appendix D Experimental details
Swimmer
, where is a unit vector pointing from the nose to the goal.
For the MuJoCo environment problems, we provide .xml task descriptions.
Discount factors
Hand: 1.0; Swimmer: 0.995; Reacher: 0.98; Gripper: 0.98; Hopper: 0.95; Cheetah: 0.98; Walker: 0.98
∗ We use one sub-network of this many hidden units per state-dimension. With the exception of the results in Figures 2 and 3, where the sizes are given.