Policy Iteration vs Value Iteration
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Overview
Policy Iteration and Value Iteration are fundamental algorithms in the field of reinforcement learning, specifically in solving Markov Decision Processes (MDPs). Understanding both algorithms is crucial for anyone looking to delve into decision-making processes under uncertainty. This article provides an in-depth exploration of these methods, their differences, applications, and implications.
Markov Decision Processes
Before diving into the algorithms, let's briefly review MDPs, the framework in which these methods operate. An MDP is defined by:
- A set of states .
- A set of actions .
- A transition model that represents the probability of moving to state from state given action .
- A reward function .
- A discount factor that models the present value of future rewards.
The objective in an MDP is to find an optimal policy that maximizes the expected sum of rewards over time.
Policy Iteration
Definition
Policy Iteration is an iterative method that involves two main steps: Policy Evaluation and Policy Improvement.
- Policy Evaluation: Given a policy , compute the value function which measures the expected return when starting from state and following policy from there onwards. This is accomplished by solving the Bellman expectation equation:
- Policy Improvement: Given the computed value function , generate a new policy by choosing the action that yields the highest value function:
Algorithm Steps
- Initialize an arbitrary policy .
- Perform Policy Evaluation for .
- Apply Policy Improvement to derive a new policy .
- Repeat steps 2 and 3 until the policy stabilizes (i.e., ).
Advantages and Disadvantages
- Advantages: It often converges in fewer iterations compared to Value Iteration as it directly refines the policy.
- Disadvantages: Each iteration may require a substantial amount of computation, particularly in large state spaces, due to the policy evaluation step.
Value Iteration
Definition
Value Iteration is a simpler method but uses similar principles. It iterates directly on the value function rather than undergoing separate evaluation and improvement phases.
- Bellman Optimality Equation: The core update rule is derived from this equation:
This process iteratively updates the value function without explicitly maintaining a policy until convergence.
Algorithm Steps
- Initialize arbitrarily (often to zeros).
- For each state , update the value function using the Bellman update:
- Repeat the above step until the change in is below a given threshold for all .
- Derive the optimal policy using:
Advantages and Disadvantages
- Advantages: Conceptually simpler and doesn't distinctly separate evaluation from policy improvement.
- Disadvantages: Typically requires more iterations to converge compared to Policy Iteration.
Comparison Table
| Criteria | Policy Iteration | Value Iteration |
| Process | Separate Policy Evaluation and Policy Improvement steps. | Iteratively updates value estimates. |
| Convergence Speed | Fewer iterations but costlier per iteration. | More iterations but cheaper per iteration. |
| Policy at Each Step | Generates a policy explicitly in the improvement step. | Maintains an implicit policy until the final step. |
| Complexity | High computation per iteration due to solving simultaneous equations. | Lower computational overhead per iteration. |
| Practical Use Cases | Useful when iteration count matters more than computation speed. | Useful when ease of implementation is a priority over computational cost. |
| Performance | Effective in environments where policies change less frequently. | Strong in dynamic, frequently changing state environments. |
Additional Considerations
Convergence Criteria
For both methods, convergence is typically determined when the change in the value function is less than a predefined threshold across all states:
- In Policy Iteration, convergence is reached when the policy no longer changes.
- In Value Iteration, convergence is reached when the value function updates are negligible.
Applicability
While both methods achieve the same end result (an optimal policy), the choice between them depends on the specific problem characteristics and constraints like state-action space size, computational resources, and the need for intermediate policies.
Conclusion
Both Policy Iteration and Value Iteration are powerful in optimal policy determination for MDPs. Understanding their mechanics allows for informed decisions on which method suits a particular problem, balancing between computational efficiency and implementation complexity. By mastering these techniques, practitioners can better address complex decision-making scenarios where uncertainties prevail.
Related reading
- Polygon infill algorithm
- polygon union without holes
- Polynomial time and exponential time
- Polynomial time solution for Tetris Puzzle
- Poor man's authentication algorithm?
- Popularity decay algorithm for popular website posts
- Possible Interview Question How to Find All Overlapping Intervals
- Possible permutations of BST's input

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.