mlr-org / mlr3mbo

Flexible Bayesian Optimization in R
https://mlr3mbo.mlr-org.com
25 stars 1 forks source link

mlr3mbo 0.2.3 replacements for Archive #151

Closed hududed closed 3 months ago

hududed commented 3 months ago

I have some code with Archive that was running ok with mlr3mbo 0.2.2 (and maybe bbotk 0.8.0), for example:

archive$add_evals(xdt = data[, names(parameter_info), with = FALSE],
                  ydt = data[, output_column_names, with = FALSE])

tmp_archive = archive$clone(deep = TRUE)

for (col_name in archive$cols_y) {
                    min_values[, (col_name) := min_value(archive$data[[col_name]])]
                }

And these functions are no longer there in mlr3mbo 0.2.3 (bbotk 1.0.1) - how are these replaced?

sumny commented 3 months ago

Hi @hududed can you elaborate which functions exactly are no longer there in mlr3mbo >= 0.2.3? archive$cols_y should still exist as a field; regarding min_value I am not sure if it was part of package and if yes of which. Or are you referring to another function? If yes, which?

hududed commented 3 months ago

Ah my mistake I guess not for all those functions. For example

library(mlr3mbo)
library(mlr3)
library(mlr3learners)
library(bbotk)
library(data.table)
library(tibble)

    data = data.table(
      Power = c(45, 14, 66, 12, 23, 40, 56, 64, 48),
      Speed = c(49, 33, 30, 22, 46, 15, 20, 25, 12),
      DPI = c(5, 5, 7, 3, 2, 5, 6, 3, 5),
      N2gas = c(1, 0, 0, 1, 0, 1, 0, 0, 1),
      Defocus = c(-0.2, 0.2, 0.1, 0.1, -0.1, 0.1, 0, 0, 0.2),
      Resistance = c(5000000, 5000000, 5000000, 5000000, 5000000, 12.1, 3.7, 13.9, 4.6)
    )
    domain = ps(Power = p_int(lower = 10, upper = 70),
                Speed = p_int(lower = 10, upper = 60),
                DPI = p_int(lower = 1, upper = 7),
                N2gas = p_int(lower = 0, upper = 1),
                Defocus = p_dbl(lower = -0.3, upper = 0.3))
    codomain = ps(Resistance = p_dbl(tags = "minimize"))

    archive = Archive$new(search_space = domain, codomain = codomain)
    archive$add_evals(xdt = data[, c("Power", "Speed", "DPI", "N2gas", "Defocus")], ydt = data[, c("Resistance")])

In particular I get this error:

     archive$add_evals(xdt = data[, c("Power", "Speed", "DPI", "N2gas", "Defocus")], ydt = data[, c("Resistance")])
Error: attempt to apply non-function

You are right cols_y is still there, but add_evals or data is no longer available

> archive$
archive$.__enclos_env__  archive$clone            archive$cols_y           archive$initialize       archive$print            
archive$check_values     archive$codomain         archive$format           archive$label            archive$search_space     
archive$clear            archive$cols_x           archive$help             archive$man              archive$start_time 
be-marc commented 3 months ago

Hey, sorry Archive is an abstract base class now. You have to use ArchiveBatch$new() .

hududed commented 3 months ago

Perfekt! That solves it thanks - closing this.