FixTheRobot Explore Robotics / Robot Learning / M10 / M10-L3

This lab works on phones, but writing code is much easier on a laptop.

Robot Learning · Sim-to-Real Transfer and Robustness · M10-L3 · Intermediate

Detect When the Policy Is Out of Distribution

Experiment log · Scout at Meridian General Hospital

Experiment log, Meridian General Hospital, east corridor. Scout's tight policy was trained in the nominal simulator and works there every time. On the real floor it is slower to respond, and last Tuesday it clipped the pillar. Nobody noticed the change in its behaviour until the crash: its velocity readings had looked different for days.

You will write the monitor that would have noticed. Four small functions: describe the training readings by a mean and a covariance, score each new reading by how far it lies from that cloud in units of the cloud's own spread, choose a threshold from the training scores for a chosen false-alarm rate, and combine several scores into one alarm that hands Scout to the cautious policy. The page generates the logs, measures false alarms and detections on shifted logs, and replays the episodes with your alarms.

Your task

    Simulation
    solution.pyLoading Python…
    Ctrl+Enter runs
    What Python can I use?

    Plain Python with math and heapq. Your code runs in a background worker: an endless loop is stopped after a few seconds and the page stays usable. It runs in your browser and is never sent anywhere.

    Hints

    What this lab teaches

    Stage 1 fits a Gaussian to a small batch with the sample covariance (divide by n - 1). Stage 2 scores readings by Mahalanobis distance, which accounts for the different spread of vx and vy and for their correlation. Stage 3 sets the threshold as the (1 - fpr) quantile of the training scores and shows the trade-off: a histogram of nominal and shifted scores that overlap, and an ROC curve of detection rate against false-alarm rate. Stage 4 requires several scores in a window to exceed the threshold, looking only backwards in time, and replays the episodes switching to the cautious policy at the alarm.

    Grading is result-based, on logs you do not see: fresh nominal readings give the false-alarm rate, four kinds of shifted logs (a mild gain change, the floor, a noisy sensor, a severe mix) give the detection rate, and in the last stage the replayed episodes count false alarms, crashes avoided and goals reached.

    The questions ask what the monitor cannot tell you: that a reading is unusual is not the same as the policy being about to fail (lesson M10-T5).

    Theory for this lab

    Sim-to-Real Transfer and Robustness labs

    1. M10-L1: Randomize the Simulator
    2. M10-L2: Stress-Test a Policy
    3. M10-L3: Detect When the Policy Is Out of Distribution: this lab.
    4. M10-L4: Plan a Staged Rollout

    Educational simplification: two features (the velocity readings of the toy momentum robot), a Gaussian model for a log that is heavy-tailed and correlated in time, shifts that are simulated worlds (no real robot data), a fixed cautious policy as the fallback, and a replay that is exact because the simulator is. A toy monitor, not a certified one.

    Get the next lab

    Get notified when new robotics labs are released. One email per new lab, nothing else.