code wiki / _hdl_build / nx_char_identity_gate.nx

nx_char_identity_gate.nx source

↩ module page · 236 lines · 12641 B

1// nx_char_identity_gate.nx -- proves the identity vector behaves like a LoRA: the SAME token yields the 2// SAME woman under any style/pose/outfit, different tokens yield GENUINELY different women, and the 3// proportions sit inside MEASURED anthropometry rather than refuted folklore. 4// MUTATION TARGET (documented): let style leak into an identity field (e.g. anime widens the eye dial) 5// => T2 RED (the same woman stops being the same woman when you restyle her) while diversity/canon hold. 6// license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_char_identity.nx" 9import "nx_gamesave.nx" 10 11func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 12func pn(v: i64) -> i64 { 13 let t: *u8 = sys_mmap(32) as *u8 14 var m: i64 = v 15 var w: i64 = 0 16 if m < 0 { t[w] = 45 as u8; w = w + 1; m = 0 - m } 17 if m == 0 { t[w] = 48 as u8; sys_write(1, t, w + 1); return 0 } 18 let d: *u8 = sys_mmap(32) as *u8 19 var k: i64 = 0 20 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 21 var j: i64 = 0 22 while j < k { t[w] = d[k - 1 - j]; w = w + 1; j = j + 1 } 23 sys_write(1, t, w) 24 return 0 25} 26func nl() -> i64 { p("\n" as *u8); return 0 } 27func newidv() -> *i64 { return sys_mmap(IDV_SLOTS * 8) as *i64 } 28 29const NPOP: i64 = 500 30 31func main() -> i64 { 32 p("=== nx_char_identity_gate (a LoRA for riggable models: same token, same woman) ===\n" as *u8) 33 var pass: i64 = 0 34 let checks: i64 = 8 35 36 // ---------- T1 DETERMINISM: the same seed is the same woman, forever ---------- 37 let a1: *i64 = newidv() 38 let b1: *i64 = newidv() 39 idv_from_seed(a1, 8675309) 40 idv_from_seed(b1, 8675309) 41 let c1: *i64 = newidv() 42 idv_from_seed(c1, 8675310) 43 var t1: i64 = 0 44 if idv_same(a1, b1) == 1 { if idv_key(a1) == idv_key(b1) { if idv_same(a1, c1) == 0 { t1 = 1 } } } 45 if t1 == 1 { pass = pass + 1; p("T1 GREEN deterministic: seed 8675309 reproduced byte-identical (key " as *u8); pn(idv_key(a1)); p("), and seed+1 is a DIFFERENT woman\n" as *u8) } 46 if t1 == 0 { p("T1 RED determinism\n" as *u8) } 47 48 // ---------- T2 ★THE LoRA PROPERTY: style changes PROPORTIONS, never IDENTITY ---------- 49 // Render the same token realistic / anime / cartoon / VN. The identity half must be untouched, 50 // and the proportions must ACTUALLY differ (else the tooth would pass by doing nothing). 51 let base2: *i64 = newidv() 52 idv_from_seed(base2, 424242) 53 let ref2: *i64 = newidv() 54 idv_serialize(base2, ref2) 55 let sp: *i64 = sys_mmap(16 * 8) as *i64 56 var identity_held: i64 = 1 57 var head_ratios: i64 = 0 58 var distinct_hr: i64 = 0 59 let seenhr: *i64 = sys_mmap(8 * 8) as *i64 60 var z: i64 = 0 61 while z < 4 { seenhr[z] = 0; z = z + 1 } 62 var st: i64 = 0 63 while st < 4 { 64 base2[IDV_STYLE] = st 65 base2[IDV_POSE] = st * 3 66 base2[IDV_OUTFIT] = st 67 base2[IDV_EXPR] = st 68 idv_style_params(base2, st, sp) 69 if idv_same(base2, ref2) == 0 { identity_held = 0 } 70 head_ratios = head_ratios + sp[0] 71 seenhr[st] = sp[0] 72 st = st + 1 73 } 74 var u: i64 = 0 75 while u < 4 { 76 var dup: i64 = 0 77 var v: i64 = 0 78 while v < u { if seenhr[v] == seenhr[u] { dup = 1 } v = v + 1 } 79 if dup == 0 { distinct_hr = distinct_hr + 1 } 80 u = u + 1 81 } 82 var t2: i64 = 0 83 if identity_held == 1 { if distinct_hr == 4 { t2 = 1 } } 84 if t2 == 1 { pass = pass + 1; p("T2 GREEN THE LoRA PROPERTY: across realistic/anime/cartoon/VN + pose + outfit + expression, the identity half is BYTE-UNCHANGED while head-ratio took " as *u8); pn(distinct_hr); p(" distinct values (" as *u8); pn(seenhr[0]); p("/" as *u8); pn(seenhr[1]); p("/" as *u8); pn(seenhr[2]); p("/" as *u8); pn(seenhr[3]); p(") -- restyling her does not make her someone else\n" as *u8) } 85 if t2 == 0 { p("T2 RED style leaked into identity? held=" as *u8); pn(identity_held); p(" distinct_hr=" as *u8); pn(distinct_hr); nl() } 86 87 // ---------- T3 DIVERSITY / NO MODE COLLAPSE (the "every output is the same girl" failure) ---------- 88 let pop: *i64 = sys_mmap(NPOP * IDV_SLOTS * 8) as *i64 89 let keys: *i64 = sys_mmap(NPOP * 8) as *i64 90 var i3: i64 = 0 91 while i3 < NPOP { 92 let cur: *i64 = ((pop as i64) + i3 * IDV_SLOTS * 8) as *i64 93 idv_from_seed(cur, 1000003 + i3 * 7919) 94 keys[i3] = idv_key(cur) 95 i3 = i3 + 1 96 } 97 var dupkeys: i64 = 0 98 var q: i64 = 0 99 while q < NPOP { 100 var r: i64 = 0 101 while r < q { if keys[r] == keys[q] { dupkeys = dupkeys + 1 } r = r + 1 } 102 q = q + 1 103 } 104 // mean pairwise distance over a sampled window (full N^2 on 500 is 125k -- sample 100 pairs) 105 var dsum: i64 = 0 106 var dmin: i64 = 999999 107 var pairs: i64 = 0 108 var w3: i64 = 0 109 while w3 < 100 { 110 let x: *i64 = ((pop as i64) + w3 * IDV_SLOTS * 8) as *i64 111 let y: *i64 = ((pop as i64) + (w3 + 100) * IDV_SLOTS * 8) as *i64 112 let dd: i64 = idv_distance(x, y) 113 dsum = dsum + dd 114 if dd < dmin { dmin = dd } 115 pairs = pairs + 1 116 w3 = w3 + 1 117 } 118 let dmean: i64 = dsum / pairs 119 var t3: i64 = 0 120 if dupkeys == 0 { if dmean > 200 { if dmin > 0 { t3 = 1 } } } 121 if t3 == 1 { pass = pass + 1; p("T3 GREEN no mode collapse: " as *u8); pn(NPOP); p(" identities, 0 duplicate keys, mean pairwise distance " as *u8); pn(dmean); p(" (min " as *u8); pn(dmin); p(") -- they are genuinely different women, not one woman with recolours\n" as *u8) } 122 if t3 == 0 { p("T3 RED dupkeys=" as *u8); pn(dupkeys); p(" dmean=" as *u8); pn(dmean); p(" dmin=" as *u8); pn(dmin); nl() } 123 124 // ---------- T4 CANON CONFORMANCE vs MEASURED anthropometry ---------- 125 var conform: i64 = 0 126 var lbrsum: i64 = 0 127 var i4: i64 = 0 128 while i4 < NPOP { 129 let cur: *i64 = ((pop as i64) + i4 * IDV_SLOTS * 8) as *i64 130 conform = conform + idv_canon_ok(cur) 131 lbrsum = lbrsum + cur[IDV_LBR] 132 i4 = i4 + 1 133 } 134 let lbrmean: i64 = lbrsum / NPOP 135 var t4: i64 = 0 136 var dl: i64 = lbrmean - IDV_LBR_MEAN 137 if dl < 0 { dl = 0 - dl } 138 if conform == NPOP { if dl <= 12 { t4 = 1 } } 139 if t4 == 1 { pass = pass + 1; p("T4 GREEN canon conformance: " as *u8); pn(conform); p("/" as *u8); pn(NPOP); p(" inside the MEASURED bands; mean leg-to-body ratio " as *u8); pn(lbrmean); p(" permil vs the published 491 +- 15 (Versluys 2018), biased to the measured +0.5SD optimum\n" as *u8) } 140 if t4 == 0 { p("T4 RED conform=" as *u8); pn(conform); p(" lbrmean=" as *u8); pn(lbrmean); nl() } 141 142 // ---------- T5 ★PHI + WHR REGRESSION GUARD -- refuted folklore cannot creep back in ---------- 143 // phi = 1618/1000. WHR 0.7 = 700 permil. Neither may appear as a canon target, and the LBR band must 144 // NOT be centred on a phi-derived value. This tooth exists because "use the golden ratio" is the single 145 // most likely wrong thing for a future session to add to a beauty system. 146 var phi_free: i64 = 1 147 if IDV_LBR_MEAN == 618 { phi_free = 0 } 148 if IDV_LBR_MEAN == 1618 { phi_free = 0 } 149 if IDV_LBR_MEAN == 382 { phi_free = 0 } 150 // no generated identity may cluster on WHR 0.70 -- our ANSUR II parse found 0.0% of 1,986 women there 151 var at_whr70: i64 = 0 152 var i5: i64 = 0 153 while i5 < NPOP { 154 let cur: *i64 = ((pop as i64) + i5 * IDV_SLOTS * 8) as *i64 155 if cur[IDV_SHIP] == 70 { at_whr70 = at_whr70 + 1 } 156 i5 = i5 + 1 157 } 158 var t5: i64 = 0 159 if phi_free == 1 { if at_whr70 == 0 { if IDV_LBR_MEAN == 491 { t5 = 1 } } } 160 if t5 == 1 { pass = pass + 1; p("T5 GREEN refuted-folklore guard: no phi-derived constant (golden ratio ACTIVELY REFUTED -- Naini 2024, 32 Miss Universe winners measured invalid) and 0 identities on the dead WHR 0.70 target (0.0% of 1,986 ANSUR II women reach it)\n" as *u8) } 161 if t5 == 0 { p("T5 RED phi_free=" as *u8); pn(phi_free); p(" at_whr70=" as *u8); pn(at_whr70); nl() } 162 163 // ---------- T6 PERSISTENCE: an identity round-trips gs_save bit-exact ---------- 164 let S: *i64 = sys_mmap(IDV_SLOTS * 8) as *i64 165 idv_serialize(a1, S) 166 let rcs: i64 = gs_save("knowledge/nx_identity_t6.sav" as *u8, 9303, S, IDV_SLOTS, 3000) 167 let L: *i64 = sys_mmap(IDV_SLOTS * 8) as *i64 168 let meta: *i64 = sys_mmap(64) as *i64 169 let rcl: i64 = gs_load("knowledge/nx_identity_t6.sav" as *u8, L, IDV_SLOTS, meta) 170 let back: *i64 = newidv() 171 idv_restore(back, L) 172 var t6: i64 = 0 173 if rcs > 0 { if rcl >= 0 { if idv_same(back, a1) == 1 { if idv_key(back) == idv_key(a1) { t6 = 1 } } } } 174 if t6 == 1 { pass = pass + 1; p("T6 GREEN persistent: the identity survived save/load byte-exact -- the woman you made is the woman you get back\n" as *u8) } 175 if t6 == 0 { p("T6 RED rcs=" as *u8); pn(rcs); p(" rcl=" as *u8); pn(rcl); nl() } 176 177 // ---------- T7 ★THE GAMEPLAY WIRE: her GENOME is her FACE ---------- 178 // identical genomes -> identical twins; different alleles -> visibly different women; and the coat 179 // locus must actually drive hair colour, so the genetics the player breeds IS what she looks like. 180 let g1: *i64 = newidv() 181 let g2: *i64 = newidv() 182 var genoA: i64 = gx_set(0, GX_COAT, 1, 1) // crimson (RR) 183 genoA = gx_set(genoA, GX_HORN, 1, 0) 184 var genoB: i64 = gx_set(0, GX_COAT, 0, 0) // white (WW) 185 genoB = gx_set(genoB, GX_HORN, 0, 0) 186 idv_from_companion(g1, genoA, 85, gx_sexgene(GX_SEX_F,1,0), 0, 1) 187 let twin: *i64 = newidv() 188 idv_from_companion(twin, genoA, 85, gx_sexgene(GX_SEX_F,1,0), 0, 1) 189 idv_from_companion(g2, genoB, 200, gx_sexgene(GX_SEX_F,1,0), 0, 2) 190 var t7: i64 = 0 191 if idv_same(g1, twin) == 1 { // identical genome => identical twin 192 if idv_same(g1, g2) == 0 { // different alleles => different woman 193 if g1[IDV_HAIR] != g2[IDV_HAIR] { // the coat locus REACHED her hair 194 if g1[IDV_STATURE] != g2[IDV_STATURE] { // the polygenic dose REACHED her height 195 if idv_distance(g1, g2) > 0 { t7 = 1 } 196 } 197 } 198 } 199 } 200 if t7 == 1 { pass = pass + 1; p("T7 GREEN her genome IS her face: identical genomes produced IDENTICAL TWINS, different alleles produced a different woman (hair " as *u8); pn(g1[IDV_HAIR]); p(" vs " as *u8); pn(g2[IDV_HAIR]); p(", stature " as *u8); pn(g1[IDV_STATURE]); p("mm vs " as *u8); pn(g2[IDV_STATURE]); p("mm) -- the companion you BRED is the woman you SEE\n" as *u8) } 201 if t7 == 0 { p("T7 RED genome-wire twins=" as *u8); pn(idv_same(g1, twin)); p(" differ=" as *u8); pn(idv_same(g1, g2)); nl() } 202 203 // ---------- T8 THE EMITTER WIRE + anti-vacuity ---------- 204 // the identity must produce a real nx_body_proc argv, and the anime style must actually move the 205 // stylize knob (else "wireable into the emitter" is a claim, not a fact). 206 let ar: *i64 = sys_mmap(16 * 8) as *i64 207 let n8: i64 = idv_bodyproc_args(a1, 0, ar) 208 let sty_real: i64 = ar[5] 209 idv_bodyproc_args(a1, 1, ar) 210 let sty_anime: i64 = ar[5] 211 let wts: *i64 = sys_mmap(16 * 8) as *i64 212 let nd: i64 = idv_dials(a1, wts) 213 var dialsok: i64 = 1 214 var nonzero: i64 = 0 215 var i8: i64 = 0 216 while i8 < nd { 217 if wts[i8] < 0 { dialsok = 0 } 218 if wts[i8] > IDV_DIALMAX { dialsok = 0 } 219 if wts[i8] > 0 { nonzero = nonzero + 1 } 220 i8 = i8 + 1 221 } 222 var t8: i64 = 0 223 if n8 == 7 { if nd == IDV_NDIAL { if dialsok == 1 { if nonzero >= 4 { 224 if sty_anime > sty_real { if ar[4] == a1[IDV_SEED] { t8 = 1 } } 225 } } } } 226 if t8 == 1 { pass = pass + 1; p("T8 GREEN wireable: emits a real 7-knob nx_body_proc argv (stylize " as *u8); pn(sty_real); p(" realistic -> " as *u8); pn(sty_anime); p(" anime) and " as *u8); pn(nd); p(" morph dials all inside nx_morph's 0..256 weight range, " as *u8); pn(nonzero); p(" of them live\n" as *u8) } 227 if t8 == 0 { p("T8 RED n8=" as *u8); pn(n8); p(" nd=" as *u8); pn(nd); p(" dialsok=" as *u8); pn(dialsok); p(" nonzero=" as *u8); pn(nonzero); nl() } 228 229 p("nx_char_identity_gate: " as *u8); pn(pass); p("/" as *u8); pn(checks); nl() 230 p("SCOPE: this gates CONSISTENCY, DIVERSITY and MEASURED-canon conformance. It deliberately does NOT\n" as *u8) 231 p("score beauty -- the optimum FLIPS with stimulus realism (Versluys 2018), so a judge calibrated at\n" as *u8) 232 p("our clay fidelity would teach the WRONG target. Aesthetic judgement belongs to the high-fidelity lane.\n" as *u8) 233 if pass == checks { p("VERDICT GREEN\n" as *u8); return 0 } 234 p("VERDICT RED\n" as *u8) 235 return 1 236}