Dynamic Programming (DP) is a core set of algorithms used in Reinforcement Learning (RL) to solve problems modeled as a Markov Decision Process (MDP)1. DP methods are particularly effective when the agent has full knowledge of the environment’s dynamics (the transition probabilities P(s’|s, a) and the reward function R(s, a, s’).

The fundamental challenge in solving MDPs is that the Bellman Equation — which defines the value of a state or action — creates a massive system of simultaneous equations. For a problem with S states and A actions, solving this system directly is computationally infeasible.

DP circumvents this by using iterative updates and the concept of bootstrapping (where updates to the value function are based on estimated values of successor states). This approach falls into two main categories: Policy Iteration and Value Iteration.

1. The Two Goals: Policy Evaluation and Policy Control

DP algorithms are built around two interlocking sub-problems:

  1. Policy Evaluation: Given a specific policy pi, calculate the state-value function $V_{\pi}(s)$ (the expected long-term return from state s if policy pi is followed). This is an intermediate step.
  2. Policy Control: Find the optimal policy pi* that maximizes the value function V*(s) for all states. This is the ultimate goal.

2. Policy Iteration: Evaluate, then Improve

The Policy Iteration method is a complete solution that alternates between Policy Evaluation and Policy Improvement until the optimal policy is found.

Step 1: Policy Evaluation (Iterative Policy Evaluation)

This step calculates the value function $V_{\pi}$ for the current policy pi. It uses the Bellman Expectation Equation iteratively:

Process: Starting with an arbitrary value function $V_0(s)$ (often all zeros) , the value of each state $s$ is updated based on the estimated value of the next state s’ (bootstrapping).

Step 2: Policy Improvement (Greedy Policy)

Once $V_{\pi}$ is accurately calculated, the policy is improved by taking an action that is greedy with respect to the new value function.

Convergence to Optimal Policy

Policy iteration alternates between evaluation and improvement. Since there is a finite number of policies in a finite MDP, this process is guaranteed to converge to the optimal policy pi* and its optimal value function V*.

3. Value Iteration: Combining Evaluation and Improvement

Value Iteration is a simplified DP algorithm that implicitly combines the Policy Evaluation and Policy Improvement steps. It does not require a full, separate policy evaluation phase.

The Core Idea: Bellman Optimality Equation

Instead of iteratively solving the Bellman Expectation Equation (Policy Evaluation), Value Iteration directly uses the Bellman Optimality Equation for V*:

Convergence and Final Policy

Policy Iteration vs. Value Iteration (Generalized Policy Iteration)

Both Policy Iteration and Value Iteration are forms of Generalized Policy Iteration (GPI), where Policy Evaluation ($V \to V$) and Policy Improvement ($\mu \to \mu’$) interact until convergence.

Value Iteration typically converges faster by reducing the number of evaluation steps, making it computationally more efficient, especially in large MDPs.

<hr><p>Dynamic Programming in RL: Policy Iteration vs. Value Iteration 🚀 was originally published in KAIST Include AI Club on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>