5.2.6 · D1Deep & Advanced RL

Foundations — REINFORCE algorithm

2,273 words10 min readBack to topic

This page assumes nothing. Before you touch the REINFORCE algorithm derivation on the parent note, you must be able to read every symbol in it on sight. We build them one at a time, each picture leaning on the last. If a term appears in the parent, it appears here first, defined and drawn.


0. The cast of characters (the stage)

Reinforcement learning has an agent living inside an environment. Look at the loop below.

Figure — REINFORCE algorithm

1. Probability, and why an action needs one

Before we can say "make this action more likely", we need the word likely as a number.

Figure — REINFORCE algorithm

2. The policy — the decision-maker

Now we assemble state + action + probability into the central object.

Two standard ways to build appear in the parent: the Softmax Policy (for a handful of discrete actions — turns raw scores into a pie-chart) and the Gaussian Policy (for continuous actions — outputs a bell-curve of where to aim). Both are just concrete recipes for the box.


3. Trajectory — one full play-through


4. Discounting: and the return ,

Rewards arrive over time. We need one number summarizing a whole play-through, and a way to say "sooner is worth a bit more than later."

Figure — REINFORCE algorithm

5. The objective — the score we push up


6. Expectation — averaging over luck

The return is random (different each time). To talk about "the typical return", we need the average operator.

So the parent's objective reads, in plain words: " is the average return you get when the policy plays."


7. The gradient — which way is uphill

To increase , we need the direction that increases it. That direction is the gradient.

Figure — REINFORCE algorithm

8. Baseline, Value, Advantage — the last three


Prerequisite map

Probability 0 to 1

Policy pi_theta of a given s

State s

Action a

Parameters theta the knobs

Trajectory tau one playthrough

Reward r_t

Return and reward-to-go G_t

Discount gamma

Objective J theta average return

Expectation E average over luck

Gradient nabla ascent uphill

Log turns product into sum

Value V of s

Baseline and Advantage

REINFORCE algorithm


Equipment checklist

Cover the right side; can you answer before revealing?

What does output?
A probability for each action, given the state ; controlled by the knob-bag .
What is the vertical bar read as?
"given" — a conditional probability.
What is a trajectory ?
The full recorded sequence of one episode.
What does do and what range is it in?
Discounts future rewards by ; it lives in .
Difference between and ?
is the whole-episode total; is the reward-to-go counted only from step forward.
What is in words?
The average (expected) return when policy plays.
What does mean and why is it here?
Probability-weighted average; trajectories are random, so we average over them.
What does point toward?
The steepest-uphill direction in as we vary .
Why gradient ascent not descent?
We want to maximize ; descent would minimize it (hence the minus sign in code).
What single algebra fact makes useful here?
— turns the trajectory product into a sum.
What is the advantage ?
: how much better than the state's average return this outcome was.
Why subtract a baseline at all?
To recentre the signal and cut variance, without biasing the gradient direction.