Answer prose round 1: 0 🔴, 16 🟡 (0 misread); name the offline deciders and runs, and fix the help, the decision and the docstrings
This commit is contained in:
+26
-16
@@ -86,9 +86,9 @@ def logistic(samples: typing.Sequence[Sample]) -> typing.Callable[[str], float]:
|
||||
|
||||
|
||||
def classifier(samples: typing.Sequence[Sample]) -> Decider:
|
||||
"""Finished below the lowest chance any interrupt among the samples got when held out, interrupt above the highest chance any other kind got, and the judge's model between.
|
||||
"""Finished where the chance of an interrupt is below one half and below that of every interrupt among the samples; interrupt where it is at least one half and above that of every other kind; otherwise the judge's model decides.
|
||||
|
||||
Each sample's chance is the one a model trained on the other folds of the samples gives it, so the bounds don't rest on how well the model fits what it trained on. A bound is where the samples held no miss; that doesn't promise the next verdict holds none."""
|
||||
A sample's chance is the one a model trained on the other folds of the samples gives it, so the bounds don't rest on how well the model fits what it trained on. A bound is where the samples held no miss; that doesn't promise the next verdict holds none."""
|
||||
interrupts = [found for found in samples if found.kind == INTERRUPTED]
|
||||
if not interrupts or len(interrupts) == len(samples):
|
||||
return lambda text: None
|
||||
@@ -105,11 +105,13 @@ def classifier(samples: typing.Sequence[Sample]) -> Decider:
|
||||
return decide
|
||||
|
||||
|
||||
METHODS: dict[str, Method] = {"a question mark": question_mark, "decision table": decision_table, "classifier": classifier}
|
||||
# Rules are fixed, and run on the whole archive; a learner trains on samples, and runs on samples it didn't train on.
|
||||
RULES: dict[str, Method] = {'"?" rule': question_mark, "decision table": decision_table}
|
||||
LEARNERS: dict[str, Method] = {"classifier": classifier}
|
||||
|
||||
|
||||
def folds_of(samples: typing.Sequence[Sample], count: int) -> list[tuple[list[Sample], list[Sample]]]:
|
||||
"""count folds of the samples, dealt in turn; each is what to learn from and what to test on, the samples the fold's test leaves out."""
|
||||
"""count folds of the samples, dealt in turn. Each fold is the samples to learn from, which are all those its test leaves out, and the samples to test on."""
|
||||
return [([found for place, found in enumerate(samples) if place % count != fold], [found for place, found in enumerate(samples) if place % count == fold]) for fold in range(count)]
|
||||
|
||||
|
||||
@@ -123,18 +125,26 @@ def plain(kind: Kind) -> str:
|
||||
return kind.removeprefix("Verdict: ")
|
||||
|
||||
|
||||
def offline_report(model: str, samples: typing.Sequence[Sample], methods: typing.Mapping[str, Method], folds: int = FOLDS) -> str:
|
||||
def offline_report(model: str, samples: typing.Sequence[Sample], rules: typing.Mapping[str, Method], learners: typing.Mapping[str, Method], folds: int = FOLDS, skipped: int = 0) -> str:
|
||||
"""samples are in the order the verdicts were judged, oldest first, so the latest fifth is the newest verdicts."""
|
||||
kinds = collections.Counter(found.kind for found in samples)
|
||||
lines = [f"Replayed {len(samples)} archived verdicts of {model} projects offline, nothing sent to an outside service: {', '.join(f'{count} {plain(kind)}' for kind, count in sorted(kinds.items(), key=lambda each: plain(each[0])))}."]
|
||||
lines = [f"Replayed {len(samples)} archived verdicts of {model} projects offline, without sending anything to an outside service. The archive gives them as {', '.join(f'{count} {plain(kind)}' for kind, count in sorted(kinds.items(), key=lambda each: plain(each[0])))}."]
|
||||
if skipped:
|
||||
lines.append(f"Skipped {skipped} verdicts whose transcript could not be read.")
|
||||
for name, rule in rules.items():
|
||||
lines += decided_lines(f"{name}, on the whole archive", evaluate(rule, [], samples), kinds)
|
||||
split = len(samples) - max(1, len(samples) // LATEST)
|
||||
for name, method in methods.items():
|
||||
held_out = sum((evaluate(method, trained, tested) for trained, tested in folds_of(samples, folds)), Counts())
|
||||
lines += [result_line(f"{name}, on held-out folds", held_out), *decides_lines(name, held_out, kinds)]
|
||||
lines.append(result_line(f"{name}, on the latest fifth after learning from the rest", evaluate(method, samples[:split], samples[split:])))
|
||||
for name, learner in learners.items():
|
||||
held_out = sum((evaluate(learner, trained, tested) for trained, tested in folds_of(samples, folds)), Counts())
|
||||
lines += decided_lines(f"{name}, on held-out folds", held_out, kinds)
|
||||
lines.append(result_line(f"{name}, on the latest fifth after learning from the rest", evaluate(learner, samples[:split], samples[split:])))
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def decided_lines(how: str, found: Counts, kinds: collections.Counter[Kind]) -> list[str]:
|
||||
return [result_line(how, found), *decides_lines(how, found, kinds)]
|
||||
|
||||
|
||||
def result_line(how: str, found: Counts) -> str:
|
||||
decided = collections.Counter({kind: sum(count for (_, said), count in found.items() if said == kind) for kind in {said for _, said in found if said}})
|
||||
missed = sum(count for (archived, said), count in found.items() if archived == INTERRUPTED and said not in (None, INTERRUPTED))
|
||||
@@ -143,18 +153,18 @@ def result_line(how: str, found: Counts) -> str:
|
||||
|
||||
|
||||
def wrong_kinds(decided: Kind, found: Counts) -> str:
|
||||
"""The archived kinds a decider returned decided for, where the archive gave another kind."""
|
||||
"""The kinds the archive gives the verdicts that were decided as decided, where the archive gives another kind than decided."""
|
||||
wrong = sorted(((plain(archived), count) for (archived, said), count in found.items() if said == decided and archived != decided), key=lambda each: each[0])
|
||||
return f" (archived {', '.join(f'{kind} {count}' for kind, count in wrong)})" if wrong else ""
|
||||
return f" (of these, archived {', '.join(f'{kind} {count}' for kind, count in wrong)})" if wrong else ""
|
||||
|
||||
|
||||
def decides_lines(name: str, found: Counts, kinds: collections.Counter[Kind]) -> list[str]:
|
||||
"""For finished and for unfinished: whether the decider decided it where the archive holds no interrupt, and how much of that kind it got right."""
|
||||
def decides_lines(how: str, found: Counts, kinds: collections.Counter[Kind]) -> list[str]:
|
||||
"""For finished and for unfinished that the decider decided at all: whether it decided no archived interrupt as that kind, and how many of the kind it got right."""
|
||||
lines = []
|
||||
for kind in (FINISHED, UNFINISHED):
|
||||
decided = sum(count for (_, said), count in found.items() if said == kind)
|
||||
if decided and not found[(INTERRUPTED, kind)]:
|
||||
lines.append(f"{name} decides {plain(kind)} with no missed interrupt: {found[(kind, kind)]} of {kinds[kind]} {plain(kind)}.")
|
||||
lines.append(f"{how}, decides {plain(kind)} with no missed interrupt: {found[(kind, kind)]} of {kinds[kind]} {plain(kind)}.")
|
||||
elif decided:
|
||||
lines.append(f"{name} does not decide {plain(kind)} with no missed interrupt.")
|
||||
lines.append(f"{how}, does not decide {plain(kind)} with no missed interrupt: it decided {found[(INTERRUPTED, kind)]} archived interrupt(s) as {plain(kind)}.")
|
||||
return lines
|
||||
|
||||
Reference in New Issue
Block a user