nx_face_novelty_gate.nx source
↩ module page · 58 lines · 2457 B
1// nx_face_novelty_gate.nx -- REFEREE for nx_face_novelty's metric machinery.
2// Synthetic descriptors with KNOWN structure (D=4): three identical + one
3// different. Asserts chi2(identical)=0, chi2(different)=200000, near-duplicate
4// pair count=3 (the three identical pairs), and cluster_greedy=2 clusters.
5// Proves the self-similarity + repetition metric is correct before trusting its
6// reading on the real store. Sovereign: nx_syscalls + nx_lbp_core.
7// license_tier: ORIGINAL
8import "nx_syscalls.nx"
9import "nx_lbp_core.nx"
10import "nx_gate_verdict.nx"
11
12const D: i64 = 4
13
14func main() -> i64 {
15 let M: i64 = 4
16 let descrs: *i64 = sys_mmap(8 * M * D) as *i64
17 var z: i64 = 0
18 while z < M * D { descrs[z] = 0; z = z + 1 }
19 descrs[0 * D + 0] = 100 // d0
20 descrs[1 * D + 0] = 100 // d1 == d0
21 descrs[2 * D + 0] = 100 // d2 == d0
22 descrs[3 * D + 3] = 100 // d3 different
23
24 let scale: i64 = 1000
25 let c01: i64 = chi2_at(descrs, 0, 1, D, scale)
26 let c03: i64 = chi2_at(descrs, 0, 3, D, scale)
27
28 let tau: i64 = 1000
29 var nd: i64 = 0
30 var i: i64 = 0
31 while i < M {
32 var j: i64 = i + 1
33 while j < M { if chi2_at(descrs, i, j, D, scale) < tau { nd = nd + 1 } j = j + 1 }
34 i = i + 1
35 }
36 let assign: *i64 = sys_mmap(8 * M) as *i64
37 let reps: *i64 = sys_mmap(8 * M) as *i64
38 let nc: i64 = cluster_greedy(descrs, M, D, tau, scale, assign, reps)
39
40 lp("NOVELTY-GATE c01=" as *u8); ln(c01); lp(" c03=" as *u8); ln(c03)
41 lp(" neardup=" as *u8); ln(nd); lp(" clusters=" as *u8); ln(nc); lp("\n" as *u8)
42
43 var ok: i64 = 1
44 if c01 != 0 { ok = 0 } // identical -> zero distance
45 if c03 != 200000 { ok = 0 } // different -> known distance
46 if nd != 3 { ok = 0 } // 3 identical pairs flagged as near-dup
47 if nc != 2 { ok = 0 } // collapses to 2 distinct faces
48
49 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
50 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
51 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
52 let ctr__dry: *i64 = gv_ctr()
53 ctr__dry[0] = ok
54 ctr__dry[1] = 1
55 let rc__dry: i64 = gv_verdict("FACE-NOVELTY-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
56 sys_exit(rc__dry)
57 return rc__dry
58}