ai theory
Reinforcement Learning Basics (14) — How Actor and Critic Divide the Work
Junyoung Park · 2024-06-14 · 6 min
Introduction
REINFORCE was the simplest method we had seen for learning a policy directly.
The problem is that we must wait until the end of the episode to know . Even the return following the same action can vary widely because of what happens by chance later in the episode, making the update noisy.
Actor-Critic divides the job into two parts.
- Actor: learns the policy that determines which action to choose.
- Critic: evaluates how good the current state or action is.
The Actor improves its policy using the Critic's evaluation, while the Critic improves that evaluation using actual rewards. Both functions learn together from the same experience.
A Raw Return Has No Point of Comparison
Suppose the agent chooses action in state and receives a return of . Was that a good result?
- If this state normally produces , it was excellent.
- If it normally produces , it was actually poor.
The absolute return is difficult to judge on its own. Subtracting what we expected on average in the current state tells us how much better or worse the action was than usual.
is the advantage function.
- : an action better than the average for this state
- : an action worse than the average
- : an action about as good as expected
For example, if
then
and
The Actor should increase the probability of A and decrease the probability of B.
A Baseline Does Not Change the Expected Direction
Subtracting a state-only function from a policy gradient does not change the expected gradient.
This follows from the fact that action probabilities sum to .
A baseline reduces unnecessary variation without changing the average update direction. The most natural baseline is .
What Does the Critic Learn?
Let the Critic be a state-value function parameterized by .
The Critic can be trained with a TD target.
The TD error is
It tells us whether the outcome was better than expected after actually taking one step. This makes a useful one-step estimate of the advantage.
Reading a TD Error with Numbers
Suppose we observe
The TD error is
We expected about from the current state, but after receiving reward , the next state still held worth of future value. The one-step outcome was therefore better than expected.
Conversely, if , we regard the chosen action as worse than expected.
Updating the Actor
The Actor uses the TD error in place of the return.
- If , increase the probability of the selected action.
- If , decrease its probability.
- If is close to , barely move the policy.
REINFORCE waits for an episode-wide return. Actor-Critic can update after every step.
Updating the Critic
The Critic updates its value parameters to reduce the TD error.
For a linear function,
while a neural network obtains the gradient through backpropagation.
The Actor and Critic usually have separate learning rates. If the Critic learns too slowly, the Actor follows inaccurate evaluations. If it changes too aggressively, it sends the Actor an unstable signal.
The Complete Flow in One Step
- The Actor samples .
- The environment returns and .
- The Critic computes .
- The Critic uses to update its value estimate.
- The Actor uses the same to update the probability of the selected action.
- Repeat from .
The Actor chooses a direction; the Critic quickly reports whether that direction worked better than expected.
Trading Bias for Variance
The Monte Carlo return uses the completed episode, so it has no bootstrapping bias but high variance.
A one-step TD error uses the Critic's estimate to reduce variance, but it becomes biased when the Critic is wrong.
| Advantage estimate | Length of actual rewards observed | Character |
|---|---|---|
| REINFORCE | To the end of the episode | Low bootstrap bias, high variance |
| One-step | One step | Potentially higher bias, lower variance |
| n-step advantage | n steps | A tunable point between the two |
Generalized Advantage Estimation, or GAE, follows the same idea by mixing TD errors over several horizons.
A small places more trust in short TD errors. A value near incorporates more of the distant future.
Actor-Critic Can Still Be Unstable
When the Actor changes, the policy that the Critic must evaluate changes as well. When the Critic changes, so does the advantage signal received by the Actor. Each learner is moving the other's target.
A large policy update can quickly separate the current policy from the one that collected the available experience and destabilize training. PPO, the subject of the next article, examines the probability ratio between an old and a new policy and prevents the policy from moving too far in a single update.
What to Remember
The Actor learns an action distribution, the Critic learns expected value, and TD error connects their updates.
- Advantage, , measures how much better an action is than the state's average.
- Subtracting a state-dependent baseline preserves the expected gradient while reducing variance.
- provides a one-step estimate of advantage.
- The Actor improves action probabilities; the Critic improves value predictions.
- n-step returns and GAE let us tune the trade-off between bias and variance.