File size: 3,509 Bytes
7675a7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Use bundled model predictions with the existing four-file paired example."""
import argparse
import json
import subprocess
import sys
from pathlib import Path


def main():
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument('--bundle', type=Path, required=True)
    p.add_argument('--protocol', default='external/low-pass/source_nonoverlap')
    p.add_argument('--pair', choices=('qwen/intern', 'lfm/d1'), default='qwen/intern')
    p.add_argument('--seed', type=int, choices=(0, 1, 2), default=0)
    p.add_argument('--output', type=Path, required=True)
    a = p.parse_args()
    from hudec.bundle import Bundle
    bundle = Bundle(a.bundle)
    base, decision = a.pair.split('/')
    keys = [('before-base', base, 'untrained-fixed'),
            ('before-decision', decision, 'untrained-fixed'),
            ('after-base', base, f'human-seed{a.seed}'),
            ('after-decision', decision, f'human-seed{a.seed}')]
    cases = {flag: bundle.baseline(f'common-selection/{a.protocol}/{model}_{target}')
             for flag, model, target in keys}
    command = [sys.executable, '-B', str(Path(__file__).with_name('paired_change_example.py')),
               '--bundle', str(bundle.root), '--protocol', a.protocol, '--output', str(a.output)]
    for flag, _, _ in keys:
        command.extend(['--' + flag, str(bundle.root / cases[flag]['predictions'])])
    subprocess.run(command, check=True)
    report = json.loads(a.output.read_text())
    report['reference_cases'] = {flag: {'case_id': row['case_id'], 'metadata': row['metadata']}
                                 for flag, row in cases.items()}
    report['reference_pair'] = a.pair
    report['reference_training_seed'] = a.seed
    a.output.write_text(json.dumps(report, indent=2, allow_nan=False))
    lines = ['# 决策模型前后配对评分', '', f"本例使用已完成的{a.pair}、种子{a.seed},协议为`{a.protocol}`。没有训练或模型推理。", '',
             '| 指标 | 适配前决策减底座 | 适配后决策减底座 | 配对变化及95%区间 |',
             '| --- | --- | --- | --- |']
    names = {'nll': '人类选择NLL', 'kappa': '正确错误κ', 'wrong_label': '双方均错时答案一致率', 'accuracy': '每图等权正确率'}
    for metric, name in names.items():
        pre, post, change = [report[key][metric] for key in ('pre_gap', 'post_gap', 'adaptation_change')]
        def value(row):
            return '未定义' if row['point'] is None else f"{row['point']:+.6f}"
        ci = '区间未定义' if change['ci95'] is None else f"[{change['ci95'][0]:+.6f}, {change['ci95'][1]:+.6f}]"
        lines.append(f"| {name} | {value(pre)} | {value(post)} | {value(change)} {ci} |")
    lines.extend(['', 'NLL变化为正表示决策模型的相对优势减弱,其他三项变化为负表示减弱。区间含0表示这项比较没有确定方向,不表示等效。相对优势减弱也不表示两个模型都变差。', '',
                  '四组使用相同目标、类别顺序及2000次刺激与观察者配对抽样,外部按原图聚类。全部组的点估计、区间、覆盖和未定义次数保存在JSON中。', '',
                  '来源验证选模与校准固定。这里的前后变化不能单独区分人类标签作用、其他微调目标或权重与校准因素,也不是内部视觉机制的因果定位。'])
    a.output.with_suffix('.md').write_text('\n'.join(lines) + '\n', encoding='utf-8')


if __name__ == '__main__':
    main()