Download dopamine/scripts/plot_one_episode.py from Vio1etV/Robustness_of_progress_model: direct link, hf CLI and curl.
- Browser
- Download file 2.71 kB
-
https://huggingface.co/datasets/Vio1etV/Robustness_of_progress_model/resolve/main/dopamine/scripts/plot_one_episode.py
- Command line
-
hf download hf://datasets/Vio1etV/Robustness_of_progress_model/dopamine/scripts/plot_one_episode.py
-
curl -L -o plot_one_episode.py https://huggingface.co/datasets/Vio1etV/Robustness_of_progress_model/resolve/main/dopamine/scripts/plot_one_episode.py
2.71 kB
| #!/usr/bin/env python3 | |
| """Plot the 5 anchoring-mode progress curves for a single episode. | |
| Usage: | |
| python plot_one_episode.py chunk-000_episode_000039 | |
| python plot_one_episode.py chunk-000_episode_000039 --out /tmp/x.png | |
| """ | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| MODES = ["incremental", "forward", "backward", "interval_half", "interval_double"] | |
| BASELINE = "incremental" | |
| COLORS = {"incremental": "tab:blue", "forward": "tab:orange", | |
| "backward": "tab:green", "interval_half": "tab:red", | |
| "interval_double": "tab:purple"} | |
| FRACS = ["1/4", "2/4", "3/4", "end"] | |
| p = argparse.ArgumentParser() | |
| p.add_argument("episode_dir", help="e.g. chunk-000_episode_000039") | |
| p.add_argument("--results-root", | |
| default=str(Path(__file__).resolve().parent.parent / "results_full")) | |
| p.add_argument("--out", default=None) | |
| a = p.parse_args() | |
| ep_dir = Path(a.results_root) / "episode_results" / a.episode_dir | |
| out = Path(a.out) if a.out else ep_dir / "curves.png" | |
| data = {} | |
| for m in MODES: | |
| f = ep_dir / f"{m}.json" | |
| if f.exists(): | |
| data[m] = json.loads(f.read_text()) | |
| if not data: | |
| raise SystemExit(f"no mode json found in {ep_dir}") | |
| meta0 = data.get(BASELINE, next(iter(data.values()))) | |
| base_after = meta0["after_frames"] | |
| L = len(base_after) | |
| tgts = [base_after[int(round((L - 1) * k / 4))] for k in (1, 2, 3, 4)] | |
| def score_at(payload, taf): | |
| afs = payload["after_frames"] | |
| j = min(range(len(afs)), key=lambda i: abs(afs[i] - taf)) | |
| return payload["scores_100"][j] | |
| fig, ax = plt.subplots(figsize=(13, 6)) | |
| for m in MODES: | |
| if m not in data: | |
| continue | |
| xs = np.array(data[m]["after_frames"], dtype=float) | |
| ax.plot(xs, data[m]["scores_100"], color=COLORS[m], lw=1.6, | |
| marker=".", ms=4, label=m) | |
| for frac, taf in zip(FRACS, tgts): | |
| ax.axvline(taf, color="0.6", ls=":", lw=1) | |
| ax.text(taf, 96, f"{frac} (f={taf})", ha="center", fontsize=9, color="0.4") | |
| scores = {frac: [score_at(data[m], taf) for m in MODES if m in data] | |
| for frac, taf in zip(FRACS, tgts)} | |
| rngs = ", ".join(f"{frac}: {max(v)-min(v):.1f}" for frac, v in scores.items()) | |
| ax.set_title(f"{a.episode_dir} ({meta0['camera']}, baseline pool={L})\n" | |
| f"task: {meta0['task'][:100]}\nAnchor Range @ checkpoints -> {rngs}", | |
| fontsize=10) | |
| ax.set_xlabel(f"physical AFTER-frame index " | |
| f"(raw {meta0['total_raw_frames']} frames @ {meta0['native_fps']:.0f} fps)") | |
| ax.set_ylabel("progress score (0-100)") | |
| ax.set_ylim(0, 100) | |
| ax.grid(alpha=0.25) | |
| ax.legend(fontsize=9) | |
| fig.tight_layout() | |
| fig.savefig(out, dpi=140) | |
| print("saved:", out) | |