nx_pair_synchrony.nx source
↩ module page · 173 lines · 7535 B
1// nx_pair_synchrony.nx -- pair-relation scoring for multi-character scenes.
2//
3// Image #55: synchronized blonde pair both bent over at the beach with
4// matching innie aesthetic. This is the pair-level signal substrate
5// needs to detect/encourage.
6//
7// Three pair axes:
8// 1. POSE_SYNC — are both characters in the same/mirror pose?
9// 2. AESTHETIC_MATCH — do they share aesthetic target (innie / hair color etc.)?
10// 3. IDENTITY_DISTINCT — do they read as TWO people, not clones?
11//
12// Pair synchrony is the OPPOSITE of identity-distinctness in one sense
13// (matched poses = synced) but POSE matching is independent from FACE
14// distinctness. Two clearly distinct faces in matched poses + matched
15// aesthetic = the image #55 pattern.
16//
17// Output flat-array per pair:
18// result[0] = pose_sync_q10 (1024=identical, 0=opposite)
19// result[1] = pose_mirror_q10 (1024=mirrored L/R, 0=not mirrored)
20// result[2] = aesthetic_match_q10 (1024=same aesthetic target, 0=mismatched)
21// result[3] = identity_distinct_q10 (1024=distinct, 0=clones)
22// result[4] = scale_coherence_q10 (1024=similar body scale)
23// result[5] = verdict
24// 0=DISCORDANT, 1=ASYMMETRIC, 2=MATCHED, 3=SYNCHRONIZED_PAIR
25
26// nx_safety_envelope:
27// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
28// sil_target: SIL1
29// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
30// verdict: NOT_YET_EVALUATED
31
32import "nx_syscalls.nx"
33import "nx_v7_bundle.nx"
34import "nx_pose_classify.nx"
35const NX_MAGIC_1024: i64 = 1024
36
37const NX_PAIR_RES_POSE_SYNC: i64 = 0
38const NX_PAIR_RES_POSE_MIRROR: i64 = 1
39const NX_PAIR_RES_AES_MATCH: i64 = 2
40const NX_PAIR_RES_DISTINCT: i64 = 3
41const NX_PAIR_RES_SCALE_COH: i64 = 4
42const NX_PAIR_RES_VERDICT: i64 = 5
43const NX_PAIR_RES_FIELDS: i64 = 6
44
45const NX_PAIR_V_DISCORDANT: i64 = 0
46const NX_PAIR_V_ASYMMETRIC: i64 = 1
47const NX_PAIR_V_MATCHED: i64 = 2
48const NX_PAIR_V_SYNCHRONIZED_PAIR: i64 = 3
49
50// Compare two bundles' pose_kind slots. Same enum value = full sync.
51func nx_pair_pose_sync_q10(bundle_a: *i64, bundle_b: *i64) -> i64 {
52 let pose_a: i64 = bundle_a[NX_V7_POSE_KIND]
53 let pose_b: i64 = bundle_b[NX_V7_POSE_KIND]
54 if pose_a == pose_b { return NX_MAGIC_1024 }
55 // Adjacent poses (e.g. STANDING_FACING vs LEANING_FORWARD) = partial sync.
56 var diff: i64 = pose_a - pose_b
57 if diff < 0 { diff = -diff }
58 if diff == 1 { return 614 }
59 if diff == 2 { return 256 }
60 return 0
61}
62
63// Mirror sync: face_x positions L/R relative to scene midline.
64// If A's face is on left of scene midline and B's is on right (or vice
65// versa) at similar distance, mirror_q10 = high.
66func nx_pair_pose_mirror_q10(bundle_a: *i64, bundle_b: *i64,
67 scene_midline_x: i64) -> i64 {
68 let a_face_cx: i64 = (bundle_a[NX_V7_FACE_X0] + bundle_a[NX_V7_FACE_X1]) / 2
69 let b_face_cx: i64 = (bundle_b[NX_V7_FACE_X0] + bundle_b[NX_V7_FACE_X1]) / 2
70 var a_off: i64 = a_face_cx - scene_midline_x
71 var b_off: i64 = b_face_cx - scene_midline_x
72 // Mirror means signs are opposite.
73 let signs_oppose: i64 = a_off * b_off
74 if signs_oppose >= 0 { return 0 }
75 // Magnitude similarity.
76 if a_off < 0 { a_off = -a_off }
77 if b_off < 0 { b_off = -b_off }
78 var bigger: i64 = a_off
79 if b_off > bigger { bigger = b_off }
80 if bigger == 0 { return 0 }
81 var smaller: i64 = a_off
82 if b_off < smaller { smaller = b_off }
83 return (smaller * NX_MAGIC_1024) / bigger
84}
85
86// Identity distinctness — uses eye-width as a crude proxy for visual
87// distinctness. In a fuller implementation this reads identity registry
88// phenotype Hamming distance (per the Python multi_identity_scene).
89// For now: if eye_width and iris_radius are notably different → distinct.
90func nx_pair_identity_distinct_q10(bundle_a: *i64, bundle_b: *i64) -> i64 {
91 let ew_a: i64 = bundle_a[NX_V7_EYE_WIDTH_PX]
92 let ew_b: i64 = bundle_b[NX_V7_EYE_WIDTH_PX]
93 if ew_a == 0 { return 512 } // unknown — middle
94 if ew_b == 0 { return 512 }
95 var diff: i64 = ew_a - ew_b
96 if diff < 0 { diff = -diff }
97 var max_ew: i64 = ew_a
98 if ew_b > max_ew { max_ew = ew_b }
99 let rel_diff_q10: i64 = (diff * NX_MAGIC_1024) / max_ew
100 // 0 diff = clones (0 distinct). 20% diff = clearly distinct (1024).
101 let dist: i64 = rel_diff_q10 * 5
102 if dist > NX_MAGIC_1024 { return NX_MAGIC_1024 }
103 return dist
104}
105
106// Aesthetic match: compare arousal_q10 + reproductive_state slots.
107func nx_pair_aesthetic_match_q10(bundle_a: *i64, bundle_b: *i64) -> i64 {
108 let ar_a: i64 = bundle_a[NX_V7_AROUSAL_Q10]
109 let ar_b: i64 = bundle_b[NX_V7_AROUSAL_Q10]
110 let rs_a: i64 = bundle_a[NX_V7_REPRODUCTIVE_STATE]
111 let rs_b: i64 = bundle_b[NX_V7_REPRODUCTIVE_STATE]
112 var arousal_diff: i64 = ar_a - ar_b
113 if arousal_diff < 0 { arousal_diff = -arousal_diff }
114 if arousal_diff > NX_MAGIC_1024 { arousal_diff = NX_MAGIC_1024 }
115 let arousal_match: i64 = NX_MAGIC_1024 - arousal_diff
116 var state_match: i64 = NX_MAGIC_1024
117 if rs_a != rs_b { state_match = 256 }
118 return (arousal_match + state_match) / 2
119}
120
121// Scale coherence: body bbox heights similar?
122func nx_pair_scale_coherence_q10(bundle_a: *i64, bundle_b: *i64) -> i64 {
123 let h_a: i64 = bundle_a[NX_V7_TORSO_Y1] - bundle_a[NX_V7_TORSO_Y0]
124 let h_b: i64 = bundle_b[NX_V7_TORSO_Y1] - bundle_b[NX_V7_TORSO_Y0]
125 if h_a <= 0 { return 512 }
126 if h_b <= 0 { return 512 }
127 var smaller: i64 = h_a
128 var larger: i64 = h_b
129 if h_b < smaller { smaller = h_b; larger = h_a }
130 return (smaller * NX_MAGIC_1024) / larger
131}
132
133// Compose the pair verdict from the 5 axis scores.
134func nx_pair_synchrony(bundle_a: *i64, bundle_b: *i64,
135 scene_midline_x: i64, result: *i64) -> i64 {
136 var i: i64 = 0
137 while i < NX_PAIR_RES_FIELDS { result[i] = 0; i = i + 1 }
138
139 let pose_sync: i64 = nx_pair_pose_sync_q10(bundle_a, bundle_b)
140 let pose_mirror: i64 = nx_pair_pose_mirror_q10(bundle_a, bundle_b, scene_midline_x)
141 let aes_match: i64 = nx_pair_aesthetic_match_q10(bundle_a, bundle_b)
142 let distinct: i64 = nx_pair_identity_distinct_q10(bundle_a, bundle_b)
143 let scale_coh: i64 = nx_pair_scale_coherence_q10(bundle_a, bundle_b)
144
145 result[NX_PAIR_RES_POSE_SYNC] = pose_sync
146 result[NX_PAIR_RES_POSE_MIRROR] = pose_mirror
147 result[NX_PAIR_RES_AES_MATCH] = aes_match
148 result[NX_PAIR_RES_DISTINCT] = distinct
149 result[NX_PAIR_RES_SCALE_COH] = scale_coh
150
151 // Verdict ladder:
152 // SYNCHRONIZED_PAIR — pose_sync >= 768 AND aes_match >= 768 AND distinct >= 410 AND scale_coh >= 768
153 // MATCHED — pose_sync >= 410 AND aes_match >= 614
154 // ASYMMETRIC — pose_sync >= 256 OR aes_match >= 410
155 // DISCORDANT — everything else
156 var verdict: i64 = NX_PAIR_V_DISCORDANT
157 if pose_sync >= 768 {
158 if aes_match >= 768 {
159 if distinct >= 410 {
160 if scale_coh >= 768 { verdict = NX_PAIR_V_SYNCHRONIZED_PAIR }
161 }
162 }
163 }
164 if verdict == NX_PAIR_V_DISCORDANT {
165 if pose_sync >= 410 { if aes_match >= 614 { verdict = NX_PAIR_V_MATCHED } }
166 }
167 if verdict == NX_PAIR_V_DISCORDANT {
168 if pose_sync >= 256 { verdict = NX_PAIR_V_ASYMMETRIC }
169 else { if aes_match >= 410 { verdict = NX_PAIR_V_ASYMMETRIC } }
170 }
171 result[NX_PAIR_RES_VERDICT] = verdict
172 return 0
173}