> ## Documentation Index
> Fetch the complete documentation index at: https://aegean.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Actor-Critic Methods

> A learned value function that bootstraps the policy gradient.

[REINFORCE](https://aegean.ai/aiml-common/lectures/reinforcement-learning/policy-based-algorithms/reinforce/index.md) weights the score of each action by the return $G_t$ that followed it. The return is an unbiased estimate of $q_\pi(S_t, A_t)$, but it sums every reward until the end of the episode, so its variance is large. Subtracting a learned baseline $\hat v(S_t; \mathbf w)$ reduces the variance without adding bias. Even then, every update waits for the end of the episode, because $G_t$ is not known until then.

An *actor-critic* method goes one step further. It replaces the return by a target that bootstraps from the learned value function, as TD prediction does. The policy $\pi(a \mid s, \boldsymbol\theta)$ is the *actor*, and the value function $\hat v(s; \mathbf w)$ is the *critic*. What makes a method actor-critic is that the critic's estimate enters the target, not only the baseline (Sutton & Barto, 2018).

## The advantage

The policy gradient theorem weights each action by $q_\pi(s, a)$. Any baseline that depends only on the state can be subtracted, and the natural choice is the state value. The difference

$$
a_\pi(s, a) = q_\pi(s, a) - v_\pi(s)
$$

is the *advantage* of action $a$ in state $s$: how much better it is than the average action under $\pi$. With it, the gradient reads

$$
\nabla_{\boldsymbol\theta} J(\boldsymbol\theta) \propto \mathbb E_\pi [ a_\pi(S_t, A_t)\, \nabla_{\boldsymbol\theta} \log \pi(A_t \mid S_t, \boldsymbol\theta) ].
$$

An action with positive advantage becomes more likely and one with negative advantage less likely. In a state where all actions are equally good, every advantage is zero and the policy does not move there. The [two-state example on the PPO minimal page](https://aegean.ai/aiml-common/lectures/reinforcement-learning/policy-based-algorithms/PPO/ppo-explained-minimal/ppo_explained_minimal.md) shows what goes wrong without this: with the trajectory reward as the weight, an action that has no effect on the reward still collapses onto one choice.

The advantage is not observed, so it has to be estimated. The TD error of the true value function does this without a model:

$$
\begin{aligned}
\delta_t &= R_{t+1} + \gamma\, v_\pi(S_{t+1}) - v_\pi(S_t), \\
\mathbb E_\pi[ \delta_t \mid S_t = s, A_t = a ] &= q_\pi(s, a) - v_\pi(s) = a_\pi(s, a).
\end{aligned}
$$

The identity follows from the definition of $q_\pi$: given $S_t$ and $A_t$, the expected value of $R_{t+1} + \gamma v_\pi(S_{t+1})$ is $q_\pi(S_t, A_t)$. With the critic $\hat v$ in place of $v_\pi$, the TD error is a biased estimate of the advantage, and the bias shrinks as the critic improves.

## One-step actor-critic

One-step actor-critic updates both parameter vectors after every transition, using the same TD error for both:

```text theme={null}
Input: policy π(a | s, θ), state-value function v̂(s; w), step sizes α_θ, α_w
Initialize θ and w
For each episode:
    S ← first state of the episode;  I ← 1
    For each step, until S is terminal:
        A ~ π(· | S, θ)
        Take action A, observe R, S'
        δ ← R + γ v̂(S'; w) − v̂(S; w)        (v̂(S'; w) = 0 if S' is terminal)
        w ← w + α_w δ ∇_w v̂(S; w)            (critic: semi-gradient TD(0))
        θ ← θ + α_θ I δ ∇_θ log π(A | S, θ)   (actor: policy gradient)
        I ← γ I
        S ← S'
```

The critic is TD(0) prediction for the current policy, written for a function approximator. The actor step is the REINFORCE update with $\delta$ in place of $G_t - \hat v(S_t)$. The factor $I = \gamma^t$ makes the update follow the gradient of the discounted objective from the start state; most implementations drop it.

Compared with REINFORCE, the update is online and incremental: the agent learns during the episode and does not need episodes at all, so the method also works on continuing tasks. The price is bias. Early in training the critic is wrong, and its errors enter the actor's update through $\delta$. This is the same bias-variance trade-off as between TD and Monte Carlo prediction, now applied to the policy gradient.

## Generalized advantage estimation

The one-step TD error and the Monte Carlo advantage $G_t - \hat v(S_t)$ are the two ends of a family. Summing discounted TD errors over several steps gives an $n$-step estimate, and an exponentially weighted average over all $n$ gives *generalized advantage estimation* (GAE), introduced by Schulman et al. (2016):

$$
\begin{aligned}
\hat A_t^{\text{GAE}(\gamma, \lambda)} &= \sum_{l=0}^{\infty} (\gamma\lambda)^l\, \delta_{t+l}, \\
\delta_{t+l} &= R_{t+l+1} + \gamma\, \hat v(S_{t+l+1}) - \hat v(S_{t+l}).
\end{aligned}
$$

With $\lambda = 0$ the estimate is the one-step TD error $\delta_t$: low variance, biased by the critic. With $\lambda = 1$ the sum telescopes to $G_t - \hat v(S_t)$: unbiased, high variance. Values such as $\lambda = 0.95$ sit in between. This is the same interpolation as the $\lambda$-return of [n-step TD](https://aegean.ai/aiml-common/lectures/reinforcement-learning/value-based-algorithms/prediction/n-step-td.md), applied to advantages. In practice the sum runs to the end of a rollout of fixed length and is computed backward in one pass. [PPO](https://aegean.ai/aiml-common/lectures/reinforcement-learning/policy-based-algorithms/PPO/index.md) uses GAE for its advantages.

## Continuous actions

A softmax over action preferences covers discrete actions. For a continuous action, such as a turn rate, the policy can be a Gaussian whose mean and standard deviation are functions of the state:

$$
\pi(a \mid s, \boldsymbol\theta) = \frac{1}{\sigma(s, \boldsymbol\theta)\sqrt{2\pi}} \exp\left( -\frac{\big(a - \mu(s, \boldsymbol\theta)\big)^2}{2\sigma(s, \boldsymbol\theta)^2} \right).
$$

Its score for the mean is

$$
\frac{\partial \log \pi(a \mid s, \boldsymbol\theta)}{\partial \mu} = \frac{a - \mu(s, \boldsymbol\theta)}{\sigma(s, \boldsymbol\theta)^2},
$$

so an action above the mean with a positive advantage pulls the mean up, and one with a negative advantage pushes it down. The standard deviation sets how widely the policy explores, and it is learned too, usually through $\log \sigma$ to keep it positive. Everything else in actor-critic stays the same.

The [DDPG](https://aegean.ai/aiml-common/lectures/reinforcement-learning/robot-navigation/ddpg-navigation/index.md) and [TD3](https://aegean.ai/aiml-common/lectures/reinforcement-learning/robot-navigation/td3-navigation/index.md) navigation sections take a different route for continuous actions: a deterministic actor $\mu_{\boldsymbol\theta}(s)$ and a critic for action values $\hat q(s, a)$, trained off-policy with the replay buffer and target networks of [DQN](https://aegean.ai/aiml-common/lectures/reinforcement-learning/value-based-algorithms/control/dqn/dqn.md).

## From actor-critic to modern methods

Most deep RL policy-gradient methods are actor-critic methods with a neural network for each part, or one network with two heads. A2C and A3C (Mnih et al., 2016) collect short rollouts from several copies of the environment and update with $n$-step advantages. PPO adds the clipped probability ratio, so that the same rollout can be reused for several gradient steps without moving the policy too far. GRPO drops the critic altogether and replaces its baseline with the mean reward of a group of samples, which suits language models whose reward arrives only at the end of a long sequence.

**Key references**: (Sutton & Barto, 2018; Mnih et al., 2016); Schulman et al. (2016), *High-dimensional continuous control using generalized advantage estimation*.

## References

* Mnih, V., Badia, A., Mirza, M., Graves, A., Lillicrap, T., et al. (2016). *Asynchronous Methods for Deep Reinforcement Learning*. arXiv \[cs.LG]. [Link](http://arxiv.org/abs/1602.01783)
* Sutton, R., Barto, A. (2018). *Reinforcement Learning: An Introduction*. [Link](https://www.andrew.cmu.edu/course/10-703/textbook/BartoSutton.pdf)

***

Found an error on this page? [Report an issue](https://github.com/aegean-ai/eaia-feedback/issues/new?template=page-issue.yml\&page=/aiml-common/lectures/reinforcement-learning/policy-based-algorithms/actor-critic).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.