yanyachen / rBayesianOptimization

Bayesian Optimization of Hyperparameters
81 stars 21 forks source link

names of init_grid and bounds have to be in the same order #20

Open scworland opened 7 years ago

scworland commented 7 years ago

Currently, the names of the initial grid data frame and the names of the bounds list have to be in the exact same order, otherwise there is an error. The issue is with the following code:

identical(names(init_grid_dt), c(DT_bounds[, Parameter], "Value"))

From the init_grid_dt loop:

  ## init_grid_dt
  setDT(init_grid_dt)
  if (nrow(init_grid_dt) != 0) {
    if (identical(names(init_grid_dt), DT_bounds[, Parameter]) == TRUE) {
      init_grid_dt[, Value := -Inf]
    } else if (identical(names(init_grid_dt), c(DT_bounds[, Parameter], "Value")) == TRUE) {
      paste(nrow(init_grid_dt), "points in hyperparameter space were pre-sampled\n", sep = " ") %>%
        cat(.)
    } else {
      stop("bounds and init_grid_dt should be compatible")
    }
  }

Unless I am missing something, wouldn't setequal accomplish the same thing and avoid the ordering issue?

one <- c("a","b")
two <- c("b","a")

identical(one,two)
[1] FALSE

setequal(one,two)
[2] TRUE