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.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-29 09:10:00 +03:00
parent 69dc566665
commit 25dc0a1b44
128 changed files with 23742 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
"""Checks for isolation, ignored pixels, fixed comparator, and spatial limits."""
import importlib
import importlib.util
import sys
import unittest
from pathlib import Path
import numpy as np
if importlib.util.find_spec("cv2") is None:
raise unittest.SkipTest("Scientific checks run in the pinned Worker image")
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "simulation/semantic-learning"))
probe = importlib.import_module("paint_evidence_probe")
class PaintEvidenceTests(unittest.TestCase):
def test_unknown_pixels_do_not_change_score(self):
pos = np.zeros((8, 8), bool)
pos[1, 1] = True
neg = np.zeros_like(pos)
neg[6, 6] = True
a = pos.copy()
b = np.ones_like(pos)
b[6, 6] = False
self.assertEqual(probe.counts(a, pos, neg), probe.counts(b, pos, neg))
def test_conflicting_review_rejected(self):
with self.assertRaises(AssertionError):
probe.probe_masks(
dict(positive=[[[1, 1], [5, 5]]], negative=[[[0, 0], [10, 0], [10, 10], [0, 10]]])
)
def test_threshold_uses_validation_false_positive_limit(self):
probability = np.array([[0.9, 0.7, 0.65, 0.2]])
positive = np.array([[True, True, False, False]])
negative = ~positive
threshold, _ = probe.choose_threshold(
[(probability, positive, negative)], [0.5, 0.6, 0.7, 0.8]
)
self.assertEqual(threshold, 0.7)
def test_spatial_filter_cannot_invent_empty_line(self):
mask = np.zeros((64, 64), bool)
self.assertFalse(probe.spatial_rule(mask).any())
mask[30:33, 5:20] = True
mask[30:33, 40:59] = True
out = probe.spatial_rule(mask)
self.assertFalse(out[:, 23:37].any())
self.assertTrue(out[31, 10])
def test_uniform_brightness_is_not_fixed_paint_evidence(self):
_, mask, _ = probe.features(np.full((64, 64, 3), 180, np.uint8))
self.assertFalse(mask.any())
def test_pixel_features_do_not_encode_position(self):
image = np.full((80, 80, 3), 110, np.uint8)
a, fixed, names = probe.features(image)
b, other, other_names = probe.features(image)
np.testing.assert_array_equal(a, b)
np.testing.assert_array_equal(fixed, other)
self.assertEqual(names, other_names)
self.assertEqual(a.shape, (80, 80, 10))
np.testing.assert_array_equal(a[30, 30], a[40, 40])
if __name__ == "__main__":
unittest.main()