Search

Search papers and lessons

Deterministic Policy Gradient

Level 3 · 10 min read

A deterministic policy gradient follows the critic's action-gradient through the policy, so a policy that outputs one action per state can be improved without sampling actions.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Reinforcement learning
  • Linear algebra
  • Discrete math
  • Stochastic processes
  • Sign in to see your progress

TL;DR

A deterministic policy outputs one action for each state, instead of a distribution over actions. Its gradient is the gradient of a learned action-value function with respect to the action, multiplied by the gradient of the policy's output with respect to its parameters. This avoids the sum over actions that makes the stochastic version noisy.

Where you'll see it: continuous-control agents such as robot arm controllers, where the action is a vector of motor torques and a deterministic actor with a learned critic (DDPG) is a common approach.

Intuition

Suppose you are tuning the throttle of a car to reach a target speed. A stochastic policy says "use a throttle near 40 percent, with some spread". To improve it, you can try a few throttle values, see which did better, and move toward those. That works, but each try is noisy, and you need many of them to see which way to go.

A deterministic policy says "use 40 percent". If you already have a critic that predicts the return for each throttle value, you can ask it directly: if I raise the throttle a little, does the predicted return go up or down? The answer is a slope, the derivative of the critic with respect to the action. You then nudge the policy in the direction that increases that slope-weighted return. No sampling of nearby throttle values is needed, because the critic gives you the direction.

This is the appeal of the method. Stochastic policy gradients have to estimate how the return changes by sampling actions and seeing what happens. The deterministic version replaces that sampling with a derivative that the critic provides. The derivative is smooth, so the estimate has far less noise, at the price of needing a differentiable critic and continuous actions.

flowchart LR
  S[State s] --> A["Actor: a = mu_theta(s)"]
  A --> C["Critic: Q(s, a)"]
  C --> G["Action gradient: dQ/da"]
  G --> U["Chain rule: push through mu_theta"]
  U --> T[Update theta]
  T --> A

The math

Use the notation from Policy Gradient. A deterministic policy μθ:S→A\mu_\theta : \mathcal{S} \to \mathcal{A} maps each state to one action, with parameters θ\theta. The discount factor is γ∈[0,1)\gamma \in [0, 1). Write ρμ(s)\rho^\mu(s) for the discounted distribution over states visited when following μ\mu, and Qμ(s,a)Q^\mu(s, a) for the expected discounted return after taking action aa in state ss and then following μ\mu.

The objective is the expected return from the start distribution,

J(θ)=Es∼ρ0[Vμθ(s)],J(\theta) = \mathbb{E}_{s \sim \rho_0}\big[V^{\mu_\theta}(s)\big],

where Vμ(s)=Qμ(s,μ(s))V^\mu(s) = Q^\mu(s, \mu(s)) is the value of ss under μ\mu.

The deterministic policy gradient theorem

Definition: Deterministic policy gradient

Under mild smoothness assumptions on μθ\mu_\theta, QμQ^\mu and the transition model,

∇θJ(θ)=Es∼ρμ[ ∇θμθ(s) ∇aQμθ(s,a)∣a=μθ(s)].\nabla_\theta J(\theta) = \mathbb{E}_{s \sim \rho^{\mu}}\Big[\, \nabla_\theta \mu_\theta(s)\, \nabla_a Q^{\mu_\theta}(s, a)\big|_{a = \mu_\theta(s)} \Big].

Here ∇θμθ(s)\nabla_\theta \mu_\theta(s) is the Jacobian of the policy's output with respect to its parameters, a matrix of size (action dimension) by (parameter count). The term ∇aQ\nabla_a Q is the gradient of the critic with respect to the action, a vector of the action's size.

The notation ∇θμθ(s)\nabla_\theta \mu_\theta(s) is a Jacobian, so the product with ∇aQ\nabla_a Q is the Chain Rule at work. The derivation starts from Vμ(s)=Qμ(s,μθ(s))V^\mu(s) = Q^\mu(s, \mu_\theta(s)). Differentiate with respect to θ\theta. The chain rule gives one term through the action, ∇θμθ(s) ∇aQ(s,a)\nabla_\theta \mu_\theta(s)\,\nabla_a Q(s, a). There is a second term through the next state, because QQ depends on the value of the next state. Expanding that term recursively over future states, and collecting the discounting, gives the formula above, with ρμ\rho^\mu as the weighting over states.

Notice what is absent. There is no integral over actions, and no ∇θlog⁡π\nabla_\theta \log \pi factor. The gradient never differentiates a probability. That is why no action sampling is needed, and the second worked example shows how noisy the sampled alternative is.

Connection to the stochastic gradient

The stochastic policy gradient uses Ea[∇θlog⁡πθ(a∣s)Q(s,a)]\mathbb{E}_a[\nabla_\theta \log \pi_\theta(a \mid s) Q(s, a)]. If the policy is a Gaussian with mean μθ(s)\mu_\theta(s) and variance σ2\sigma^2, and the variance shrinks to zero, the expected stochastic gradient approaches the deterministic one. Silver and colleagues proved this limit, so the deterministic version can be seen as the zero-noise case of the stochastic one.

Learning Q

In practice QQ is not known. It is learned by a critic Qw(s,a)Q_w(s, a) with parameters ww, using the usual temporal-difference target y=r+γQw(s′,μθ(s′))y = r + \gamma Q_w(s', \mu_\theta(s')). The actor and the critic are updated in turn. The actor uses the critic's action-gradient, and the critic is trained to match the returns the actor produces. This pairing is the Actor-Critic Methods structure applied to a deterministic actor.

Worked examples

Example
A one-step problem with a known critic

Take a single state s=2s = 2, and let the episode end after one action, so V(s)=Q(s,μ(s))V(s) = Q(s, \mu(s)). Let the policy be linear, μθ(s)=θs\mu_\theta(s) = \theta s, so the action is μ=2θ\mu = 2\theta and ∇θμ=s=2\nabla_\theta \mu = s = 2. Let the critic be Q(s,a)=−(a−6)2Q(s, a) = -(a - 6)^2, which is highest at the target action a=6a = 6.

  1. The action gradient of the critic is ∇aQ=−2(a−6)\nabla_a Q = -2(a - 6).
  2. Start at θ=1\theta = 1, so μ=2\mu = 2. Then ∇aQ=−2(2−6)=8\nabla_a Q = -2(2 - 6) = 8.
  3. Apply the theorem: ∇θJ=∇θμ⋅∇aQ=2⋅8=16\nabla_\theta J = \nabla_\theta \mu \cdot \nabla_a Q = 2 \cdot 8 = 16.
  4. Check by direct differentiation: J(θ)=−(2θ−6)2J(\theta) = -(2\theta - 6)^2, so dJ/dθ=−4(2θ−6)dJ/d\theta = -4(2\theta - 6). At θ=1\theta = 1 this is −4(−4)=16-4(-4) = 16. The two agree.
  5. Take a gradient step with learning rate α=0.1\alpha = 0.1: θ←1+0.1⋅16=2.6\theta \leftarrow 1 + 0.1 \cdot 16 = 2.6. The new action is μ=5.2\mu = 5.2, which is closer to the target 6.
  6. The optimum is at θ=3\theta = 3, where μ=6\mu = 6, and the gradient −8θ+24-8\theta + 24 is zero there.

Interpretation: the critic's slope tells the actor which way to move the action, and the policy's Jacobian turns that into a parameter update. No action was sampled.

Example
Why the stochastic estimate is noisy in the same problem

Keep the same state, policy and critic, and now make the policy stochastic: a∼N(μ,σ2)a \sim \mathcal{N}(\mu, \sigma^2) with μ=2θ\mu = 2\theta. At θ=1\theta = 1 the mean action is μ=2\mu = 2, and the distance to the target is μ−6=−4\mu - 6 = -4. The score-function estimate of the gradient, with respect to θ\theta, is one sample of g=∇θlog⁡π(a)⋅Q(s,a)g = \nabla_\theta \log \pi(a) \cdot Q(s, a). Write a=μ+εa = \mu + \varepsilon with ε∼N(0,σ2)\varepsilon \sim \mathcal{N}(0, \sigma^2). Since ∇μlog⁡π(a)=ε/σ2\nabla_\mu \log \pi(a) = \varepsilon / \sigma^2 and ∇θμ=2\nabla_\theta \mu = 2,

g=−2σ2 ε (−4+ε)2=−2σ2(16ε−8ε2+ε3).g = -\frac{2}{\sigma^2}\, \varepsilon\,(-4 + \varepsilon)^2 = -\frac{2}{\sigma^2}\left(16\varepsilon - 8\varepsilon^2 + \varepsilon^3\right).
  1. The mean of gg uses E[ε]=0\mathbb{E}[\varepsilon] = 0, E[ε2]=σ2\mathbb{E}[\varepsilon^2] = \sigma^2 and E[ε3]=0\mathbb{E}[\varepsilon^3] = 0. So E[g]=−2σ2(−8σ2)=16\mathbb{E}[g] = -\frac{2}{\sigma^2}(-8\sigma^2) = 16. This matches the deterministic gradient.
  2. For the variance, expand E[g2]=4σ4 E[(16ε−8ε2+ε3)2]\mathbb{E}[g^2] = \frac{4}{\sigma^4}\,\mathbb{E}[(16\varepsilon - 8\varepsilon^2 + \varepsilon^3)^2]. Using E[ε4]=3σ4\mathbb{E}[\varepsilon^4] = 3\sigma^4 and E[ε6]=15σ6\mathbb{E}[\varepsilon^6] = 15\sigma^6, the expectation inside is 256σ2+288σ4+15σ6256\sigma^2 + 288\sigma^4 + 15\sigma^6.
  3. So E[g2]=1024/σ2+1152+60σ2\mathbb{E}[g^2] = 1024/\sigma^2 + 1152 + 60\sigma^2, and the variance is Var(g)=1024/σ2+896+60σ2\mathrm{Var}(g) = 1024/\sigma^2 + 896 + 60\sigma^2.
  4. With σ=1\sigma = 1, the variance is 19801980, so the standard deviation is about 44.544.5.
  5. With σ=0.1\sigma = 0.1, the variance is about 103,300103{,}300, so the standard deviation is about 321321, roughly twenty times the mean.

Interpretation: both estimators have mean 16, but the stochastic one needs many samples before its average settles near 16, and the spread grows as the policy gets sharper. The deterministic gradient is exact for this critic, with no sampling at all. These numbers are analytic, from the formulas above, not from a simulation.

Tradeoffs and failure modes

The method is strong when actions are continuous and the critic is good. It has costs that the stochastic version does not.

SituationWhat goes wrongBetter choice
Discrete actionsThe action gradient does not exist, since there is no smooth action spaceStochastic policy gradient or Q-learning
No explorationA deterministic policy only tries one action per state, so it may never find better onesAdd noise to the action during training, which makes learning off-policy
Critic errorsThe actor follows the critic's slope, so a wrong slope pushes the action the wrong wayTarget networks and a replay buffer to stabilise the critic
Sharp or flat criticA very flat critic gives a near-zero gradient, and a sharp one gives huge stepsGradient clipping, smaller learning rates
Need a probability over actionsThe policy outputs no distributionStochastic policy with the score-function estimator

Because the actor follows the critic, the method is only as good as the critic's action-gradient. Errors in the critic's slope cause the actor to drift. Practical systems therefore slow the actor down relative to the critic and keep a lagged copy of the critic for the targets.

History

The stochastic policy gradient came first. Sutton and colleagues wrote down the policy gradient theorem with function approximation in 2000, and later work refined it. Silver, Lever, Heess, Degris, Wierstra and Riedmiller introduced the deterministic policy gradient at ICML in 2014, proving the theorem above and showing that the deterministic form is the limit of the stochastic one. Lillicrap and colleagues applied it in 2015 with deep networks for both actor and critic, along with a replay buffer and target networks, to continuous-control tasks. That combination is usually called DDPG. The DDPG paper reports solving more than 20 simulated physics tasks with one algorithm, network architecture and set of hyperparameters, and learning from raw pixels on many of them.

Check yourself

QuestionWhy does the deterministic policy gradient need the critic to be differentiable with respect to the action?Show answer

The formula multiplies the policy's Jacobian by ∇aQ\nabla_a Q, the critic's gradient with respect to the action. If the critic is not differentiable in the action, that term does not exist and the update cannot be computed. This is also why the method is limited to continuous actions: a discrete action has no smooth direction to move in.

QuestionUsing the one-step example, if the critic is Q(s,a)=−(a−6)2Q(s,a) = -(a-6)^2 and the policy is μθ(s)=θs\mu_\theta(s) = \theta s with s=2s = 2, what is the deterministic gradient at θ=2\theta = 2?Show answer

At θ=2\theta = 2 the action is μ=4\mu = 4. The critic's gradient is ∇aQ=−2(4−6)=4\nabla_a Q = -2(4 - 6) = 4. The policy's Jacobian is ∇θμ=s=2\nabla_\theta \mu = s = 2. The product is 2⋅4=82 \cdot 4 = 8. Since dJ/dθ=−4(2θ−6)dJ/d\theta = -4(2\theta - 6), at θ=2\theta = 2 this gives −4(−2)=8-4(-2) = 8, which agrees.

QuestionWhy does a deterministic policy need extra exploration to learn well?Show answer

A deterministic policy picks the same action in each state, so it only ever observes returns for that action. It cannot discover that another action is better, because it never tries one. Adding noise to the action during training gives it nearby actions to compare against. That noise makes learning off-policy relative to the deterministic target, which is one reason replay buffers are used in these methods.

QuestionApplied: you are training a robot arm with a deterministic actor and a learned critic. The arm's actions are joint torques. The critic's predicted best torque keeps moving in a jerky way between updates. What would you check first?Show answer

Check the critic's training first. The actor follows the critic's action-gradient, so a noisy or unstable critic makes the actor jump. Look at the target network update rate and whether the critic's loss is stable. Then check the actor's learning rate relative to the critic's, and whether gradients are clipped. Reducing the actor's step size or slowing the critic's target update is a common fix when the actor is moving faster than the critic can settle.

Sources