Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Suggests:
ggplot2,
future, future.apply
VignetteBuilder: knitr
Remotes: mlr-org/mlr3torch@dont-require-batch-size
10 changes: 3 additions & 7 deletions man/batch_sampler_stratified.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,20 @@ count_tab/sum(count_tab) # ~10% R, ~90% M.

## Not a typical use case, but shows class distribution in each batch.
sonar_list <- list(task=sonar_task)
batch_sampler_class <- mlr3torchAUM::batch_sampler_stratified(
min_samples_per_stratum = 1)
batch_sampler_class <- mlr3torchAUM::batch_sampler_stratified(min_samples_per_stratum = 1)
batch_sampler_instance <- batch_sampler_class(sonar_list)
## In the counts below there is 1 R per batch/column.
sapply(batch_sampler_instance$batch_list, function(i)table(Class_vec[i]))

## Whereas some batches have 0 R with random:
random_sampler_class <- mlr3torchAUM::batch_sampler_random(
batch_size = 10)
random_sampler_class <- mlr3torchAUM::batch_sampler_random(batch_size = 10)
random_sampler_instance <- random_sampler_class(sonar_list)
sapply(random_sampler_instance$batch_list, function(i)table(Class_vec[i]))

## Typical use case below is as the batch_sampler param in a TorchLearner.
if(torch::torch_is_installed() && requireNamespace("mlr3torch")){
L <- mlr3torch::LearnerTorchMLP$new(task_type="classif")
L$param_set$set_values(
epochs=1, batch_size=10, seed=1,
batch_sampler=batch_sampler_class)
L$param_set$set_values(epochs=1, shuffle=NULL, batch_sampler=batch_sampler_class)
L$train(sonar_task)
}

Expand Down
2 changes: 1 addition & 1 deletion vignettes/Typical_usage.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ if(torch_available){
L$predict_type <- "prob"
L$callbacks <- mlr3torch::t_clbk("history")
L$param_set$set_values(
epochs=20, batch_size=batch_size, seed=1,
epochs=20, shuffle=NULL, seed=1,
measures_valid=measure_list,
measures_train=measure_list,
batch_sampler=batch_sampler_list[[batching]])
Expand Down
Loading