tidymodels / dials

Tools for creating tuning parameter values
https://dials.tidymodels.org/
Other
111 stars 26 forks source link

Possible bug with `batch_size()` parameter? #177

Closed tonyk7440 closed 3 years ago

tonyk7440 commented 3 years ago

The problem

I'm trying to generate a parameter grid using the parameter batch_size, I know this has an unknown range like mtry so I thought defining a range would work but it seems like the numbers are encountering a possible coercion problem and producing a column of NA's, not sure if it is a bug?

Reproducible example

library(dials)
#> Loading required package: scales

grid_spec_xg <- grid_latin_hypercube(
  parameters(
    tree_depth(),
    mtry(range = c(1L, 20L))
  ),
  size = 5
)

grid_spec_xg
#> # A tibble: 5 x 2
#>   tree_depth  mtry
#>        <int> <int>
#> 1          8     5
#> 2          5    17
#> 3          1     1
#> 4         10    15
#> 5         14     9

grid_spec_deep_ar <- grid_latin_hypercube(
  parameters(
    epochs(c(10, 20)), 
    batch_size(range = c(32, 64))
  ),
  size = 5
)
#> Warning in encode_unit.quant_param(.x[[i]], .y[[i]], ...): NAs introduced by
#> coercion to integer range

grid_spec_deep_ar
#> # A tibble: 4 x 2
#>   epochs batch_size
#>    <int>      <int>
#> 1     12         NA
#> 2     18         NA
#> 3     14         NA
#> 4     16         NA

Created on 2021-08-24 by the reprex package (v2.0.1)

EmilHvitfeldt commented 3 years ago

batch_size() defaults to a log2 transformation. This is the reason you are getting the error because batch_size() tried to create integers between 2^32 and 2^64 both of which are above the integer limit of your machine

.Machine$integer.max
#> [1] 2147483647

2^32
#> [1] 4294967296

If you want the range to be between 32 and 64, you can set the range to be c(5, 6).

library(dials)
#> Loading required package: scales

grid_spec_deep_ar <- grid_latin_hypercube(
  parameters(
    epochs(c(10, 20)), 
    batch_size(range = c(5, 6))
  ),
  size = 5
)

grid_spec_deep_ar
#> # A tibble: 5 × 2
#>   epochs batch_size
#>    <int>      <int>
#> 1     12         50
#> 2     19         56
#> 3     13         36
#> 4     17         40
#> 5     14         44

Created on 2021-08-24 by the reprex package (v2.0.1)

tonyk7440 commented 3 years ago

Ah I see, you are right, that is great, thanks very much for the help! I'll close the issue

github-actions[bot] commented 3 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.