sampler function

Creates a new Sampler

Creates a new Sampler

Samplers can be used with dataloader() when creating batches from a torch dataset().

sampler( name = NULL, inherit = Sampler, ..., private = NULL, active = NULL, parent_env = parent.frame() )

Arguments

  • name: (optional) name of the sampler
  • inherit: (optional) you can inherit from other samplers to re-use some methods.
  • ...: Pass any number of fields or methods. You should at least define the initialize and step methods. See the examples section.
  • private: (optional) a list of private methods for the sampler
  • active: (optional) a list of active methods for the sampler.
  • parent_env: used to capture the right environment to define the class. The default is fine for most situations.

Details

A sampler must implement the .iter and .length() methods.

  • initialize takes in a data_source. In general this is a dataset().
  • .iter returns a function that returns a dataset index everytime it's called.
  • .length returns the maximum number of samples that can be retrieved from that sampler.
  • Maintainer: Daniel Falbel
  • License: MIT + file LICENSE
  • Last published: 2025-02-14