-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_common.py
More file actions
30 lines (19 loc) · 1.03 KB
/
Copy pathplot_common.py
File metadata and controls
30 lines (19 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Shared helpers for the Ch2 competitor / scaling plots.
Consolidates the bootstrap-CI + tidy-CSV loading that was copy-pasted across
plot_scaling / plot_guesser_matrix / plot_tradeoff_opener / plot_holdout_comparison.
"""
from __future__ import annotations
import csv
import numpy as np
from ci import bootstrap_ci # single percentile-bootstrap implementation (seed 42, B=10000)
TIDY = "results/ch2/competitor/competitor_eval_tidy.csv"
def load_tidy(path: str = TIDY) -> list[dict]:
return list(csv.DictReader(open(path)))
def pct_ci(flags_) -> tuple[float, float, float]:
"""(point%, lo%, hi%) bootstrap 95% CI for a 0/1 sequence."""
p, lo, hi = bootstrap_ci(np.asarray(flags_, dtype=float))
return p * 100, lo * 100, hi * 100
def flags(rows: list[dict], giver: str, guesser: str, result: str = "win") -> list[int]:
"""0/1 list: 1 where this giver×guesser row has `result` (win/miss/violation)."""
return [1 if r["result"] == result else 0
for r in rows if r["giver"] == giver and r["guesser"] == guesser]