Part XVI — Reinforcement Learning: Bandits, MDPs, Policy Gradients & PPO · Chapter 2

Markov Decision Processes (MDP)

Hook

Every pull of a bandit's arm started the same way the last one did — there was no "situation" to carry from one pull to the next. What happens the moment an action doesn't just pay a reward, but also decides where you are for the next decision?

Intuition
S0
S1
S2
S3
0 moves — discounted return so far: 0.00

A row of four states, the last one a goal. Move left or right — each move costs 1-1, except the one that lands you on the goal, which pays +10+10. Unlike the bandit, your position now depends on every choice you've made so far, and every future choice depends on where those moves left you.

Formalize

A Markov decision process is the tuple (S,A,P,R,γ)(S, A, P, R, \gamma) — states, actions, a transition rule, a reward function, and a discount factor. For a fixed policy π\pi, the value of a state is its expected discounted future reward, defined recursively by the Bellman equation:

Vπ(s)=R(s,π(s))+γVπ(P(s,π(s)))V^\pi(s) = R(s, \pi(s)) + \gamma\, V^\pi\big(P(s,\pi(s))\big)
  • Vπ(s)V^\pi(s) — the value of state ss under policy π\pi: its expected discounted future reward.
  • ss — the current state, one of the situations the agent can be in.
  • π(s)\pi(s) — the policy: which action it prescribes from state ss.
  • R(s,π(s))R(s, \pi(s)) — the reward function: the immediate reward for taking that action in that state.
  • γ\gamma — the discount factor, shrinking the value of reward that takes longer to arrive.
  • P(s,π(s))P(s,\pi(s)) — the transition rule: the state landed in after taking that action.
  1. The same idea as the chain rule

    This is the exact same idea as Part I's chain rule — the value of right now depends on the value of whatever comes next — just unrolled over an action-dependent sequence of states instead of a fixed chain of functions.

Play
S0V=6.2
S1V=8.0
S2V=10.0
S3V=0.0
V(s) under the always-right policy — higher near the goal, discounted going backward

Every state's value is highest closest to the goal and lower further away — not because those states are inherently better, but because γ<1\gamma < 1 discounts reward that takes longer to arrive. The value function is entirely a consequence of the policy and the discount, not something separately assigned to each state.

Worked example

With γ=0.9\gamma = 0.9, under the policy "always move right":

  1. Start from the goal and work backward

    V(3)=0V(3) = 0 (nothing left to earn). V(2)=10+0.9(0)=10V(2) = 10 + 0.9(0) = 10 — one move from +10+10.

  2. Two states from the goal

    V(1)=1+0.9(10)=8V(1) = -1 + 0.9(10) = 8. V(0)=1+0.9(8)=6.2V(0) = -1 + 0.9(8) = 6.2.

  3. A policy that never arrives

    Under "always move left," any state above 00 eventually gets stuck bouncing at the boundary forever, each bounce costing 1-1. Solving V=1+0.9VV = -1 + 0.9V for a fixed point: subtract 0.9V0.9V from both sides to get V0.9V=1V - 0.9V = -1, i.e. 0.1V=10.1V = -1, so V=1/0.1=1/(10.9)=10V = -1/0.1 = -1/(1-0.9) = -10 — a genuinely worse value than even the very first state gets under "always right."

Checkpoint

Reach the goal with a discounted return above 5 — wasted moves cost you.

S0
S1
S2
S3
discounted return: 0.00
Move to try it
Summary
Vπ(s)=R(s,π(s))+γVπ(P(s,π(s)))V^\pi(s) = R(s, \pi(s)) + \gamma\, V^\pi\big(P(s,\pi(s))\big)

Every value in this chapter came from a policy that was already fixed and handed to you — "always right" was simply given, not learned. The real question reinforcement learning exists to answer is the one this chapter sidesteps: which policy should an agent follow, when nobody tells it in advance? The next chapter is the first algorithm that actually learns the answer.