← ml-viz my Ch. 13 notes

Policy Gradients: REINFORCE & Actor-Critic

Value-based control learns action values and acts nearly deterministically, which breaks when the best policy must genuinely randomize. Policy gradient methods parameterize π(a | s, θ) directly and climb expected return by gradient ascent — first via Monte Carlo REINFORCE, then with variance-reducing baselines, and finally online at every step with Actor-Critic. Everything here is computed live in your browser with fixed seeds.

Short Corridor with Switched Actions (Sutton & Barto, Example 13.1). Four states: s0, s1, s2, and terminal goal G. Every step costs −1 (γ = 1). In s0 and s2, right moves +1 and left moves −1 (clamped at s0). In s1, the actions are switched: right goes back to s0, while left advances to s2. Because all states look identical to the agent, the policy must choose a single probability p = π(right) everywhere.

Corridor dynamics & live walker

action: right (prob p) action: left (prob 1 − p) s1 switched actions terminal goal G

Exact value v(s0; p) across stochastic policies

Closed form: v(s0; p) = −2(2 − p) / [p(1 − p)]
exact v(s0; p) optimal stochastic policy p* = 2 − √2 ≈ 0.586 (v* ≈ −11.66) ε-greedy (ε = 0.1): p = 0.05 (−82.1) & p = 0.95 (−44.2) current slider p