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:
@@ -0,0 +1,45 @@
|
||||
"""Finite-group pooling, coordinate alignment and invalid input checks."""
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
np = pytest.importorskip("numpy")
|
||||
for dependency in ["cv2", "scipy", "shapely"]:
|
||||
pytest.importorskip(dependency)
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "simulation/semantic-learning"))
|
||||
study = importlib.import_module("c4_admission_study")
|
||||
|
||||
|
||||
def test_uniform_pool_is_cyclically_invariant_without_best_angle():
|
||||
orbit = np.random.default_rng(61).normal(size=(4, 8, 512)).astype(np.float32)
|
||||
mean = study.c4_mean(orbit)
|
||||
for k in range(4):
|
||||
assert np.array_equal(mean, study.c4_mean(np.roll(orbit, k, axis=0)))
|
||||
assert np.allclose(mean, orbit.astype(np.float64).sum(0) / 4)
|
||||
assert not np.array_equal(mean, orbit.max(0))
|
||||
|
||||
|
||||
def test_mask_field_alignment_commutes_with_quarter_turns():
|
||||
mask = np.zeros((512, 512), bool)
|
||||
mask[51:211, 91:93] = True
|
||||
mask[101:122, 50:211] = True
|
||||
field = np.random.default_rng(19).normal(size=(128, 128)).astype(np.float32)
|
||||
original = np.sum(study.fractional_weights(mask, (128, 128)) * field)
|
||||
for k in range(4):
|
||||
rotated = np.sum(
|
||||
study.fractional_weights(np.rot90(mask, k), (128, 128)) * np.rot90(field, k)
|
||||
)
|
||||
assert rotated == pytest.approx(original, abs=1e-7)
|
||||
restored = np.rot90(np.rot90(field, k), -k)
|
||||
assert np.array_equal(restored, field)
|
||||
|
||||
|
||||
def test_partial_or_nonfinite_orbit_refused():
|
||||
with pytest.raises(ValueError):
|
||||
study.c4_mean(np.zeros((3, 1, 512)))
|
||||
with pytest.raises(ValueError):
|
||||
study.c4_mean(np.full((4, 1, 512), np.nan))
|
||||
assert study.c4_mean(np.empty((4, 0, 512))).shape == (0, 512)
|
||||
Reference in New Issue
Block a user