Sampler

Sampler define the way of iterating over the dataset and returning samples.

AbstractSampler

class AbstractSampler(indices=None)[source]

Bases: object

Class to define an abstract Sampling API

_get_indices(n_indices)[source]

Function to return a specific number of indices. Implements the actual sampling strategy.

Parameters:n_indices (int) – Number of indices to return
Returns:List with sampled indices
Return type:list
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset, **kwargs)[source]

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler

LambdaSampler

class LambdaSampler(indices, sampling_fn)[source]

Bases: delira.data_loading.sampler.abstract_sampler.AbstractSampler

Implements Arbitrary Sampling methods specified by a function which takes the index_list and the number of indices to return

_get_indices(n_indices)[source]

Actual Sampling

Parameters:n_indices (int) – number of indices to return
Returns:list of sampled indices
Return type:list
Raises:StopIteration – Maximum number of indices sampled
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset, **kwargs)

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler

RandomSampler

class RandomSampler(indices)[source]

Bases: delira.data_loading.sampler.abstract_sampler.AbstractSampler

Implements Random Sampling from whole Dataset

_get_indices(n_indices)[source]

Actual Sampling

Parameters:n_indices (int) – number of indices to return
Returns:list of sampled indices
Return type:list
Raises:StopIteration – If maximal number of samples is reached
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset, **kwargs)

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler

PrevalenceRandomSampler

class PrevalenceRandomSampler(indices, shuffle_batch=True)[source]

Bases: delira.data_loading.sampler.abstract_sampler.AbstractSampler

Implements random Per-Class Sampling and ensures same number of samplers per batch for each class

_get_indices(n_indices)[source]

Actual Sampling

Parameters:n_indices (int) – number of indices to return
Returns:list of sampled indices
Return type:list
Raises:StopIteration – If maximal number of samples is reached
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset, **kwargs)[source]

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler

StoppingPrevalenceRandomSampler

class StoppingPrevalenceRandomSampler(indices, shuffle_batch=True)[source]

Bases: delira.data_loading.sampler.abstract_sampler.AbstractSampler

Implements random Per-Class Sampling and ensures same number of samplers per batch for each class; Stops if out of samples for smallest class

_get_indices(n_indices)[source]

Actual Sampling

Parameters:n_indices (int) – number of indices to return
Raises:StopIteration: If end of class indices is reached for one class
Returns:list
Return type:list of sampled indices
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset, **kwargs)[source]

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler

SequentialSampler

class SequentialSampler(indices)[source]

Bases: delira.data_loading.sampler.abstract_sampler.AbstractSampler

Implements Sequential Sampling from whole Dataset

_get_indices(n_indices)[source]

Actual Sampling

Parameters:n_indices (int) – number of indices to return
Raises:StopIteration : If end of dataset reached
Returns:list of sampled indices
Return type:list
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset, **kwargs)

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler

PrevalenceSequentialSampler

class PrevalenceSequentialSampler(indices, shuffle_batch=True)[source]

Bases: delira.data_loading.sampler.abstract_sampler.AbstractSampler

Implements Per-Class Sequential sampling and ensures same number of samples per batch for each class; If out of samples for one class: restart at first sample

_get_indices(n_indices)[source]

Actual Sampling

Parameters:n_indices (int) – number of indices to return
Raises:StopIteration : If end of class indices is reached
Returns:list of sampled indices
Return type:list
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset, **kwargs)[source]

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler

StoppingPrevalenceSequentialSampler

class StoppingPrevalenceSequentialSampler(indices, shuffle_batch=True)[source]

Bases: delira.data_loading.sampler.abstract_sampler.AbstractSampler

Implements Per-Class Sequential sampling and ensures same number of samples per batch for each class; Stops if all samples of first class have been sampled

_get_indices(n_indices)[source]

Actual Sampling

Parameters:n_indices (int) – number of indices to return
Raises:StopIteration : If end of class indices is reached for one class
Returns:list of sampled indices
Return type:list
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset)[source]

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler

WeightedRandomSampler

class WeightedRandomSampler(indices, weights=None, cum_weights=None)[source]

Bases: delira.data_loading.sampler.abstract_sampler.AbstractSampler

Implements Weighted Random Sampling

_get_indices(n_indices)[source]

Actual Sampling

Parameters:

n_indices (int) – number of indices to return

Returns:

list of sampled indices

Return type:

list

Raises:
  • StopIteration – If maximal number of samples is reached
  • TypeError – if weights and cum_weights are specified at the same time
  • ValueError – if weights or cum_weights don’t match the population
classmethod from_dataset(dataset: delira.data_loading.dataset.AbstractDataset, **kwargs)[source]

Classmethod to initialize the sampler from a given dataset

Parameters:dataset (AbstractDataset) – the given dataset
Returns:The initialzed sampler
Return type:AbstractSampler