← Research

Technical Report · Self Model Research · Rung 4

The Margin Was Rigid: Surprise Attribution Under Simultaneous Disturbances and a Simulated Compliant Joint

The attribution rule never mistakes a push for a body change on a rigid pendulum, but its margin is thin, and on a simulated soft, noisy joint it disappears

Abstract

A self-model that adapts online has to decide whether each surprise came from its own body or from the world. Earlier reports in this series built a rule that makes that call from the time course of one-step prediction error and tested it on one disturbance at a time. Here we stress it twice. First, a 2×2 factorial on the rigid Pendulum-v1, 120 trials per cell, delivers a body change and an external push at the same moment, unannounced. The rule never mistakes a push for a body change (0/120, 95% CI 0.0–3.1%), but it misses 19/120 body changes (15.8%, 95% CI 10.4–23.4%) when a push lands with them, all through one route: the pendulum never settles, and its error flickers below the alarm requirement. The settled scores that separate body from world are apart by only +0.0014. Second, we rerun the identical trials on a simulated compliant joint (series-elastic, hysteretic, damped, with sensor noise) at 4 stiffnesses and 3 noise levels, with a forward model retrained for each body. The margin is negative in every other configuration where it can be computed. On medium and soft joints every body change is missed even with no push, false positives reach 26/120 (soft, no noise) and 52/120 (soft, low noise), and at medium noise the rule alarms on nearly every trial, undisturbed runs included. With its rigid-tuned settings, the rule is a rigid-body result. The compliant body here is simulated, not hardware.

Status of this result

This is a negative result, and it is reported as one. The rigid-body numbers are solid within their design (120 trials per cell, fixed seed, Wilson intervals). The compliant-body numbers come from a numerical model whose parameters were chosen, not measured, with one trained model and one run per configuration. They show that the rule's margin does not survive this model of compliance. They do not show how a physical joint would behave.

1Motivation

The rule tested here was designed and tuned one disturbance at a time, on a rigid pendulum with perfect sensing: a body change alone, or a push alone. Two assumptions behind that design had not been tested.

The first is that disturbances arrive separately. A robot that is loaded with a weight while being bumped, or that is damaged in a collision, gets a body change and a world event at the same instant. If the push hides the body change, the rule says “world”, the self-model does not adapt, and the robot keeps planning against a body it no longer has.

The second is that the body is rigid and the sensors are clean. A real actuator has elasticity between motor and link, hysteresis, friction and noisy encoders. All of these raise the prediction error the self-model sees while nothing is wrong, and the rule's body/world call rests on a margin between “normal” error and “changed” error.

This report tests both assumptions with the rule frozen exactly as it was. It answers how often the rule fails when both disturbances overlap, why it fails, and whether its margin survives a softer, noisier body, before any hardware is built.

2The rule under test

alarm_classifier.decide, used unchanged in both experiments. It returns one of three verdicts:

  1. Settled path. It waits for the pendulum to settle: at least 0.5 s continuously near upright and slow, starting 1 s or more after the onset. It averages the prediction error over 2 s of settled steps. If that average is above the body/world threshold, the verdict is body; otherwise it is world.
  2. Persistent path. If the pendulum never settles within 10 s, it looks at the 1 s block-mean errors from 5 to 10 s. If at least 80% of them are above the alarm threshold, the verdict is alarm.
  3. Decayed path. Otherwise the verdict is world.

How the thresholds are set:

How verdicts are scored:

3Experiment 1: simultaneous disturbances on a rigid pendulum

What it tested

The question: can the rule tell a body change from a push when both happen at the same moment, unannounced? The body is the rigid Gymnasium Pendulum-v1. The design is a 2×2 factorial:

factorlevels
body changenone · mass ×U[1.3, 1.7] · length ×U[1.2, 1.5] (half the body trials each)
world pushnone · |torque| ∈ {1, 2, 4} N·m (random sign) × duration {short 0.2 s, medium 0.5 s}
overlappush onset = body onset + U[−0.25, +0.25] s
Table 1.

The design settings come from factorial_config.py (they are not repeated in the result files).

120 trials per cell. Inside the push cells, the 6 magnitude × duration combinations are balanced at 20 each. 50 separate calibration episodes. The CSV has 530 rows: 4 × 120 trials plus 50 calibration episodes.

Results

Thresholds: body/world 0.01377 (from 50 undisturbed episodes, all of which settled); alarm 0.04042 (frozen).

ground truth→ body→ world→ alarmn
neither01200120
body only11703120
world only01200120
body + world701931120
Table 2.
ratevalue
overall misattribution19/480 = 4.0% (95% CI 2.5–6.1%)
false positive (world only → body or alarm)0/120 = 0.0% (95% CI 0.0–3.1%); 0 body, 0 alarm
masking (body + world → world)19/120 = 15.8% (95% CI 10.4–23.4%)
body only → world (reference)0/120 = 0.0%
neither → body/alarm (reference)0/120 = 0.0%
Table 3.
pushfalse positivemasking
1 N·m, short0/200/20
1 N·m, medium0/208/20 = 40%
2 N·m, short0/201/20 = 5%
2 N·m, medium0/2010/20 = 50%
4 N·m, short0/200/20
4 N·m, medium0/200/20
Table 4. By push magnitude and duration.

Masking does not grow with push size. From trials.csv, the body+world verdict paths at 4 N·m were: short pushes: all 20 went to alarm via the persistent path; medium pushes: all 20 went to body via the settled path.

groupsettledsettled score min / median / max
body present187/2400.0143 / 0.0313 / 0.0986
body absent239/2400.0080 / 0.0107 / 0.0129
Table 5. Margin: the values the rule actually used.
cellsettledpersistentdecayed
neither12000
body only11730
world only11901
body + world703119
Table 6. Verdict paths per cell.

Mechanism behind the masking

From results_factorial/trials.csv:

So the rule fails here because the error is raised but flickers around the alarm line, and it falls through the “decayed → world” branch.

Not measured here

Not in these files: why those pendulums never settled. The factorial CSV does not log the pendulum's angle. In the earlier overlap experiment (results_overlap/), an ad-hoc analysis of results_overlap/traces.npz found the masked pendulums lying fallen for the whole 5–10 s window, while their body-only and push-only twins stayed up. That analysis was not saved as a summary number. It is consistent with this experiment, but it was not re-measured here.

4Experiment 2: the same factorial on a simulated compliant joint

Simulated, not hardware

The compliant joint in this section is a numerical model with chosen parameters, not a physical device. Nothing in this report has been run on hardware.

What it tested

The question: does the separation survive when the body is compliant and noisy instead of rigid and clean? The same factorial (same master seed, same draws, same start states) was run on a simulated compliant pendulum (compliant_env.py):

stiffnessk (N·m/rad)noiseσ angle (rad)σ velocity (rad/s)
rigid(stock Pendulum-v1)none00
stiff200low0.0020.02
medium30medium0.010.1
soft4
Table 7. Grid (stiffness from summary.json; noise levels from compliant_config.py and summary.json).

Procedure for each of the 12 configurations:

  1. A forward model is retrained on 2000 random-action transitions from that body, as sensed (with noise).
  2. Rigid with no noise uses the original model and reproduces Experiment 1 exactly: same confusion matrix, gap +0.0014.
  3. The rule sees the observed (noisy) angle and velocity, not the simulator's true state.
  4. The body/world threshold is recalibrated per configuration (50 separate undisturbed episodes); the alarm threshold stays frozen at 0.04042.

Results

Definitions for the table:

configheld-outcalib settlednormal errorbody/world thrFP (body/alarm)maskmissed (no push)flagged undisturbedmisattributiongapAUC
rigid, none0.016250/500.01070.01380 (0/0)19004.0%+0.00141.000
rigid, low0.031150/500.02480.03540 (0/0)6746123.8%−0.01670.930
rigid, medium0.126550/500.12450.186715 (0/15)72120143.3%−0.10840.291
stiff, none0.007450/500.05060.05683 (3/0)8429024.2%−0.01260.980
stiff, low0.026350/500.06360.08301 (1/0)9477236.2%−0.05410.830
stiff, medium0.12200/50n/an/a116 (0/116)3311950.2%−0.02410.767
medium, none0.078650/500.06720.09195 (1/4)117120050.4%−0.02710.955
medium, low0.082450/500.04820.063118 (2/16)120120053.8%−0.02810.373
medium, medium0.14621/500.1367n/a120 (0/120)1012050.2%n/an/a
soft, none0.052750/500.09070.125626 (0/26)120120055.4%−0.04010.202
soft, low0.058550/500.06900.101152 (0/52)119120060.6%−0.04100.286
soft, medium0.13770/50n/an/a120 (0/120)0012050.0%n/an/a
Table 8.

Note on the “n/a” cells: where calibration episodes never settled, summary.json logs NaN for the threshold and the gap. For medium/medium, the normal error comes from the single calibration episode that settled. AUC is P(settled score with body change > settled score without one); 0.5 means no separation, and below 0.5 means inverted.

Four panels versus sensor noise (none, low, medium), one line per stiffness (rigid, stiff, medium, soft): false-positive rate, masking rate, rate of body changes missed with no push, and settled-score AUC.
Figure 1. The unchanged attribution rule across 4 stiffnesses and 3 noise levels, 120 trials per cell per configuration. At medium noise the masking and no-push miss rates on compliant bodies fall only because the rule alarms on every trial, undisturbed runs included (see the false-positive panel). AUC below 0.5 means the settled scores are inverted. Simulated compliant body, not hardware.

The headline numbers

  1. False positives (world only → body or alarm), with no sensor noise:
    rigidstiffmediumsoft
    0/1203/1205/12026/120 (21.7%)
    Table 9.
    With low noise: 0, 1, 18 and 52/120 (43.3%). With medium noise: 15/120 on rigid, and 116–120/120 on every compliant body.
  2. Masking (body+world → world), with no noise: rigid 15.8%, stiff 70.0%, medium 97.5%, soft 100.0%.
  3. Body changes missed with no push at all, with no noise: rigid 0/120, stiff 29/120, medium 120/120, soft 120/120.
  4. The settled-score margin. It goes from +0.0014 (rigid, no noise) to negative in every other configuration where it could be computed. The stiffest joint with no noise is already at −0.0126.
  5. AUC falls below 0.5, meaning the scores invert, in four configurations: soft/none 0.202, soft/low 0.286, rigid/medium 0.291, medium/low 0.373. There, trials without a body change have higher settled scores than trials with one.
  6. Noise breaks it on the rigid body too. On rigid, body changes missed with no push go 0 → 46 → 120/120, AUC goes 1.000 → 0.930 → 0.291, and at medium noise 15/120 pushes alarm.
config1 N·m2 N·m4 N·m
soft, none01016
soft, low01933
medium, low3411
rigid, medium078
stiff, none300
Table 10. False positives by push magnitude (by_push in summary.json; world-only trials called body or alarm, out of 40 per magnitude).

1. The normal error rises with compliance, so a body change no longer stands out.

2. Many compliant trials never settle, so the settled score is often not used at all.

settled b/nb counts trials that reached a settled verdict, with and without a body change:

configbody present settled (of 240)body absent settled (of 240)
stiff/none134196
stiff/low51185
medium/none7185
medium/low13192
Table 11.

On medium stiffness, body-change trials almost never settle. They fall through the persistence branch and, below the alarm threshold, end up as world. That is why medium/none misses 120/120 body changes even though its settled-score AUC is 0.955 on the few that did settle.

3. At medium noise on compliant bodies, the rule alarms on everything.

4. Why the scores invert (AUC < 0.5) is not diagnosed.

5Discussion

On the rigid pendulum, the rule's most important property holds: in 120 world-only trials it never called a push a body change, so a push alone never triggered adaptation. Its failures go in the conservative direction. When a push and a body change overlap, it sometimes says “world” and fails to adapt. All 19 of those failures came from one branch of the rule, the decayed path, where the error stays raised but not consistently enough to alarm. That points to a specific, testable fix (how the persistence branch treats raised but intermittent error) rather than to a flaw in the idea.

The compliant results are different in kind. Three separate things break, and they compound. The error while balancing normally rises several-fold, so a body change no longer stands out above it. Body-change trials stop settling, so the settled score that does the discriminating is often never computed. And at medium noise the frozen alarm threshold sits below the noise floor, so the rule alarms on everything. None of these is the rule misbehaving on its own terms. Each is a rigid-tuned setting (the calm limits, the settle windows, the alarm threshold) meeting a body it was not tuned for.

One observation stands out: the stiff joint's model is more accurate than the rigid one on held-out random data (0.0074 vs 0.0162), yet its error while balancing is about five times higher. Held-out accuracy on random actions is not a reliable proxy for how quiet the self-model is during closed-loop control. We have not isolated the cause. The hidden motor and spring states are the leading candidate, and that is an interpretation, not a measurement.

What this report does not test, and what would need to be tested before claiming the rule transfers: recalibrating the calm limits, settle windows and alarm threshold per body; giving the forward model a short history so it can infer hidden actuator state; filtering sensor noise before scoring; and, ultimately, a physical compliant joint. Each is a separate experiment, and none of them has been run.

6Limitations

A negative result

The central finding of this report is a failure: the attribution rule, with its rigid-tuned settings, does not transfer to this simulated compliant, noisy body. The limitations below bound how far that failure, and the rigid-body success, can be generalised.

1

Simulated compliance, not hardware. The compliant body is a model: series-elastic + hysteresis + damping + Gaussian noise. The parameters (J_MOTOR, B_MOTOR, B_JOINT, HYST, SPRING_ZETA, N_SUBSTEPS) were chosen, not measured from a real joint. They are logged in results_compliant/versions_and_seed.json.

2

The spring damper was added after a pilot, and the pilot isn't logged. It was added after a balance-only pilot showed the undamped joint could not balance. The stiffness levels were picked so each joint balanced 6/6 in that pilot, before any attribution trial. The pilot's numbers are not saved in any results file. It was an ad-hoc check, and only its design consequence is recorded (the SPRING_ZETA comment in compliant_env.py).

3

Rigid-tuned settings were held fixed. The alarm threshold stayed frozen at 0.04042 (chosen on the rigid dev set). The “calm” limits (|θ| < 0.3 rad, |θ̇| < 0.5 rad/s) and the settle/persistence windows are the rigid values. Only the body/world threshold was recalibrated per configuration, by the rule's own procedure. Recalibrating the others might change the result; that is untested.

4

One trained model per configuration. Model-to-model variation (training seed) is not measured.

5

Rigid/no-noise uses the original model (forward_model.pt). A retrained rigid model differed slightly in its weights, which I attributed to CPU thread count. That comparison was not logged; the original model was used so the earlier factorial is reproduced exactly.

6

One run per configuration, fixed seed. The confidence intervals in summary.json cover trial-to-trial variation, not reruns.

7

The fallen-pendulum explanation for masking comes from the earlier overlap experiment's traces and is not logged in the factorial results (see Experiment 1).

7Reproducibility

itemvalue
Python3.11.15
numpy2.4.6
torch2.14.0+cpu
gymnasium1.3.0
master seed90000 (all trial seeds derive from it; same draws in every configuration)
Table 12. Shared by both experiments (versions_and_seed.json in each results folder).

Compliance parameters (results_compliant/versions_and_seed.json): J_MOTOR 0.05, B_MOTOR 0.5, B_JOINT 0.3, HYST 0.3, SPRING_ZETA 0.3, N_SUBSTEPS 10.

filerole
run_factorial.py, factorial_config.pyExperiment 1
run_compliant.py, compliant_config.py, compliant_env.py, compliant_trials.py, plot_compliant.pyExperiment 2
alarm_classifier.py, classifier.pythe rule (unchanged)
results_alarm/chosen_alarm.jsonthe frozen alarm threshold
overlap_trials.pyepisode loop for Experiment 1
forward_model.ptthe rigid model
compliant_models/*.ptretrained models, one per non-rigid-none configuration
Table 13. Code (in surprise_attribution/).
pathcontents
results_factorial/summary.txtExperiment 1 summary
results_factorial/trials.csv530 rows: per-trial ground truth, verdict, path, settle time, settled score, late-window persistence values, overlap timing
results_factorial/versions_and_seed.jsonversions and seed
results_compliant/summary.txt, summary.jsonall 12 configurations
results_compliant/<config>.jsonper-configuration detail, including by_push and the confusion matrix
results_compliant/trials_<config>.csvper-trial results, 12 files
results_compliant/sweep.pngfalse-positive, masking, no-push miss rate and AUC versus noise, per stiffness
results_compliant/versions_and_seed.jsonversions, seed and compliance parameters
Table 14. Results.

Commands:

python run_factorial.py # Experiment 1
python run_compliant.py # Experiment 2, all configs (resumes from cached per-config JSON)
python run_compliant.py --only soft_low # one configuration
python run_compliant.py --summary # rebuild summary + figure from finished configs

Conclusion

On the rigid pendulum, the rule never mistook a push for a body change (0/120). But it missed 15.8% of body changes when a push landed at the same time, all through one route: never settled, error flickering below the alarm requirement. The settled scores separated by only +0.0014. On a simulated compliant body that margin disappears. Every compliant or noisy configuration has a negative gap, four configurations invert outright (AUC 0.202–0.373), and false positives climb to 21.7% (soft, no noise) and 43.3% (soft, low noise). On medium and soft joints, every body change is missed even with no push. Sensor noise does the same on the rigid body. At medium noise on compliant bodies the rule alarms on everything, undisturbed runs included. The rule, with its rigid-tuned settings, is a rigid-body result. In this simulation it does not transfer to a compliant, noisy body.

Self Model Research
  1. Rung 1The Planner Hides the Model
  2. Rung 2A Wrong Model Is Worse Than None
  3. Rung 3Surprise Has a Signature
  4. Rung 4The Margin Was Rigid (this report)
  5. Rung 5An Arc of Elimination
  6. Rung 6The Quiet Body
  7. Rung 7Why Prediction Error Falls When the Body Changes