Files
NODEDC_MISSION_CORE/simulation/semantic-learning/annotation_training_view.py
T
DCCONSTRUCTIONS 25dc0a1b44 feat(semantics): add portable annotation, learning and review contracts
Add portable corpus, annotation provenance, admission, review and bounded agent-cycle contracts. Preserve dataset ownership and explicit research acceptance limits.
2026-10-29 09:10:00 +03:00

45 lines
1.7 KiB
Python

"""Apply reviewed known-to-unknown withdrawals to TRAIN-only paired targets."""
import numpy as np
def training_view(record, revised):
if record["split"] != "train":
raise ValueError("TRAIN records only")
old, base = record["target"], record["base_target"]
arrays = [old, base, revised]
if any(
a.dtype != np.uint8
or a.ndim != 2
or a.shape != old.shape
or not np.isin(a, [0, 1, 255]).all()
for a in arrays
):
raise ValueError("Aligned uint8 targets required")
if not np.array_equal(old[base != 255], base[base != 255]):
raise ValueError("Parent base labels conflict")
if not np.array_equal(old == 0, base == 0):
raise ValueError("Parent comparison admits paint only")
changed = old != revised
if np.any(changed & ((old == 255) | (revised != 255))):
raise ValueError("Known-to-unknown withdrawal only")
for name in ["weak", "clear", "added"]:
mask = record[name]
if mask.dtype != bool or mask.shape != old.shape or np.any(mask & (old != 1)):
raise ValueError("Pinned condition masks must select parent paint")
if not np.array_equal(record["added"], (base == 255) & (old == 1)):
raise ValueError("Added cohort differs from parent labels")
if np.any(changed & (record["weak"] | record["added"])):
raise ValueError("This fixed comparison preserves all weak and added paint")
target = revised.copy()
original = base.copy()
original[changed] = 255
return dict(
record,
target=target,
base_target=original,
weak=record["weak"].copy(),
added=record["added"].copy(),
clear=record["clear"] & (target == 1),
)