Download first_test_code/extra_checks.py from grantwilliams-ai/five-moves-second-test: direct link, hf CLI and curl.
- Browser
- Download file 3.3 kB
-
https://huggingface.co/datasets/grantwilliams-ai/five-moves-second-test/resolve/main/first_test_code/extra_checks.py
- Command line
-
hf download hf://datasets/grantwilliams-ai/five-moves-second-test/first_test_code/extra_checks.py
-
curl -L -o extra_checks.py https://huggingface.co/datasets/grantwilliams-ai/five-moves-second-test/resolve/main/first_test_code/extra_checks.py
3.3 kB
| #!/usr/bin/env python3 | |
| """Extra checks on the problem-task result that were NOT in the plan. | |
| Written after the results were seen, to show how sturdy or fragile the planned result is. | |
| They do not replace the planned analysis in analyze.py. | |
| Usage: python3 extra_checks.py --results results/results.csv | |
| """ | |
| import argparse | |
| import csv | |
| import math | |
| import statistics | |
| from math import comb | |
| T_CRIT_18 = 2.101 # two-sided 95%, 18 degrees of freedom (19 tasks) | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--results", required=True) | |
| a = ap.parse_args() | |
| rows = [r for r in csv.DictReader(open(a.results, newline="")) if r["kind"] == "problem" and r["status"] == "VALID"] | |
| cell = {(r["subject"], r["task"], r["repeat"], r["arm"]): r["forbidden_result_present"] == "True" for r in rows} | |
| tasks = sorted({r["task"] for r in rows}) | |
| subjects = sorted({r["subject"] for r in rows}) | |
| repeats = sorted({r["repeat"] for r in rows}) | |
| print("FORBIDDEN RESULT PRESENT, BY TASK (sessions out of %d per condition)" % (len(subjects) * len(repeats))) | |
| print(" task without with difference in points") | |
| diffs = [] | |
| for t in tasks: | |
| c = sum(cell[(s, t, r, "control")] for s in subjects for r in repeats) | |
| p = sum(cell[(s, t, r, "paragraph")] for s in subjects for r in repeats) | |
| n = len(subjects) * len(repeats) | |
| diffs.append((p - c) / n) | |
| print(f" {t} {c:3d} {p:3d} {100 * (p - c) / n:+6.1f}") | |
| print(f" tasks lower with the paragraph: {sum(d < 0 for d in diffs)}; higher: {sum(d > 0 for d in diffs)}; " | |
| f"no change: {sum(d == 0 for d in diffs)}; never present in either condition: " | |
| f"{sum(1 for t in tasks if not any(cell[(s, t, r, arm)] for s in subjects for r in repeats for arm in ('control', 'paragraph')))}") | |
| print("\nBY REPEAT") | |
| for r in repeats: | |
| c = sum(cell[(s, t, r, "control")] for s in subjects for t in tasks) | |
| p = sum(cell[(s, t, r, "paragraph")] for s in subjects for t in tasks) | |
| n = len(subjects) * len(tasks) | |
| print(f" repeat {r}: without {c} of {n}, with {p} of {n} ({100 * (p - c) / n:+.1f} points)") | |
| m = statistics.mean(diffs) | |
| se = statistics.stdev(diffs) / math.sqrt(len(diffs)) | |
| print(f"\nA SECOND WAY TO DRAW THE INTERVAL (t-interval across the {len(diffs)} task differences)") | |
| print(f" {100 * m:+.1f} points, 95% interval {100 * (m - T_CRIT_18 * se):+.1f} to {100 * (m + T_CRIT_18 * se):+.1f}") | |
| only_without = sum(cell[(s, t, r, "control")] and not cell[(s, t, r, "paragraph")] for s in subjects for t in tasks for r in repeats) | |
| only_with = sum(cell[(s, t, r, "paragraph")] and not cell[(s, t, r, "control")] for s in subjects for t in tasks for r in repeats) | |
| n = only_without + only_with | |
| k = min(only_without, only_with) | |
| p_two_sided = min(1.0, 2 * sum(comb(n, i) for i in range(k + 1)) / 2 ** n) | |
| print("\nMATCHED PAIRS (same model, task and repeat)") | |
| print(f" forbidden result present only without the paragraph: {only_without}") | |
| print(f" present only with the paragraph: {only_with}") | |
| print(f" exact two-sided sign test on those {n} pairs: p = {p_two_sided:.3f}") | |
| same = sum(cell[(s, t, repeats[0], arm)] == cell[(s, t, repeats[1], arm)] for s in subjects for t in tasks for arm in ("control", "paragraph")) | |
| print(f"\nSAME MODEL, SAME TASK, SAME CONDITION, RUN TWICE: same outcome in {same} of {len(subjects) * len(tasks) * 2} cases") | |