OverviewFilesCommitsIssuesDocsReleasesPeers

atomspace-layer-discovery / experiments / level2 / summarize-dict.py

32 lines · python ref:
#!/usr/bin/env python3
# Score results-dict/<stamp> against PREREG-dict.md.
import glob, math, os, sys
T975 = {9: 2.262}
def mean(x): return sum(x) / len(x)
def ci(d):
    n = len(d); m = mean(d); sd = math.sqrt(sum((v - m) ** 2 for v in d) / (n - 1))
    h = T975.get(n - 1, 1.96) * sd / math.sqrt(n)
    return m, m - h, m + h
def fmt(c): return f'{c[0]:+.4f} [{c[1]:+.4f}, {c[2]:+.4f}]'
D = {}
for f in glob.glob(os.path.join(sys.argv[1], 'seed-*.tsv')):
    for line in open(f):
        p = line.rstrip('\n').split('\t')
        if p[0] == 'DP': D[(int(p[2]), p[3], int(p[4]), int(p[1]))] = (float(p[5]), float(p[6]))
seeds = sorted({k[3] for k in D}); tiers = sorted({k[0] for k in D}); top = max(tiers)
out = []
def say(s=''): out.append(s); print(s)
def d(t, x, i, j=0): return [D[(t, x, i, s)][j] for s in seeds]
say('## Link F1 (mean): MST (iteration 0), DICT iterations 1-3, [oracle of the candidate set]')
for t in tiers:
    for x in ['G', 'RP1']:
        say(f'{t} {x}: MST {mean(d(t, x, 0)):.4f}  ' + '  '.join(f'it{i} {mean(d(t, x, i)):.4f} [{mean(d(t, x, i, 1)):.3f}]' for i in (1, 2, 3)))
say(f'\n## Predictions (at {top})')
def verdict(n, ok, txt): say(f'{n}: {"PASS" if ok else "FAIL"} — {txt}')
def diff(a, b): return ci([p - q for p, q in zip(a, b)])
c = diff(d(top, 'G', 1), d(top, 'G', 0)); verdict('D1', c[1] > 0, f'G: DICT it1 − G-MST {fmt(c)}')
c = diff(d(top, 'RP1', 1), d(top, 'RP1', 0)); verdict('D2', c[1] > 0, f'RP1: DICT it1 − RP1-MST {fmt(c)}')
c = diff(d(top, 'RP1', 3), d(top, 'RP1', 1)); verdict('D3', c[1] > 0, f'RP1: it3 − it1 {fmt(c)}')
c = diff(d(top, 'RP1', 3), d(top, 'G', 0)); verdict('D4', c[1] > 0, f'RP1 it3 − G-MST {fmt(c)}')
open(os.path.join(sys.argv[1], 'summary.txt'), 'w').write('\n'.join(out) + '\n')