Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sebffischer committed Apr 16, 2024
1 parent cc5c828 commit 874cd7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions R/ParamSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,15 @@ ParamSet = R6Class("ParamSet",
values = keep(values, inherits, "TuneToken")
if (!length(values)) return(ParamSet$new())
params = map(names(values), function(pn) {
domain = self$params[pn, on = "id"]
domain = private$.params[pn, on = "id"]
set_class(domain, c(domain$cls, "Domain", class(domain)))
})
names(params) = names(values)

# package-internal S3 fails if we don't call the function indirectly here
partsets = pmap(list(values, params), function(...) tunetoken_to_ps(...))
partsets = pmap(list(values, params), function(tt, param) {
tunetoken_to_ps(tt, param, param_aggr = private$.aggrs[list(param$id), "aggr", on = "id"][[1L]][[1L]])
})

pars = ps_union(partsets) # partsets does not have names here, wihch is what we want.

Expand Down
16 changes: 8 additions & 8 deletions R/to_tune.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ print.InnerTuneToken = function(x, ...) {
#
# Makes liberal use to `pslike_to_ps` (converting Param, ParamSet, Domain to ParamSet)
# param is a data.table that is potentially modified by reference using data.table set() methods.
tunetoken_to_ps = function(tt, param) {
tunetoken_to_ps = function(tt, param, param_aggr) {
UseMethod("tunetoken_to_ps")
}

tunetoken_to_ps.InnerTuneToken = function(tt, param) {
tt$content$aggr = tt$content$aggr %??% param$.aggr
tunetoken_to_ps.InnerTuneToken = function(tt, param, param_aggr) {
tt$content$aggr = tt$content$aggr %??% param_aggr
if (is.null(tt$content$aggr)) {
stopf("%s (%s): Provide an aggregation function for inner tuning.", tt$call, param$id)
}
Expand All @@ -245,20 +245,20 @@ tunetoken_to_ps.InnerTuneToken = function(tt, param) {
return(ps)
}

tunetoken_to_ps.FullTuneToken = function(tt, param) {
tunetoken_to_ps.FullTuneToken = function(tt, param, param_aggr) {
if (!domain_is_bounded(param)) {
stopf("%s must give a range for unbounded parameter %s.", tt$call, param$id)
}
if (isTRUE(tt$content$logscale)) {
if (!domain_is_number(param)) stop("%s (%s): logscale only valid for numeric / integer parameters.", tt$call, param$id)
tunetoken_to_ps.RangeTuneToken(list(content = list(logscale = tt$content$logscale, aggr = tt$content$aggr), tt$call), param)
tunetoken_to_ps.RangeTuneToken(list(content = list(logscale = tt$content$logscale, aggr = tt$content$aggr), tt$call), param, param_aggr)
} else {
pslike_to_ps(param, tt$call, param)
pslike_to_ps(param, tt$call, param, param_aggr)
}
}


tunetoken_to_ps.RangeTuneToken = function(tt, param) {
tunetoken_to_ps.RangeTuneToken = function(tt, param, param_aggr) {
if (!domain_is_number(param)) {
stopf("%s for non-numeric param must have zero or one argument.", tt$call)
}
Expand Down Expand Up @@ -286,7 +286,7 @@ tunetoken_to_ps.RangeTuneToken = function(tt, param) {
pslike_to_ps(content, tt$call, param)
}

tunetoken_to_ps.ObjectTuneToken = function(tt, param) {
tunetoken_to_ps.ObjectTuneToken = function(tt, param, param_aggr) {
pslike_to_ps(tt$content, tt$call, param)
}

Expand Down

0 comments on commit 874cd7f

Please sign in to comment.