braindecode.samplers.BalancedSequenceSampler#

class braindecode.samplers.BalancedSequenceSampler(metadata, n_windows, n_sequences=10, random_state=None)[source]#

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:
  • metadata (pd.DataFrame) – See RecordingSampler. Must contain a column target with categorical targets.

  • n_windows (int) – Number of consecutive windows in a sequence.

  • n_sequences (int) – Number of sequences to sample.

  • random_state (np.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). perslev/U-Time

Methods

sample_class(rec_ind=None)[source]#

Return a random class.

Parameters:

rec_ind (int | 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.