File size: 1,529 Bytes
7c61ee6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Pick (output variant, CFG) per family by mean val CD; the test set is then generated/evaluated once with the pick."""
import glob
import json
import os

import numpy as np

O = "/home/hubin/trellis_work/outputs/valsel"
FAMILIES = {"no_labels": ["ridge_k64_rescaled"],
            "labels": ["clsfirst_knn1_resid_k64_rescaled", "v2ens5_coef_rescaled", "v2ens5_clsmean_resid",
                       "v2ens5_clsmean"]}


def main():
    table = {}
    for d in sorted(glob.glob(f"{O}/val/*_cfg*/metrics.json")):
        name = os.path.basename(os.path.dirname(d))
        rows = json.load(open(d))["rows"]
        cd = np.array([r["cd"] for r in rows]) * 1e3
        table[name] = {"n": len(rows), "cd_x1e3": float(cd.mean()), "median": float(np.median(cd)),
                       "fscore@0.02": float(np.mean([r["fscore"] for r in rows]))}
    sel = {}
    for fam, variants in FAMILIES.items():
        cands = {n: m for n, m in table.items() if n.rsplit("_cfg", 1)[0] in variants}
        best = min(cands, key=lambda n: cands[n]["cd_x1e3"])
        v, c = best.rsplit("_cfg", 1)
        sel[fam] = {"variant": v, "cfg": c, "val_cd_x1e3": cands[best]["cd_x1e3"]}
    for n, m in sorted(table.items(), key=lambda kv: kv[1]["cd_x1e3"]):
        print(f"{n:45s} n={m['n']:3d} CD {m['cd_x1e3']:6.2f} median {m['median']:6.2f} F {m['fscore@0.02']:.3f}")
    print(json.dumps(sel, indent=1))
    json.dump({"selection": sel, "val_table": table}, open(f"{O}/selection.json", "w"), indent=1)


if __name__ == "__main__":
    main()