FixedRandomSampler

class axtreme.data.fixed_random_sample.FixedRandomSampler(data_source: Sized, num_samples: int | None = None, seed: int | None = None, *, replacement: bool = False)

Bases: Sampler[int]

Samples elements randomly.

This sampler differs from torch’s RandomSampler as it will return the same random sample each time it is iterated in full. If without replacement, then sample from a shuffled dataset. If with replacement, then user can specify num_samples to draw.

__init__(data_source: Sized, num_samples: int | None = None, seed: int | None = None, *, replacement: bool = False) None

Initalise the sampler.

Parameters:
  • data_source – dataset to sample from

  • replacement – samples are drawn on-demand with replacement if True, default=``False``

  • num_samples – number of samples to draw, default=`len(dataset)`.

  • seed – seed for the random number generator, if None one will be allocated randomly.

Methods

__init__(data_source[, num_samples, seed, ...])

Initalise the sampler.

Attributes

data_source: Sized
property num_samples: int
replacement: bool