Full Value Iteration to Convergence
Problem Statement
Run value iteration to convergence on a finite MDP and return the optimal values. The MDP is given as mdp[s] = list of actions, each {"reward": r, "probs": [...], "next": [...]}. Start from all-zero values and repeat synchronous optimality sweeps until the max-norm change is below theta, or max_iters is reached.
Implement value_iteration(mdp, gamma, theta, max_iters) returning the optimal values (list of floats, rounded is not required).
Example
value_iteration([[{"reward":0.0,"probs":[1.0],"next":[0]}]], 0.9, 1e-9, 1000)[0.0]
- Initialization: The MDP contains a single state (). The value function is initialized to all zeros, so .
- First Iteration (Sweep): For state 0, the only available action has a reward of and transitions to state 0 with probability . The Q-value is calculated as . Since this is the only action, the new value for state 0 is .
- Convergence Check: The maximum change in values is . This change is compared against the threshold . Since , the convergence criterion is met immediately after the first iteration.
- Termination: The loop breaks because the values have stabilized (the change is below the threshold). The algorithm does not need to perform further iterations.
- The final output is
[0.0]
Constraints
- Synchronous updates (a full sweep uses the previous sweep's values).
- Stop when max_s |V_new - V_old| < theta or after max_iters sweeps.
0 <= gamma < 1guarantees convergence.