File size: 4,135 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
import json
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
OUT = Path("D:/GraphEvolve/docs/paper_v3/tables")
MODELS = [("qwen3vl", "Qwen3-VL-8B"), ("qwen25vl", "Qwen2.5-VL-7B")]
FAMILIES = [("left_right", "left/right"), ("above_below", "above/below"),
            ("front_behind", "front/behind"), ("on_not_on", "on/not-on")]
KEYS = ("v", "t", "k")


def load(path):
    path = Path(path)
    return json.loads(path.read_text(encoding="utf-8")) if path.exists() else None


def pct(value, digits=1):
    return "--" if value is None else f"{value * 100:.{digits}f}"


def ci(value):
    if not isinstance(value, dict):
        return ""
    low, high = value["ci95"]
    return f" [{low * 100:.1f}, {high * 100:.1f}]"


def write(name, text):
    OUT.mkdir(parents=True, exist_ok=True)
    (OUT / name).write_text(text, encoding="utf-8")
    print(f"WROTE {name}")


def tab_matrix():
    lines = [
        r"\begin{tabular}{lcccccc}",
        r"\toprule",
        r"Model & $V$ & $T$ & $K$ & PFC$(T{+})$ & PFC$(T{-})$ & $n$ \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/matrix_{key}.json")
        if not table:
            continue
        matrix = table["matrix"]
        cells = [f"{pct(matrix[k]['value'])}{ci(matrix[k])}" for k in KEYS]
        cells.append(pct(matrix["pfc_Tpos"]["value"]))
        cells.append(pct(matrix["pfc_Tneg"]["value"]))
        lines.append(f"{label} & " + " & ".join(cells) + f" & {table['n_scene_pairs']} \\\\")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_matrix.tex", "\n".join(lines) + "\n")


def tab_family_matrix():
    lines = [
        r"\begin{tabular}{llccc}",
        r"\toprule",
        r"Model & Family & $V$ & $T$ & $K$ \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/matrix_{key}.json")
        if not table:
            continue
        for family, family_label in FAMILIES:
            cell = table["by_family"].get(family)
            if not cell:
                continue
            matrix = cell["matrix"]
            values = [pct(matrix[k]["value"] if isinstance(matrix[k], dict) else matrix[k]) for k in KEYS]
            lines.append(f"{label} & {family_label} & " + " & ".join(values) + r" \\")
        lines.append(r"\addlinespace[2pt]")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_family_matrix.tex", "\n".join(lines) + "\n")


def tab_gate():
    lines = [
        r"\begin{tabular}{lcccc}",
        r"\toprule",
        r"Model & Direct & Trust-all & Gated-support & Gated \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/vcg_test_{key}.json")
        if not table:
            continue
        methods = {row["method"]: row for row in table["methods"]}
        cells = [pct(methods[name]["accuracy"]) for name in
                 ("direct_only", "trust_all", "vcg_support_only", "vcg")]
        lines.append(f"{label} & " + " & ".join(cells) + r" \\")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_gate_v2.tex", "\n".join(lines) + "\n")


def tab_gate_family():
    lines = [
        r"\begin{tabular}{llccccc}",
        r"\toprule",
        r"Model & Family & Direct & Gated-support & Gated & Support & Refute \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/vcg_test_{key}.json")
        if not table:
            continue
        for family, family_label in FAMILIES:
            cell = table["by_family"].get(family)
            if not cell:
                continue
            lines.append(
                f"{label} & {family_label} & {pct(cell['direct_only'])} & {pct(cell['vcg_support_only'])} & "
                f"{pct(cell['vcg'])} & {pct(cell['support_rate'])} & {pct(cell['refute_rate'])} \\\\"
            )
        lines.append(r"\addlinespace[2pt]")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_gate_family.tex", "\n".join(lines) + "\n")


if __name__ == "__main__":
    tab_matrix()
    tab_family_matrix()
    tab_gate()
    tab_gate_family()