protosleepnet.figure_reconstruction.threshold_sweep#
Joint sweep of the six thresholds of the AASM-inspired coherence checklist.
Feeds Supplementary Note 6 (threshold sweeps and joint margins, Table “How far the checklist thresholds can move”, prototype by prototype) and the “Threshold margin” column of main-text Table 2. Optionally draws the tolerance curve.
The checklist is boolean logic on a handful of per-prototype quantities that are already stored, so re-evaluating it on a grid needs no GPU and no retraining. There is no sweep range chosen by the analyst: the rule is “every threshold is free to vary by +/- t of its own value, all six together”, and the result is reported for every t. For each prototype the break margin is the smallest tolerance at which its verdict can change. The enumeration is exact (no sampling): a verdict depends only on the criteria of the prototype’s own stage, and a criterion “x exceeds T” has a single breakpoint, x. The percentile cuts sit at 50 +/- 10 rank points and it is the half-width that varies, so the two cuts stay ordered.
- Three things are computed:
one-at-a-time sweeps (the other thresholds stay at their published value) over the ranges Wake alpha 5-20%, N2 sigma 10-25%, REM EOG 20-40%, N1 alpha 3-10%, N3 delta 20-50%, and percentile cuts 55/45, 60/40 and 70/30;
the tolerance curve (number of verdicts unchanged, and range of the coherent count, when all six thresholds move together by t) and the per-prototype break margin;
propagation: prototypes in which a criterion flips without moving the verdict.
Published rules (thresholds): Wake alpha > 10%, N1 alpha < 5%, N2 sigma > 15% in either sub-band, N3 delta > 30%, REM EOG share > 30%, tonic/active > 60th percentile, atonic/quiescent < 40th. The rule set below is the parametric form of the checklist in rule_learning.PHYSIOLOGY_CHECKLIST (which hard-codes the published values); at the published values the two agree and the sweep must reproduce 10 coherent / 10 partial / 4 non-canonical entries or it stops.
- Inputs (per backbone <reconstructions>/<model>/<method>/):
ablation/proto_NNN/metadata.json stage, band direction, band relevance, channel shares spectral_analysis/statistics/proto_NNN.json EOG total power, EMG tone
Outputs: <root>/analysis/threshold_sweep/threshold_sweep.json (and the figure when asked).
- Usage:
- python -m protosleepnet.figure_reconstruction.threshold_sweep
[–reconstructions data/reconstructions/M12] [–root outputs/protosleepnet] [–figure curve.pdf]
Attributes#
Functions#
|
Checklist criteria of stage (default: the prototype's own), one per element, under the |
|
Tolerance curve: one step per prototype whose verdict changes, coloured by stage. |
|
The 24 per-prototype records (12 per backbone) of one reconstruction method. |
|
|
|
Smallest tolerance at which the verdict can change, by bisection. None if it does not |
|
Number of verdicts that move, per threshold, over its declared range. |
|
Verdicts the prototype can take when every threshold of its stage moves by up to +/- t. |
|
Percentile rank within a codebook: the share of strictly smaller values, in percent |
|
Values to try for one threshold at tolerance t: both ends of the interval plus the |
|
C (all criteria), P (at least half), X (fewer than half). |
Module Contents#
- protosleepnet.figure_reconstruction.threshold_sweep.criteria(d: dict, thr: dict, stage: str | None = None) list[bool]#
Checklist criteria of stage (default: the prototype’s own), one per element, under the thresholds thr. Percentile ranks stay those of the prototype’s codebook.
- protosleepnet.figure_reconstruction.threshold_sweep.draw_figure(data: dict, dest: pathlib.Path) None#
Tolerance curve: one step per prototype whose verdict changes, coloured by stage.
- protosleepnet.figure_reconstruction.threshold_sweep.load_records(recon: pathlib.Path, method: str = 'hybrid') list[dict]#
The 24 per-prototype records (12 per backbone) of one reconstruction method.
- protosleepnet.figure_reconstruction.threshold_sweep.margin(d: dict, base: str, maximum: float = 3.0, steps: int = 40) float | None#
Smallest tolerance at which the verdict can change, by bisection. None if it does not change even at maximum.
- protosleepnet.figure_reconstruction.threshold_sweep.one_at_a_time(records: list[dict], base: list[str]) dict[str, int]#
Number of verdicts that move, per threshold, over its declared range.
- protosleepnet.figure_reconstruction.threshold_sweep.outcomes(d: dict, t: float) set[str]#
Verdicts the prototype can take when every threshold of its stage moves by up to +/- t.
- protosleepnet.figure_reconstruction.threshold_sweep.rank(value: float, values: list[float]) float#
Percentile rank within a codebook: the share of strictly smaller values, in percent (equivalent to np.searchsorted(sorted(values), value) / len(values) * 100).
- protosleepnet.figure_reconstruction.threshold_sweep.thresholds_at_tolerance(key: str, t: float) list[float]#
Values to try for one threshold at tolerance t: both ends of the interval plus the published value. A criterion “x exceeds T” is monotone in T, so the ends exhaust the outcomes.
- protosleepnet.figure_reconstruction.threshold_sweep.verdict(d: dict, thr: dict, stage: str | None = None) str#
C (all criteria), P (at least half), X (fewer than half).
- protosleepnet.figure_reconstruction.threshold_sweep.DEFAULT_RECON#
- protosleepnet.figure_reconstruction.threshold_sweep.EXPECTED_COUNTS = (10, 10, 4)#
- protosleepnet.figure_reconstruction.threshold_sweep.GRID#
- protosleepnet.figure_reconstruction.threshold_sweep.HALF_WIDTH = 10.0#
- protosleepnet.figure_reconstruction.threshold_sweep.MODELS#
- protosleepnet.figure_reconstruction.threshold_sweep.PUBLISHED#
- protosleepnet.figure_reconstruction.threshold_sweep.STAGES = ['W', 'N1', 'N2', 'N3', 'REM']#
- protosleepnet.figure_reconstruction.threshold_sweep.TOLERANCES = [0.1, 0.2, 0.25, 0.33, 0.5, 0.75, 1.0]#
- protosleepnet.figure_reconstruction.threshold_sweep.USES#