File size: 7,572 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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"), ("deepseekvl2s", "DeepSeek-VL2-Small")]
CONDITIONS = [("T0", "T0"), ("Tpos", "T$+$"), ("Tneg", "T$-$"), ("Tabs", "T$\\varnothing$"), ("Tunk", "Tu")]
FAMILIES = [("left_right", "left/right"), ("above_below", "above/below"),
            ("front_behind", "front/behind"), ("on_not_on", "on/not-on")]
METHODS = [("direct_only", "Direct"), ("trust_all", "Trust-all"), ("vcg", "Gated"),
           ("vcg_support_only", "Gated-support"), ("vcg_confident", "Gated-conf"),
           ("witness_only", "Witness only"), ("independent_vlm_check", "Independent VLM")]


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):
    if value is None:
        return "--"
    return f"{value * 100:.{digits}f}"


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_conditions():
    lines = [
        r"\begin{tabular}{llccccc}",
        r"\toprule",
        r"Model & Metric & T0 & T$+$ & T$-$ & T$\varnothing$ & Tu \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/synth_{key}.json")
        if not table:
            continue
        acc = [pct(table["overall"]["conditions"][c]["acc"]) for c, _ in CONDITIONS]
        yes = [pct(table["overall"]["conditions"][c]["yes_rate"]) for c, _ in CONDITIONS]
        lines.append(f"{label} & acc. & " + " & ".join(acc) + r" \\")
        lines.append(f" & yes & " + " & ".join(yes) + r" \\")
        lines.append(r"\addlinespace[2pt]")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_conditions.tex", "\n".join(lines) + "\n")


def tab_vtk():
    lines = [
        r"\begin{tabular}{lccccccccc}",
        r"\toprule",
        r"Model & V & T & K & R & PFC & FCA(T$+$) & FCA(T$-$) & TEU(T$+$) & TEU(T$-$) \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/synth_{key}.json")
        if not table:
            continue
        vtk = table["overall"]["vtk"]
        cells = [pct(vtk["v"]), pct(vtk["t"]), pct(vtk["k"]), pct(vtk["r"]),
                 pct(table["overall"].get("pfc")),
                 pct(table["overall"].get("fca_Tpos")), pct(table["overall"].get("fca_Tneg")),
                 pct(table["overall"].get("teu_Tpos")), pct(table["overall"].get("teu_Tneg"))]
        lines.append(f"{label} & " + " & ".join(cells) + r" \\")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_vtk.tex", "\n".join(lines) + "\n")


def tab_family():
    lines = [
        r"\begin{tabular}{llcccc}",
        r"\toprule",
        r"Model & Family & V & T & K & R \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/synth_{key}.json")
        if not table:
            continue
        for fam, fam_label in FAMILIES:
            vtk = table["by_family"][fam]["vtk"]
            lines.append(
                f"{label} & {fam_label} & {pct(vtk['v'])} & {pct(vtk['t'])} & {pct(vtk['k'])} & {pct(vtk['r'])} \\\\"
            )
        lines.append(r"\addlinespace[2pt]")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_family.tex", "\n".join(lines) + "\n")


def tab_gate():
    lines = [
        r"\begin{tabular}{lcccccc}",
        r"\toprule",
        r"Model & Method & Acc. & Cov. & Induced & Harm & Repair \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/vcg_test_{key}.json")
        if not table:
            continue
        lookup = {m["method"]: m for m in table["methods"]}
        for method, method_label in METHODS:
            cell = lookup.get(method)
            if not cell:
                continue
            lines.append(
                f"{label} & {method_label} & {pct(cell['accuracy'])} & {pct(cell['coverage'])} & "
                f"{pct(cell['induced_error'])} & {pct(cell['harm_rate'])} & {pct(cell['repair_rate'])} \\\\"
            )
        lines.append(r"\addlinespace[2pt]")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_gate.tex", "\n".join(lines) + "\n")


def tab_natural():
    lines = [
        r"\begin{tabular}{llccccc}",
        r"\toprule",
        r"Model & Collection & T0 & T$+$ & T$-$ & T$\varnothing$ & Tu \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        cells = {}
        base = Path(f"/mnt/f70f6709-366e-49a0-861f-497645d98975/lyz/GraphEvolve/n_full_v1/predictions/natural")
        for collection in ("spatialsense", "vsr"):
            table = load(ROOT / f"analysis/natural_{key}_{collection}.json")
            if table:
                cells[collection] = table
        if not cells:
            continue
        for collection, data in cells.items():
            row = [pct(data[c]["acc"]) for c, _ in CONDITIONS]
            lines.append(f"{label} & {collection} & " + " & ".join(row) + r" \\")
        lines.append(r"\addlinespace[2pt]")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_natural.tex", "\n".join(lines) + "\n")


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


def pct_ci(point, ci, digits=1):
    if point is None:
        return "--"
    if not ci:
        return pct(point, digits)
    return f"{point * 100:.{digits}f} [{ci['lo'] * 100:.{digits}f}, {ci['hi'] * 100:.{digits}f}]"


def tab_ci():
    lines = [
        r"\begin{tabular}{lcccccc}",
        r"\toprule",
        r"Model & V & T & K & R & FCA(T$+$) & TEU(T$+$) \\",
        r"\midrule",
    ]
    for key, label in MODELS:
        table = load(ROOT / f"analysis/synth_{key}.json")
        boot = load(ROOT / f"analysis/boot_{key}.json")
        if not table or not boot:
            continue
        point = boot["point"]
        ci = boot["ci"]
        cells = [pct_ci(point["v"], ci.get("v")), pct_ci(point["t"], ci.get("t")),
                 pct_ci(point["k"], ci.get("k")), pct_ci(point["r"], ci.get("r")),
                 pct_ci(point["fca_Tpos"], ci.get("fca_Tpos")),
                 pct_ci(point["teu_Tpos"], ci.get("teu_Tpos"))]
        lines.append(f"{label} & " + " & ".join(cells) + r" \\\\")
    lines += [r"\bottomrule", r"\end{tabular}"]
    write("tab_ci.tex", "\n".join(lines) + "\n")


def main():
    tab_conditions()
    tab_vtk()
    tab_family()
    tab_gate()
    tab_gate_family()
    tab_natural()
    tab_ci()


if __name__ == "__main__":
    main()