61 lines
2.5 KiB
Nim
61 lines
2.5 KiB
Nim
## G1 oracle-convergence test (spec §12 Tier C, G1).
|
|
##
|
|
## For every kernel K in the M2 set: generate K's exact oracle intent stream over
|
|
## the synthetic arena, replay it through the ledger + Hedge, and require
|
|
## posterior(K) >= 0.9 within T* = 300 ticks. A failure here indicts the
|
|
## inference layer (implementation bug) — it is reported, never hidden.
|
|
##
|
|
## Run: from ChimeraBot_garage/src, `nimble test`.
|
|
|
|
import std/[math, strutils]
|
|
import chimera/dsl
|
|
import chimera/oracle
|
|
|
|
const TStar = 300
|
|
const Threshold = 0.9
|
|
|
|
var failed = 0
|
|
proc check(name: string, cond: bool, detail: string = "") =
|
|
if cond: echo " ok ", name
|
|
else: echo " FAIL ", name, " [", detail, "]"; inc failed
|
|
|
|
let kernels = allKernels()
|
|
let env = defaultEnv()
|
|
|
|
block:
|
|
echo "G1: oracle convergence over the M2 kernel set (T* = ", TStar, " ticks)"
|
|
echo " ", align("kernel", 16), align("idTick", 8), align("posterior", 11),
|
|
align("censor", 8)
|
|
for i in 0 ..< kernels.len:
|
|
let r = runG1(kernels, i, env, TStar)
|
|
let idStr = if r.idTick < 0: " NEVER" else: align($r.idTick, 8)
|
|
echo " ", align(r.kernel, 16), idStr, " ", formatFloat(r.finalPosterior,
|
|
ffDecimal, 5), " ", formatFloat(r.censorRate, ffDecimal, 4)
|
|
# Spec G1 wording: the weight must REACH >= 0.9 within T*. We report the
|
|
# final posterior separately: a kernel that is observationally equivalent to
|
|
# another once in a steady state (e.g. STATIC_CORNER vs STATIC after the
|
|
# corner park) can cross 0.9 during its distinctive phase and then decay.
|
|
let ok = r.idTick > 0 and r.idTick <= TStar
|
|
check("G1 " & r.kernel & " identified within T*", ok,
|
|
"idTick=" & $r.idTick & " posterior=" & formatFloat(r.finalPosterior,
|
|
ffDecimal, 4))
|
|
|
|
block:
|
|
echo ""
|
|
echo "G1 determinism: identical reruns"
|
|
let a = runG1(kernels, 0, env, TStar)
|
|
let b = runG1(kernels, 0, env, TStar)
|
|
check("same idTick", a.idTick == b.idTick, $a.idTick & " vs " & $b.idTick)
|
|
check("same posterior", a.finalPosterior == b.finalPosterior)
|
|
let s1 = generateOracle(kernels[2], kernels[2].defaultParams, env, 100)
|
|
let s2 = generateOracle(kernels[2], kernels[2].defaultParams, env, 100)
|
|
var same = s1.scans.len == s2.scans.len
|
|
for i in 0 ..< min(s1.scans.len, s2.scans.len):
|
|
if s1.scans[i].x != s2.scans[i].x or s1.scans[i].direction != s2.scans[i].direction:
|
|
same = false
|
|
check("oracle stream is byte-identical", same)
|
|
|
|
echo ""
|
|
if failed == 0: echo "all G1 oracle tests passed"
|
|
else: echo failed, " G1 test(s) FAILED"; quit(1)
|