braindecode.samplers.RelativePositioningSampler

class braindecode.samplers.RelativePositioningSampler(metadata, tau_pos, tau_neg, n_examples, tau_max=None, same_rec_neg=True, random_state=None)

Sample examples for the relative positioning task from [1].

Sample examples as tuples of two window indices, with a label indicating whether the windows are close or far, as defined by tau_pos and tau_neg.

Parameters
metadatapd.DataFrame

See RecordingSampler.

tau_posint

Size of the positive context, in samples. A positive pair contains two windows x1 and x2 which are separated by at most tau_pos samples.

tau_negint

Size of the negative context, in samples. A negative pair contains two windows x1 and x2 which are separated by at least tau_neg samples and at most tau_max samples. Ignored if same_rec_neg is False.

n_examplesint

Number of pairs to extract.

tau_maxint | None

See tau_neg.

same_rec_negbool

If True, sample negative pairs from within the same recording. If False, sample negative pairs from two different recordings.

random_stateNone | np.RandomState | int

Random state.

References

1

Banville, H., Chehab, O., Hyvärinen, A., Engemann, D. A., & Gramfort, A. (2020). Uncovering the structure of clinical EEG signals with self-supervised learning. arXiv preprint arXiv:2007.16104.

Attributes
n_recordings

Methods

presample()

Presample examples.

sample_recording()

Return a random recording index.

sample_window([rec_ind])

Return a specific window.

__iter__()

Iterate over pairs.

Yields
(int): position of the first window in the dataset.

(int): position of the second window in the dataset. (float): 0 for negative pair, 1 for positive pair.

presample()

Presample examples.

Once presampled, the examples are the same from one epoch to another.

sample_recording()

Return a random recording index.

sample_window(rec_ind=None)

Return a specific window.

Examples using braindecode.samplers.RelativePositioningSampler