70 lines
4.0 KiB
Python
70 lines
4.0 KiB
Python
"""Frozen same-roster component statistics and pre-specified candidate decisions."""
|
|
import math
|
|
|
|
from phase3_seed1_postfit_statistics import comparisons as seed_comparisons
|
|
from r4bc_common import paired_difference
|
|
|
|
|
|
def comparisons(rows, candidate):
|
|
# This is the same estimator and bootstrap as the independently reviewed seed result.
|
|
out = seed_comparisons([dict(row, seed1=row[candidate]) for row in rows])
|
|
for m in out.values():
|
|
m['means'][candidate] = m['means'].pop('seed1')
|
|
m['components'][candidate] = m['components'].pop('seed1')
|
|
m['part_counts'][candidate] = m['part_counts'].pop('seed1')
|
|
m['undefined_parts'][candidate] = m['undefined_parts'].pop('seed1')
|
|
m['candidate_minus_seed0'] = m.pop('seed1_minus_seed0')
|
|
return out
|
|
|
|
|
|
def decision(item, metrics, seed_metrics):
|
|
primary = 'last_location' if item == 'c' else 'relative_l2'
|
|
delta = metrics[primary]['candidate_minus_seed0']
|
|
field = metrics['relative_l2']['candidate_minus_seed0']
|
|
if delta['components'] != 204 or field['components'] != 204:
|
|
return dict(status='INCOMPLETE_PRIMARY_PAIR_SUPPORT', primary=primary)
|
|
if seed_metrics is None or seed_metrics[primary]['seed1_minus_seed0']['components'] != 204:
|
|
return dict(status='WAIT_SEED_REFERENCE', primary=primary)
|
|
noise = seed_metrics[primary]['seed1_minus_seed0']
|
|
if noise['component_ids'] != delta['component_ids']:
|
|
raise ValueError('Seed and candidate contrasts must have identical components')
|
|
magnitude_pass = abs(delta['value']) > abs(noise['value'])
|
|
if item == 'c':
|
|
gate = delta['value'] <= -.010 and delta['high'] < 0 and field['high'] < .001
|
|
else:
|
|
gate = field['high'] < -.001
|
|
return dict(status='PASSES_OLD_CORPUS_SCREEN' if gate and magnitude_pass else 'DOES_NOT_PASS_FIXED_SCREEN',
|
|
primary=primary, registered_metric_gate=gate, exceeds_same_endpoint_seed_difference=magnitude_pass,
|
|
signed_candidate_delta=delta['value'], signed_seed1_minus_seed0=noise['value'],
|
|
independent_fresh_family_confirmation=False)
|
|
|
|
|
|
def tail_comparisons(rows, item, include_seed):
|
|
groups = {}
|
|
for row in rows:
|
|
groups.setdefault(row['component_id'], []).append(row)
|
|
arms = [item, 'seed0'] + (['seed1'] if include_seed else [])
|
|
values = {}
|
|
for key in ('E_tail', 'Miss', 'False_alarm'):
|
|
by_arm = {arm:{g:math.fsum(r['tail']['arms'][arm]['overlap'][key] for r in parts) / len(parts)
|
|
for g, parts in groups.items()} for arm in arms}
|
|
values[key] = dict(
|
|
means={arm:math.fsum(v.values())/len(v) for arm,v in by_arm.items()},
|
|
candidate_minus_seed0=paired_difference(by_arm[item], by_arm['seed0']),
|
|
seed1_minus_seed0=paired_difference(by_arm['seed1'], by_arm['seed0']) if include_seed else None,
|
|
)
|
|
return dict(metrics=values, parts=len(rows), components=len(groups), secondary_endpoint='E_tail',
|
|
seed1_regional_status='COMPLETE' if include_seed else 'NOT_COMPUTED',
|
|
constant_truth_parts=sum(r['tail']['truth']['constant_field'] for r in rows),
|
|
truth_threshold_tied_parts=sum(r['tail']['truth']['plateau_nodes'] > 1 for r in rows),
|
|
arms={arm:dict(
|
|
threshold_tied_parts=sum(r['tail']['arms'][arm]['prediction']['plateau_nodes'] > 1 for r in rows),
|
|
peak={domain:dict(
|
|
certified=sum(r['tail']['arms'][arm][domain]['certified'] for r in rows),
|
|
near_boundary=sum(r['tail']['arms'][arm][domain]['near_boundary'] for r in rows),
|
|
trivial_radius=sum(r['tail']['arms'][arm][domain]['trivial_radius'] for r in rows),
|
|
categories={key:sum(r['tail']['arms'][arm][domain]['category'] == key for r in rows)
|
|
for key in sorted({r['tail']['arms'][arm][domain]['category'] for r in rows})},
|
|
) for domain in ('query','full')},
|
|
) for arm in arms})
|