Skip to content
advanced

Deriving the Deterministic Policy Gradient Through the Critic

The deterministic actor loss is one line: maximize $Q(s, \mu_\theta(s))$. It looks like a trick because the log-probability term — the entire engine of the…

Published 2026-10-02Updated 2026-10-0410 min read
Colorful koi fish swimming gracefully in a serene pond.
Colorful koi fish swimming gracefully in a serene pond. Photo by Mario Rodriguez on Pexels.

The deterministic actor loss is one line: maximize Q(s,μθ(s))Q(s, \mu_\theta(s)). It looks like a trick because the log-probability term — the entire engine of the stochastic policy gradient — has vanished. The gradient did not vanish with it. It moved.

If you already know the likelihood-ratio estimator, you know the shape of the problem. That estimator multiplies a return by ∇θlog⁡πθ(a∣s)\nabla_\theta \log \pi_\theta(a \mid s), and that log term only exists because π\pi is a distribution over actions. A deterministic policy μθ(s)\mu_\theta(s) returns one action. There is no density to differentiate, so the estimator collapses to nothing.

The gradient survives anyway, and it comes from a different place: the critic's sensitivity to the action. This article traces that chain link by link — from the objective, through the chain rule, into the update you actually run — and names the assumptions holding it together.

Notation and the Deterministic Objective

Before the derivation, fix the symbols.

  • s∈Ss \in \mathcal{S}: state.
  • a∈Aa \in \mathcal{A}: action, assumed continuous.
  • μθ(s)\mu_\theta(s): deterministic policy mapping states to actions, parameterized by θ\theta.
  • Qμθ(s,a)Q^{\mu_\theta}(s, a): action-value function — expected discounted return from taking aa in ss and following μθ\mu_\theta thereafter.
  • γ∈[0,1)\gamma \in [0, 1): discount factor.
  • ρβ(s)\rho^\beta(s): state distribution induced by the behavior policy β\beta that collects data.

The objective is the expected discounted return of the deterministic policy:

J(θ)=Es∼ρβ[Qμθ(s,μθ(s))]J(\theta) = \mathbb{E}_{s \sim \rho^\beta}\left[ Q^{\mu_\theta}(s, \mu_\theta(s)) \right]

Two things about this expression matter more than they look.

First, the expectation is over states, not state-action pairs. A deterministic policy contributes no action distribution, so there is nothing to average over in action space. The only randomness left is which states you visit.

Second, the state distribution is ρβ\rho^\beta, not the distribution μθ\mu_\theta would induce on its own. This is the off-policy subtlety. Samples come from a behavior policy — typically the deterministic policy plus injected noise, or a separate stochastic explorer — so the states you train on are drawn from someone else's trajectory distribution.

Here is the part that trips people up. Qμθ(s,a)Q^{\mu_\theta}(s, a) depends on θ\theta in two ways: through the current action a=μθ(s)a = \mu_\theta(s), and through the future actions the policy will take after this step. The deterministic policy gradient theorem accounts for both, and its proof carries the future-policy dependence into the state distribution the gradient is taken over. That is why the theorem is stated with an occupancy measure tied to the policy, not an arbitrary behavior distribution.

The practical actor update you write in code does something narrower. It treats the critic as a fixed estimator Q^ϕ(s,a)\hat{Q}_\phi(s, a) and differentiates only through the current action, holding the state distribution fixed at whatever the replay buffer provides. That is a semi-gradient: a gradient of a surrogate, not the full theorem-level gradient. It works well enough in practice, and it is what every DDPG-style implementation actually runs — but it is not the same object as the theorem, and conflating them hides the assumption doing the real work.

Knowledge check

Check your understanding

Answer this question before you continue.

In the practical actor update described here, what is treated as fixed while differentiating the critic value with respect to the actor parameters?
Misconception Check

Focus: Distinguish the theorem-level deterministic policy gradient from the practical replay-buffer surrogate described in the article.

The Chain Rule That Carries the Critic Into the Actor

A state enters the actor, which produces an action for the critic. The critic’s action-value slope and the actor’s Jacobian combine to form the parameter-space gradient, ∇θJ ≈ ∇aQ̂ ∇θμθ.
The critic supplies the action-space slope; the actor’s Jacobian maps it into a parameter update.

Start from the practical surrogate and differentiate with respect to θ\theta:

∇θJ(θ)≈∇θEs∼ρβ[Q^ϕ(s,μθ(s))]\nabla_\theta J(\theta) \approx \nabla_\theta \mathbb{E}_{s \sim \rho^\beta}\left[ \hat{Q}_\phi(s, \mu_\theta(s)) \right]

Because ss is drawn from the replay buffer and treated as a constant with respect to θ\theta, the gradient passes inside the expectation and touches only the action argument:

∇θJ(θ)≈Es∼ρβ[∇θQ^ϕ(s,μθ(s))]\nabla_\theta J(\theta) \approx \mathbb{E}_{s \sim \rho^\beta}\left[ \nabla_\theta \hat{Q}_\phi(s, \mu_\theta(s)) \right]

Now apply the chain rule. With the critic held fixed, Q^ϕ\hat{Q}_\phi depends on θ\theta only through the action a=μθ(s)a = \mu_\theta(s):

∇θQ^ϕ(s,μθ(s))=∇aQ^ϕ(s,a)∣a=μθ(s)⋅∇θμθ(s)\nabla_\theta \hat{Q}_\phi(s, \mu_\theta(s)) = \nabla_a \hat{Q}_\phi(s, a)\big|_{a = \mu_\theta(s)} \cdot \nabla_\theta \mu_\theta(s)

Substituting back gives the actor-through-critic gradient:

∇θJ(θ)≈Es∼ρβ[∇aQ^ϕ(s,a)∣a=μθ(s) ∇θμθ(s)]\nabla_\theta J(\theta) \approx \mathbb{E}_{s \sim \rho^\beta}\left[ \nabla_a \hat{Q}_\phi(s, a)\big|_{a = \mu_\theta(s)} \, \nabla_\theta \mu_\theta(s) \right]

Read the two factors as a conversation between two networks.

∇aQ^ϕ(s,a)\nabla_a \hat{Q}_\phi(s, a) is the critic answering a question: if I nudge the action in each direction, how does value change? It is a vector in action space, pointing toward higher value.

∇θμθ(s)\nabla_\theta \mu_\theta(s) is the actor answering a different question: if I nudge my parameters, how does my output action move? It is a Jacobian mapping parameter changes to action changes.

Multiply them and you get a vector in parameter space: the direction to move θ\theta so that the action moves in the direction the critic likes. The critic does not choose the action. It only supplies the slope. The actor supplies the reach.

In practice you estimate this by averaging over a batch of sampled states:

∇θJ(θ)≈1N∑i=1N∇aQ^ϕ(si,a)∣a=μθ(si) ∇θμθ(si)\nabla_\theta J(\theta) \approx \frac{1}{N} \sum_{i=1}^{N} \nabla_a \hat{Q}_\phi(s_i, a)\big|_{a = \mu_\theta(s_i)} \, \nabla_\theta \mu_\theta(s_i)

No action sampling. No log-probability. Just a slope and a Jacobian.

Knowledge check

Check your understanding

Answer this question before you continue.

Which interpretation correctly describes the two factors in the practical actor gradient?
Single Choice

Focus: Interpret the two factors in the actor-through-critic chain rule and their roles in forming a parameter-space update.

A Worked Example: One State, One Action Dimension

Strip it to the smallest case. One state, one scalar action, one actor parameter.

Suppose the critic near the current action has slope ∇aQ^ϕ=3.0\nabla_a \hat{Q}_\phi = 3.0 — increasing the action raises value. Suppose the actor's parameter gradient at this state is ∇θμθ(s)=0.5\nabla_\theta \mu_\theta(s) = 0.5 — increasing θ\theta raises the output action.

The chain-rule product is:

∇θJ(θ)=3.0×0.5=1.5\nabla_\theta J(\theta) = 3.0 \times 0.5 = 1.5

Gradient ascent on θ\theta moves the parameter up, which moves the action up, which the critic says is good. The sign is consistent all the way through.

Now flip the critic's slope to −3.0-3.0. The product is −1.5-1.5. Gradient ascent moves θ\theta down, the action drops, and value rises. The actor never needed to know why the critic preferred a smaller action. It only needed the sign and magnitude of the slope.

Geometrically, the actor is being pushed along the direction in which the critic's surface rises fastest, projected through the actor's own parameterization. If the actor cannot express that direction — if ∇θμθ(s)\nabla_\theta \mu_\theta(s) is near zero — the critic's slope is multiplied by almost nothing, and the update stalls even when the critic is screaming.

That last observation is the seed of the failure modes.

Knowledge check

Check your understanding

Answer this question before you continue.

At one state, suppose the critic action slope is −3.0 and the actor output derivative with respect to its parameter is 0.5. Under gradient ascent, which direction does the parameter move, and why?
Scenario Interpretation

Focus: Use the chain-rule product and gradient-ascent convention to determine the actor-parameter update direction in the scalar example.

What the Derivation Assumes, and What Breaks

The chain-rule product is clean. Reality is not. Each factor carries an assumption, and each assumption has a visible failure mode.

The critic must be differentiable in the action. If Q^ϕ\hat{Q}_\phi is piecewise-constant, uses a non-smooth action path, or is built from operations with zero or undefined gradients in aa, then ∇aQ^ϕ\nabla_a \hat{Q}_\phi is zero or undefined. The actor receives no signal — not a weak signal, no signal. A critic that cannot tell you which way is uphill cannot steer anyone.

The policy must be differentiable in its parameters. Discrete or argmax-style action selection breaks the chain. You cannot differentiate through an arg⁡max⁡\arg\max. This is why the technique lives in continuous control.

Action bounds and squashing distort the gradient. A tanh⁡\tanh or clip applied to the actor output changes the effective ∇θμθ\nabla_\theta \mu_\theta. Near the bounds, tanh⁡\tanh saturates: its derivative approaches zero, the second factor flattens, and the actor stops responding even when the critic has a strong opinion. If your actions are bounded and your actor keeps pinning them at the limits, suspect saturation before you suspect the critic.

State sampling determines representativeness. The expectation is over ρβ\rho^\beta. If the behavior policy never visits a region, the actor never receives gradient there. Coverage is not a nicety; it is the sampling assumption made visible.

Critic approximation error becomes actor bias. The actor follows ∇aQ^ϕ\nabla_a \hat{Q}_\phi, not ∇aQμθ\nabla_a Q^{\mu_\theta}. A critic that overestimates value in some action direction will steer the actor in a biased direction, confidently. This is why neighboring algorithms add target critics and delayed updates — the actor is only as good as the slope it is chasing.

Common mistake: Treating a stalled actor as a learning-rate problem. If ∇aQ^ϕ\nabla_a \hat{Q}_\phi is near zero because the critic is flat or non-smooth in the action, no learning rate will fix it. Check the critic's action gradient first.

Knowledge check

Check your understanding

Answer this question before you continue.

An actor repeatedly outputs actions near a tanh bound. The critic has a strong action gradient there, but actor updates are tiny. Which diagnosis best follows from the derivation?
Debugging

Focus: Identify actor-output saturation as a cause of a weak deterministic policy-gradient update despite a strong critic action slope.

Deterministic vs Stochastic: Two Different Sources of Gradient

The contrast is the point of the whole derivation.

Stochastic policy gradientDeterministic policy gradient
Learning signalReturn weighted by ∇θlog⁡πθ(a∣s)\nabla_\theta \log \pi_\theta(a \mid s)∇aQ^ϕ\nabla_a \hat{Q}_\phi chained through ∇θμθ\nabla_\theta \mu_\theta
What movesProbability mass toward actions that paid offThe action itself toward higher value
ExplorationFrom the policy's own distributionBorrowed from a behavior policy or injected noise
Data useNaturally on-policyOff-policy estimation from replay, with the target-policy occupancy approximated by behavior states
Dominant errorHigh variance from action samplingBias from the critic

The stochastic gradient shifts a distribution. The deterministic gradient shifts a point. One explores by sampling; the other must import exploration from outside. One is naturally on-policy; the other can reuse a replay buffer because the actor step treats the state distribution as fixed — an approximation, not a free lunch.

The variance-bias trade is the honest summary. The deterministic gradient avoids the high variance of sampling actions, but it inherits whatever bias lives in the critic. You traded a noisy signal for a confident one that might be wrong.

From the Expression to the Update You Actually Run

The practical form is almost embarrassingly short. The actor loss is the negative mean of the critic evaluated at the actor's output:

actor_loss = -critic(states, actor(states)).mean()
actor_loss.backward()
actor_optimizer.step()

Autograd produces exactly the chain-rule product derived above. It computes ∇aQ^ϕ\nabla_a \hat{Q}_\phi from the critic, ∇θμθ\nabla_\theta \mu_\theta from the actor, and multiplies them on the way back through the graph.

Two implementation details keep the derivation honest.

The state is a constant for the actor step. Only the actor's parameters should receive gradient. The critic's parameters are frozen during the actor update — otherwise you would be changing the slope while you climb it. In code, this is why the critic's parameters are excluded from the actor optimizer, and why some implementations detach the state tensor.

The critic is chasing a moving target. The actor follows the critic's gradient, so an unstable critic produces an unstable actor. Target networks and delayed actor updates exist to slow the critic down enough that the actor is chasing something that holds still for a moment. That machinery is the natural next topic, and it is where the derivation meets engineering.

When not to use this: discrete action spaces, non-differentiable critics, or policies with argmax selection. The chain rule has nothing to grab. Use a likelihood-ratio estimator instead.

The deterministic policy gradient is the critic's action gradient chained through the actor, and it exists only because both the critic and the policy are differentiable in the right places. Everything else — the noise, the replay buffer, the target networks — is scaffolding around that one product.

Your next move: re-derive the chain-rule product on paper for a two-dimensional action, writing out the Jacobian ∇θμθ\nabla_\theta \mu_\theta as a matrix and ∇aQ^ϕ\nabla_a \hat{Q}_\phi as a row vector. Then open an actor loss in code, set a breakpoint after .backward(), and confirm that the actor's parameter gradients match the two factors you multiplied by hand. When they match, the formula stops being memorized and becomes something you can debug.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

Which comparison best explains both why the deterministic update avoids action-sampling variance and why it still needs exploration support?
Question 1 of 2Comparison Reasoning

Focus: Compare the source of the learning signal and exploration in deterministic and stochastic policy gradients.

During the actor step, which implementation choice is consistent with maximizing critic value through the actor while keeping the critic fixed?
Question 2 of 2Misconception Check

Focus: Relate the negative-critic actor loss and critic parameter handling to the chain-rule actor update.

References

  1. Deep Deterministic Policy Gradient — Spinning Up documentationspinningup.openai.com
  2. Deep Deterministic Policy Gradient (DDPG)mattlanders.net
Practical resource

Build a stronger RL mental model

Use structured resources to connect equations, algorithms, and observable agent behavior.

Browse resources
Related sites

Continue across related AI foundations

Use LearnPyFast for Python foundations and LearnLLMFast for practical language-model and agent application concepts.

Python tutorialstutorial

LearnPyFast

Beginner-friendly Python tutorials, examples, and learning paths for practical programming foundations.

PythonProgrammingBeginners
Visit LearnPyFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related reinforcement learning tutorials

Continue with nearby RL concepts, algorithms, and experiments that build on the same decision process.