File size: 2,845 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
import csv
import json
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
AN = ROOT / "analysis"
RES = ROOT / "results"
MODELS = ["qwen3vl", "qwen25vl"]
METHOD_CALLS = {
    "direct_only": (0, 0),
    "trust_all": (0, 0),
    "vcg": (2, 0),
    "vcg_support_only": (2, 0),
    "vcg_confident": (2, 0),
    "witness_only": (2, 0),
    "independent_vlm_check": (0, 1),
}


def load(path):
    with path.open(encoding="utf-8") as fh:
        return json.load(fh)


def main():
    RES.mkdir(parents=True, exist_ok=True)
    paired = {"schema": "graphevolve.n_full_v1.paired_metrics.v1", "models": {}}
    vcg = {"schema": "graphevolve.n_full_v1.vcg_results.v1", "models": {}}
    for model in MODELS:
        matrix = load(AN / f"matrix_{model}.json")
        paired["models"][model] = {
            "n_scene_pairs": matrix["n_scene_pairs"],
            "matrix": matrix["matrix"],
            "cells": matrix["cells"],
            "by_family": matrix["by_family"],
            "fca_Tpos": matrix["fca_Tpos"],
            "fca_Tneg": matrix["fca_Tneg"],
            "teu_Tpos": matrix["teu_Tpos"],
            "teu_Tneg": matrix["teu_Tneg"],
        }
        gate = load(AN / f"vcg_test_{model}.json")
        vcg["models"][model] = {
            "params": gate["params"],
            "methods": gate["methods"],
            "by_family": gate["by_family"],
            "risk_coverage": gate["risk_coverage"],
        }
    (RES / "paired_metrics.json").write_text(
        json.dumps(paired, indent=2, ensure_ascii=False), encoding="utf-8"
    )
    (RES / "vcg_results.json").write_text(
        json.dumps(vcg, indent=2, ensure_ascii=False), encoding="utf-8"
    )

    rows = []
    for model in MODELS:
        gate = load(AN / f"vcg_test_{model}.json")
        for stats in gate["methods"]:
            method = stats["method"]
            tool_calls, vlm_calls = METHOD_CALLS.get(method, (0, 0))
            rows.append(
                {
                    "model": model,
                    "method": method,
                    "accuracy": round(stats["accuracy"], 4),
                    "coverage": round(stats["coverage"], 4),
                    "induced_error": round(stats["induced_error"], 4),
                    "harm_rate": round(stats["harm_rate"], 4),
                    "repair_rate": round(stats["repair_rate"], 4),
                    "extra_tool_calls": tool_calls,
                    "extra_vlm_calls": vlm_calls,
                }
            )
    with (RES / "costs.csv").open("w", encoding="utf-8", newline="") as fh:
        writer = csv.DictWriter(fh, fieldnames=list(rows[0].keys()))
        writer.writeheader()
        writer.writerows(rows)
    print(f"WROTE {RES/'paired_metrics.json'} {RES/'vcg_results.json'} {RES/'costs.csv'} rows={len(rows)}")


if __name__ == "__main__":
    main()