examples for sampler
https://github.com/mlverse/torch/blob/main/man/sampler.Rd#L23 references an examples section which does not exist on that man page. Can it be added please? Maybe based on https://docs.pytorch.org/docs/stable/data.html#torch.utils.data.Sampler ?
the simplest "example" I can find of a usage of sampler, is in the source code: https://github.com/mlverse/torch/blob/main/R/utils-data-sampler.R#L57
SequentialSampler <- sampler(
name = "utils_sampler_sequential",
initialize = function(data_source) {
self$data_source <- data_source
},
.iter_batch = function(batch_size) {
n <- length(self$data_source)
as_batch_iterator(seq_len(n), batch_size)
},
.iter = function() {
self$.iter_batch(1L)
},
.length = function() {
length(self$data_source)
}
)
however this uses as_batch_iterator, which is not exported. @dfalbel can you please explain what would be an acceptable way forward, to allow users to define their own samplers? Can as_batch_iterator be exported? Or can users make it work without using that?
here is an example that seems to work. https://github.com/mlr-org/mlr3torch/issues/417#issuecomment-3109001613 would it be acceptable to submit a PR which adds this as an example?