Step 1
The reach as a decision process
Cut the arm's configuration space into a grid of states, write a policy that lifts the hand over the wall, and measure how good it is with policy evaluation.
The task as a decision process
The arm must carry its hand from the ball side of the table to above the cup, and the Motion Planning wall is in the way. Here it thinks in a grid, a 24 × 24 slice of its configuration space. Rows are the shoulder angle (row 0 holds the hand high, row 23 brushes the table), columns the base angle (column 0 far left, column 20 facing the cup); the elbow and wrist stay fixed. Each cell is a state , for row and column .
A Markov decision process (MDP) describes the task:
| Symbol | Here |
|---|---|
an action: one of 8 moves to a neighbouring cell, UP, DOWN, LEFT, RIGHT or a diagonal | |
| the chance that takes the arm from to : the intended cell 90 % of the time, otherwise a slip 90° to one side | |
| the expected reward: −1 per move, −10 for a move into something (the arm stays put) | |
| the discount, 0.95: a reward moves away counts times |
The goal, cell (17, 20) above the cup, ends the task: nothing more is earned there.
Policies and their value
A policy picks an action in every state. Its value is the expected return (the discounted sum of the rewards ) when you start in and follow : minus a discounted count of moves, so closer to 0 is better. It obeys the Bellman equation
Policy evaluation turns it into an update: start from and apply the right-hand side to every state, sweep after sweep, until no value changes by more than a tolerance. In numpy, P[np.arange(S), policy] picks each state's row for its own action, an S × S matrix , and R[np.arange(S), policy] the rewards . One sweep is R_pi + gamma * P_pi @ V.
Your task
- Write
evaluate_policy(P, R, gamma, policy, tol).mdp.Pis (S, A, S) andmdp.Ris (S, A). - Fix
my_policy(i, j). It heads straight for the cup's column, and the wall stops it. Make it lift the hand over the wall first: rows 0 to 10 are clear all the way across.
The Images tab shows your (blue low, yellow high, blocked cells black) with the path from start 1, and the arm drives it. From all three starts your policy must reach the goal without touching anything.