File size: 3,584 Bytes
2027f34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Verify public archives and official-input structure; no references/models needed."""
from pathlib import Path
import csv,hashlib,io,json,math,zipfile
ROOT=Path(__file__).resolve().parent
def read_csv(data):return list(csv.DictReader(io.StringIO(data.decode('utf-8'))))
def main():
    checked=0
    for line in (ROOT/'SHA256SUMS').read_text().splitlines():
        expected,relative=line.split('  ',1);p=(ROOT/relative).resolve()
        assert p.is_relative_to(ROOT.resolve()) and hashlib.sha256(p.read_bytes()).hexdigest()==expected,relative
        checked+=1
    schema=read_csv((ROOT/'official_schema.csv').read_bytes());ids=[x['table_id'] for x in schema]
    assert len(ids)==len(set(ids))==2000
    with zipfile.ZipFile(ROOT/'proximal-official-inputs-v1.zip') as z:
        assert z.testzip() is None
        allowed={'README.md','schema.csv','queries.csv','predictions_template.csv','load_observed.py'}
        allowed|={folder+'/'+tid+'.csv' for tid in ids for folder in ['tables','folds']}
        assert set(z.namelist())==allowed
        assert z.read('schema.csv')==(ROOT/'official_schema.csv').read_bytes()
        query=read_csv(z.read('queries.csv'));pred=read_csv(z.read('predictions_template.csv'))
        assert [x['table_id'] for x in query]==ids==[x['table_id'] for x in pred]
        assert all(set(r)=={'table_id','estimate','ci_lower','ci_upper'} and all(r[k]=='' for k in ['estimate','ci_lower','ci_upper']) for r in pred)
        for tid in ids:
            rows=read_csv(z.read('tables/'+tid+'.csv'));folds=read_csv(z.read('folds/'+tid+'.csv'))
            assert len(rows)==len(folds)==500 and set(rows[0])=={'X1','X2','Z','W','A','Y'}
            assert all(all(math.isfinite(float(v)) for v in r.values()) for r in rows)
            assert set(r['A'] for r in rows)=={'0','1'}
            labels=[int(r['fold']) for r in folds];assert set(labels)==set(range(5))
            for f in range(5):
                assert labels.count(f)==100
                assert {r['A'] for r,l in zip(rows,labels) if l==f}=={'0','1'}
    with zipfile.ZipFile(ROOT/'proximal-starter-v1.zip') as z:
        assert z.testzip() is None
        all_ids=set()
        for split,n in [('train',48),('dev',16),('test',32)]:
            truth=read_csv(z.read(split+'/truth.csv'));queries=read_csv(z.read(split+'/queries.csv'))
            catalog=read_csv((ROOT/'catalog'/f'{split}.csv').read_bytes())
            assert len(truth)==len(queries)==len(catalog)==n
            assert {r['table_id'] for r in truth}=={r['table_id'] for r in queries}=={r['table_id'] for r in catalog}
            truth_by_id={r['table_id']:float(r['truth']) for r in truth}
            assert all(math.isfinite(float(r[k])) for r in queries for k in ['X1','X2'])
            for r in catalog:
                assert r['table_id'] not in all_ids;all_ids.add(r['table_id'])
                assert math.isfinite(float(r['truth']))
                assert float(r['truth'])==truth_by_id[r['table_id']]
                observed=read_csv(z.read(r['archive_path']))
                assert len(observed)==500 and set(observed[0])=={'X1','X2','Z','W','A','Y'}
                assert all(math.isfinite(float(v)) for rr in observed for v in rr.values())
                assert set(rr['A'] for rr in observed)=={'0','1'}
        assert not all_ids.intersection(ids)
    print(json.dumps(dict(passed=True,checksums_verified=checked,official_tables=2000,n=500,official_fold_rows=1000000,
        public_starter_tables=96,official_truth_files_present=False,model_or_DGP_calls=0)))
if __name__=='__main__':main()