code wiki / (root) / nx_semruler_lib.nx

nx_semruler_lib.nx

buildroot/runtime/nx_semruler_lib.nx

6472 B116 linesdepth 8pulls 16 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_semruler_lib.nx -- THE SEMANTIC RULER'S DECISION CORE (/compare/mediaingest; nx_imgsearch's own declared next step). license_tier: ORIGINAL WHY THIS EXISTS, IN THE SUBJECT ORGAN'S OWN WORDS. nx_imgsearch status publishes, honestly: {"class":"semantic-lookalike","permille":-1,"status":"UNMEASURED", "note":"-1 means NEVER MEASURED, not zero. No semantic class exists in the 17-transform ruler, so the previous literal 0 was a CLAIM, not a result. Order: (1) build a semantic ruler from labelled same-concept pairs, (2) measure the EXISTING descriptors as the honest baseline, (3) only then a quantised learned image-embedding tier (NX_IT_KIND_SEMANTIC reserved)." This lib is step (1)'s decision core, and it is deliberately TINY because steps of it already existed: NOT WRITTEN HERE, COMPOSED INSTEAD -- each one would have been a duplicate ruler: nx_recall_eval the estate's IR scorecard (nDCG/MRR/Recall/P/AP). No rate math beyond the one abstaining ratio below, which exists only to refuse the empty set. it_copy_distance the copy tier's own bit-Hamming over the 64-bit dHash. The admissibility floor is expressed in THAT metric so the bar and the tier it guards against cannot drift apart. (nx_hamming is BYTE-wise and would have mis-scaled the floor by 8x while still returning a plausible number.) NX_IT_CLASS_IDENTITY / NX_IT_CLASS_SIMILAR the tier partition is already a first-class concept in the base class; this lib only NAMES the reading so a caller cannot mistake one for the other. THE ONE THING THAT DID NOT EXIST, AND THE WHOLE POINT OF THE FILE: A "SAME-CONCEPT" PAIR THAT IS ACTUALLY A NEAR-DUPLICATE MEASURES THE COPY TIER, NOT SEMANTICS. Tiers 0-2 are copy detectors and they are excellent -- 992 permil overall across rescale, crop, watermark and recompress. Feed this ruler re-crops and re-encodes of one photograph and it will report near 1000 permil and "prove" the engine is already semantic. The number would be real and the SUBJECT would be wrong: that is the vacuous-test defect wearing a benchmark's clothes, and it is the single most likely way this measurement gets faked without anyone lying. sr_pair_admissible REFUSES such a pair. Its caller MUST publish the refusal count -- a ruler that silently drops inadmissible pairs has chosen its own population, which is the same defect one layer up. AND THE MIRROR CASE, WHICH THE OBVIOUS ONE-LINE VERSION GETS WRONG: a mirrored or quarter-turned re-upload has a LARGE copy distance and a TINY orient distance, because tier 1 is dihedral-invariant by construction. A predicate that tested only the copy distance would admit every mirrored duplicate and quietly re-measure tier 1 while claiming to measure semantics. The floor is applied to the MINIMUM of the two, i.e. "is this the same photograph under ANY dihedral transform".

dependencies 2 imports · 2 importers

nx_syscalls.nx nx_imgsearch_tier.nx nx_semruler_lib.nx nx_semruler.nx nx_semruler_gate.nx

imports: nx_syscalls.nxnx_imgsearch_tier.nx

imported by: nx_semruler.nxnx_semruler_gate.nx

structs

none

consts

46const SR_UNOBSERVABLE: i64 = 0 - 1
47const SR_PERMIL: i64 = 1000
51const SR_CLASS_UNKNOWN: i64 = 0

functions

53func sr_min(a: i64, b: i64) -> i64
62func sr_pair_admissible(copy_dist: i64, orient_dist: i64) -> i64
called by 2: mainmain calls 1: sr_min
74func sr_rate_permil(hits: i64, admitted: i64) -> i64
82func sr_hit_is_semantic(klass: i64) -> i64
called by 1: main
87func sr_hit_is_identity(klass: i64) -> i64
called by 1: main
93func sr_klass_known(klass: i64) -> i64
called by 1: main
101func sr_partition_sums(identity: i64, semantic: i64, unknown: i64, total: i64) -> i64
called by 1: main
114func sr_semantic_permil(semantic_hits: i64, admitted: i64) -> i64
called by 2: mainmain calls 1: sr_rate_permil