27 lines
1.6 KiB
Python
27 lines
1.6 KiB
Python
"""Exact sampling concentration and full discrete mass from saved E6 outputs."""
|
|
import csv
|
|
import json
|
|
from pathlib import Path
|
|
import numpy as np
|
|
|
|
|
|
def main():
|
|
out=Path('artifacts/e6-kernel-2026-11-14');r=json.loads((out/'run.json').read_text());rows=[]
|
|
for a in r['cases']:
|
|
f=np.load(out/(a['name']+'_fields.npz'));counts=np.bincount(f['draw_to_unique']);s=a['statistics'];p=a['plan']['positive_distance_mass_fraction'];b=a['plan']['boundary_unscored_mass_fraction']
|
|
row=dict(case=a['case'][:8],rule=a['rule'],draws=len(f['draw_to_unique']),unique_N=len(counts),max_multiplicity=int(counts.max()),positive_distance_share=p,boundary_unscored=b)
|
|
for k,v in s['modes'].items():row['full_mass_mode_'+k]=p*v['estimate']
|
|
for k,v in s['near_cut'].items():row['full_mass_near_'+k]=p*v['estimate']
|
|
row['full_mass_not_near_either']=p-row['full_mass_near_either']
|
|
row['full_mass_neff_failed']=p*s['neff_failed']['estimate']
|
|
np.testing.assert_allclose(sum(row['full_mass_mode_'+str(k)] for k in [-1,0,1,2,3])+b,1)
|
|
np.testing.assert_allclose(row['full_mass_near_either']+row['full_mass_not_near_either']+b,1)
|
|
rows.append(row)
|
|
with (out/'sampling_full_mass.csv').open('w') as f:
|
|
w=csv.DictWriter(f,fieldnames=list(rows[0]),lineterminator='\n');w.writeheader();w.writerows(rows)
|
|
(out/'sampling_full_mass.json').write_text(json.dumps(dict(measure='Full discrete lumped mass contributions; conditional p multiplied by positive-distance mass, boundary unscored',rows=rows),indent=2)+'\n')
|
|
print(json.dumps(rows,indent=2))
|
|
|
|
|
|
if __name__=='__main__':main()
|