Skip to content
StackDecode
AI & ML Atlas
Reinforcement LearningalgorithmInteractive simulation

REINFORCE Algorithm

The basic Monte Carlo policy gradient: reinforce actions in proportion to the return.

The idea

After each full episode, increase the log-probability of every action taken, weighted by the return that followed. Subtracting a baseline (such as the average return) leaves the expected gradient unchanged but greatly reduces variance.

θ ← θ + α · ∇θ log π(a|s) · (G − b)

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

action 1true reward 0.425%action 2true reward 0.625%action 3true reward 0.125%action 4true reward 0.925%
  • probability of action
  • sample pushed up
  • sample pushed down

The policy starts uniform: every action is equally likely.

iteration:
0
expected reward:
0.5
1/41

Dots under each bar are the sampled actions in the latest batch.

Step by step

  1. 1Play one episode with the current policy.
  2. 2For each step compute the return Gₜ.
  3. 3Compute ∇ log π(aₜ|sₜ)·(Gₜ − b).
  4. 4Update θ in that direction.

Where it is used

Simple problems and teaching.

Watch out for

Very noisy and sample-inefficient.

Related