Datasets:
File size: 5,243 Bytes
a863f79 | 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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | import json
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.insert(0, str(Path("D:/GraphEvolve/figures_workspace/_utils")))
import plot_utils as pu
ROOT = Path(__file__).resolve().parents[1]
OUT = ROOT / "figures"
CONDITIONS = ["T0", "Tpos", "Tneg", "Tabs", "Tunk"]
LABELS = {"T0": "T0", "Tpos": "T+", "Tneg": "T-", "Tabs": "T∅", "Tunk": "Tu"}
MODELS = [("qwen3vl", "Qwen3-VL-8B"), ("qwen25vl", "Qwen2.5-VL-7B"), ("deepseekvl2s", "DeepSeek-VL2-Small")]
FAMILIES = {"left_right": "left/right", "above_below": "above/below",
"front_behind": "front/behind", "on_not_on": "on/not-on"}
def load(path):
return json.loads(Path(path).read_text(encoding="utf-8"))
def synth(model):
path = ROOT / f"analysis/synth_{model}.json"
return load(path) if path.exists() else None
def gate(model):
path = ROOT / f"analysis/vcg_test_{model}.json"
return load(path) if path.exists() else None
def colors(n):
keys = ["primary", "secondary", "accent", "highlight", "light"]
return [pu.COLORS[keys[i % len(keys)]] for i in range(n)]
def fig_conditions(models):
fig, axes = plt.subplots(1, 2, figsize=(7.0, 2.6))
width = 0.8 / len(models)
xs = np.arange(len(CONDITIONS))
for ax, key, title in ((axes[0], "acc", "Accuracy"), (axes[1], "yes_rate", "Yes rate")):
for i, (model, label) in enumerate(models):
table = synth(model)
if not table:
continue
vals = [table["overall"]["conditions"][c][key] for c in CONDITIONS]
ax.bar(xs + i * width - 0.4 + width / 2, vals, width, label=label, color=colors(len(models))[i])
ax.set_xticks(xs)
ax.set_xticklabels([LABELS[c] for c in CONDITIONS])
ax.set_ylim(0, 1)
ax.set_title(title, fontsize=9)
ax.grid(axis="y", alpha=0.25)
axes[0].set_ylabel("value")
axes[0].legend(frameon=False, fontsize=7, loc="lower left")
fig.tight_layout()
pu._save(fig, str(OUT / "fig_conditions.pdf"))
plt.close(fig)
def fig_vtk(models):
fig, ax = plt.subplots(figsize=(6.4, 2.4))
metrics = ["v", "t", "k", "r"]
names = ["V", "T", "K", "R"]
width = 0.8 / len(models)
xs = np.arange(len(metrics))
for i, (model, label) in enumerate(models):
table = synth(model)
if not table:
continue
vtk = table["overall"]["vtk"]
vals = [vtk[m] for m in metrics]
ax.bar(xs + i * width - 0.4 + width / 2, vals, width, label=label, color=colors(len(models))[i])
ax.axhline(0, color="0.3", lw=0.6)
ax.set_xticks(xs)
ax.set_xticklabels(names)
ax.set_ylabel("value")
ax.grid(axis="y", alpha=0.25)
ax.legend(frameon=False, fontsize=7, ncol=3, loc="upper right")
fig.tight_layout()
pu._save(fig, str(OUT / "fig_vtk.pdf"))
plt.close(fig)
def fig_family(models):
fig, axes = plt.subplots(1, len(models), figsize=(7.0, 2.2), sharey=True)
fams = list(FAMILIES)
for ax, (model, label) in zip(np.atleast_1d(axes), models):
table = synth(model)
if not table:
continue
v = [table["by_family"][f]["vtk"]["v"] for f in fams]
t = [table["by_family"][f]["vtk"]["t"] for f in fams]
xs = np.arange(len(fams))
ax.bar(xs - 0.19, v, 0.36, label="V", color=colors(2)[0])
ax.bar(xs + 0.19, t, 0.36, label="T", color=colors(2)[1])
ax.set_xticks(xs)
ax.set_xticklabels([FAMILIES[f] for f in fams], rotation=18, fontsize=6, ha="right")
ax.set_title(label, fontsize=7)
ax.set_ylim(0, 1)
ax.grid(axis="y", alpha=0.25)
np.atleast_1d(axes)[0].set_ylabel("value")
np.atleast_1d(axes)[0].legend(frameon=False, fontsize=6)
fig.tight_layout()
pu._save(fig, str(OUT / "fig_family.pdf"))
plt.close(fig)
def fig_gate(models):
methods = ["direct_only", "trust_all", "vcg", "vcg_support_only", "vcg_confident"]
names = ["direct", "trust-all", "gated", "gated-support", "gated-conf"]
fig, ax = plt.subplots(figsize=(6.2, 2.4))
width = 0.8 / len(models)
xs = np.arange(len(methods))
for i, (model, label) in enumerate(models):
table = gate(model)
if not table:
continue
lookup = {m["method"]: m["accuracy"] for m in table["methods"]}
vals = [lookup[m] for m in methods]
ax.bar(xs + i * width - 0.4 + width / 2, vals, width, label=label, color=colors(len(models))[i])
ax.set_xticks(xs)
ax.set_xticklabels(names, fontsize=7)
ax.set_ylim(0.4, 0.9)
ax.set_ylabel("accuracy")
ax.grid(axis="y", alpha=0.25)
ax.legend(frameon=False, fontsize=6, ncol=3)
fig.tight_layout()
pu._save(fig, str(OUT / "fig_gate.pdf"))
plt.close(fig)
def main():
OUT.mkdir(parents=True, exist_ok=True)
pu.setup_style(palette="olive-apricot", language="en", font_family=["Arial", "DejaVu Sans"])
models = [(m, l) for m, l in MODELS if synth(m)]
if not models:
raise RuntimeError("no synthetic results yet")
fig_conditions(models)
fig_vtk(models)
fig_family(models)
fig_gate(models)
print(f"WROTE figures for {[m for m, _ in models]}")
if __name__ == "__main__":
main()
|