Download experiments/task-transfer/paper/plot.py from MLL-Lab/LAGEN-datasets: direct link, hf CLI and curl.
- Browser
- Download file 3.29 kB
-
https://huggingface.co/datasets/MLL-Lab/LAGEN-datasets/resolve/main/experiments/task-transfer/paper/plot.py
- Command line
-
hf download hf://datasets/MLL-Lab/LAGEN-datasets/experiments/task-transfer/paper/plot.py
-
curl -L -o plot.py https://huggingface.co/datasets/MLL-Lab/LAGEN-datasets/resolve/main/experiments/task-transfer/paper/plot.py
3.29 kB
| """Demon Attack training cross-task evaluation companion figure.""" | |
| from __future__ import annotations | |
| import csv | |
| from pathlib import Path | |
| import sys | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| from matplotlib.lines import Line2D | |
| from matplotlib.ticker import FuncFormatter | |
| HERE = Path(__file__).resolve().parent | |
| PAPER = HERE.parents[1] | |
| sys.path.insert(0, str(PAPER)) | |
| import paper_colors | |
| TASKS = ("Demon Attack", "Asterix", "Atlantis", "AirRaid") | |
| SERIES = ( | |
| ("zero_latency_train", "Zero-latency training", paper_colors.GRAY), | |
| ("mixed_latency_train", "Mixed-latency training", paper_colors.PURPLE), | |
| ) | |
| def read_rows() -> dict[str, list[dict[str, float]]]: | |
| by_task: dict[str, list[dict[str, float]]] = {task: [] for task in TASKS} | |
| with (HERE / "data.csv").open(newline="", encoding="utf-8") as stream: | |
| for row in csv.DictReader(stream): | |
| by_task[row["task"]].append({ | |
| "eval_latency": float(row["eval_latency"]), | |
| "zero_latency_train": float(row["zero_latency_train"]), | |
| "mixed_latency_train": float(row["mixed_latency_train"]), | |
| }) | |
| for rows in by_task.values(): | |
| rows.sort(key=lambda item: item["eval_latency"]) | |
| return by_task | |
| def compact_int(value: float, _position: int) -> str: | |
| if abs(value) >= 1000: | |
| return f"{value / 1000:g}k" | |
| return f"{value:g}" | |
| def main() -> None: | |
| plt.style.use(PAPER / "plot_style.mplstyle") | |
| plt.rcParams.update(paper_colors.RC_COLORS) | |
| data = read_rows() | |
| fig, axes = plt.subplots(1, 4, figsize=(7.2, 2.25), sharex=True) | |
| fig.subplots_adjust(left=0.075, right=0.995, top=0.76, bottom=0.24, wspace=0.32) | |
| for ax, task in zip(axes, TASKS): | |
| rows = data[task] | |
| xs = [row["eval_latency"] for row in rows] | |
| max_value = max(row[key] for row in rows for key, _label, _color in SERIES) | |
| ymin = 0 | |
| ymax = max_value * 1.18 | |
| for key, label, color in SERIES: | |
| ys = [row[key] for row in rows] | |
| ax.plot( | |
| xs, | |
| ys, | |
| marker="o", | |
| markersize=3.1, | |
| linewidth=1.25, | |
| color=color, | |
| label=label, | |
| ) | |
| ax.set_title(task, fontsize=8.4, weight="bold", pad=6) | |
| ax.set_xlim(-0.2, 4.2) | |
| ax.set_ylim(ymin, ymax) | |
| ax.set_xticks((0, 2, 4)) | |
| ax.yaxis.set_major_formatter(FuncFormatter(compact_int)) | |
| ax.tick_params(axis="both", labelsize=6.5) | |
| ax.grid(True, axis="y") | |
| ax.grid(False, axis="x") | |
| axes[0].set_ylabel("Mean return", fontsize=7.2) | |
| fig.supxlabel("Evaluation latency (raw frames)", fontsize=7.2, y=0.07) | |
| handles = [ | |
| Line2D([0], [0], color=color, marker="o", markersize=3.2, linewidth=1.25, label=label) | |
| for _key, label, color in SERIES | |
| ] | |
| fig.legend( | |
| handles=handles, | |
| loc="upper center", | |
| bbox_to_anchor=(0.52, 0.995), | |
| ncols=2, | |
| columnspacing=1.6, | |
| handlelength=1.8, | |
| fontsize=6.5, | |
| ) | |
| for extension in ("pdf", "png"): | |
| fig.savefig(HERE / f"fig.{extension}", dpi=300, bbox_inches="tight", pad_inches=0.025) | |
| plt.close(fig) | |
| if __name__ == "__main__": | |
| main() | |