Repeats the Bellman optimality sweep
V(s) <- max_a sum_s2 P(s2|s,a) [ r(s,a) + gamma V(s2) ] until the
largest change in a sweep falls below tol, then returns the
deterministic greedy policy with ties broken to the lowest action
index (Sutton & Barto 2018, Sec. 4.4 boxed algorithm, p. 83).
Arguments
- P
List of A transition matrices, each (S, S), rows summing to 1;
P[[a]][s, s2] = P(s2 | s, a).- R
Reward: (S, A) matrix of r(s, a), or a list of A (S, S) per-transition reward matrices averaged under P.
- gamma
Discount factor.
- tol
Sweep-change threshold.
- max_iter
Maximum sweeps.
- V0
Optional initial value vector.
Value
A list with elements estimate (V), policy
(0-based actions), q, n_iter, delta,
converged, method.
