mlr-org / mlr3mbo

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

Extract multi-objective models #142

Closed hududed closed 5 months ago

hududed commented 6 months ago

@sumny How to access the model when trained this way?

    data = data.table(
      x1 = c(3000, 4000, 5000, 4500),
      x2 = c(2000, 3000, 4000, 3500),
      x3 = c(1, 2, 3, 2),
      y1 = c(2.0, 3.0, 4.0, 3.5),
      y2 = c(1.0, 2.0, 3.0, 2.5))
    domain = ps(x1 = p_int(lower = 2000, upper = 5500),
                x2 = p_int(lower = 1000, upper = 20000),
                x3 = p_int(lower = 1, upper = 10))
    codomain = ps(y1 = p_int(tags = "minimize"), y2 = p_dbl(tags = "minimize"))

    archive = Archive$new(search_space = domain, codomain = codomain)
    archive$add_evals(xdt = data[, c("x1", "x2", "x3")], ydt = data[, c("y1","y2")])
    surrogate = srlrn(list(default_gp(), default_gp()), archive = archive)
    acq_function = acqf("ehvi", surrogate = surrogate)
    acq_optimizer = acqo(
      opt("focus_search", n_points = 1000, maxit = 10),
      terminator = trm("evals", n_evals = 11000),
      acq_function = acq_function)

    set.seed(42)
    acq_function$surrogate$update()
    acq_function$update()
    candidate = acq_optimizer$optimize()
    candidate

    #
    model <- acq_function$surrogate$model$model

Usually for single-objective, I can the extract the model via model <- acq_function$surrogate$model$model but that returns null in this case.

sumny commented 6 months ago

@hududed In v0.2.1 the $model field was changed to the $learner field to be more consistent (see https://github.com/mlr-org/mlr3mbo/blob/main/NEWS.md)

acq_function$surrogate$learner will return a list of learners for each of the objectives you are modeling in your multi-objective scenario.

Then, acq_function$surrogate$learner$y1$model allows for accessing the actual trained model for your first objective y1.