reinforcement learning
policy iteration
value iteration
decision-making algorithms
dynamic programming

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.

Practice algorithms

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 SS.
  • A set of actions AA.
  • A transition model P(ss,a)P(s' | s, a) that represents the probability of moving to state ss' from state ss given action aa.
  • A reward function R(s,a)R(s, a).
  • A discount factor γ[0,1)\gamma \in [0, 1) that models the present value of future rewards.

The objective in an MDP is to find an optimal policy π\pi^* 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.

  1. Policy Evaluation: Given a policy π\pi, compute the value function Vπ(s)V^\pi(s) which measures the expected return when starting from state ss and following policy π\pi from there onwards. This is accomplished by solving the Bellman expectation equation:
    Vπ(s)=aAπ(as)[R(s,a)+γsSP(ss,a)Vπ(s)]V^\pi(s) = \sum_{a \in A} \pi(a|s) \left[ R(s, a) + \gamma \sum_{s' \in S} P(s' | s, a) V^\pi(s') \right]
  2. Policy Improvement: Given the computed value function Vπ(s)V^\pi(s), generate a new policy π\pi' by choosing the action that yields the highest value function:
    π(s)=argmaxa[R(s,a)+γsSP(ss,a)Vπ(s)]\pi'(s) = \arg\max_a \left[ R(s, a) + \gamma \sum_{s' \in S} P(s' | s, a) V^\pi(s') \right]

Algorithm Steps

  1. Initialize an arbitrary policy π\pi.
  2. Perform Policy Evaluation for π\pi.
  3. Apply Policy Improvement to derive a new policy π\pi'.
  4. Repeat steps 2 and 3 until the policy stabilizes (i.e., π=π\pi' = \pi).

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:
    V(s)=maxa[R(s,a)+γsSP(ss,a)V(s)]V(s) = \max_a \left[ R(s, a) + \gamma \sum_{s' \in S} P(s' | s, a) V(s') \right]

This process iteratively updates the value function without explicitly maintaining a policy until convergence.

Algorithm Steps

  1. Initialize V(s)V(s) arbitrarily (often to zeros).
  2. For each state ss, update the value function using the Bellman update:
    V(s)maxa[R(s,a)+γsSP(ss,a)V(s)]V(s) \leftarrow \max_a \left[ R(s, a) + \gamma \sum_{s' \in S} P(s' | s, a) V(s') \right]
  3. Repeat the above step until the change in V(s)V(s) is below a given threshold for all ss.
  4. Derive the optimal policy using:
    π(s)=argmaxa[R(s,a)+γsSP(ss,a)V(s)]\pi^*(s) = \arg\max_a \left[ R(s, a) + \gamma \sum_{s' \in S} P(s' | s, a) V(s') \right]

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

CriteriaPolicy IterationValue Iteration
ProcessSeparate Policy Evaluation and Policy Improvement steps.Iteratively updates value estimates.
Convergence SpeedFewer iterations but costlier per iteration.More iterations but cheaper per iteration.
Policy at Each StepGenerates a policy explicitly in the improvement step.Maintains an implicit policy until the final step.
ComplexityHigh computation per iteration due to solving simultaneous equations.Lower computational overhead per iteration.
Practical Use CasesUseful when iteration count matters more than computation speed.Useful when ease of implementation is a priority over computational cost.
PerformanceEffective 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
Course
Intermediate
27 lessons
15 hours
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 course
Track 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.

Practice algorithms

All Rights Reserved.