4 Perfect Knowledge, Optimal Policy: Dynamic Programming
This chapter introduces dynamic programming as the most direct way to solve a Markov decision process when the full environment model is known. It contrasts model-based and model-free approaches, then shows how dynamic programming fits among the main reinforcement learning paradigms: bandits, temporal difference learning, Monte Carlo methods, tree search, and planning with full knowledge. The central message is that dynamic programming is elegant because it exploits transition probabilities and rewards to reason about the future, but it is also expensive and therefore best understood as a foundation for later RL methods rather than a universally practical solution.
The core of the chapter is the Bellman equation, presented as a recursive “domino rule” that breaks a decision’s value into immediate reward plus discounted future value. The text distinguishes between state-value functions, action-value functions, and advantage, showing how each helps evaluate behavior from a different angle. Backup diagrams are used to build intuition for how value propagates backward through possible future states. With these concepts in place, generalized policy iteration is introduced as the main dynamic programming loop: evaluate the current policy, improve it greedily using the resulting values, and repeat until the policy stabilizes.
Two worked examples make the theory concrete. In the inventory problem, repeated policy evaluation and improvement gradually transform a naive “always order one” policy into an optimal state-dependent strategy that orders more when stock is low and stops ordering when inventory is sufficient. In the resource allocation example, the chapter gives code for defining states, actions, transition probabilities, rewards, policy evaluation, policy improvement, and a full generalized policy iteration routine. The resulting learned policy behaves like a smart portfolio manager, choosing safer projects when resources are scarce and riskier ones when the budget allows. The chapter closes by emphasizing dynamic programming’s main limitations: the explosion of state space and the unrealistic requirement for a perfect model of the environment.
Five different paradigms in solving Markov decision process.
State value function representation
Backup diagram for state value function.
Action value function representation.
Backup diagram for action value function.
General algorithm and schema of general policy iteration algorithm.
Generalized policy iteration algorithm.
Visualization of results for resource allocation problem.
Summary
- Dynamic programming is a collection of model-based algorithms used to solve Markov decision processes by breaking a problem into a sequence of smaller, recursive subproblems.
- Fundamental requirement of dynamic programming is the perfect model of the environment, meaning the state transition probabilities and reward function are completely and fully given and known.
- The Bellman equations are the core mathematical tool, defining the value of a state or state-action pair recursively in terms of the values of successor states.
- We use two key metrics: the state-value function which measures the long-term value of being in a state, and the action-value function which measures the value of taking an action from that state.
- Generalized Policy Iteration is the central pattern for solving Markov decision process, involving an interaction between two processes:
- Policy Evaluation: Calculating the value function for the current policy.
- Policy Improvement: Greedily updating the policy based on the current values.
- Value Iteration is an efficient dynamic programming algorithm that combines a single sweep of evaluation with an improvement step in each iteration, guaranteeing convergence to the optimal policy.
- The hands-on resource allocation example showed dynamic programming uncovering a nuanced strategy—be conservative with low budgets, takes balanced actions with medium budgets, and acts opportunistically with high budgets.
- Dynamic programming is severely limited by the curse of dimensionality, making it computationally and memory-wise intractable for problems with large state spaces.
- The requirement of a perfect model is a second major weakness of dynamic programming as such models are unavailable or inaccurate for most real-world problems, motivating the need for model-free methods.
Applied Reinforcement Learning ebook for free