Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/yang/blob/main/scripts/summarize_middle_cut.py # yang This project has not described itself yet. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `yang / scripts / summarize_middle_cut.py` 49 lines ยท 2125 bytes Raw Blame History 1 """Reduce each hot/cold chain separately. All losses are base-ten log fractions.""" 2 import csv 3 from itertools import groupby 4 import sys 5 6 import numpy as np 7 8 9 def summarize(rows): 10 for key, group in groupby(rows, lambda r: tuple(r[k] for k in 11 ('group', 'side', 'warmup', 'samples', 'stride', 'beta', 'start', 'seed'))): 12 group = list(group) 13 if [int(r['sample']) for r in group] != list(range(int(key[3]))): 14 raise ValueError('incomplete or reordered sample series') 15 def col(name): 16 return np.array([float(r[name]) for r in group]) 17 source = np.abs(np.tanh(col('source_j'))) 18 if 'narrow1_j' in group[0]: 19 families = (('narrow1', 'narrow2'), ('wide1', 'wide2')) 20 elif 'radius1_j' in group[0]: 21 families = (('radius1', 'radius2'),) 22 else: 23 families = (('cut',), ('slab',)) 24 for family in families: 25 w = source 26 for name in family: 27 counts = col(name+'_faces') 28 if not np.all(counts == counts[0]): 29 raise ValueError('geometry changed in chain') 30 j = col(name+'_j') 31 live = w > 0 32 if live.any(): 33 lognum = np.log(w[live])+np.log(2.)-np.logaddexp(0., 2*np.abs(j[live])) 34 logsum = np.logaddexp.reduce(lognum) 35 loss = (logsum-np.log(w.sum()))/np.log(10.) 36 largest_share = np.exp(lognum.max()-logsum) 37 else: 38 loss = largest_share = float('nan') # No surviving preceding weight. 39 print(key[0], key[5], key[6], len(j), name, int(counts[0]), f'{j.min():.8g}', 40 f'{j.max():.8g}', f'{loss:.8g}', f'{largest_share:.8g}') 41 if name != family[-1]: 42 w = w * np.abs(np.tanh(j)) 43 44 45 if __name__ == '__main__': 46 print('group beta start pairs middle split_faces min_J max_J log10_loss largest_loss_share') 47 for path in sys.argv[1:]: 48 with open(path) as f: 49 summarize(csv.DictReader(f, delimiter='\t'))