Foundations of Reinforcement Learning
Reinforcement learning is the third paradigm: an agent learns to act by interacting with an environment that returns rewards, not labels. We formalize the interaction as a Markov decision process, define the value functions that rank states and actions, and derive the Bellman expectation and optimality equations that every method downstream solves.
╌╌╌╌
Supervised learning fits a function to labelled examples; unsupervised learning models the structure of unlabelled data. Reinforcement learning is the third paradigm: there are no labels, only a stream of interaction, and a scalar reward that says how good the last move was but never which move was right.1 An agent must discover a good behaviour by trying actions and observing their consequences, trading off the reward available now against the states its choices lead to later. This lesson builds the formal object that makes the problem tractable, the Markov decision process, and derives the equations that every algorithm in the rest of the module solves, exactly or approximately.
The agent-environment interface
At each discrete step the agent observes a state , selects an action , and the environment responds with a scalar reward and a next state . The loop closes and repeats. Everything the agent can learn is contained in the resulting trajectory .
The environment is the source of both signals the agent does not control, the reward and the next state. The agent controls only its action. The whole of reinforcement learning is the question of how to choose actions, from experience alone, so that the long-run reward is large.
The single most important distinction from supervised learning: the reward is evaluative, not instructive. A label tells the model the correct output; a reward only scores the action taken, leaving the agent to infer, across many trials, which actions were responsible. This is the credit-assignment problem, and it is why the value functions below exist.
Markov decision processes
The interface becomes solvable once we assume the dynamics are Markov: the next state and reward depend only on the current state and action, not on the full history. The history collapses into the present state.
A finite Markov decision process packages the dynamics into a five-tuple.
The kernel and reward together are the model. When the agent knows them, the problem is one of planning, solved exactly by the dynamic programming of the last section. When it does not, it must learn from sampled transitions, the subject of later lessons. For example, in a small gridworld, states are cells, actions move between adjacent cells, and the reward is per step until a goal cell is reached.
The Markov assumption is a modelling choice, not a law of nature. If the raw observation is not Markov (a single video frame hides velocity), the standard fix is to engineer a state that is, by stacking frames or carrying a recurrent summary, so that the tuple above applies to the constructed state.
Returns and discounting
The agent maximizes the return , the discounted sum of future rewards. The discount weights a reward steps away by .
The definition obeys a one-step recursion that drives every equation downstream: peel off the first reward and the rest is a return from .
Two regimes arise. An episodic task terminates in an absorbing state (a game ends, a maze is solved), so the sum is finite and is admissible. A continuing task runs forever, and the sum converges only because bounds it: if then .
| Quantity | |||
|---|---|---|---|
| Effective horizon | step | steps | steps |
| Weight on reward steps out | |||
| Behaviour | myopic | balanced | far-sighted |
Beyond guaranteeing convergence, discounting encodes a genuine preference: a reward now is worth more than the same reward later, and it caps the influence of the distant, uncertain future on the present decision. The weight the return places on the reward steps ahead is exactly , and the two discount factors decay at visibly different rates.
Policies and value functions
A policy is the agent's behaviour: a mapping from states to a distribution over actions, . A deterministic policy is the special case that puts all mass on one action, . The agent's task is to find a policy whose return is large, and to rank policies we need to measure the return a policy earns, which is what the value functions do.
The two are linked by averaging over the policy's action distribution, and conversely by expanding one step of dynamics:
The first identity says a state's value is the policy-weighted average of its action-values; the second says an action's value is its immediate reward plus the discounted value of where it leads.
The Bellman expectation equations
Substituting each identity into the other produces a self-consistency condition on alone, the Bellman expectation equation. We derive it from the return recursion .
The third line splits the expectation and conditions the second term on the next state; the fourth uses , the definition of the value function one step later. The same argument applied to gives its Bellman expectation equation:
These equations are read off a backup diagram: a one-step look-ahead tree that averages over the action chosen by (open circles) and the next state drawn by (filled circles), backing the successor values up to the root.
A backup by hand
Take a gridworld cell whose action is fixed by the policy to up, with reward per step and . Suppose the move is stochastic: with probability the agent lands in the intended cell , and with probability each it slips left into or right into . From a current value estimate , , , the Bellman expectation backup evaluates one line of arithmetic:
The successor values are averaged under the transition probabilities, scaled by , and offset by the one-step reward. Every method in this module reduces to a rule for producing and repeating that single number.
Optimal value functions
A policy is at least as good as if for every state. This partial order has a maximum: there always exists an optimal policy that dominates all others simultaneously. Its value functions are the optimal value functions:
Optimality replaces the policy-average in the Bellman equation with a over actions: the optimal value of a state is the value of its best action, not the average over a fixed policy. The two backups differ at exactly one node, where the action branches meet.
The optimality equation immediately yields the optimal policy: act greedily with respect to . There is no need to look further than one step, because has already folded the entire future into each action-value.
This is why the model-free methods of later lessons, such as -learning, target rather than : with in hand, the agent acts optimally without ever consulting a model.
Dynamic programming
When the model is known, the Bellman equations can be turned into algorithms that compute the value functions exactly. Two ideas combine: policy evaluation computes for a fixed policy, and policy improvement turns a value function into a better policy.
Iterative policy evaluation treats the Bellman expectation equation as an assignment, sweeping it to convergence:
Policy improvement replaces with the policy greedy w.r.t. its own value:
Alternating the two is policy iteration: evaluate the current policy fully, then improve it, and repeat until the policy stops changing.
- 1initialize and an arbitrary policy for all
- 2repeat
- 3repeatpolicy evaluation: solve
- 4for each do
- 5
- 6until changes by less than tolerance
- 7stable true
- 8for each dopolicy improvement: act greedily
- 9
- 10if then
- 11; stable false
- 12until stable
- 13return
The two operations alternate around a cycle: evaluation makes consistent with , improvement makes greedy w.r.t. , and the fixed point of the cycle satisfies the Bellman optimality equation.
Value iteration short-circuits the cycle: rather than evaluate each policy to convergence, it applies the Bellman optimality update once per sweep, folding improvement and evaluation into a single .
- 1initialize for all
- 2repeat
- 3
- 4for each do
- 5
- 6optimality backup
- 7
- 8until
- 9for each doextract the greedy policy
- 10
- 11return
Each sweep contracts the error toward zero, so the value estimate converges geometrically to . The error after sweeps shrinks like .
Convergence as a contraction
Both algorithms converge for the same reason: the Bellman operator is a contraction in the max norm, so iterating it is a Banach fixed-point iteration that converges geometrically to the unique fixed point. Define the optimality operator acting on a value function by
The discount factor is doing double duty: it makes the return finite and it is exactly the contraction modulus that guarantees the algorithms converge. As the contraction weakens, convergence slows, and planning over a long horizon becomes harder, the geometric counterpart of the discounting trade-off in the table above.
Policy iteration versus value iteration
The same idea, alternating evaluation and improvement, admits a spectrum of schedules collectively called generalized policy iteration. Policy iteration evaluates fully before improving; value iteration improves after a single evaluation sweep; the general scheme interleaves partial amounts of each.
| Property | Policy iteration | Value iteration | Generalized PI |
|---|---|---|---|
| Evaluation per round | to convergence | one sweep | partial, any amount |
| Improvement | greedy, after full eval | folded into the backup | greedy, interleaved |
| Backup operator | Bellman expectation, then | Bellman optimality | mixture |
| Cost per round | high (inner loop) | low (one sweep) | tunable |
| Rounds to converge | few | more | between |
| Fixed point |
The two processes are simultaneously cooperative and competitive: improvement makes the value stale by changing the policy, evaluation corrects the value, and the joint fixed point, where the policy is greedy in its own value, is precisely the Bellman optimality equation, hence .
Where the model breaks down
Dynamic programming is exact, but it needs two things that vanish at scale: the model and a value table with one entry per state. Both fail the moment the state space is large, and the failures are what the rest of this module — and the standalone reinforcement-learning subject — exist to fix.
The model is usually unknown. A robot does not know its transition kernel; a game-playing agent is not handed the rules as equations. When is unavailable, the Bellman backups above cannot be computed, and the agent must sample transitions instead. Replacing the expectation with an average over sampled successors carries dynamic programming into Monte Carlo and temporal-difference learning, the subject of the next lesson.
The table does not fit. A tabular needs one number per state; backgammon has states and Go has , so no table can hold them and no sweep can visit them all. The fix is function approximation: replace the table with a parameterized or — a neural network — and learn from samples. That single substitution is what makes the subject deep
reinforcement learning, and it is where the deep Q-network lesson picks up.
The contraction guarantee is fragile under approximation. The clean -contraction proof above assumes exact backups on a table. Combine it with function approximation and off-policy sampling and the guarantee can break — the value estimates can diverge. This is the deadly triad (function approximation, bootstrapping, off-policy training), and much of modern deep RL is engineering around it. Sutton and Barto's text treats it at length; this module meets it concretely when DQN's target network and replay buffer appear, both of which exist precisely to keep the approximate backup stable.1
In short, this lesson is the exact, small-state ideal, and everything downstream is what survives when the model disappears and the table is replaced by a network. The Bellman equations do not change; only how their expectations are computed and stored does.
Takeaways
- Reinforcement learning is interaction-driven: an agent maps states to actions and receives an evaluative reward, maximizing the discounted return rather than any immediate signal.
- The Markov decision process is the formal object; the Markov property lets the present state summarize the past, and sets the effective horizon .
- Value functions rank behaviour: scores a state, a state-action pair, and they satisfy the Bellman expectation equations, a linear self-consistency on the value of a fixed policy.
- The optimal value functions satisfy the Bellman optimality equations (a over actions), and any policy greedy w.r.t. is optimal, which is why model-free methods target .
- With a known model, policy iteration and value iteration compute exactly; both converge because the Bellman operator is a -contraction in the max norm, giving the geometric rate .
- The unifying picture is generalized policy iteration: evaluation and improvement drive the value and policy to the mutually consistent fixed point . The same loop, with sampled experience replacing the model, becomes Monte Carlo and temporal-difference learning; the sampling and convergence intuitions connect to Monte Carlo methods and to the fixed-point geometry of the optimization landscape.
Footnotes
╌╌ END ╌╌