Step 2
Planning with value iteration
Back up the Bellman optimality equation until the values settle, watch them spread out from the goal, and drive the arm over the wall from four starts.
From evaluating to planning
Step 1 measured one policy. Value iteration finds the best one. The optimal value , the best expected return from , obeys the Bellman optimality equation
The bracket is the action value : take now and act optimally afterwards. A backup applies the right-hand side to every state at once. P @ V sums over for every state and action, so Q = R + gamma * (P @ V) is (S, A); Q.max(axis=1) gives the new values and Q.argmax(axis=1) the greedy policy, the best action in each state. Value iteration starts from and backs up until no value changes by more than a tolerance.
Why it settles
A backup is a contraction: it brings any two value functions and at least times closer, , where is one backup. So the largest change in each sweep shrinks by a factor of or better, and its in the Plots tab falls along a straight line, or faster.
A wave from the goal
After sweeps, is the best return within moves. A state more than moves from the goal hasn't heard of it yet, and its greedy action is no better than a guess. The Images tab shows the values after 5, 10 and 20 sweeps: they spread out from the goal one move per sweep. Start 1 is 21 moves away, so its greedy path only works after about 19 sweeps.
Your task
- Write
backup(P, R, gamma, V), one sweep, returning(V_new, policy). - Write
value_iteration(P, R, gamma, tol). From , back up until a sweep changes no value by more thantol. Return(V, policy, changes), wherechangeslists each sweep's largest change , in order.
The program compares with your step-1 policy, then drives the arm from four starts, one of them on the cup's side of the wall. Each drive must end within 1 cm of the goal and touch nothing.