protosleepnet.clinical_probing.subject_stats#

Per-subject records for the clinical cohorts: kept epochs, embeddings and prototype assignment.

For each clinical cohort (ASD = alzheimers, KPD = parkinsons) and backbone it reads the frozen epoch embeddings and expert stage labels, keeps the staged epochs inside the analysis window (ASD: all staged epochs; KPD: staged epochs from the LIGHTS_OFF marker onwards, because the recordings start long before sleep and the pre-sleep epochs are not sleep), assigns each kept epoch to its nearest prototype for each codebook size M, and writes one npz per (cohort, backbone, M). Also stored: disease label, recording-hardware variant (KPD chin-EMG channel name: 0 = EMG Chin family, 1 = EMG1; always 0 for ASD) and covariates (age, AHI, RBDSQ, staged fraction). Expert stages are used only to define the window, never as features.

Feeds Supplementary Note 7 (Table tab:cp_dictionary) through protosleepnet.clinical_probing.build_features.

Inputs (under --root):

epoch-embeddings/<model>/<cohort dir>/all/<sid>_{embeddings.npy,labels.npy,metadata.json} models/<model>/vq_kmeans/<M>/codebook.npy KPD raw recordings under --raw (<sid>/<sid>_r1_a1.tsv, <sid>/<sid>_r1.edf)

Outputs (under --out, default <root>/analysis/clinical_probing):
stats/<cohort>_<backbone>_M<M>.npz keys: sids, label, hw, offsets (n_subjects+1), idx, emb,

assign, d1, age, ahi, rbdsq, staged_fraction; per-epoch arrays are concatenated, subject i is [offsets[i]:offsets[i+1]]

Usage:
python -m protosleepnet.clinical_probing.subject_stats –cohorts alzheimers,parkinsons

–backbones seq,st –Ms 15,32,65,100 [–root DIR] [–raw DIR] [–out DIR]

Attributes#

Functions#

build(cohort, backbone, Ms, root, raw, out)

default_out(root)

hardware_variant(raw, sid)

Recording-hardware variant from the chin-EMG channel name in the EDF header.

lights_off_epoch(raw, sid)

Epoch at which the lights go off, from the annotation marker; None if absent.

load_cohort(root, backbone, cohort)

Embeddings, expert stages and disease label per subject.

load_metadata(root, cohort, sids)

Covariates stored with the sequence-backbone embeddings.

main()

stats_path(cohort, backbone, M, out)

window_mask(subject, criterion[, lights])

Boolean mask over the embedding epochs: staged and inside the window.

Module Contents#

protosleepnet.clinical_probing.subject_stats.build(cohort, backbone, Ms, root, raw, out)#
protosleepnet.clinical_probing.subject_stats.default_out(root)#
protosleepnet.clinical_probing.subject_stats.hardware_variant(raw, sid)#

Recording-hardware variant from the chin-EMG channel name in the EDF header.

protosleepnet.clinical_probing.subject_stats.lights_off_epoch(raw, sid)#

Epoch at which the lights go off, from the annotation marker; None if absent.

protosleepnet.clinical_probing.subject_stats.load_cohort(root, backbone, cohort)#

Embeddings, expert stages and disease label per subject.

protosleepnet.clinical_probing.subject_stats.load_metadata(root, cohort, sids)#

Covariates stored with the sequence-backbone embeddings.

protosleepnet.clinical_probing.subject_stats.main()#
protosleepnet.clinical_probing.subject_stats.stats_path(cohort, backbone, M, out)#
protosleepnet.clinical_probing.subject_stats.window_mask(subject, criterion, lights=None)#

Boolean mask over the embedding epochs: staged and inside the window.

protosleepnet.clinical_probing.subject_stats.CHIN_CHANNELS = ['EMG Chin', 'EMG Chin1', 'EMG chin', 'EMG1']#
protosleepnet.clinical_probing.subject_stats.COHORTS#
protosleepnet.clinical_probing.subject_stats.CRITERION#
protosleepnet.clinical_probing.subject_stats.DEFAULT_ROOT#
protosleepnet.clinical_probing.subject_stats.EPOCH = 30.0#
protosleepnet.clinical_probing.subject_stats.HW_VARIANT#
protosleepnet.clinical_probing.subject_stats.LIGHTS = ('LIGHTS_OFF', 'LIGHT_OFF')#
protosleepnet.clinical_probing.subject_stats.STAT_KEYS = ('sids', 'label', 'hw', 'offsets', 'idx', 'emb', 'assign', 'd1', 'age', 'ahi', 'rbdsq',...#