Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract multi-objective models #142

Closed
hududed opened this issue Mar 10, 2024 · 1 comment
Closed

Extract multi-objective models #142

hududed opened this issue Mar 10, 2024 · 1 comment

Comments

@hududed
Copy link

hududed commented Mar 10, 2024

@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
Copy link
Sponsor Member

sumny commented Mar 11, 2024

@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.

@sumny sumny closed this as completed Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants