nx_mvault_measure.nx source
↩ module page · 128 lines · 4952 B
1// nx_mvault_measure.nx -- NishiCaption-grade MEASUREMENT atom for the vault's
2// comprehensive first-pass tagging (the training-corpus label).
3//
4// WHY (operator 2026-07-17): "first tagging pass comprehensive ... joy caption
5// like exercise ... classification for our models and loras both llm and image
6// ... state of the art." The elder-ai NishiCaption design (95 axes, 3 legs,
7// round-trip) is the SOTA schema; this is its capture atom on the sovereign
8// store so the EXPENSIVE VLM/math ensemble pass runs ONCE and nothing is lost.
9//
10// A measurement is a triangulated axis reading:
11// "<axis>=<value>@<leg>#<conf>" e.g. hip_waist_ratio=700/1000@math#920
12// hair_color=blonde@vlm#980
13// value = lossless (ivalue/scale) for regressors, a token for enum/classifier
14// leg = which of MATH/VLM/HUMAN/FUSED produced it (triangulation)
15// conf = permille confidence (training threshold + fusion weight)
16// Round-trip variance (directive vs measured) = the self-improvement + LoRA
17// training signal. Caption modes = the 3 NishiCaption emit forms.
18//
19// Extensible by construction (like nx_mvault_tag): NO axis list is hardcoded,
20// so all 95 axes -- and future ones -- are just data. Composes nx_mvault_tag
21// (mv_u_dec). license_tier: ORIGINAL
22
23import "nx_syscalls.nx"
24import "nx_mvault_tag.nx"
25
26// ===== source legs (triangulation) =====
27const MV_LEG_MATH: i64 = 1 // HMR2.0/DWPose/SMPL measurement
28const MV_LEG_VLM: i64 = 2 // the multi-head captioner
29const MV_LEG_HUMAN: i64 = 3 // calibration gallery (gold)
30const MV_LEG_FUSED: i64 = 4 // triangulated composite
31
32// ===== measurement kinds (NishiCaption: 35 regressor / 53 enum / 2 classifier)
33const MV_MK_REGRESSOR: i64 = 1
34const MV_MK_ENUM: i64 = 2
35const MV_MK_CLASSIFIER: i64 = 3
36
37// ===== caption emit modes (NishiCaption 3 forms + length variants) =====
38const MV_CAP_MANIFEST: i64 = 1 // JSON manifest
39const MV_CAP_TOKEN: i64 = 2 // pipe-token string
40const MV_CAP_NATURAL: i64 = 3 // natural language
41const MV_CAP_SHORT: i64 = 4
42const MV_CAP_LONG: i64 = 5
43const MV_CAP_TRAINING: i64 = 6 // the training-prompt form
44
45func mv_leg_str(leg: i64) -> *u8 {
46 let m: *u8 = "math" as *u8
47 let v: *u8 = "vlm" as *u8
48 let h: *u8 = "human" as *u8
49 let f: *u8 = "fused" as *u8
50 let u: *u8 = "unknown" as *u8
51 if leg == MV_LEG_MATH { return m }
52 if leg == MV_LEG_VLM { return v }
53 if leg == MV_LEG_HUMAN { return h }
54 if leg == MV_LEG_FUSED { return f }
55 return u
56}
57
58func mv_capmode_str(mode: i64) -> *u8 {
59 let a: *u8 = "manifest" as *u8
60 let b: *u8 = "token" as *u8
61 let c: *u8 = "natural" as *u8
62 let d: *u8 = "short" as *u8
63 let e: *u8 = "long" as *u8
64 let f: *u8 = "training" as *u8
65 let u: *u8 = "unknown" as *u8
66 if mode == MV_CAP_MANIFEST { return a }
67 if mode == MV_CAP_TOKEN { return b }
68 if mode == MV_CAP_NATURAL { return c }
69 if mode == MV_CAP_SHORT { return d }
70 if mode == MV_CAP_LONG { return e }
71 if mode == MV_CAP_TRAINING { return f }
72 return u
73}
74
75// lossless "ivalue/scale" (value only; the regressor reading)
76func mv_ratio_str(out: *u8, ivalue: i64, scale: i64) -> i64 {
77 var o: i64 = mv_u_dec(out, 0, ivalue)
78 out[o] = 47 as u8; o = o + 1 // '/'
79 o = mv_u_dec(out, o, scale)
80 out[o] = 0 as u8
81 return o
82}
83
84// "<axis>=<value>@<leg>#<conf>"
85func mv_meas_make(out: *u8, axis: *u8, value: *u8, leg: i64, conf: i64) -> i64 {
86 var o: i64 = 0
87 var i: i64 = 0
88 while axis[i] != (0 as u8) { out[o] = axis[i]; o = o + 1; i = i + 1 }
89 out[o] = 61 as u8; o = o + 1 // '='
90 i = 0
91 while value[i] != (0 as u8) { out[o] = value[i]; o = o + 1; i = i + 1 }
92 out[o] = 64 as u8; o = o + 1 // '@'
93 let ls: *u8 = mv_leg_str(leg)
94 i = 0
95 while ls[i] != (0 as u8) { out[o] = ls[i]; o = o + 1; i = i + 1 }
96 out[o] = 35 as u8; o = o + 1 // '#'
97 o = mv_u_dec(out, o, conf)
98 out[o] = 0 as u8
99 return o
100}
101
102// training filter: keep a reading only if confident enough.
103func mv_meas_keep(conf: i64, threshold: i64) -> i64 {
104 if conf >= threshold { return 1 }
105 return 0
106}
107
108// round-trip |directive - measured| (same scale) = the self-improvement signal.
109func mv_meas_variance(a: i64, b: i64) -> i64 {
110 if a >= b { return a - b }
111 return b - a
112}
113
114// "cap:<mode>:<text>" (a caption emit in one of the NishiCaption forms)
115func mv_caption_make(out: *u8, mode: i64, text: *u8) -> i64 {
116 let p: *u8 = "cap:" as *u8
117 var o: i64 = 0
118 var i: i64 = 0
119 while p[i] != (0 as u8) { out[o] = p[i]; o = o + 1; i = i + 1 }
120 let ms: *u8 = mv_capmode_str(mode)
121 i = 0
122 while ms[i] != (0 as u8) { out[o] = ms[i]; o = o + 1; i = i + 1 }
123 out[o] = 58 as u8; o = o + 1 // ':'
124 i = 0
125 while text[i] != (0 as u8) { out[o] = text[i]; o = o + 1; i = i + 1 }
126 out[o] = 0 as u8
127 return o
128}