Give the blind test by two measures, first and last months and also no wrong gap in the middle: 114 of 148 and 105 of 148, stored, scored and stated together

This commit is contained in:
swaits committed 2026-11-20 14:16:26 -07:00
1 parent 535d2bebaa
commit e8ca8e862e
13 files changed
+183 -68

No files matched your search

+5 -3
View File
@@ -719,7 +719,8 @@ def check(root, fetch):
trail, or the sourced trails it is compared with), when the
leave-one-out match share has fallen by more than 0.02 from
tools/season_fit.json, or when the blind test of the judged method
(tools/season_blind_test.json) is missing or below the bar. A changed
(tools/season_blind_test.json) is missing, or is below the bar on its
ends-only measure (the strict measure is recorded beside it). A changed
estimate is a flag for a person to look at, not a rewrite."""
import season_judge
try:
@@ -776,8 +777,9 @@ def check(root, fetch):
lines += [f"tools/season_blind_test.json: {p}" for p in problems]
elif blind["share"] < BAR["within1_min"]:
ok = False
lines.append(f"the blind test matched {blind['share']:.2f}, under the bar of "
f"{BAR['within1_min']:.2f}; estimates must not ship")
lines.append(f"the blind test matched {blind['share']:.2f} on the ends-only measure, under the "
f"bar of {BAR['within1_min']:.2f} on that measure (the strict figure is "
f"{blind['strict_share']:.2f}); estimates must not ship")
except (OSError, ValueError, KeyError):
ok = False
lines.append("tools/season_blind_test.json is missing or unreadable")
+13 -4
View File
@@ -1,24 +1,33 @@
{
"date": "2026-11-20",
"measure": "within one month at each end of the season a page states",
"measure": "the first and last months of the reviewer's season within a month of the season a page states",
"strict_measure": "the ends as above, and every window of the season (such as a gap in the middle) also within a month of the page's, with no window added or missing",
"tested": 148,
"matched": 114,
"share": 0.77,
"strict_matched": 105,
"strict_share": 0.71,
"by_confidence": {
"high": {
"tested": 52,
"matched": 48,
"share": 0.92
"share": 0.92,
"strict_matched": 48,
"strict_share": 0.92
},
"medium": {
"tested": 76,
"matched": 55,
"share": 0.72
"share": 0.72,
"strict_matched": 46,
"strict_share": 0.61
},
"low": {
"tested": 20,
"matched": 11,
"share": 0.55
"share": 0.55,
"strict_matched": 11,
"strict_share": 0.55
}
}
}
+59 -31
View File
@@ -6,14 +6,18 @@ sets it from a packet: the trail's location, elevation, monthly climate
normals (tools/season_climate.py), the machine estimate of
tools/estimate_season.py and the most similar sourced trails. The method
was tested blind: the same reviewers estimated the trails whose season a
page states, from identical packets with the season hidden, and the share
they matched is in tools/season_blind_test.json, which the site reads.
page states, from identical packets with the season hidden. The shares they
matched are in tools/season_blind_test.json, which the site reads, by two
measures that are always given together: the ends only (the first and last
months within a month of the page's) and the strict one (also no wrong gap
or missing window in the middle).
docs/season-judging.md says how a reviewer works.
Commands:
packets write one packet per trail, and the three part lists
score score reviewers' answer files against the sourced seasons
(--write records the figures in tools/season_blind_test.json)
(prints both measures; --write records them in
tools/season_blind_test.json)
proposals stage the judged seasons for the trails with no season, for
python3 tools/refresh.py collect and apply
inputs record the machine estimate and the inputs of every estimate,
@@ -297,12 +301,16 @@ def read_answers(path, known):
def score(answers, truth):
"""The blind result: for every trail whose season a page states (truth,
{id: months}) whether the reviewer's months match within a month at each
end, in all and by the reviewer's confidence. A trail with no answer is
{id: months}) whether the reviewer's months match, in all and by the
reviewer's confidence, by two measures: `matched`, the first and last
months within a month of the page's, and `strict_matched`, which also
needs every window of the season, and no other, to correspond (so a gap
the page does not have, or one it has and the reviewer lacks, is a miss).
A trail with no answer is
tested and counts as missed; an answer for a trail not in truth is not
scored."""
by = {c: {"tested": 0, "matched": 0} for c in CONFIDENCES}
tested = matched = unanswered = 0
by = {c: {"tested": 0, "matched": 0, "strict_matched": 0} for c in CONFIDENCES}
tested = matched = strict_matched = unanswered = 0
for tid, months in sorted(truth.items()):
tested += 1
if tid not in answers:
@@ -310,28 +318,35 @@ def score(answers, truth):
continue
got, _phrase, conf, _why = answers[tid]
hit = bool(M.score(got, months)[0])
strict = M.match_strict(got, months)
matched += hit
strict_matched += strict
by[conf]["tested"] += 1
by[conf]["matched"] += hit
return {"tested": tested, "matched": matched, "unanswered": unanswered, "by_confidence": by}
by[conf]["strict_matched"] += strict
return {"tested": tested, "matched": matched, "strict_matched": strict_matched,
"unanswered": unanswered, "by_confidence": by}
def _share(matched, tested):
return round(matched / tested, 2) if tested else 0.0
ENDS_MEASURE = ("the first and last months of the reviewer's season within a month of the season "
"a page states")
STRICT_MEASURE = ("the ends as above, and every window of the season (such as a gap in the middle) "
"also within a month of the page's, with no window added or missing")
def write_blind_test(path, figures, date):
doc = {
"date": date,
"measure": "within one month at each end of the season a page states",
"tested": figures["tested"],
"matched": figures["matched"],
"share": _share(figures["matched"], figures["tested"]),
"by_confidence": {
c: {"tested": v["tested"], "matched": v["matched"],
"share": _share(v["matched"], v["tested"])}
for c, v in figures["by_confidence"].items()},
}
def part(v):
return {"tested": v["tested"], "matched": v["matched"],
"share": _share(v["matched"], v["tested"]),
"strict_matched": v["strict_matched"],
"strict_share": _share(v["strict_matched"], v["tested"])}
doc = {"date": date, "measure": ENDS_MEASURE, "strict_measure": STRICT_MEASURE}
doc.update(part(figures))
doc["by_confidence"] = {c: part(v) for c, v in figures["by_confidence"].items()}
with open(path, "w", encoding="utf-8") as f:
json.dump(doc, f, indent=1, sort_keys=False)
f.write("\n")
@@ -343,22 +358,33 @@ def load_blind_test(path=BLIND_TEST):
def check_blind_test(doc):
"""Problems with the figure file: the parts must add up to the whole and
each share must be the matched count over the tested count."""
"""Problems with the figure file: both measures must be present, the
parts must add up to the whole, each share must be the count over the
tested count, and the strict count may not exceed the ends-only count."""
problems = []
by = doc.get("by_confidence") or {}
if sorted(by) != sorted(CONFIDENCES):
problems.append("by_confidence must hold high, medium and low")
return problems
if sum(v["tested"] for v in by.values()) != doc["tested"]:
problems.append("the confidence groups do not add up to the trails tested")
if sum(v["matched"] for v in by.values()) != doc["matched"]:
problems.append("the confidence groups do not add up to the trails matched")
for name, v in [("all", doc)] + list(by.items()):
if v["matched"] > v["tested"]:
parts = [("all", doc)] + list(by.items())
for name, v in parts:
for key in ("tested", "matched", "share", "strict_matched", "strict_share"):
if key not in v:
problems.append(f"{name}: {key} is missing")
if problems:
return problems
for key in ("tested", "matched", "strict_matched"):
if sum(v[key] for v in by.values()) != doc[key]:
problems.append(f"the confidence groups do not add up to the trails {key.replace('_', ' ')}")
for name, v in parts:
if v["matched"] > v["tested"] or v["strict_matched"] > v["tested"]:
problems.append(f"{name}: more matched than tested")
elif v["strict_matched"] > v["matched"]:
problems.append(f"{name}: the strict measure cannot match more than the ends-only one")
elif v["share"] != _share(v["matched"], v["tested"]):
problems.append(f"{name}: the share is not matched over tested")
elif v["strict_share"] != _share(v["strict_matched"], v["tested"]):
problems.append(f"{name}: the strict share is not matched over tested")
return problems
@@ -560,13 +586,15 @@ def cmd_score(args):
print(f"{path} line {n}: {text}")
answers.update(got)
figures = score(answers, truth)
t, m = figures["tested"], figures["matched"]
print(f"owner's measure (within one month at each end): {m} of {t} = {100 * m / t:.1f}%"
t, m, s = figures["tested"], figures["matched"], figures["strict_matched"]
print(f"ends only (first and last months within a month of the page's): {m} of {t} = {100 * m / t:.1f}%"
f" ({figures['unanswered']} unanswered)")
print(f"strict (also no wrong gap or missing window in the middle): {s} of {t} = {100 * s / t:.1f}%")
for c in CONFIDENCES:
v = figures["by_confidence"][c]
print(f" {c:<7} {v['matched']:>3} of {v['tested']:<3} = "
f"{100 * v['matched'] / v['tested'] if v['tested'] else 0:.1f}%")
n = v["tested"] or 1
print(f" {c:<7} ends only {v['matched']:>3} of {v['tested']:<3} = {100 * v['matched'] / n:.1f}%"
f" strict {v['strict_matched']:>3} of {v['tested']:<3} = {100 * v['strict_matched'] / n:.1f}%")
if args.write:
write_blind_test(args.write, figures, args.date or datetime.date.today().isoformat())
print(f"written to {args.write}")
+19
View File
@@ -137,6 +137,25 @@ def match(estimated, sourced):
return season.grade(to_months(est), to_months(src)) != "worse"
def match_strict(estimated, sourced):
"""The stricter measure: match() and, besides, every window of the
estimate and of the sourced season must have a partner within a month at
both ends in the other. An estimate with a gap in the middle that the
sourced season does not have (or the other way round) is a miss, which
match() does not see when the sourced season is a single window. A
sourced season of eleven or twelve months is judged as match() judges
it."""
est = estimated if isinstance(estimated, int) else to_mask(estimated)
src = sourced if isinstance(sourced, int) else to_mask(sourced)
if not match(est, src):
return False
if bin(src).count("1") >= 11:
return True
est_runs, src_runs = _runs(est), _runs(src)
return (all(any(_near(a, c) and _near(b, d) for c, d in est_runs) for a, b in src_runs)
and all(any(_near(a, c) and _near(b, d) for c, d in src_runs) for a, b in est_runs))
def score(estimated, sourced):
"""(match 1 or 0, share of the twelve months classified correctly,
Jaccard overlap of the month sets)."""
+7 -6
View File
@@ -391,13 +391,14 @@ class ProposeCheckTest(unittest.TestCase):
def blind_doc(self, root, share=0.77, tested=100):
matched = int(round(share * tested))
doc = {"date": "2026-11-20", "tested": tested, "matched": matched,
"share": round(matched / tested, 2),
sh = round(matched / tested, 2)
doc = {"date": "2026-11-20", "tested": tested, "matched": matched, "share": sh,
"strict_matched": matched, "strict_share": sh,
"by_confidence": {
"high": {"tested": tested, "matched": matched,
"share": round(matched / tested, 2)},
"medium": {"tested": 0, "matched": 0, "share": 0.0},
"low": {"tested": 0, "matched": 0, "share": 0.0}}}
"high": {"tested": tested, "matched": matched, "share": sh,
"strict_matched": matched, "strict_share": sh},
"medium": {"tested": 0, "matched": 0, "share": 0.0, "strict_matched": 0, "strict_share": 0.0},
"low": {"tested": 0, "matched": 0, "share": 0.0, "strict_matched": 0, "strict_share": 0.0}}}
with open(os.path.join(root, "tools", "season_blind_test.json"), "w") as f:
json.dump(doc, f)
+43 -14
View File
@@ -158,26 +158,35 @@ class AnswersTest(unittest.TestCase):
class ScoreTest(unittest.TestCase):
def test_matches_are_counted_within_a_month_at_each_end_by_confidence(self):
truth = {"a": [6, 7, 8, 9], "b": [6, 7, 8, 9], "c": [6, 7, 8, 9], "d": [1, 2, 3]}
def test_matches_are_counted_both_ways_by_confidence(self):
truth = {"a": [6, 7, 8, 9], "b": [6, 7, 8, 9], "c": [6, 7, 8, 9], "d": [1, 2, 3],
"e": [3, 4, 5, 6, 7, 8, 9, 10, 11]}
ans = {"a": ([6, 7, 8, 9], "", "high", ""), # exact
"b": ([7, 8, 9, 10], "", "medium", ""), # one month at each end
"c": ([1, 2, 3], "", "low", ""), # wrong
"e": ([3, 4, 5, 9, 10, 11], "", "medium", ""), # right ends, wrong gap
"x": ([1], "", "high", "")} # not a sourced trail: ignored
got = J.score(ans, truth)
self.assertEqual(got["tested"], 4)
self.assertEqual(got["matched"], 2)
self.assertEqual(got["by_confidence"]["high"], {"tested": 1, "matched": 1})
self.assertEqual(got["by_confidence"]["medium"], {"tested": 1, "matched": 1})
self.assertEqual(got["by_confidence"]["low"], {"tested": 1, "matched": 0})
self.assertEqual(got["tested"], 5)
self.assertEqual(got["matched"], 3)
self.assertEqual(got["strict_matched"], 2)
self.assertEqual(got["by_confidence"]["high"], {"tested": 1, "matched": 1, "strict_matched": 1})
self.assertEqual(got["by_confidence"]["medium"], {"tested": 2, "matched": 2, "strict_matched": 1})
self.assertEqual(got["by_confidence"]["low"], {"tested": 1, "matched": 0, "strict_matched": 0})
# d was never answered: it counts as tested and missed
self.assertEqual(got["unanswered"], 1)
def test_the_trails_judged_from_pages_that_differ_are_not_scored_against_themselves(self):
truth = J._truth(J.ROOT)
self.assertEqual(len(truth), 148)
for tid in ("sierra-high-route", "cohos", "ouachita"):
self.assertNotIn(tid, truth)
def test_the_figure_file_round_trips_and_shares_are_computed(self):
figures = {"tested": 148, "matched": 114, "unanswered": 0,
"by_confidence": {"high": {"tested": 52, "matched": 48},
"medium": {"tested": 76, "matched": 55},
"low": {"tested": 20, "matched": 11}}}
figures = {"tested": 148, "matched": 114, "strict_matched": 105, "unanswered": 0,
"by_confidence": {"high": {"tested": 52, "matched": 48, "strict_matched": 44},
"medium": {"tested": 76, "matched": 55, "strict_matched": 50},
"low": {"tested": 20, "matched": 11, "strict_matched": 11}}}
d = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, d, True)
path = os.path.join(d, "t.json")
@@ -187,22 +196,42 @@ class ScoreTest(unittest.TestCase):
self.assertEqual(got["tested"], 148)
self.assertEqual(got["matched"], 114)
self.assertEqual(got["share"], 0.77)
self.assertEqual(got["strict_matched"], 105)
self.assertEqual(got["strict_share"], 0.71)
self.assertEqual(got["by_confidence"]["high"]["share"], 0.92)
self.assertEqual(got["by_confidence"]["high"]["strict_share"], 0.85)
self.assertEqual(got["by_confidence"]["low"]["share"], 0.55)
self.assertEqual(J.check_blind_test(got), [])
self.assertIn("first and last", got["measure"])
self.assertIn("gap", got["strict_measure"])
def test_a_loaded_file_must_add_up(self):
bad = {"date": "2026-11-20", "tested": 10, "matched": 5, "share": 0.5,
"by_confidence": {"high": {"tested": 4, "matched": 5, "share": 1.0},
"medium": {"tested": 3, "matched": 1, "share": 0.33},
"low": {"tested": 3, "matched": 1, "share": 0.33}}}
"strict_matched": 4, "strict_share": 0.4,
"by_confidence": {"high": {"tested": 4, "matched": 5, "share": 1.0, "strict_matched": 1, "strict_share": 0.25},
"medium": {"tested": 3, "matched": 1, "share": 0.33, "strict_matched": 1, "strict_share": 0.33},
"low": {"tested": 3, "matched": 1, "share": 0.33, "strict_matched": 1, "strict_share": 0.33}}}
self.assertTrue(J.check_blind_test(bad))
def test_the_strict_figure_may_not_exceed_the_ends_figure_or_be_missing(self):
doc = {"date": "2026-11-20", "tested": 10, "matched": 5, "share": 0.5,
"strict_matched": 6, "strict_share": 0.6,
"by_confidence": {"high": {"tested": 10, "matched": 5, "share": 0.5, "strict_matched": 6, "strict_share": 0.6},
"medium": {"tested": 0, "matched": 0, "share": 0.0, "strict_matched": 0, "strict_share": 0.0},
"low": {"tested": 0, "matched": 0, "share": 0.0, "strict_matched": 0, "strict_share": 0.0}}}
self.assertTrue(J.check_blind_test(doc))
del doc["strict_matched"]
self.assertTrue(J.check_blind_test(doc))
class CommittedFilesTest(unittest.TestCase):
def test_the_committed_blind_test_adds_up_and_passes_the_bar(self):
got = J.load_blind_test(os.path.join(J.ROOT, "tools", "season_blind_test.json"))
self.assertEqual(J.check_blind_test(got), [])
self.assertGreaterEqual(got["share"], E.BAR["within1_min"])
# both measures are stored, and the strict one is the lower
self.assertEqual((got["tested"], got["matched"], got["strict_matched"]), (148, 114, 105))
self.assertLessEqual(got["strict_matched"], got["matched"])
def test_every_judged_row_is_well_formed_and_matches_its_record(self):
ids = R.trail_ids(J.ROOT)
+24
View File
@@ -45,6 +45,30 @@ class MatchTest(unittest.TestCase):
self.assertFalse(M.match([3, 4, 5], spring_fall))
self.assertFalse(M.match([3, 4, 5, 7, 9, 10, 11], spring_fall))
def test_the_strict_measure_counts_a_wrong_gap_in_the_middle_as_a_miss(self):
# the ends-only measure passes March to May plus September to November
# against a continuous March to November; the strict one does not
gap = [3, 4, 5, 9, 10, 11]
whole = list(range(3, 12))
self.assertTrue(M.match(gap, whole))
self.assertFalse(M.match_strict(gap, whole))
self.assertFalse(M.match_strict(whole, gap))
self.assertTrue(M.match_strict(whole, whole))
self.assertTrue(M.match_strict([4, 5, 6, 7, 8, 9, 10], whole))
self.assertTrue(M.match_strict(gap, gap))
# a stray one-month window of the estimate has no partner in the truth
self.assertFalse(M.match_strict([3, 4, 5, 6, 7, 11], [3, 4, 5, 6, 7]))
self.assertTrue(M.match_strict(list(range(1, 11)), list(range(1, 13))))
self.assertFalse(M.match_strict([], whole))
def test_strict_never_matches_what_the_ends_only_measure_misses(self):
import itertools
seasons = [[3, 4, 5, 9, 10, 11], list(range(3, 12)), [6, 7, 8], [11, 12, 1, 2], [1, 2, 3, 7, 8],
list(range(1, 13)), [5, 6, 7, 8, 9, 10]]
for est, src in itertools.product(seasons, seasons):
if M.match_strict(est, src):
self.assertTrue(M.match(est, src), (est, src))
def test_masks_and_lists_agree(self):
self.assertEqual(M.to_months(M.to_mask([3, 1, 12])), [1, 3, 12])
self.assertEqual(M.match(M.to_mask([6, 7]), [6, 7]), True)