what the expert DID (3).\nobs, act = make_reach(seed=1)\nprint(\"observations:\", obs.shape, \" actions:\", act.shape)\nprint(\"a joint delta stays inside the +/-0.04 rad limit:\", float(np.abs(act).max()) <= 0.041)","label":"The reach task, as data"},{"code":"# A hand-written controller: \"turn each joint toward the target by a fixed gain.\"\n# This is the code you'd write WITHOUT learning. Tune K to make it as good as you can.\nK = 0.010 # <- TODO: try 0.02, 0.04, 0.08 ...\ndef hand_policy(o):\n # use only the target-error columns (3,4); ignore joints & obstacle\n te = o[:, 3:5]\n a = np.zeros((o.shape[0], 3))\n a[:,0] = K*te[:,0]; a[:,1] = K*te[:,1]; a[:,2] = K*(te[:,0]+te[:,1])\n return np.clip(a, -0.04, 0.04)\nhand_mse = float(((hand_policy(obs) - act)**2).mean())\nmean_base = float(((act - act.mean(0))**2).mean())\nprint(f\"hand-coded MSE {hand_mse:.2e} vs predict-the-mean {mean_base:.2e}\")","label":"A hand-written controller · tune K"},{"code":"# The point of the course: a LEARNED policy will beat both of these without you\n# hand-designing the rule. We just need the data to teach it.\nprint(\"hand-coded error is real, and hand-tuning K only goes so far.\")\nprint(\"PASS - you have the data and a baseline to beat.\")","label":"Why we'll learn instead"}],"intro":"Load the reach task as data, then hand-code a controller and measure how far it falls short of the expert.","key":"robot-learning/program-vs-policy","kind":"python","title":"Program vs. Policy"}">
PYTHON · NUMPY · IN-BROWSER
Program vs. Policy
Load the reach task as data, then hand-code a controller and measure how far it falls short of the expert.
You read
the arrays and values already in scope
You change
the code you write in each cell
Fixed
the dataset and the checks that grade you