Skip to content
AI360XpertBeta
Playgrounds

Evaluation & RL

Policy Gradient

REINFORCE turns sampled returns into changes in the probabilities of future actions.

Data seed 20260906

Guided steps 1 / 3

Stage 1 of 3: The grid

Selected Column 1, row 5, Open.

  • Agent

The same move can hit a wall or reach a reward, depending on where you start.

Select a cell to inspect or edit it. The start is fixed. A goal or penalty ends an episode, and a wall leaves the agent in place.

Check this stage

Check your understanding

Sample a batch of routes through a grid world and inspect how REINFORCE changes the probability of each move.

From a sampled route to a new policy

REINFORCE adjusts the parameters of a stochastic policy to improve expected return. Open Action probabilities and select a cell. Four logits go through softmax, so all four directions start at 25%. A direction that hits a wall stays in the distribution. If it is sampled, the agent stays in place.

Open REINFORCE and predict whether the first sampled action will become more likely. Reveal the answer, then press Step. Every episode in that batch uses the same policy. The update averages the episode gradients before changing the logits.

Open Under the hood and choose an episode and a move. Its return-to-go starts with that move's reward and discounts the rewards that follow. The update also multiplies by the discount from the start of the episode. With positive weight, this move's contribution pushes the chosen logit up relative to the others. The batch can revisit the cell with other actions or returns, so inspect both the single-move contribution and the final probability.

What a baseline changes

Turn on Use value baseline to subtract the expected return for the same cell and remaining moves. The lab computes this value from the known grid and the frozen policy. The weight now depends on how the sampled return compares with that expectation.

With at least two episodes, the inspector shows the sample standard deviation of the first move's contribution to the Right logit, with and without the baseline on the same samples. This comparison covers one gradient component. A finite batch can show more or less spread. An action-independent baseline leaves the expected gradient unchanged.

When one update goes too far

Choose Try an oversized update and press Step. Compare the exact chance of reaching the goal before and after. These odds account for every possible path up to the move limit, including paths ending in a penalty. One sampled route can drive a large update that sharply lowers those odds. Use Back to working to restore your run.

Try increasing Move cost to see how the return changes even on an episode with no terminal reward. The cost is paid on every move, including blocked moves. It changes the objective. The exact goal odds still measure whether the policy reaches a goal, which is a separate quantity from expected discounted reward.

Stage recap

  1. The grid

    Select a cell to inspect or edit it. The start is fixed. A goal or penalty ends an episode, and a wall leaves the agent in place.

  2. Action probabilities

    Select an open cell and read the four bars. Softmax converts its four logits into probabilities that add to one. Even a move blocked by a wall can be sampled.

  3. REINFORCE

    Step applies one batch. Inspect a sampled move and compare its contribution with the final change at the cell after all visits are combined.

Reference

REINFORCE
Average the sampled return-weighted log-probability gradients, then add the result to the logits.
Baseline
An action-independent estimate subtracted from the sampled return. It changes the sampled gradient while preserving its expectation.
Reward shaping
An extra signal in the reward. The move cost in this lab changes the objective.

Break it on purpose

The last update lowered the exact chance of reaching the goal by at least five percentage points.