5.1.2 · D2Reinforcement Learning Foundations

Visual walkthrough — Markov Decision Processes (MDP)

3,060 words14 min readBack to topic

Step 1 — Standing on a state

WHAT. Picture a little world made of a handful of places you can be. Each place is a state, written . Think of squares on a board. Right now you are standing on one of them.

WHY. Before we can ask "how good is it here?", we need a "here". A state is just a labelled dot: it holds everything you need to know to decide your next move (that is the memoryless Markov property from the parent note — the dot remembers nothing about how you arrived).

PICTURE. Below, three states sit in a line. The orange dot is where you are now. That is all means: a location.

Figure — Markov Decision Processes (MDP)

Step 2 — Acting, and the coin the world flips

WHAT. From your dot you pick an action — say "go right" — out of the whole set of allowed actions. But the world may be shaky: pushing "right" might land you where you aimed most of the time, and slip some of the time.

WHY. We need a rule for what happens after you act. That rule is the transition probability : read it as "the chance of landing on dot , given I was on dot and pushed ". The bar means "given". These chances over all possible add to — you always land somewhere.

PICTURE. From , action "right" splits into arrows: a fat teal arrow (0.8, most likely) to and a thin plum arrow (0.2, slip) staying at . The arrow thickness is the probability.

Figure — Markov Decision Processes (MDP)

Step 3 — Reward: painting the arrows with numbers

WHAT. Each arrow (each transition) hands you a number the instant you cross it: the reward . Good things are big positive numbers; bad things are negative.

WHY. Goals must be turned into numbers or a machine cannot chase them. is how the world says "that was good / that was bad" — immediately, on the arrow itself, not later.

PICTURE. Same branches as before, now each arrow carries a tag. The arrow into the goal is painted ; the slip-arrow is painted .

Figure — Markov Decision Processes (MDP)

Step 4 — The return: adding up a whole future

WHAT. One reward is not enough — you live a whole sequence. Follow a strategy and you get a chain: The total haul from time onward is the return .

WHY. "How good is here?" cannot mean "the next reward only" — a step that pays now but opens the door to later is great. So we must sum the whole future. Each term is just Step 3's reward at successive ticks: . But a naive infinite sum can blow up to infinity, and it treats a reward 1000 steps away as equal to one right now. Both are bad.

PICTURE. A timeline of rewards as bars. The undiscounted bars are all equal height (dangerous); we are about to shrink the far ones.

Figure — Markov Decision Processes (MDP)

Step 5 — Why the discount , and why this tool

WHAT. Introduce the discount factor . Multiply a reward steps ahead by before adding it:

WHY this tool and not another? We needed a shrinker with two properties: (1) it fades smoothly with distance so "later = worth a little less", and (2) it tames the infinite sum. Geometric shrinking does both. Let ==== be an upper bound on the size of any single reward — that is, for every transition. Then every , so because a geometric series with ratio converges. No other simple weighting gives you the beautiful self-reference we exploit in the next step.

PICTURE. The same reward bars, now each multiplied by its faded factor — the tower of shrinking bars whose total area is finite.

Figure — Markov Decision Processes (MDP)

Step 6 — The value function: averaging over all futures

WHAT. The world flips coins (), so the return is random — different rolls give different totals. The state-value function is the average return you would collect, starting at and always obeying strategy :

WHY expectation ()? Because you cannot pin down a single future — Step 2 gave you branches. The honest answer to "how good is here?" is the probability-weighted average over every branch. That is exactly what (expected value) computes: sum of (chance outcome). The condition "" (using from Step 1) says "given that at tick the dot we actually stand on is ".

PICTURE. A tree fanning out of : many possible reward-chains, each labelled with its probability. is the balance point — the weighted average of all the chain totals.

Figure — Markov Decision Processes (MDP)

Step 7 — The self-reference trick (the heart of Bellman)

WHAT. Split the return into "the very next reward" plus "everything after": The bracket is itself a return, just starting one step later.

WHY. This is the crucial observation. Take the average (under , as defined in Step 6) of both sides. The average of , given you land on some (i.e. given ), is by definition again — the same function, one step downstream. Value is defined in terms of value. That circularity is not a bug; it is the equation we can solve.

PICTURE. A single dot with one short arrow to a "cloud" ; inside the cloud sits a tiny copy of the whole tree — value pointing at value. The recursion, drawn.

Figure — Markov Decision Processes (MDP)

Step 8 — Unfolding the average into the Bellman equation

WHAT. Now write the expectation explicitly using the pieces from Steps 2–3. Under a deterministic policy you take action . The world then picks with chance . Averaging = summing (chance payoff) over every branch in the state space :

WHY. This is Step 7's abstract turned into arithmetic you can actually run: one term per branch (the symbol under the sum is the state space from Step 1 — we range over every dot on the board), each term = (how likely) (reward now + discounted value later). That is the Bellman Expectation Equation.

PICTURE. The full annotated diagram: state on the left, arrows fanning to each , each arrow tagged with and , and each landing dot tagged — the equation laid over the geometry.

Figure — Markov Decision Processes (MDP)

Worked check (a fully specified line world). To exercise the equation we now fix a complete reward function on our three-state line — stated here in full so every number is defined on this page:

Apply the boxed equation at , summing over the two branches : (The reward on the winning arrow is now inside the bracket, matching Step 3's picture exactly.)


Step 9 — From "follow " to "do the best thing" (optimality)

WHAT. So far was fixed. What if at each state we choose the best action instead? First we need a way to score a single action. The action-value function answers "if I take action right now in state , then act optimally forever after, what is my expected return?" It is built from exactly the same pieces: Because the best you can do from a state is to take its best-scoring action, the optimal state-value is just the biggest available:

WHY the and not a sum? Because the optimal agent is not averaging its own choices — it picks the single best one. The world still averages (that inner over stays), but over your own action (ranging over the whole menu from Step 2) you take the maximum. That one swap — — turns "evaluate a strategy" into "find the best strategy".

PICTURE. From two action-branches: safe (value 55) and risky (value 60). A spotlight highlights the larger — the chooses .

Figure — Markov Decision Processes (MDP)

Worked check (a fully specified choice, all numbers defined here). Consider a fresh state with exactly two actions, whose transitions and rewards we state in full:

Plug each action into : Since , the picks : and . See 5.4.01-Q-Learning for how machines learn these values without knowing .


The one-picture summary

Everything above collapses into a single backup diagram: you stand on , the world fans you to next-states (ranging over the state space ) weighted by , each arrow pays , each landing dot carries , and is the weighted average of all of it (or the max over your own actions, for ).

Figure — Markov Decision Processes (MDP)
Recall Feynman retelling — say it back in plain words

Imagine standing on a square. You ask: "How good is standing here?" The answer can't just be the next payout, because a boring square that leads to a jackpot is secretly wonderful. So the value of here is: the reward you'll grab on your very next step, plus a slightly-shrunk copy of the value of wherever you land next. But the world is shaky — you might slip — so you don't get one clean next-square; you get several possible ones, each with a chance. So you take a weighted average: for every place you might land, multiply "how likely" by "reward there + shrunk value there", and add them up. That single sentence, drawn as arrows fanning out of a dot, is the Bellman equation. And if instead of blindly following a fixed strategy you get to choose the best action, you swap "average over my choice" for "pick my best choice" — a max — and you've written the optimality equation. Same picture, one word changed.

Recall Quick self-test

Why must use an expectation and not a plain sum of rewards? ::: Because transitions are random ( has branches), so the return is a random quantity; averages over all possible futures weighted by their probabilities, under policy . What single change turns the Bellman expectation equation into the Bellman optimality equation? ::: Replace the policy's chosen action with a over all actions in — you pick the best action instead of following . In , why does the sum stay finite? ::: With and rewards bounded by , the geometric series converges to at most . What does do to the agent's behaviour? ::: It makes the agent totally short-sighted — only the immediate reward counts; all future rewards are multiplied by . What is the difference between bare and ? ::: Bare is the state space — the whole set of dots; is the single random state the agent occupies at time .


Prerequisites & neighbours: Markov-Chains (the memoryless dynamics behind ), Dynamic-Programming (how the recursion gets solved), 5.1.01-Reinforcement-Learning-Problem-Formulation, 5.2.01-Dynamic-Programming-inRL, 5.3.01-Monte-Carlo-Methods, 5.3.02-Temporal-Difference-Learning.