v9.1.1
Menu

Policy Stability Check

easyPRODynamic ProgrammingReinforcement LearningRL 1: Foundations

Problem Statement

Policy iteration stops when the policy no longer changes. Given two deterministic policies old and new (lists of action indices), return True if they are identical (policy is stable), else False.

Implement policy_stable(old, new).

Example

Input
policy_stable([0, 1, 1], [0, 1, 1])
Output
True
Reasoning
  • Inputs: each list is a deterministic policy π\pi over 3 states. Position ss holds the action chosen in state ss, so old =[0,1,1]=[0, 1, 1] means πold(0)=0\pi_{\text{old}}(0)=0, πold(1)=1\pi_{\text{old}}(1)=1, πold(2)=1\pi_{\text{old}}(2)=1.
  • Stability condition: policy iteration has converged when improvement changed nothing, i.e. πnew(s)=πold(s)\pi_{\text{new}}(s)=\pi_{\text{old}}(s) for every state ss.
  • Sample: state 0: 0=00=0; state 1: 1=11=1; state 2: 1=11=1. All three states keep their action, so the result is True.
  • Output: a single Python bool, not a per-state list of matches.
  • Notice: one disagreement is enough to break stability. With new =[0,0,1]=[0, 0, 1], state 1 switches from action 1 to action 0, so the answer becomes False and iteration must continue.

Constraints

  • len(old) == len(new).
  • Return a Python bool.

Learn this in

More from RL 1: Foundations

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.