class
SubsetRandomSampler
extends
SamplerSubsetRandomSampler(indices: Sequence[int], generator: Generator | int | None = None)Yield a random permutation of a fixed list of indices each epoch.
Useful when the caller already knows which subset of the dataset should be visited (e.g., a precomputed train/val split) and only wants shuffling among that subset.
Parameters
indiceslist of intIndices into the parent dataset to sample from.
Stream the order is drawn from; advances from epoch to epoch.
None (default) draws from the default generator, so
lucid.manual_seed reproduces the order.Notes
The index pool itself is fixed at construction time; only the
order changes between epochs. Useful with precomputed
cross-validation folds — store the per-fold index list once, then
instantiate one SubsetRandomSampler per fold.
Examples
>>> fold_indices = [3, 5, 7, 9, 11]
>>> sampler = SubsetRandomSampler(fold_indices)
>>> sorted(list(sampler)) == fold_indices
TrueUsed by 1
Constructors
1dunder
__init__
→None__init__(indices: Sequence[int], generator: Generator | int | None = None)Store the index pool and optional generator handle.
Parameters
indicessequence of intIndices to sample from.
See class docstring.