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:
1 parent
535d2bebaa
commit
e8ca8e862e
13 files changed
+183
-68
No files matched your search
+1
-1
@@ -5,7 +5,7 @@
|
||||
- All 223 trails now have a season. 148 come from a page that states one. 6 were set by judgement from pages that disagree, none of them the trail's own, its association's or its route author's. The other 69 are estimates, because no page states a season for them.
|
||||
- An estimate never reads as a fact. A trail's page shows it as "About April to October", with a short note: no page states a season, it was estimated from the climate at the trail's elevation and from similar trails, what sets the season there, how confident the estimate is, and that people do walk the trail outside those months. Lists and tables mark an estimate, and it is left out of the data that search engines read. The 6 set from pages that disagree read the same way, and their note says the pages differ.
|
||||
- How an estimate is made: a reviewer is given the trail's location and elevation, its monthly climate (CHELSA, public domain, with NOAA elevation), a climate model's own estimate, and the ten most similar trails whose season a page states, and sets the months. The climate model alone matched 67.6 percent of the known seasons within a month at each end, under the 75 percent the owner asked for, so it is one input and not the answer.
|
||||
- How it was tested: the same reviewers estimated the 148 trails whose season a page does state, from packets with that season hidden. They matched 114 of them (77.0 percent) within a month at each end: 48 of 52 where they were highly confident, 55 of 76 at medium confidence, and 11 of 20 at low. The reference page and the glossary give these figures, read from a data file.
|
||||
- How it was tested: the same reviewers estimated the 148 trails whose season a page does state, from packets with that season hidden. Two measures, given together: 114 of 148 (77 percent) had their first and last months within a month of the page's; 105 (71 percent) also had no wrong gap in the middle. By confidence, first and last months: 48 of 52 where they were highly confident, 55 of 76 at medium confidence, and 11 of 20 at low; with no wrong gap as well: 48 of 52, 46 of 76 and 11 of 20. The 75 percent bar was set on the first and last months, and the method clears it there but not on the stricter measure. The owner decided the estimates ship with both figures stated. The reference page and the glossary give these figures, read from a data file.
|
||||
- The "By month" lists now include every trail and mark the estimated seasons, and the note that only some trails have a season is gone. The month filter has a box to leave estimated seasons out.
|
||||
- An estimate is replaced when a page that states a season is found. The monthly audit searches again for every one, and a monthly check reruns the climate model for each estimate and flags any whose inputs have changed.
|
||||
- For contributors: `hike.season_basis` may now be `estimate`, with a `hike.season_method` that ends "Confidence: high.", "Confidence: medium." or "Confidence: low." and one source that cites the climate data; a season is required on every trail, and the validator refuses an estimate that cites an ordinary page. The packet builder and the blind scorer are `tools/season_judge.py`, the reviewers' instruction is `docs/season-judging.md`, and the audit steps are in `docs/audit.md`.
|
||||
|
||||
+1
-1
@@ -38,6 +38,6 @@ down the list in order and stop at the first step that fails.
|
||||
Every trail has a season. Where a page states one, the season is that page's. Where none does, the season is an estimate: set by a reviewer from the trail's climate and the seasons of similar trails, with its confidence on the record (`docs/season-judging.md`). The aim of this audit is that estimates shrink over time, and that none goes stale unnoticed.
|
||||
|
||||
1. Search afresh for a page that states the season of every trail still marked `estimate`. List them with `python3 tools/estimate_season.py estimates`. For each, follow `docs/season-research.md`: the trail's holder or a government page first, then an established hiking reference, a guidebook publisher's page or an association list. When a page states a season, replace the estimate through `tools/refresh.py` (propose, collect, apply): give the page's season and months, the basis (`primary`, `sources` or `source`), the page as a `[[hike.source]]` naming `season` and `months`, and remove the climate source and `season_method`. A change to the season gets a `[[history]]` entry like any other fact. Then run `python3 tools/season_judge.py inputs` so that the record of estimate inputs drops the trail. A trail with no page found stays an estimate, and nothing else about it changes.
|
||||
2. Re-run the machine estimate and flag any estimate whose inputs have changed: `python3 tools/estimate_season.py check`. It reruns the machine estimate for every estimate, compares it, the climate at the trail and the sourced trails it is compared with against what was recorded in `tools/season_inputs.json` when the season was set, and lists each trail whose inputs differ. The listing is a flag, not a rewrite. For each trail listed, build its packet (`python3 tools/season_judge.py packets`), look at what changed, and either keep the season or set it again by judgement. Then run `python3 tools/season_judge.py inputs` to record the inputs as they now are. The check also fails when the blind test of the method (`tools/season_blind_test.json`) is below its bar, or when the fit of the machine estimate against the sourced seasons has got worse.
|
||||
2. Re-run the machine estimate and flag any estimate whose inputs have changed: `python3 tools/estimate_season.py check`. It reruns the machine estimate for every estimate, compares it, the climate at the trail and the sourced trails it is compared with against what was recorded in `tools/season_inputs.json` when the season was set, and lists each trail whose inputs differ. The listing is a flag, not a rewrite. For each trail listed, build its packet (`python3 tools/season_judge.py packets`), look at what changed, and either keep the season or set it again by judgement. Then run `python3 tools/season_judge.py inputs` to record the inputs as they now are. The check also fails when the blind test of the method (`tools/season_blind_test.json`) is below its bar on the ends-only measure (the first and last months within a month of the page's: 77 percent when set, against a bar of 75; the strict measure, which also needs no wrong gap in the middle, was 71 percent and is recorded beside it), or when the fit of the machine estimate against the sourced seasons has got worse.
|
||||
|
||||
The same check runs on its own on the first of each month (`.github/workflows/season-check.yml`), so a changed estimate is noticed even when the audit is late. The audit is still the step that acts on it.
|
||||
@@ -4,7 +4,7 @@ Where no page states a season, it is set by a reviewer from a packet, and the me
|
||||
|
||||
## The test
|
||||
|
||||
The reviewers also estimated every trail whose season a page states, from packets identical in form with the season hidden: the trail's own timing sentences were removed, and its comparable trails were never dealt to the same part as it. The three parts were reviewed separately, and the figures are added together. The result is in `tools/season_blind_test.json`, which the site reads; `python3 tools/season_judge.py score <answer files> --write tools/season_blind_test.json` produces it. A season "matches" when each end of the reviewer's months is within one month of the stated season's, on the circle of the year. The machine estimate on its own matches 67.6 percent on the same measure, under the 75 percent bar, so it is not written to a record; the judged method passes, and its confidence labels are honest: high matches most often, low least.
|
||||
The reviewers also estimated every trail whose season a page states, from packets identical in form with the season hidden: the trail's own timing sentences were removed, and its comparable trails were never dealt to the same part as it. The three parts were reviewed separately, and the figures are added together. The result is in `tools/season_blind_test.json`, which the site reads; `python3 tools/season_judge.py score <answer files> --write tools/season_blind_test.json` produces it. The result is given by two measures, always together. The ends-only measure counts a season as matching when the first and last months of the reviewer's months are each within one month of the stated season's, on the circle of the year. The strict measure also needs every window to correspond: a gap in the middle that the page does not have, or one the page has and the reviewer lacks, is a miss, and so is a window with no partner. The result: 114 of 148 (77 percent) had their first and last months within a month of the page's; 105 (71 percent) also had no wrong gap in the middle. By the reviewer's confidence, ends only and strict: high 48 and 48 of 52, medium 55 and 46 of 76, low 11 and 11 of 20. The 75 percent bar was set on the ends-only measure: there the judged method clears it (77 percent); on the strict measure it does not (71 percent). The owner decided that the estimates ship with both figures stated. The machine estimate on its own matches 67.6 percent on the ends-only measure, under the bar, so it is not written to a record. The confidence labels are honest on both measures: high matches most often, low least. The six trails judged from pages that disagree are not scored: only trails whose season a page states are tested.
|
||||
|
||||
## What a packet lacks
|
||||
|
||||
|
||||
@@ -196,10 +196,10 @@ What the tool does:
|
||||
|
||||
## What changed in the method
|
||||
|
||||
The plan above chose a rule over climate normals for Step 3. It was built and tested (`tools/estimate_season.py`, `tools/season_model.py`; CHELSA V2.1 1981 to 2010 normals, CC0, with NOAA ETOPO 2022 elevation), and it matched only 67.6 percent of the sourced seasons within one month at each end, under the owner's bar of 75 percent. Its output is therefore not written to a record. What was decided instead:
|
||||
The plan above chose a rule over climate normals for Step 3. It was built and tested (`tools/estimate_season.py`, `tools/season_model.py`; CHELSA V2.1 1981 to 2010 normals, CC0, with NOAA ETOPO 2022 elevation), and it matched only 67.6 percent of the sourced seasons by the ends-only measure (the first and last months each within a month of the page's), under the owner's bar of 75 percent. Its output is therefore not written to a record. What was decided instead:
|
||||
|
||||
- **A reviewer judges each estimate.** For each of the 75 trails with no season, a reviewer set the months from a packet: the trail's location, elevation, monthly climate normals, the machine estimate, and the ten most similar sourced trails (`tools/season_judge.py packets`; the reviewer's instruction is `docs/season-judging.md`). The machine estimate stays in the repository as an input to the packets and as the monthly check.
|
||||
- **The method is tested blind.** The same reviewers estimated the 148 trails whose season a page states, from identical packets with the season hidden, and a trail's comparable trails never came from its own part of the split. They matched 114 of 148 (77.0 percent), by the reviewer's confidence 48 of 52 (high), 55 of 76 (medium) and 11 of 20 (low). The figures are in `tools/season_blind_test.json`, written by `season_judge.py score`, and the site reads them.
|
||||
- **The method is tested blind.** The same reviewers estimated the 148 trails whose season a page states, from identical packets with the season hidden, and a trail's comparable trails never came from its own part of the split. Two measures are given, always together. 114 of 148 (77 percent) had their first and last months within a month of the page's; 105 (71 percent) also had no wrong gap in the middle. The ends-only measure is the one the 75 percent bar was set on, and on it the method clears the bar (77 percent); the strict measure (every window of the season must correspond, so a wrong gap counts as a miss) is lower, and the method does not reach 75 percent on it (71 percent). The owner decided the estimates ship with both figures stated. By the reviewer's confidence, ends only and strict: high 48 and 48 of 52, medium 55 and 46 of 76, low 11 and 11 of 20. The figures are in `tools/season_blind_test.json`, written by `season_judge.py score`, and the site reads them. The six trails judged from pages that disagree are not scored against themselves.
|
||||
- **An estimate is stricter.** `season_basis = "estimate"` means no page states a season. `season` is built from `months`; `season_method` is one or two plain sentences saying how it was set and what sets the season there, ending "Confidence: high.", "medium." or "low."; and its one `[[hike.source]]` names `season` and `months` and cites the climate data. The validator refuses an estimate with any ordinary page naming the season, or with no method, and requires a season on every trail.
|
||||
- **Pages that disagree.** Six trails have pages that disagree where none is the managing body, association or route author. Their season is set by judgement from all the pages and the estimate: basis `sources`, the pages cited as sources naming the season, and a `season_method` saying the pages differ and how it was settled. A season with a method is shown as an estimate (it reads "About" with a note), left out of structured data, and not counted among the seasons a page states.
|
||||
- **The monthly check** (`estimate_season.py check`) reruns the machine estimate for every estimate and flags any whose inputs have changed since `tools/season_inputs.json` recorded them. It does not rewrite anything. The audit (`docs/audit.md`) also searches afresh for a page for every estimate.
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
@@ -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}")
|
||||
|
||||
@@ -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)."""
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -116,9 +116,10 @@ def season_section(records, blind):
|
||||
{pagekit.table(["Where a trail's season comes from", "Trails"], rows, caption="Where the seasons come from", numeric=(1,))}"""]
|
||||
if blind:
|
||||
by = blind["by_confidence"]
|
||||
conf = ", ".join(f"{name} {by[name]['matched']} of {by[name]['tested']} ({_pct(by[name]['share'])})"
|
||||
conf = ", ".join(f"{name} {by[name]['matched']} of {by[name]['tested']} ({_pct(by[name]['share'])}) and "
|
||||
f"{by[name]['strict_matched']} ({_pct(by[name]['strict_share'])})"
|
||||
for name in ("high", "medium", "low") if by[name]["tested"])
|
||||
out.append(f"""<p>How the estimates were tested. On {esc(blind["date"])} the method was run blind on {blind["tested"]} trails whose seasons a page does state, with those seasons hidden. It matched {blind["matched"]} of them ({_pct(blind["share"])}) within one month at each end of the season the page states. By the confidence it gave each estimate: {esc(conf)}. This measures how the method did where the answer is known, not a promise for any one trail.</p>""")
|
||||
out.append(f"""<p>How the estimates were tested. On {esc(blind["date"])} the method was run blind on {blind["tested"]} trails whose seasons a page does state, with those seasons hidden. Two measures are given together. {blind["matched"]} of {blind["tested"]} ({_pct(blind["share"])}) had their first and last months within a month of the page’s; {blind["strict_matched"]} ({_pct(blind["strict_share"])}) also had no wrong gap in the middle, so the second measure counts a season with a gap that the page does not have, or without one that it has, as a miss. By the confidence it gave each estimate, first and last months and then also no wrong gap: {esc(conf)}. This measures how the method did where the answer is known, not a promise for any one trail.</p>""")
|
||||
return "\n ".join(out)
|
||||
|
||||
|
||||
|
||||
@@ -673,10 +673,12 @@ class RealDataTest(unittest.TestCase):
|
||||
blind = datafiles.blind_test(ROOT)
|
||||
text = self.method_text()
|
||||
self.assertIn(f"the method was run blind on {blind['tested']} trails whose seasons a page does state", text)
|
||||
self.assertIn(f"It matched {blind['matched']} of them ({round(blind['share'] * 100)} percent) within one month at "
|
||||
"each end", text)
|
||||
self.assertIn(f"{blind['matched']} of {blind['tested']} ({round(blind['share'] * 100)} percent) had their first "
|
||||
f"and last months within a month of the page\u2019s; {blind['strict_matched']} "
|
||||
f"({round(blind['strict_share'] * 100)} percent) also had no wrong gap in the middle", text)
|
||||
for name, v in blind["by_confidence"].items():
|
||||
self.assertIn(f"{name} {v['matched']} of {v['tested']} ({round(v['share'] * 100)} percent)", text)
|
||||
self.assertIn(f"{name} {v['matched']} of {v['tested']} ({round(v['share'] * 100)} percent) and "
|
||||
f"{v['strict_matched']} ({round(v['strict_share'] * 100)} percent)", text)
|
||||
self.assertIn("not a promise for any one trail", text)
|
||||
|
||||
def test_the_glossary_no_longer_says_only_some_records_state_a_season(self):
|
||||
|
||||
Reference in new issue
Block a user