Lesson 63
REINFORCE
Wait until the end of an episode, then scale each action's log probability by the full return from that step. One example is on this page.
Intermediate12 min
What You Will Learn
- Idea
- Example
- When to use it
Idea
REINFORCE is the Monte Carlo policy gradient. It runs a full episode, computes the return after each step, and updates the policy with that return times the log probability of the action. No bootstrapped next-state value is involved. The update waits for the episode to finish.
Example
rewards = [0.0, 0.0, 1.0]
gamma = 0.9
returns = []
running = 0.0
for m in reversed(rewards):
running = m + gamma * running
returns.append(running)
returns.reverse()
print([round(m, 2) for m in returns])Output:
[0.81, 0.9, 1.0]When to use it
- Use it to understand policy gradients on short episodes.
- The first printed return includes every later reward, discounted.
- Variance is high. Actor-critic methods replace the full return with a learned baseline.
Loading playground…