summaryrefslogtreecommitdiff
path: root/experiments/rain_ep_centered_r3.sh
blob: be44649062f6df764a1dd7e10da6440d81baf218 (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
#!/usr/bin/env bash
set -euo pipefail

ROOT=/home/yurenh2/sdil
AUTHOR=/scratch/yurenh2/energy-based-learning
PYTHON=/scratch/yurenh2/venvs/burstccn/bin/python
PROFILE="$ROOT/results/physical_bias/p0_state_dependence.json"
OUT="$ROOT/results/ep_bias/centered_r3"
mkdir -p "$OUT"
cd "$AUTHOR"

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

seeds=(1988 1989)
methods=(clean raw constant innovation)
tags=(clean raw intercept sdil)
gpu=0
for seed in "${seeds[@]}"; do
  for index in "${!methods[@]}"; do
    run_cell "$gpu" "$seed" "${methods[$index]}" \
      "seed_${seed}_${tags[$index]}" &
    gpu=$((gpu + 1))
  done
done
wait

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

root = Path(sys.argv[1])
by_seed = {}
for path in sorted(root.glob("seed_*.json")):
    _, seed, method = path.stem.split("_", 2)
    report = json.loads(path.read_text())
    trajectory = [epoch["test_accuracy"] for epoch in report["metrics"]]
    by_seed.setdefault(seed, {})[method] = {
        "trajectory": trajectory,
        "best_accuracy": max(trajectory),
        "final_accuracy": trajectory[-1],
        "epochs_completed": len(trajectory),
        "finite": report["final"]["finite"],
    }

summary = {"by_seed": by_seed, "final_accuracy": {}}
for method in ("clean", "raw", "intercept", "sdil"):
    values = [methods[method]["final_accuracy"] for methods in by_seed.values()]
    summary["final_accuracy"][method] = {
        "mean": statistics.mean(values),
        "values": values,
    }
(root / "summary.json").write_text(json.dumps(summary, indent=2) + "\n")
print(json.dumps(summary, indent=2))
PY