"""Identification table with object-level bootstrap CIs (pair-count weighted, matching the pooled accuracy).""" import json import sys import numpy as np D = "/home/hubin/trellis_work/outputs/ident" def main(): names = sys.argv[1:] or list(json.load(open(f"{D}/summary.json"))) data = {n: json.load(open(f"{D}/{n}.json")) for n in names} ids = data[names[0]]["ids"] cats = np.array([i.split("/")[0] for i in ids]) w = np.array([(cats == c).sum() - 1 for c in cats], dtype=float) boot = np.random.default_rng(0).integers(0, len(ids), (10000, len(ids))) wb = w[boot] base = np.nan_to_num(np.array(data["mind3d_official"]["per_object_within_cat"])) if "mind3d_official" in data else None out = {} for n in names: assert data[n]["ids"] == ids a = np.nan_to_num(np.array(data[n]["per_object_within_cat"])) acc = (a[boot] * wb).sum(1) / wb.sum(1) row = {**data[n]["summary"], "within_cat_ci95": list(np.percentile(acc, [2.5, 97.5]))} if base is not None: diff = ((a - base)[boot] * wb).sum(1) / wb.sum(1) row["diff_vs_mind3d_ci95"] = list(np.percentile(diff, [2.5, 97.5])) out[n] = row print(f"| `{n}` | {row['within_cat_2way']:.3f} | [{row['within_cat_ci95'][0]:.3f}, {row['within_cat_ci95'][1]:.3f}] " f"| {row['all_2way']:.3f} | {row['top1_retrieval']:.3f} | " + (f"[{row['diff_vs_mind3d_ci95'][0]:+.3f}, {row['diff_vs_mind3d_ci95'][1]:+.3f}] |" if base is not None else "|")) json.dump(out, open(f"{D}/summary_ci.json", "w"), indent=1) if __name__ == "__main__": main()