mlr-org / ParamHelpers

Helpers for parameters in black-box optimization, tuning and machine learning.
https://paramhelpers.mlr-org.com
Other
25 stars 9 forks source link

generateGridDesign may create integer columns for numeric parameters, makes dfRow[s]ToList fail #205

Open mb706 opened 5 years ago

mb706 commented 5 years ago

When using generateGridDesign with a "numeric" parameter that has integer typed lower and upper bounds, and with a resolution that leads to integer valued grid points, the resulting df column is of type integer instead of numeric:

> ps = makeParamSet(makeNumericParam("test", 0L, 10L))
> design = generateGridDesign(ps, 11)
> str(design)
'data.frame':   11 obs. of  1 variable:
 $ test: int  0 1 2 3 4 5 6 7 8 9 ...
 - attr(*, "trafo")= logi FALSE

This confuses dfRow[s]ToList:

> dfRowToList(design, ps, 1)
Error in dfRowsToList(df = df, par.set = par.set, enforce.col.types = enforce.col.types,  :
  REAL() can only be applied to a 'numeric', not a 'integer'

Which ultimately leads to mlr-org/mlr#2493: doing grid search with integer parameter bounds and a fitting grid resolution fails. One could say that the user should not give integer typed bounds to makeNumericParam, but R makes otherwise basically no distinction between the integer and floating point type, so ParamHelpers should not unexpectedly fail here. Either generateGridDesign should make sure a numeric parameter's column is not integer typed, or dfRow[s]ToList should be able to handle integer columns for numeric parameters. (Probably both.)