sleepless.data.utils#
Common utilities.
Functions
|
Handle list which are a mix of channel type and channel names. |
|
Compute the weights of all the samples of the dataset to balance the cross-entropy criterion. |
|
Plot raw signal with annotation using MNE plot function. |
|
Classes
|
|
|
PyTorch dataset wrapper around Sample list. |
- sleepless.data.utils.plot_PSG_and_annotation(raw_obj, annot_obj)[source]#
Plot raw signal with annotation using MNE plot function.
- class sleepless.data.utils.ListSampleDataset(sample, normalize, pick_chan, n_past_epochs=0)[source]#
Bases:
Dataset
PyTorch dataset wrapper around Sample list. This Class takes a py:class:DelayedSample`or :py:class:`Sample object and generate a object as
torch.utils.data.dataset.Dataset
where every sample of the dataset is defined as a list. It supports indexing such that dataset[i] can be used to get the i-th sample.- Parameters:
sample (
DelayedSample
|Sample
) – sample to be wrap into the dataset objectnormalize (
bool
) – if set to True, we remove the mean of data, and divided them by the standard deviation (it is done epoch (window) wise)pick_chan (
Optional
[dict
[str
,bool
|list
[str
]]]) – the channel type (e.g. “eeg”,”eog”) or name (e.g. “Fpz-Cz”) whom extract the features, if None default compute features for all EEG channels.n_past_epochs (
int
) – it indicates how many past epochs to concatenate to the current sample epoch. E.g. if n_past_epochs = 1, then one past epoch is concatenated to the current.
- sleepless.data.utils.get_samples_weights(dataset)[source]#
Compute the weights of all the samples of the dataset to balance the cross-entropy criterion. This function takes as input a
torch.utils.data.dataset.Dataset
and computes the weights to balance each class in the dataset and the datasets themselves if we have a ConcatDataset.- Parameters:
dataset (
ConcatDataset
|Dataset
) – torch.utils.data.dataset.Dataset An instance of torch.utils.data.dataset.Dataset ConcatDataset are supported- Returns:
torch.Tensor
the weights for all the samples in the dataset given as input
- sleepless.data.utils.chan_list_to_dict(chan_list)[source]#
Handle list which are a mix of channel type and channel names. To be use then with the
mne.pick_types()
- Parameters:
chan_list (
list
[str
]) – list of channel which can be channel type or channel names- Return type:
- Returns:
dictionary where recognized channel types are assigned as key and their value set to true and other channels are expected to be channel names and are placed in a list, the key of this list is “include”. See
mne.pick_types()
for more information