\", act.shape)","label":"Setup · the reach dataset"},{"code":"# THE WHOLE PIPELINE, end to end, exactly as the course taught it. Two decisions\n# are left to you -- the two that decide whether it works. Get both right.\nNORMALIZE = False # <- lesson 2 & 5: z-score inputs and outputs?\nLR = 0.01 # <- lesson 4: is the learning rate enough to converge?\nEPOCHS, H = 600, 48\n\nn = obs.shape[0]; ep = (np.arange(n)//140) % 10 # episode-level split\nval = np.array([e in {3,8} for e in ep]); tr = ~val\nxm,xs = obs[tr].mean(0), obs[tr].std(0)+1e-6 # stats on TRAIN only\nym,ys = act[tr].mean(0), act[tr].std(0)+1e-6\nX = (obs-xm)/xs if NORMALIZE else obs\nY = (act-ym)/ys if NORMALIZE else act\n\nrng = np.random.default_rng(0) # the checkpoint's shape, smaller\nW1=rng.normal(0,0.4,(7,H)); b1=np.zeros(H); W2=rng.normal(0,0.4,(H,3)); b2=np.zeros(3)\nfor e in range(EPOCHS): # train by gradient descent\n h=np.tanh(X[tr]@W1+b1); yh=h@W2+b2; err=yh-Y[tr]\n gW2=h.T@err/tr.sum(); gb2=err.mean(0); gh=(err@W2.T)*(1-h**2)\n gW1=X[tr].T@gh/tr.sum(); gb1=gh.mean(0)\n W1-=LR*gW1; b1-=LR*gb1; W2-=LR*gW2; b2-=LR*gb2\n\nh=np.tanh(X[val]@W1+b1); yhv=h@W2+b2 # honest held-out score\npred = yhv*ys+ym if NORMALIZE else yhv\nval_mse=float(((pred-act[val])**2).mean()); base=float(((act[val]-act[tr].mean(0))**2).mean())\nve = 1 - val_mse/base\nprint(f\"held-out variance explained: {ve*100:.1f}%\")","label":"The whole pipeline · set NORMALIZE and LR"},{"code":"# A shippable policy explains at least 98% of the held-out action variance.\nassert np.isfinite(ve) and ve >= 0.98, \"apply BOTH lessons: set NORMALIZE=True and raise LR to 0.2\"\nprint(\"PASS - you built the whole pipeline: data -> policy -> a held-out-verified controller.\")\nprint(\"Now make your OWN: record a dataset in Forge, train a policy, and run it.\")","label":"Hit the bar"}],"intro":"Assemble the entire course into one pipeline and reach a shippable held-out score.","key":"robot-learning/capstone-your-own-policy","kind":"python","title":"Capstone: Build the Whole Pipeline"}">
PYTHON · NUMPY · IN-BROWSER
Capstone: Build the Whole Pipeline
Assemble the entire course into one pipeline and reach a shippable held-out score.
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