omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
GitHub aien-dev/omega-mv#252 (code only)
Apply it
git checkout -b patch-06cce05a4866f73d 9f19bc63c55e858af8608451fb7deaa6af45b9cf curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/06cce05a4866f73d.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
252
1e40ea7236b29cdf43dba6f761d44eb07c62d9f5
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":252,"url":"https://github.com/aien-dev/omega-mv/pull/252","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:59Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/docs/physics0/LEARNER.md b/docs/physics0/LEARNER.md index 6204d3361..767fdc92d 100644 --- a/docs/physics0/LEARNER.md +++ b/docs/physics0/LEARNER.md @@ -8,9 +8,10 @@ learner refuses them if offered), and it emits evidence for the independent ladder checker of `src/physics0/ladder`. It never declares a ladder state. Spec: aien-dev/physics `docs/PD0_HIDDEN_EQUATION_BENCHMARK.md` rev 2 -(2f881b1); world parameters follow rev 3 (omega #248, merged); the two rev 5 -rules (requested-reset preregistration hash, no T2 self pairs) are -implemented in the checker and the learner ahead of the spec text. +(2f881b1); world parameters follow rev 3 (omega #248, merged); the rev 5 rules +(requested-reset preregistration hash, no T2 self pairs) and the rev 6 rules +(rollout error over the pooled FIT sd, EPISODE_END records count as +observations) are implemented in the checker and the learner. ## Layout @@ -72,33 +73,30 @@ learner refits (at most three attempts). The checker runs after each stage; the harness never proceeds to trials without a HYPOTHESIS state. The scorer runs on 20 noise-free truth episodes (10 in the reset box, 10 at 1.5x). -## Development results (seeds 1..5, rev 3 world, rev 5 checker rules) +## Development results (seeds 1..5, rev 3 world, rev 6 checker rules) Learner never saw HOLDOUT/TRIAL/REP. "state" is the checker's verdict; -"scorer" is `pd0_score` against the truth. The previous receipt (rev 2 -world, DESC1) is kept beside the new one. +"scorer" is `pd0_score` against the truth. Earlier receipts (rev 2 world; +rev 5 rules) are kept beside the new one. | level | state reached (seeds) | scorer | size / bound | bits | notes | |---|---|---|---|---|---| -| L0 | PREDICTED 5/5 | PASS 5/5 (exact) | 2 / 4 | 96 | T6 "trial missing": the rev 3 L0 episode is 20 steps, the 20th record is EPISODE_END not OK, so no trial has 20 OK steps; see spec item 2 | +| L0 | PROVISIONAL_LAW 4/5, INTERVENED 1/5 | PASS 5/5 (exact) | 2 / 4 | 96 | seed 5: one replication episode left the box, batch short by one (code 261) | | L1 | PROVISIONAL_LAW 5/5 | PASS 5/5 | 3 / 5 | 144 | exact, one-step error 0 | | L2 | PROVISIONAL_LAW 5/5 | PASS 5/5 | 4 / 6 | 192 | exact | | L3 | PROVISIONAL_LAW 5/5 | PASS 5/5 | 8 / 10 | 576 | four variables, two channels, exact | -| L4 | PROVISIONAL_LAW 5/5 | PASS 5/5 (in-box 0.008 to 0.023 on the rev 3 box) | 4 / 6 | 192 | cubic term found | -| L5 | INTERVENED 1/5, CANDIDATE 4/5 (1 to 3 refutations) | PASS 5/5 (in-box 0.004 to 0.015, constants within 10%) | 4 / 6 | 192 | preregistration now matches (rev 5 rule); trials fail on in-trial NRMSE, see spec item 1 | -| L6 | CANDIDATE 5/5 (3 refutations each) | FAIL 5/5 (307 latent missing, 308 reference too good) | 5 to 6 / 9 | 240 to 288 | reported, not claimed: no latent mechanism; rev 3 constants make the hidden variable matter more (in-box 0.05 to 0.08) | -| null | OBSERVATION 5/5 | not scored | 2 / 6 | 96 | no correlation evidence once self pairs are excluded; no candidate admitted; NC-1 holds | +| L4 | PROVISIONAL_LAW 5/5 | PASS 5/5 (in-box 0.008 to 0.023) | 4 / 6 | 192 | cubic term found | +| L5 | PROVISIONAL_LAW 5/5 | PASS 5/5 (in-box 0.004 to 0.018, constants within 10%) | 4 / 6 | 192 | no refutations once the trial error is pooled-sd normalised | +| L6 | CANDIDATE 5/5 (3 refutations each) | FAIL 5/5 (307 latent missing, 308 reference too good) | 5 to 6 / 9 | 240 to 288 | reported, not claimed: no latent mechanism | +| null | OBSERVATION 5/5 | not scored | 2 / 6 | 96 | no correlation evidence, no candidate; NC-1 holds | Numbers per instance: `evidence/physics0/learner/pd0-learner-dev-<commit>.txt`. ## Failure analysis -- **L5 (noise).** The relation is right (scorer PASS on all seeds, constants - within 10%) and trials now match their preregistration. They fail T6 because - the trial error is an NRMSE normalised by the within-trial spread of the - observed trajectory: a quiet 20-step trial has a small spread, so 0.02 - observation noise alone exceeds the 0.05 bound. Same mechanism refutes - REP episodes (code 266). Not a learner defect; see spec item 1. +- **L5 (noise).** Reaches PROVISIONAL_LAW on every seed with the rev 6 + normalisation; the rev 5 failure (quiet trials judged against their own + spread) is gone. - **L6 (hidden variable).** Candidates are latent-free fits; on 1 of 5 seeds the ladder still replicates one (the checker has no latent requirement; the scorer does and rejects all five). On the other seeds the @@ -106,8 +104,9 @@ Numbers per instance: `evidence/physics0/learner/pd0-learner-dev-<commit>.txt`. model class. `hidden_state_suspected` did not fire on L6 because the latent-free fit's one-step residuals are small (0.001 to 0.005); the flag needs a rollout-based test, left for the next cut. -- **L0.** Exact relation on every seed; blocked at T6 because a 20-step - episode yields 19 OK records plus one EPISODE_END record (spec item 2). +- **L0.** PROVISIONAL_LAW on four seeds. Seed 5 lost one replication + episode to an out-of-bounds step from a random schedule, leaving that batch + at nine episodes; the harness does not top batches up (next cut). - **Null world.** With self pairs excluded (rev 5) no correlation evidence exists and the ladder stays at OBSERVATION. The MDL ranking still puts "pull to the mean" above the empty relation, which is the correct @@ -115,23 +114,20 @@ Numbers per instance: `evidence/physics0/learner/pd0-learner-dev-<commit>.txt`. ## Spec items that proved unimplementable or ambiguous as written -1. **Noisy-level trial error.** T6/T7 normalise the trial error by the - within-trial spread of the observed trajectory. On L5 (sigma 0.02) any - trial whose trajectory spread is below about 0.4 units fails the 0.05 - bound even for the true relation. The spec should normalise by the - declared reset-box scale, or set the noisy eps relative to sigma. Spec - owner decision needed; the learner claims nothing on L5. -2. **L0 episode length.** With rev 3 the L0 episode is exactly 20 steps and - the world marks the 20th step EPISODE_END, so no episode has the 20 OK - steps T5/T6/T7 require. Either the world returns OK on step 20 and - refuses step 21, or the checker counts an EPISODE_END step as observed. -3. **L6 pass rule** (factor-3 reference margin) is still open with Drake; +1. **L6 pass rule** (factor-3 reference margin) is still open with Drake; the learner reports L6 and claims nothing. -4. **Requested reset on noisy levels** (rev 5 rule as implemented): the +2. **Requested reset on noisy levels** (rev 5 rule as implemented): the ledger record does not carry the requested reset vector, so on noisy levels the checker binds the reset through the PD0EXP1 entry and the steps only; the trial error bound covers a mismatched reset. A reset record that carries the requested values would close this. +3. **Replication batches and out-of-bounds episodes.** A random replication + schedule can leave the box; the episode then has fewer than 20 outcomes + and the batch falls short (L0 seed 5). The spec should say whether the + harness may run a replacement episode in the same batch. + +Resolved by rev 5 and rev 6: noisy-reset preregistration hash, T2 self +pairs, within-trial error normalisation, EPISODE_END outcomes. ## Not implemented diff --git a/evidence/physics0/learner/pd0-learner-dev-b1ae4f609128.txt b/evidence/physics0/learner/pd0-learner-dev-b1ae4f609128.txt new file mode 100644 index 000000000..72dc0af69 --- /dev/null +++ b/evidence/physics0/learner/pd0-learner-dev-b1ae4f609128.txt @@ -0,0 +1,48 @@ +receipt: PD0_LEARNER_DEV +commit: b1ae4f609128b442554ce61411dde185aedcd1e6 +date_utc: 2026-10-04T00:42:05Z +levels: 0 1 2 3 4 5 6 null +seeds: 1 2 3 4 5 (development seeds; HOLDOUT/TRIAL/REP withheld by the harness) +--- isolation +PHYSICS0_ISOLATION: PASS (3 learner-side objects clean) +--- results +PD0L level=L0 seed=1 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=4 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L0 seed=2 desc=v2 episodes=145 steps=2898 fit=1317 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=4 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=1 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L0 seed=3 desc=v2 episodes=145 steps=2899 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=4 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=1 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L0 seed=4 desc=v2 episodes=145 steps=2899 fit=1320 select=437 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=4 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=2 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L0 seed=5 desc=v2 episodes=145 steps=2899 fit=1320 select=440 state=INTERVENED code=261 stall=261 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=4 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=1 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L1 seed=1 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=3 cand_bits=144 size_bound=5 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=1 extrap=1 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L1 seed=2 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=3 cand_bits=144 size_bound=5 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=2 extrap=2 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L1 seed=3 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=3 cand_bits=144 size_bound=5 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=6 extrap=6 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L1 seed=4 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=3 cand_bits=144 size_bound=5 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=1 extrap=1 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L1 seed=5 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=3 cand_bits=144 size_bound=5 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=8 extrap=4 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L2 seed=1 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=0 select_nrmse=1 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=2 extrap=2 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L2 seed=2 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=1 extrap=1 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L2 seed=3 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=1 extrap=2 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L2 seed=4 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=4 extrap=3 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L2 seed=5 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=1 select_nrmse=1 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=5 extrap=3 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L3 seed=1 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=8 cand_bits=576 size_bound=10 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=4 extrap=3 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L3 seed=2 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=8 cand_bits=576 size_bound=10 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=1 extrap=1 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L3 seed=3 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=8 cand_bits=576 size_bound=10 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=3 extrap=4 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L3 seed=4 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=8 cand_bits=576 size_bound=10 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=4 extrap=3 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L3 seed=5 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=8 cand_bits=576 size_bound=10 fit_nrmse=0 select_nrmse=0 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=3 extrap=2 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L4 seed=1 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=1 select_nrmse=2 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=23 extrap=28 onestep=2 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L4 seed=2 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=1 select_nrmse=1 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=9 extrap=8 onestep=1 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L4 seed=3 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=1 select_nrmse=1 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=8 extrap=6 onestep=1 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L4 seed=4 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=1 select_nrmse=1 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=9 extrap=6 onestep=0 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L4 seed=5 desc=v2 episodes=145 steps=2900 fit=1320 select=440 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=1 select_nrmse=1 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=15 extrap=6 onestep=1 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L5 seed=1 desc=v2 episodes=295 steps=5900 fit=3120 select=1040 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=30248 select_nrmse=32375 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=3903 extrap=4164 onestep=497 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L5 seed=2 desc=v2 episodes=295 steps=5900 fit=3120 select=1040 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=38039 select_nrmse=42991 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=10846 extrap=9891 onestep=1088 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L5 seed=3 desc=v2 episodes=295 steps=5900 fit=3120 select=1040 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=32341 select_nrmse=34964 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=17789 extrap=18118 onestep=2176 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L5 seed=4 desc=v2 episodes=295 steps=5900 fit=3120 select=1040 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=33607 select_nrmse=33926 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=9881 extrap=10085 onestep=1294 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L5 seed=5 desc=v2 episodes=295 steps=5900 fit=3120 select=1040 state=REPLICATED code=0 stall=0 refutations=0 attempts=1 cand_size=4 cand_bits=192 size_bound=6 fit_nrmse=31997 select_nrmse=32532 hidden_state=0 score=PASS score_code=0 mask=0x0 inbox=6186 extrap=6864 onestep=685 ref=0 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L6 seed=1 desc=v2 episodes=275 steps=5500 fit=3420 select=1040 state=CANDIDATE code=251 stall=250 refutations=3 attempts=3 cand_size=6 cand_bits=288 size_bound=9 fit_nrmse=10622 select_nrmse=10781 hidden_state=1 score=FAIL score_code=307 mask=0x183 inbox=83238 extrap=170182 onestep=0 ref=66472 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L6 seed=2 desc=v2 episodes=275 steps=5500 fit=3420 select=1040 state=CANDIDATE code=251 stall=250 refutations=3 attempts=3 cand_size=5 cand_bits=240 size_bound=9 fit_nrmse=6758 select_nrmse=6819 hidden_state=1 score=FAIL score_code=307 mask=0x181 inbox=67405 extrap=74489 onestep=0 ref=63828 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L6 seed=3 desc=v2 episodes=275 steps=5500 fit=3420 select=1040 state=CANDIDATE code=251 stall=250 refutations=3 attempts=3 cand_size=5 cand_bits=240 size_bound=9 fit_nrmse=8389 select_nrmse=8490 hidden_state=1 score=FAIL score_code=307 mask=0x181 inbox=60855 extrap=75487 onestep=0 ref=58964 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L6 seed=4 desc=v2 episodes=275 steps=5500 fit=3420 select=1040 state=CANDIDATE code=251 stall=250 refutations=3 attempts=3 cand_size=5 cand_bits=240 size_bound=9 fit_nrmse=6525 select_nrmse=6878 hidden_state=1 score=FAIL score_code=307 mask=0x181 inbox=54335 extrap=73008 onestep=0 ref=59366 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=L6 seed=5 desc=v2 episodes=275 steps=5500 fit=3420 select=1040 state=CANDIDATE code=251 stall=250 refutations=3 attempts=3 cand_size=5 cand_bits=240 size_bound=9 fit_nrmse=7792 select_nrmse=7646 hidden_state=1 score=FAIL score_code=307 mask=0x181 inbox=72836 extrap=69814 onestep=0 ref=68627 score_eps=20 law=0 checker_rc=0 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=null seed=1 desc=v2 episodes=110 steps=2200 fit=1320 select=440 state=OBSERVATION code=270 stall=211 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=6 fit_nrmse=1000700 select_nrmse=1000751 hidden_state=0 score=NOT_SCORED score_code=-1 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=0 law=-1 checker_rc=270 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=null seed=2 desc=v2 episodes=110 steps=2200 fit=1320 select=440 state=OBSERVATION code=270 stall=211 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=6 fit_nrmse=1000709 select_nrmse=1001724 hidden_state=0 score=NOT_SCORED score_code=-1 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=0 law=-1 checker_rc=270 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=null seed=3 desc=v2 episodes=110 steps=2200 fit=1320 select=440 state=OBSERVATION code=270 stall=211 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=6 fit_nrmse=999896 select_nrmse=1007210 hidden_state=0 score=NOT_SCORED score_code=-1 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=0 law=-1 checker_rc=270 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=null seed=4 desc=v2 episodes=110 steps=2200 fit=1320 select=440 state=OBSERVATION code=270 stall=211 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=6 fit_nrmse=1000521 select_nrmse=1000384 hidden_state=0 score=NOT_SCORED score_code=-1 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=0 law=-1 checker_rc=270 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 +PD0L level=null seed=5 desc=v2 episodes=110 steps=2200 fit=1320 select=440 state=OBSERVATION code=270 stall=211 refutations=0 attempts=1 cand_size=2 cand_bits=96 size_bound=6 fit_nrmse=1000243 select_nrmse=1000843 hidden_state=0 score=NOT_SCORED score_code=-1 mask=0x0 inbox=0 extrap=0 onestep=0 ref=0 score_eps=0 law=-1 checker_rc=270 oob=0 refused=0 budget_hits=0 propose_fail=0 trial_random=0 diff --git a/src/physics0/ladder/pd0_ladder.c b/src/physics0/ladder/pd0_ladder.c index 43b4a48d1..86c425dda 100644 --- a/src/physics0/ladder/pd0_ladder.c +++ b/src/physics0/ladder/pd0_ladder.c @@ -72,6 +72,23 @@ int64_t pd0_nrmse_micro(const int64_t *pred, const int64_t *obs, uint32_t n, uin for (uint32_t i = 0; i < n; i++) acc_add(&a, pred + (size_t)i * n_obs, obs + (size_t)i * n_obs, n_obs); return acc_nrmse(&a, n_obs); } +/* spec rev 6 (b): a step record carries an outcome (valid vars_after) when it is OK or EPISODE_END; + * only REFUSED_RANGE, OUT_OF_BOUNDS and BUDGET_EXHAUSTED carry none. */ +static int rec_has_outcome(const pd0_rec *r) { return r->status == PD0_ST_OK || r->status == PD0_ST_EPISODE_END; } +/* spec rev 6 (a): rollout error per variable = RMSE / pooled sd of that variable over the FIT records, + * never the within-trial spread (sd_micro[j] == 0 falls back to the plain RMSE) */ +static int64_t acc_nrmse_sd(const nrmse_acc *a, uint8_t n_obs, const int64_t *sd_micro) +{ + if (a->n == 0) return INT64_MAX; double worst = 0; + for (int j = 0; j < n_obs; j++) { double rmse = sqrt(a->se[j] / a->n), sd = (double)sd_micro[j] / 1e6; double v = sd > 1e-9 ? rmse / sd : rmse; if (v > worst) worst = v; } + return worst > 9e12 ? INT64_MAX : (int64_t)(worst * 1e6); +} +int64_t pd0_nrmse_pooled_micro(const int64_t *pred, const int64_t *obs, uint32_t n, uint8_t n_obs, const int64_t *sd_micro) +{ + nrmse_acc a; memset(&a, 0, sizeof a); + for (uint32_t i = 0; i < n; i++) acc_add(&a, pred + (size_t)i * n_obs, obs + (size_t)i * n_obs, n_obs); + return acc_nrmse_sd(&a, n_obs, sd_micro); +} uint32_t pd0_confidence_ppm(uint32_t p, uint32_t f) { return (uint32_t)((1000000ull * (p + 1)) / (p + f + 2)); } /* ---------- internal model ---------- */ @@ -101,7 +118,7 @@ static int ep_visible(const episode *e) { return e->has_tag && (e->tag == TAG_FI static int ep_fit(const episode *e) { return e->has_tag && e->tag == TAG_FIT; } static uint32_t ep_ok_steps(const ctx *c, const episode *e) { - uint32_t k = 0; for (uint32_t i = 0; i < e->n; i++) { const pd0_rec *r = &c->rec[e->first + i]; if (r->kind == PD0_KIND_STEP && r->status == PD0_ST_OK) k++; } + uint32_t k = 0; for (uint32_t i = 0; i < e->n; i++) { const pd0_rec *r = &c->rec[e->first + i]; if (r->kind == PD0_KIND_STEP && rec_has_outcome(r)) k++; } return k; } /* schedule hash over the reset record and the first n_steps OK steps */ @@ -109,7 +126,7 @@ static int ep_schedule_hash(const ctx *c, const episode *e, uint8_t n_steps, uin { const pd0_rec *r0 = &c->rec[e->first]; if (r0->kind != PD0_KIND_RESET) return 0; pd0_step st[PD0_MAX_STEPS]; uint8_t k = 0; - for (uint32_t i = 1; i < e->n && k < n_steps; i++) { const pd0_rec *r = &c->rec[e->first + i]; if (r->kind == PD0_KIND_STEP && r->status == PD0_ST_OK) { st[k].channel = r->channel; st[k].value = r->applied; k++; } } + for (uint32_t i = 1; i < e->n && k < n_steps; i++) { const pd0_rec *r = &c->rec[e->first + i]; if (r->kind == PD0_KIND_STEP && rec_has_outcome(r)) { st[k].channel = r->channel; st[k].value = r->applied; k++; } } if (k < n_steps) return 0; pd0_schedule_hash(r0->n_obs, r0->after, n_steps, st, out); return 1; @@ -123,7 +140,7 @@ static int ep_matches_prereg(const ctx *c, const episode *ep, const pd0_exp *e) { const pd0_rec *r0 = &c->rec[ep->first]; if (r0->kind != PD0_KIND_RESET || r0->n_obs != e->n_obs) return 0; pd0_step st[PD0_MAX_STEPS]; uint8_t k = 0; - for (uint32_t i = 1; i < ep->n && k < e->n_steps; i++) { const pd0_rec *r = &c->rec[ep->first + i]; if (r->kind == PD0_KIND_STEP && r->status == PD0_ST_OK) { st[k].channel = r->channel; st[k].value = r->applied; k++; } } + for (uint32_t i = 1; i < ep->n && k < e->n_steps; i++) { const pd0_rec *r = &c->rec[ep->first + i]; if (r->kind == PD0_KIND_STEP && rec_has_outcome(r)) { st[k].channel = r->channel; st[k].value = r->applied; k++; } } if (k < e->n_steps) return 0; uint8_t h[PD0_HASH]; pd0_schedule_hash(e->n_obs, e->reset, e->n_steps, st, h); if (memcmp(h, e->schedule_hash, PD0_HASH)) return 0; if (!c->P->noisy) for (int j = 0; j < e->n_obs; j++) if (r0->after[j] != e->reset[j]) return 0; @@ -149,13 +166,23 @@ static void add_experiment(ctx *c, const uint8_t *id, uint8_t kind, const uint8_ memcpy(x->prereg_hash, prereg_hash, PD0_HASH); memcpy(x->outcome_hash, outcome, PD0_HASH); x->result = result; x->first_seq = first; x->last_seq = last; } +/* pooled sd per observed variable over the outcomes of FIT records (spec rev 6 a) */ +static void fit_sd(const ctx *c, int64_t *sd_micro) +{ + uint8_t no = c->P->n_obs; double s[PD0_MAX_OBS] = { 0 }, ss[PD0_MAX_OBS] = { 0 }; uint32_t n = 0; + for (uint32_t i = 0; i < c->nep; i++) { const episode *e = &c->ep[i]; if (!ep_fit(e)) continue; + for (uint32_t j = 0; j < e->n; j++) { const pd0_rec *r = &c->rec[e->first + j]; if (r->kind != PD0_KIND_STEP || !rec_has_outcome(r)) continue; + for (int v = 0; v < no; v++) { double x = (double)r->after[v] / 1e6; s[v] += x; ss[v] += x * x; } n++; } } + for (int v = 0; v < no; v++) { double m = n ? s[v] / n : 0, var = n ? ss[v] / n - m * m : 0; sd_micro[v] = var > 0 ? (int64_t)(sqrt(var) * 1e6) : 0; } +} +static int64_t nrmse_pooled(const ctx *c, const int64_t *pred, const int64_t *obs, uint32_t m, uint8_t no) { int64_t sd[PD0_MAX_OBS]; fit_sd(c, sd); return pd0_nrmse_pooled_micro(pred, obs, m, no, sd); } /* rollout of relation along an episode's recorded applied schedule; fills pred[n][n_obs] for the first n OK steps */ static uint32_t rollout_episode(const ctx *c, const pd0_rel *rel, const episode *e, uint32_t n, int64_t *pred, int64_t *obs, const pd0_rec **last) { const pd0_rec *r0 = &c->rec[e->first]; int64_t st[PD0_MAX_VARS], nx[PD0_MAX_VARS]; uint32_t k = 0; uint8_t no = c->P->n_obs; memset(st, 0, sizeof st); for (int j = 0; j < no; j++) st[j] = r0->after[j]; for (uint32_t i = 1; i < e->n && k < n; i++) { - const pd0_rec *r = &c->rec[e->first + i]; if (r->kind != PD0_KIND_STEP || r->status != PD0_ST_OK) continue; + const pd0_rec *r = &c->rec[e->first + i]; if (r->kind != PD0_KIND_STEP || !rec_has_outcome(r)) continue; pd0_rel_step(rel, st, r->channel, r->applied, nx); for (int j = 0; j < no; j++) { pred[k * no + j] = nx[j]; obs[k * no + j] = r->after[j]; } memcpy(st, nx, sizeof st); k++; if (last) *last = r; @@ -181,7 +208,7 @@ static int try_t2(ctx *c, const pd0_corr *k) double *x = malloc(sizeof(double) * MAX_REC), *y = malloc(sizeof(double) * MAX_REC); uint32_t n = 0; if (!x || !y) { free(x); free(y); return PD0V_TOO_LARGE; } for (uint32_t i = 0; i < c->nep; i++) { const episode *e = &c->ep[i]; if (!ep_visible(e)) continue; - for (uint32_t j = 0; j < e->n; j++) { const pd0_rec *r = &c->rec[e->first + j]; if (r->kind != PD0_KIND_STEP || r->status != PD0_ST_OK) continue; + for (uint32_t j = 0; j < e->n; j++) { const pd0_rec *r = &c->rec[e->first + j]; if (r->kind != PD0_KIND_STEP || !rec_has_outcome(r)) continue; x[n] = (k->var_a == PD0_CHAN_NONE) ? (double)r->applied : (double)r->before[k->var_a]; y[n] = (double)(r->after[k->var_b] - r->before[k->var_b]); n++; } } int rc = 0; if (n < 100 || n != k->n) { set_code(c, 2, PD0V_T2_TOO_FEW_RECORDS); } @@ -211,7 +238,7 @@ static void try_t3(ctx *c, const relent *re) int64_t st[PD0_MAX_VARS], nx[PD0_MAX_VARS]; memset(st, 0, sizeof st); double prev_res[PD0_MAX_OBS] = { 0 }; int have_prev = 0; for (uint32_t j = 0; j < e->n; j++) { const pd0_rec *r = &c->rec[e->first + j]; if (r->kind == PD0_KIND_RESET) { memset(st, 0, sizeof st); for (int v = 0; v < no; v++) st[v] = r->after[v]; have_prev = 0; continue; } - if (r->status != PD0_ST_OK) continue; + if (!rec_has_outcome(r)) continue; for (int v = 0; v < no; v++) st[v] = r->before[v]; pd0_rel_step(rel, st, r->channel, r->applied, nx); acc_add(&a, nx, r->after, no); @@ -266,11 +293,11 @@ static int try_t6(ctx *c) /* evaluate every trial against the committed prediction (hypothesis index 0) */ int64_t obs[PD0_MAX_STEPS * PD0_MAX_OBS], pk[PD0_MAX_STEPS * PD0_MAX_OBS]; for (uint32_t k = 0; k < c->npre; k++) { prereg *p = &c->pre[k]; const episode *ep = &c->ep[p->matched_ep]; uint32_t m = 0; const pd0_rec *last = NULL, *worst_rec = NULL; int64_t wp = 0, wo = 0, wd = -1; - for (uint32_t i = 1; i < ep->n && m < n; i++) { const pd0_rec *r = &c->rec[ep->first + i]; if (r->kind != PD0_KIND_STEP || r->status != PD0_ST_OK) continue; + for (uint32_t i = 1; i < ep->n && m < n; i++) { const pd0_rec *r = &c->rec[ep->first + i]; if (r->kind != PD0_KIND_STEP || !rec_has_outcome(r)) continue; for (int j = 0; j < no; j++) { obs[m * no + j] = r->after[j]; int64_t d = llabs(p->e.expected[0][m][j] - r->after[j]); if (d > wd) { wd = d; worst_rec = r; wp = p->e.expected[0][m][j]; wo = r->after[j]; } } m++; last = r; } for (uint32_t s = 0; s < m; s++) for (int j = 0; j < no; j++) pk[s * no + j] = p->e.expected[0][s][j]; - int64_t err = pd0_nrmse_micro(pk, obs, m, no); c->R->last_nrmse_micro = err; + int64_t err = nrmse_pooled(c, pk, obs, m, no); c->R->last_nrmse_micro = err; uint8_t id[PD0_HASH]; sha256_hash(p->hash, PD0_HASH, id); if (err > c->R->eps_micro) { c->R->f++; add_experiment(c, id, 0, p->hash, last->record_hash, 1, c->rec[ep->first].seq, last->seq); refute(c, worst_rec, wp, wo); set_code(c, 6, PD0V_T6_TRIAL_FAILED); return 0; } c->R->p++; add_experiment(c, id, 0, p->hash, last->record_hash, 0, c->rec[ep->first].seq, last->seq); } @@ -292,10 +319,10 @@ static int try_t7(ctx *c) uint8_t h1[PD0_HASH], h2[PD0_HASH]; ep_schedule_hash(c, ep, (uint8_t)n, h1); for (uint32_t j = 0; j < c->nep; j++) if (j != i && c->ep[j].n && ep_schedule_hash(c, &c->ep[j], (uint8_t)n, h2) && !memcmp(h1, h2, PD0_HASH)) { set_code(c, 7, PD0V_T7_STREAM_REUSED); return PD0V_T7_STREAM_REUSED; } const pd0_rec *l = NULL; uint32_t m = rollout_episode(c, &c->R->candidate, ep, n, pred, obs, &l); if (!first) first = &c->rec[ep->first]; last = l; - int64_t e1 = pd0_nrmse_micro(pred, obs, m, no); + int64_t e1 = nrmse_pooled(c, pred, obs, m, no); if (e1 > 3 * c->R->eps_micro) { c->R->f++; uint8_t id[PD0_HASH]; sha256_hash(c->bat[b].hash, PD0_HASH, id); add_experiment(c, id, 1, c->bat[b].hash, l->record_hash, 1, first->seq, l->seq); refute(c, l, pred[(m - 1) * no], obs[(m - 1) * no]); set_code(c, 7, PD0V_T7_EPISODE_ABOVE_3EPS); return 0; } for (uint32_t s = 0; s < m; s++) acc_add(&a, pred + s * no, obs + s * no, no); c->R->p++; } - int64_t eb = acc_nrmse(&a, no); c->R->last_nrmse_micro = eb; uint8_t id[PD0_HASH]; sha256_hash(c->bat[b].hash, PD0_HASH, id); + int64_t sdv[PD0_MAX_OBS]; fit_sd(c, sdv); int64_t eb = acc_nrmse_sd(&a, no, sdv); c->R->last_nrmse_micro = eb; uint8_t id[PD0_HASH]; sha256_hash(c->bat[b].hash, PD0_HASH, id); if (eb > c->R->eps_micro) { c->R->f++; add_experiment(c, id, 1, c->bat[b].hash, last->record_hash, 1, first->seq, last->seq); refute(c, last, pred[(n - 1) * no], obs[(n - 1) * no]); set_code(c, 7, PD0V_T7_BATCH_FAILED); return 0; } add_experiment(c, id, 1, c->bat[b].hash, last->record_hash, 0, first->seq, last->seq); } c->R->state = LS_REPLICATED; set_code(c, 7, PD0V_OK); return 0; @@ -307,7 +334,7 @@ static void check_demotion(ctx *c, episode *ep) uint32_t n = c->P->rollout_steps; if (ep_ok_steps(c, ep) < n) return; ep->complete = 1; int64_t pred[PD0_MAX_STEPS * PD0_MAX_OBS], obs[PD0_MAX_STEPS * PD0_MAX_OBS]; const pd0_rec *l = NULL; uint32_t m = rollout_episode(c, &c->R->candidate, ep, n, pred, obs, &l); - if (pd0_nrmse_micro(pred, obs, m, c->P->n_obs) > c->R->eps_micro) { c->R->f++; refute(c, l, pred[(m - 1) * c->P->n_obs], obs[(m - 1) * c->P->n_obs]); c->R->state = LS_HYPOTHESIS; c->R->demoted = 1; c->R->have_candidate = 1; set_code(c, 8, PD0V_LAW_DEMOTED); } + if (nrmse_pooled(c, pred, obs, m, c->P->n_obs) > c->R->eps_micro) { c->R->f++; refute(c, l, pred[(m - 1) * c->P->n_obs], obs[(m - 1) * c->P->n_obs]); c->R->state = LS_HYPOTHESIS; c->R->demoted = 1; c->R->have_candidate = 1; set_code(c, 8, PD0V_LAW_DEMOTED); } else c->R->p++; } @@ -317,7 +344,7 @@ static void compute_domain(ctx *c) d->n_obs = P->n_obs; d->n_channels = P->n_channels; d->dt_micro = P->dt_micro; d->reset_min = P->reset_min; d->reset_max = P->reset_max; d->episode_len = P->episode_len; d->latent_reset = 0; int first = 1; for (uint32_t i = 0; i < c->nep; i++) { const episode *e = &c->ep[i]; if (!e->has_tag || e->tag == TAG_HOLDOUT || e->tag == TAG_REP || e->n == 0) continue; int used = 0; - for (uint32_t j = 0; j < e->n; j++) { const pd0_rec *r = &c->rec[e->first + j]; if (r->status != PD0_ST_OK) continue; used = 1; d->n_observations++; + for (uint32_t j = 0; j < e->n; j++) { const pd0_rec *r = &c->rec[e->first + j]; if (!rec_has_outcome(r)) continue; used = 1; d->n_observations++; for (int v = 0; v < P->n_obs; v++) { int64_t lo = r->before[v] < r->after[v] ? r->before[v] : r->after[v], hi = r->before[v] > r->after[v] ? r->before[v] : r->after[v]; if (first || lo < d->var_min[v]) d->var_min[v] = lo; if (first || hi > d->var_max[v]) d->var_max[v] = hi; } if (r->kind == PD0_KIND_STEP && r->channel < P->n_channels) { uint8_t ch = r->channel; if (d->chan_min[ch] == 0 && d->chan_max[ch] == 0) { d->chan_min[ch] = d->chan_max[ch] = r->applied; } if (r->applied < d->chan_min[ch]) d->chan_min[ch] = r->applied; if (r->applied > d->chan_max[ch]) d->chan_max[ch] = r->applied; } diff --git a/src/physics0/ladder/pd0_ladder.h b/src/physics0/ladder/pd0_ladder.h index ee125f837..fefb8e950 100644 --- a/src/physics0/ladder/pd0_ladder.h +++ b/src/physics0/ladder/pd0_ladder.h @@ -50,4 +50,6 @@ double pd0_pearson(const double *x, const double *y, uint32_t n); double pd0_perm_p(const double *x, const double *y, uint32_t n, uint32_t n_shuffles, uint64_t seed); /* NRMSE over pooled steps: pred/obs are [n][n_obs] in micro; returns micro (1e6 = 1.0) */ int64_t pd0_nrmse_micro(const int64_t *pred, const int64_t *obs, uint32_t n, uint8_t n_obs); +/* spec rev 6 (a): per-variable RMSE over the pooled FIT sd (micro); sd 0 falls back to the RMSE */ +int64_t pd0_nrmse_pooled_micro(const int64_t *pred, const int64_t *obs, uint32_t n, uint8_t n_obs, const int64_t *sd_micro); #endif diff --git a/src/physics0/learner/pd0_learner.c b/src/physics0/learner/pd0_learner.c index 43e4a4a2a..54341c3a7 100644 --- a/src/physics0/learner/pd0_learner.c +++ b/src/physics0/learner/pd0_learner.c @@ -43,7 +43,7 @@ int pd0_learner_observe(pd0_learner *L, const pd0_rec *r, uint8_t tag) { if (tag != TAG_FIT && tag != TAG_SELECT) return -1; /* I10: nothing else may reach the learner */ if (r->n_obs != L->d.n_obs || L->nt >= PD0L_MAX_TRANS) return -1; - if (r->kind == PD0_KIND_STEP && r->status != PD0_ST_OK) return 0; /* refused / ended steps carry no transition */ + if (r->kind == PD0_KIND_STEP && r->status != PD0_ST_OK && r->status != PD0_ST_EPISODE_END) return 0; /* spec rev 6: EPISODE_END carries an outcome; refused/out-of-bounds/budget steps do not */ trans *t = &L->t[L->nt++]; memset(t, 0, sizeof *t); memcpy(t->before, r->before, sizeof(int64_t) * r->n_obs); memcpy(t->after, r->after, sizeof(int64_t) * r->n_obs); t->chan = r->channel; t->value = r->applied; t->tag = tag; t->episode = r->episode; t->is_reset = r->kind == PD0_KIND_RESET; diff --git a/tests/physics0/verify/bundle.h b/tests/physics0/verify/bundle.h index 7e7afef0e..8ec0f99b8 100644 --- a/tests/physics0/verify/bundle.h +++ b/tests/physics0/verify/bundle.h @@ -10,12 +10,16 @@ static uint32_t pd0_null_world_records(uint64_t seed, pd0_rec *out, uint32_t cap typedef struct { int skip_corr, fake_corr, no_rival, reuse_schedule, trial_without_prereg, wrong_k, rep_before_candidate, batch_seed_reuse, all_planner, eps_above_bound, stop_after_prereg, stop_after_trials, demote_after_law; int null_world; uint64_t null_seed; + int end_last; /* rev 6 (b): the last step of every episode is EPISODE_END */ + int quiet_trials; /* rev 6 (a): trials start near rest with tiny pushes */ + int64_t obs_noise; /* observation noise sd (micro) on every recorded value */ } bundle_opts; typedef struct { uint8_t *buf; size_t len; uint8_t last[PD0_HASH]; uint8_t rec_prev[PD0_HASH]; uint64_t seq; uint32_t episode; truth_world w; pd0_ladder_params P; pd0_rng g; pd0_rec *recs; uint32_t nrec; + int end_last; int64_t obs_noise; pd0_rng nz; } bundle; static inline void b_append(bundle *b, uint8_t kind, const uint8_t *p, uint32_t n) { b->len = pd0_ledg_append(b->buf, b->len, LCAP, kind, p, n, b->last); } static inline void b_record(bundle *b, pd0_rec *r) @@ -26,12 +30,14 @@ static inline void b_record(bundle *b, pd0_rec *r) } static inline void b_tag(bundle *b, uint32_t ep, uint8_t tag, uint32_t batch, uint8_t origin) { pd0_tag t = { ep, tag, batch, origin }; uint8_t p[16]; b_append(b, LEDG_TAG, p, (uint32_t)pd0_tag_write(&t, p)); } /* run one episode of the truth world (or the null world) with the given reset and schedule; returns the episode number */ +static inline int64_t b_obs(bundle *b, int64_t v) { return b->obs_noise ? v + pd0_rng_noise(&b->nz, b->obs_noise) : v; } static inline uint32_t b_episode(bundle *b, const int64_t *reset, const pd0_step *steps, uint32_t n, const truth_world *w) { - uint32_t ep = b->episode++; int64_t st[PD0_MAX_VARS] = { 0 }, nx[PD0_MAX_VARS] = { 0 }; pd0_rec r; memset(&r, 0, sizeof r); - r.kind = PD0_KIND_RESET; r.channel = PD0_CHAN_NONE; r.episode = ep; for (int j = 0; j < 2; j++) { st[j] = reset[j]; r.before[j] = r.after[j] = reset[j]; } b_record(b, &r); + uint32_t ep = b->episode++; int64_t st[PD0_MAX_VARS] = { 0 }, nx[PD0_MAX_VARS] = { 0 }, ob[2]; pd0_rec r; memset(&r, 0, sizeof r); + r.kind = PD0_KIND_RESET; r.channel = PD0_CHAN_NONE; r.episode = ep; for (int j = 0; j < 2; j++) { st[j] = reset[j]; ob[j] = b_obs(b, reset[j]); r.before[j] = r.after[j] = ob[j]; } b_record(b, &r); for (uint32_t s = 0; s < n; s++) { memset(&r, 0, sizeof r); r.kind = PD0_KIND_STEP; r.episode = ep; r.step_in_episode = s + 1; r.time_micro = (int64_t)(s + 1) * b->P.dt_micro; r.channel = steps[s].channel; r.requested = r.applied = steps[s].value; - r.before[0] = st[0]; r.before[1] = st[1]; truth_step(w, st, steps[s].value, nx); memcpy(st, nx, sizeof st); r.after[0] = st[0]; r.after[1] = st[1]; b_record(b, &r); } + r.before[0] = b_obs(b, st[0]); r.before[1] = b_obs(b, st[1]); /* fresh observation of the state, as pd0_world_step does */ truth_step(w, st, steps[s].value, nx); memcpy(st, nx, sizeof st); ob[0] = b_obs(b, st[0]); ob[1] = b_obs(b, st[1]); r.after[0] = ob[0]; r.after[1] = ob[1]; + if (b->end_last && s + 1 == n) r.status = PD0_ST_EPISODE_END; b_record(b, &r); } return ep; } static inline void b_random_schedule(bundle *b, int64_t *reset, pd0_step *steps, uint32_t n) { for (int j = 0; j < 2; j++) reset[j] = draw_const(&b->g, -2000000, 2000000); for (uint32_t s = 0; s < n; s++) { steps[s].channel = 0; steps[s].value = draw_const(&b->g, -2000000, 2000000); } } @@ -44,6 +50,7 @@ static inline void b_free(bundle *b) { free(b->buf); free(b->recs); } /* Build the whole honest ladder (or a mutant). Returns the law bytes length via *law_len after running the checker. */ static inline int b_build(bundle *b, const bundle_opts *o, pd0_ladder_report *R) { + b->end_last = o->end_last; b->obs_noise = o->obs_noise; pd0_rng_stream(&b->nz, 4242, "obs-noise"); if (o->obs_noise) { b->P.noisy = 1; b->P.eps_bound_micro = 50000; } int64_t reset[2]; pd0_step steps[100]; const truth_world *w = &b->w; truth_world null_w = b->w; /* 1. collect 10 episodes of 100 steps */ for (int e = 0; e < 10; e++) { b_random_schedule(b, reset, steps, 100); b_episode(b, reset, steps, 100, w); } @@ -56,7 +63,7 @@ static inline int b_build(bundle *b, const bundle_opts *o, pd0_ladder_report *R) if (o->rep_before_candidate) { b_tag(b, b->episode, TAG_REP, 99, 0); b_random_schedule(b, reset, steps, 20); b_episode(b, reset, steps, 20, w); } /* 3. correlation evidence: pair (s1 at t, change of s0) */ if (!o->skip_corr) { double *x = malloc(sizeof(double) * 65536), *y = malloc(sizeof(double) * 65536); uint32_t n = 0; - for (uint32_t i = 0; i < b->nrec; i++) { const pd0_rec *r = &b->recs[i]; if (r->kind != PD0_KIND_STEP || r->status != PD0_ST_OK || r->episode >= 8) continue; x[n] = (double)r->before[1]; y[n] = (double)(r->after[0] - r->before[0]); n++; } + for (uint32_t i = 0; i < b->nrec; i++) { const pd0_rec *r = &b->recs[i]; if (r->kind != PD0_KIND_STEP || (r->status != PD0_ST_OK && r->status != PD0_ST_EPISODE_END) || r->episode >= 8) continue; x[n] = (double)r->before[1]; y[n] = (double)(r->after[0] - r->before[0]); n++; } pd0_corr c; memset(&c, 0, sizeof c); c.var_a = 1; c.var_b = 0; c.n = n; c.n_pairs = 6; c.n_shuffles = 2000; c.shuffle_seed = 77; double r = pd0_pearson(x, y, n), p = pd0_perm_p(x, y, n, 2000, 77) * 6; c.r_micro = (int64_t)(r * 1e6); c.p_micro = (int64_t)(p * 1e6); if (o->fake_corr) { c.r_micro = 900000; c.p_micro = 100; } @@ -67,12 +74,13 @@ static inline int b_build(bundle *b, const bundle_opts *o, pd0_ladder_report *R) memset(&nullr, 0, sizeof nullr); nullr.n_vars = 2; nullr.n_channels = 1; nullr.n_equations = 0; nullr.description_bits = 0; pl[0] = REL_NULL; n = pd0_rel_write(&nullr, pl + 1, sizeof pl - 1); b_append(b, LEDG_RELATION, pl, (uint32_t)n + 1); uint8_t null_hash[PD0_HASH]; memcpy(null_hash, b->last, PD0_HASH); /* 5. falsifier */ - pd0_falsifier f; memset(&f, 0, sizeof f); memcpy(f.candidate, cand_hash, PD0_HASH); f.n_rivals = o->no_rival ? 0 : 1; memcpy(f.rival[0], null_hash, PD0_HASH); f.eps_micro = o->eps_above_bound ? 50000 : 20000; f.min_trials = 5; + pd0_falsifier f; memset(&f, 0, sizeof f); memcpy(f.candidate, cand_hash, PD0_HASH); f.n_rivals = o->no_rival ? 0 : 1; memcpy(f.rival[0], null_hash, PD0_HASH); f.eps_micro = o->eps_above_bound ? 50000 : b->P.eps_bound_micro; f.min_trials = 5; b_append(b, LEDG_FALSIFIER, pl, (uint32_t)pd0_fals_write(&f, pl)); /* 6. five preregistered experiments, each followed by its trial */ pd0_exp *x = calloc(1, sizeof *x); uint8_t *xb = malloc(16384); for (int t = 0; t < 5; t++) { memset(x, 0, sizeof *x); x->n_obs = 2; x->n_hyp = 2; x->n_steps = 20; if (o->reuse_schedule && t == 0) { const pd0_rec *r0 = &b->recs[0]; x->reset[0] = r0->after[0]; x->reset[1] = r0->after[1]; for (int s = 0; s < 20; s++) { x->steps[s].channel = b->recs[1 + s].channel; x->steps[s].value = b->recs[1 + s].applied; } } + else if (o->quiet_trials) { for (int j = 0; j < 2; j++) x->reset[j] = draw_const(&b->g, -50000, 50000); for (int s = 0; s < 20; s++) { x->steps[s].channel = 0; x->steps[s].value = draw_const(&b->g, -50000, 50000); } } else b_random_schedule(b, x->reset, x->steps, 20); { int64_t tmp[40]; pd0_rel_rollout_fn(&cand, x->reset, x->steps, 20, tmp); for (int s = 0; s < 20; s++) for (int j = 0; j < 2; j++) x->expected[0][s][j] = tmp[s * 2 + j]; pd0_rel_rollout_fn(&nullr, x->reset, x->steps, 20, tmp); for (int s = 0; s < 20; s++) for (int j = 0; j < 2; j++) x->expected[1][s][j] = tmp[s * 2 + j]; } x->divergence_micro = 5000000; size_t xn = pd0_exp_write(x, xb, 16384); diff --git a/tests/physics0/verify/test_pd0_ladder.c b/tests/physics0/verify/test_pd0_ladder.c index 632efd06a..51e578d93 100644 --- a/tests/physics0/verify/test_pd0_ladder.c +++ b/tests/physics0/verify/test_pd0_ladder.c @@ -56,6 +56,15 @@ int main(void) pd0_law *l = calloc(1, sizeof *l); l->state = PDLAW_PROVISIONAL_LAW; l->rel.n_vars = 2; l->rel.n_channels = 1; l->dom.n_obs = 2; l->dom.n_channels = 1; size_t n = pd0_law_write(l, law2, sizeof law2); CHECK(pd0_ladder_verify_law(&R0, &P, law2, n) == PD0V_T8_STATE_SKIPPED); free(l); } /* demotion: a later contradicting trial pulls the law back to HYPOTHESIS */ + /* spec rev 6 (b): EPISODE_END records carry an outcome; an honest ladder whose every episode ends with one still replicates */ + memset(&o, 0, sizeof o); o.end_last = 1; rc = run(1, 1, &o, &R, law, &ln, "ladder-episode-end"); CHECK(rc == 0 && R.state == LS_REPLICATED && R.n_refutations == 0); + /* spec rev 6 (a): trial error is normalised by the pooled FIT sd, not the within-trial spread: quiet trials with + * observation noise (sd 0.02, eps 0.02 x 3 batches eps) must not refute the true relation */ + memset(&o, 0, sizeof o); o.quiet_trials = 1; o.obs_noise = 20000; rc = run(1, 1, &o, &R, law, &ln, "ladder-quiet-noisy-trials"); CHECK(rc == 0 && R.state >= LS_INTERVENED && R.n_refutations == 0); + { int64_t pred[6] = { 1000, 0, 2000, 0, 3000, 0 }, obs[6] = { 11000, 0, 12000, 0, 13000, 0 }, sd[2] = { 1000000, 1000000 }; + CHECK(pd0_nrmse_micro(pred, obs, 3, 2) > 10000000); /* within-trial spread 0.0008: error reads as 12 sd */ + CHECK(pd0_nrmse_pooled_micro(pred, obs, 3, 2, sd) == 10000); /* pooled sd 1.0: the same error is 0.01 */ + int64_t sd0[2] = { 0, 0 }; CHECK(pd0_nrmse_pooled_micro(pred, obs, 3, 2, sd0) == 10000); } /* sd 0 falls back to the RMSE */ memset(&o, 0, sizeof o); o.demote_after_law = 1; rc = run(1, 1, &o, &R, law, &ln, "ladder-demotion"); CHECK(rc == 0 && R.demoted && R.state == LS_HYPOTHESIS && R.n_refutations == 1); { bundle b; b_init(&b, 1, 1); bundle_opts h; memset(&h, 0, sizeof h); pd0_ladder_report Rh; b_build(&b, &h, &Rh); size_t n = pd0_ladder_emit_law(&Rh, &b.P, law2, sizeof law2); b_free(&b); CHECK(pd0_ladder_verify_law(&R, &P, law2, n) == PD0V_LAW_DEMOTED); }