annbatch.samplers.WeightedClassSampler#
- class annbatch.samplers.WeightedClassSampler(chunk_size, preload_nchunks, batch_size, *, classes, num_samples, class_weights=None, mask=None, drop_last=False, rng=None)#
Sample batches whose class composition follows
class_weights.Chunks are read exactly as
ClassSamplerreads them – one class per chunk – but the rows of a whole preload window are shuffled together before being split into batches, so each batch mixes classes in expectation proportionally to their weights instead of being drawn from a single class.
Attributes table#
The batch size for data loading. |
|
The observation range this sampler operates on. |
|
The random number generator used by this sampler. |
|
Whether data is shuffled. |
Methods table#
Attributes#
- WeightedClassSampler.batch_size#
- WeightedClassSampler.mask#
- WeightedClassSampler.rng#
The random number generator used by this sampler.
- WeightedClassSampler.shuffle#
Methods#
- WeightedClassSampler.n_batches(n_obs)#
Return the number of batches.
- WeightedClassSampler.sample(n_obs)#
Sample load requests given the total number of observations.
Base implementation simply calls
validate()and then yields via_sample().- Parameters:
- n_obs
int The total number of observations available.
- n_obs
- Yields:
LoadRequest – Load requests for batching data.
- Return type: