nx_fieldfit_verified_candidate_t333.nx
buildroot/runtime/nx_fieldfit_verified_candidate_t333.nx
about
nx_fieldfit_lib.nx -- FIT A PARAMETRIC IMPLICIT FIELD TO A SCANNED ORACLE. The machinery nx_skullsdf's `tune` grew
(anatomy AN17, 2026-09-18/19), extracted so any anatomy field -- a skull, an arm, a foot, a muscle belly, a tissue
layer -- is fitted by ONE optimiser with ONE objective and ONE fit-file contract, and a defect fixed here is fixed for
every field at once. The consumer hands over three functions as VALUES (NishiLang func-pointer locals and fields,
indirect calls up to six arguments):
field(px, py, pz, a, b, P) -> signed distance at `fq` units per millimetre (negative inside) for parameter vector P,
with a and b the consumer's two policy knobs (the skull passes sex and robusticity)
region(x, y, z) -> 0 .. nreg-1, the named anatomical region a point belongs to
live(k) -> 1 for a station the field reads, 0 for a retired one (the descent skips it: two
evaluations spent on a dead station are a pass that cannot move anything)
THE OBJECTIVE IS TWO-SIDED, AND IT HAS TO BE. A one-directional score -- how far is each ORACLE point from my surface --
is trivially gamed by DELETING GEOMETRY: the skull's first tuning run shrank its orbits from 22 mm to 8 and its
maxilla from 30 mm to 13, improving the number 40 percent by filling in the eye sockets, because surface that does not
exist cannot be wrong. The REVERSE term charges every lattice point on OUR zero level its distance to the nearest
oracle sample, so a deleted feature is EXPENSIVE by construction. (The reverse term uses the nearest oracle VERTEX from
a spatial hash: an upper bound on the true point-to-surface distance -- it can overstate, never understate, the safe
direction for a penalty.)
THE OBJECTIVE IS REGION-BALANCED. A plain mean is dominated by whatever region has the most samples (the skull's vault
and base held 9,335 + 8,672 of ~31,000, so a 49 mm muzzle and 4 mm drilled orbits read as a 4 mm skull and the
surface objective fell 629 -> 531 while the chin moved +4 -> +19.6 mm). Each side is the mean of the PER-REGION means
(a region with no samples abstains), so the smallest region weighs what the largest does. No weight is typed: the
population decides.
THE DESCENT is coordinate descent: per live station try +step then -step, keep a move only if the MEASURED objective
falls; the step halves per pass, floor 1. No change is ever kept on the strength of looking better.
THE FIT FILE is newline-separated integers, loaded as a PREFIX: a file shorter than the vector applies to its first
entries and the rest keep their defaults, so growing a parametrisation never discards banked convergence; a file
shorter than `minlen` changes nothing (parsed into a temp and applied only when long enough, so a truncated write
cannot half-poison a field). Written whole by ff_save.
UNITS: objectives are reported in centi-millimetres; `lat` (the reverse lattice spacing), `ext` (the half-extent the
hash covers) and `dim` (cells per axis) are the consumer's, taken from the resource it fits.
LIB, no main. license_tier: ORIGINAL. No hw writes (Rule 26).
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_fieldfit_verified_gate_t333.nxnx_skullsdf_verified_candidate_t333.nx
structs
| 50 | struct FfCtx { field: func(i64,i64,i64,i64,i64,*i64) -> i64, region: func(i64,i64,i64) -> i64, live: func(i64) -> i64, RX: *i64, RY: *i64, RZ: *i64, RG: *i64, n: i64, head: *i64, next: *i64, ext: i64, dim: i64, lat: i64, a: i64, b: i64, fq: i64, nreg: i64, sum: *i64, cnt: *i64, np: i64, cap: i64, extra: func(*i64) -> i64, has_extra: i64 } |
| 369 | struct FfFitContract { header: *u8, header_bytes: i64, np: i64, valid: func(*i64,i64) -> i64 } |
consts
| 35 | const FF_I64: i64 = 8 |
| 36 | const FF_CENTI: i64 = 100 // objectives are centi-millimetres |
| 37 | const FF_CTX_BYTES: i64 = 256 // FfCtx: 21 fields of 8 bytes, one page-rounded map |
| 38 | const FF_LOAD_HDR: i64 = 16 // the two-word length record sys_read_file fills |
| 39 | const FF_SAVE_DIGITS: i64 = 16 // bytes reserved per integer on save (sign + 19 digits fits a page-rounded map) |
| 40 | const FF_SAVE_SLACK: i64 = 64 |
| 41 | const FF_MODE644: i64 = 420 |
| 361 | const FF_FIT_LEGACY_UNVERIFIED: i64 = 0 - 2 |
| 362 | const FF_FIT_CONTRACT_MISMATCH: i64 = 0 - 3 |
| 363 | const FF_FIT_MALFORMED: i64 = 0 - 4 |
| 364 | const FF_FIT_INVALID: i64 = 0 - 5 |
| 365 | const FF_FIT_IO: i64 = 0 - 6 |
| 366 | const FF_FIT_MAGIC_BYTES: i64 = 7 |
| 367 | const FF_FIT_I64_DIGITS: i64 = 21 |
| 368 | const FF_FIT_I64_POS_LIMIT: i64 = 9223372036854775807 |
functions
| 53 | func ff_ctx_new(np: i64, nreg: i64, cap: i64, ext: i64, dim: i64, lat: i64, fq: i64) -> *FfCtx |
| 69 | func ff_cell(c: *FfCtx, x: i64, y: i64, z: i64) -> i64 called by 1: ff_bin |
| 84 | func ff_bin(c: *FfCtx) -> i64 |
| 100 | func ff_near(c: *FfCtx, x: i64, y: i64, z: i64) -> i64 |
| 145 | func ff_isqrt(v: i64) -> i64 { if v<=0 { return 0 } var x: i64=v; var y: i64=(x+1)/2; while y<x { x=y; y=(x+v/x)/2 } return x } called by 1: ff_near |
| 149 | func ff_regions(c: *FfCtx) -> i64 |
| 156 | func ff_rtab_reset(c: *FfCtx) -> i64 |
| 162 | func ff_rtab_mean(c: *FfCtx, fq: i64) -> i64 |
| 174 | func ff_score_fwd(c: *FfCtx, P: *i64) -> i64 |
| 189 | func ff_score_rev(c: *FfCtx, P: *i64) -> i64 |
| 219 | func ff_score2(c: *FfCtx, P: *i64) -> i64 |
| 228 | func ff_live_count(c: *FfCtx) -> i64 |
| 234 | func ff_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 235 | func ff_pn(v: i64) -> i64 |
| 243 | func ff_descend(c: *FfCtx, P: *i64, passes: i64, step0: i64, verbose: i64) -> i64 |
| 278 | func ff_wint(b: *u8, o: i64, v: i64) -> i64 |
| 297 | func ff_load_prefix(path: *u8, P: *i64, np: i64, minlen: i64) -> i64 |
| 342 | func ff_save(path: *u8, P: *i64, np: i64) -> i64 |
| 372 | func ff_contract_ok(C: *FfFitContract) -> i64 |
| 381 | func ff_load_verified(path: *u8, P: *i64, C: *FfFitContract) -> i64 |
| 425 | func ff_save_verified(path: *u8, P: *i64, C: *FfFitContract) -> i64 |
| 444 | func ff_descend_checked(c: *FfCtx, P: *i64, passes: i64, step0: i64, verbose: i64, valid: func(*i64,i64) -> i64) -> i64 |