braindecode.samplers.BalancedSequenceSampler¶
- class braindecode.samplers.BalancedSequenceSampler(metadata, n_windows, n_sequences=10, random_state=None)¶
Balanced sampling of sequences of consecutive windows with categorical targets.
Balanced sampling of sequences inspired by the approach of [Perslev2021]: 1. Uniformly sample a recording out of the available ones. 2. Uniformly sample one of the classes. 3. Sample a window of the corresponding class in the selected recording. 4. Extract a sequence of windows around the sampled window.
- Parameters
- metadatapd.DataFrame
See RecordingSampler. Must contain a column target with categorical targets.
- n_windowsint
Number of consecutive windows in a sequence.
- n_sequencesint
Number of sequences to sample.
- random_statenp.random.RandomState | int | None
Random state.
References
- Perslev2021
Perslev M, Darkner S, Kempfner L, Nikolic M, Jennum PJ, Igel C. U-Sleep: resilient high-frequency sleep staging. npj Digit. Med. 4, 72 (2021). https://github.com/perslev/U-Time/blob/master/utime/models/usleep.py
Methods
- sample_class(rec_ind=None)¶
Return a random class.
- Parameters
- rec_indint | None
Index to the recording to sample from. If None, the recording will be uniformly sampled across available recordings.
- Returns
- int
Sampled class.
- int
Index to the recording the class was sampled from.