Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/recuris/metaagent/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
improvement it did not cause.
4. ``Ledger`` -- the do-not-repeat record.
"""
import math
import random
import statistics
from dataclasses import dataclass, field
Expand Down Expand Up @@ -52,7 +53,20 @@ def held_out_paired_gate(base, cand, alpha=0.05, reg_cap=0, eps=1e-9,
``reg_cap`` is a hard rejection condition, counting noise there turns the
gate into a coin flip.
"""
items = sorted(set(base) & set(cand))
# A paired admission test cannot drop missing items or admit invalid scores.
# Both benchmark variants promise per-seed values in the unit interval.
def valid(matrix):
return isinstance(matrix, dict) and all(
isinstance(scores, (list, tuple)) and scores
and all(type(score) in (int, float) and math.isfinite(score)
and 0 <= score <= 1 for score in scores)
for scores in matrix.values()
)

if not valid(base) or not valid(cand) or set(base) != set(cand):
return Verdict(False, 0.0, (0.0, 0.0), 0, 0,
"invalid or unpaired held-out scores")
items = sorted(base)
diffs = [statistics.mean(cand[i]) - statistics.mean(base[i]) for i in items]
if not diffs:
return Verdict(False, 0.0, (0.0, 0.0), 0, 0, "no comparable items")
Expand Down
38 changes: 38 additions & 0 deletions tests/native_heldout_gate_unittest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Script-only admission-gate contract tests on frozen first-party Python code."""

import unittest

from recuris.metaagent.gates import held_out_paired_gate


class HeldoutInputContractTests(unittest.TestCase):
def decide(self, base, cand):
return held_out_paired_gate(base, cand, n_boot=32, seed=0)

def test_positive_infinity_cannot_claim_significant_improvement(self):
verdict = self.decide({"a": [0.0]}, {"a": [float("inf")]})
self.assertFalse(verdict.accept)

def test_score_beyond_documented_unit_interval_is_rejected(self):
verdict = self.decide({"a": [0.0]}, {"a": [1.5]})
self.assertFalse(verdict.accept)

def test_unmatched_candidate_coverage_cannot_win_paired_gate(self):
verdict = self.decide({"a": [0.0], "b": [1.0]}, {"a": [1.0]})
self.assertFalse(verdict.accept)

def test_empty_seed_list_is_reported_as_rejection(self):
verdict = self.decide({"a": []}, {"a": [1.0]})
self.assertFalse(verdict.accept)

def test_valid_matched_improvement_is_accepted(self):
verdict = self.decide({"a": [0.0], "b": [0.0]}, {"a": [1.0], "b": [1.0]})
self.assertTrue(verdict.accept)

def test_equal_scores_are_not_accepted(self):
verdict = self.decide({"a": [0.5]}, {"a": [0.5]})
self.assertFalse(verdict.accept)


if __name__ == "__main__":
unittest.main()