summaryrefslogtreecommitdiff
path: root/experiments/rain_ep_dillavou_s0b.sh
blob: 712dd0742232a1cf2000af80729a6a616aaed8b5 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
set -euo pipefail

ROOT=/home/yurenh2/sdil
AUTHOR=/scratch/yurenh2/energy-based-learning
PYTHON=/scratch/yurenh2/venvs/burstccn/bin/python
OUT="$ROOT/results/ep_bias/dillavou_s0b"
mkdir -p "$OUT"
cd "$AUTHOR"

run_cell() {
  local gpu=$1
  local tag=$2
  local beta_policy=$3
  local beta_value=$4
  local mode=$5
  local bias_ratio=$6
  CUDA_VISIBLE_DEVICES="$gpu" "$PYTHON" \
    "$ROOT/experiments/rain_ep_bias_train.py" \
    --author-root "$AUTHOR" --device cuda \
    --adapter dillavou --network-protocol comparative32 \
    --beta-policy "$beta_policy" --beta-value "$beta_value" \
    --mode "$mode" --bias-ratio "$bias_ratio" \
    --dillavou-drift-ratio 0 --predictor-rate 1 \
    --dillavou-calibration-steps 1 --neutral-cadence 0 \
    --epochs 1 --schedule-epochs 100 \
    --train-limit 10000 --test-limit 2000 --batch-size 100 \
    --training-iterations 15 --inference-iterations 60 \
    --evaluation-split train_holdout --data-seed 6200 \
    --seed 1988 --beta-seed 7100 --deterministic \
    --output "$OUT/$tag.json" > "$OUT/$tag.log" 2>&1
}

# Wave 1: select the smallest fixed offset causing at least ten accuracy points
# of damage relative to clean positive EP.  This is development-only selection.
run_cell 0 pep_clean fixed_positive 0.25 clean 0 &
run_cell 1 pep_raw_03 fixed_positive 0.25 raw 0.3 &
run_cell 2 pep_raw_1 fixed_positive 0.25 raw 1 &
run_cell 3 pep_raw_3 fixed_positive 0.25 raw 3 &
run_cell 4 pep_raw_10 fixed_positive 0.25 raw 10 &
run_cell 5 random_clean random_sign 0.25 clean 0 &
run_cell 6 centered_clean centered 0.25 clean 0 &
run_cell 7 pep_sdil_3 fixed_positive 0.25 innovation 3 &
wait

selected=$("$PYTHON" - "$OUT" <<'PY'
import json
from pathlib import Path
import sys

root = Path(sys.argv[1])
clean = json.loads((root / "pep_clean.json").read_text())["final"]["test_accuracy"]
candidates = [(0.3, "03"), (1.0, "1"), (3.0, "3"), (10.0, "10")]
rows = []
selected = candidates[-1][0]
for ratio, tag in candidates:
    final = json.loads((root / f"pep_raw_{tag}.json").read_text())["final"]
    rows.append({"ratio": ratio, "accuracy": final["test_accuracy"],
                 "finite": final["finite"]})
    if final["finite"] and final["test_accuracy"] <= clean - 0.10:
        selected = ratio
        break
(root / "selector.json").write_text(json.dumps({
    "rule": "smallest ratio with >=0.10 accuracy damage and finite parameters",
    "clean_accuracy": clean,
    "candidates": rows,
    "selected_ratio": selected,
}, indent=2) + "\n")
print(selected)
PY
)

# Wave 2: test beta centering, the two local calibrators, an oracle, and larger
# beta values at the selected hardware-offset magnitude.
run_cell 0 pep_constant_selected fixed_positive 0.25 constant "$selected" &
run_cell 1 pep_sdil_selected fixed_positive 0.25 innovation "$selected" &
run_cell 2 pep_oracle_selected fixed_positive 0.25 oracle "$selected" &
run_cell 3 random_raw_selected random_sign 0.25 raw "$selected" &
run_cell 4 centered_raw_selected centered 0.25 raw "$selected" &
run_cell 5 pep_raw_beta05 fixed_positive 0.5 raw "$selected" &
run_cell 6 pep_raw_beta1 fixed_positive 1.0 raw "$selected" &
run_cell 7 pep_raw_beta2 fixed_positive 2.0 raw "$selected" &
wait

"$PYTHON" - "$OUT" <<'PY'
import json
from pathlib import Path
import sys

root = Path(sys.argv[1])
summary = {}
for path in sorted(root.glob("*.json")):
    if path.name in {"selector.json", "summary.json"}:
        continue
    report = json.loads(path.read_text())
    summary[path.stem] = {
        "test_accuracy": report["final"]["test_accuracy"],
        "test_cost": report["final"]["test_cost"],
        "finite": report["final"]["finite"],
        "wall_seconds": report["final"]["wall_seconds"],
        "corrector": report["final"]["corrector"],
    }
(root / "summary.json").write_text(json.dumps(summary, indent=2) + "\n")
print(json.dumps(summary, indent=2))
PY