nx_fin_pbo_gate.nx source
↩ module page · 41 lines · 2133 B
1// nx_fin_pbo_gate.nx -- GATE for PBO/CSCV, hand-computed. 3 strategies x 4 groups: strategy 0 is the OVERFIT
2// trap (great in groups 0,1 / dead in 2,3), strategies 1,2 are consistent. Over the C(4,2)=6 splits, the best-IS
3// strategy lands bottom-half OOS on exactly 1 -> PBO = 166 permille. Exits 0 iff all pass. license_tier: ORIGINAL
4import "nx_gate.nx"
5import "nx_fin_pbo.nx"
6
7func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 {
8 if got == want { st[0] = st[0] + 1; gw(" PASS " as *u8); gw(name); gw("\n" as *u8) }
9 else { st[1] = st[1] + 1; gw(" FAIL " as *u8); gw(name); gw(" got=" as *u8); gn(got); gw(" want=" as *u8); gn(want); gw("\n" as *u8) }
10 return 0
11}
12
13func main() -> i64 {
14 let st: *i64 = sys_mmap(16) as *i64
15 st[0] = 0; st[1] = 0
16
17 chk("popcount(7) = 3" as *u8, pb_popcount(7), 3, st)
18 chk("popcount(0) = 0" as *u8, pb_popcount(0), 0, st)
19 chk("popcount(15) = 4" as *u8, pb_popcount(15), 4, st)
20
21 // perf[strategy*4 + group]: s0=[10,10,0,0] (overfit), s1=[3,3,3,3], s2=[2,2,2,2]
22 let perf: *i64 = sys_mmap(8*16) as *i64
23 perf[0]=10; perf[1]=10; perf[2]=0; perf[3]=0
24 perf[4]=3; perf[5]=3; perf[6]=3; perf[7]=3
25 perf[8]=2; perf[9]=2; perf[10]=2; perf[11]=2
26 chk("PBO = 166 permille (1 of 6 splits)" as *u8, pb_pbo_permille(perf, 3, 4), 166, st)
27 chk("PBO 166 not overfit-likely (<500)" as *u8, pb_overfit_likely(166, 500), 0, st)
28 chk("PBO 700 overfit-likely (>=500)" as *u8, pb_overfit_likely(700, 500), 1, st)
29
30 // a genuinely CONSISTENT winner: strategy 0 best in every group -> should NOT flag overfit
31 let perf2: *i64 = sys_mmap(8*16) as *i64
32 perf2[0]=9; perf2[1]=9; perf2[2]=9; perf2[3]=9
33 perf2[4]=3; perf2[5]=3; perf2[6]=3; perf2[7]=3
34 perf2[8]=2; perf2[9]=2; perf2[10]=2; perf2[11]=2
35 chk("consistent winner -> PBO 0" as *u8, pb_pbo_permille(perf2, 3, 4), 0, st)
36
37 gw("nx_fin_pbo_gate: PASS=" as *u8); gn(st[0]); gw(" FAIL=" as *u8); gn(st[1]); gw("\n" as *u8)
38 if st[1] == 0 { gw("nx_fin_pbo: GREEN (combinatorial overfit probability proven)\n" as *u8); return 0 }
39 gw("nx_fin_pbo: RED\n" as *u8)
40 return 1
41}