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

add 'distinct' argument to VectorParams #206

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ Suggests:
LazyData: yes
ByteCompile: yes
Version: 1.11
RoxygenNote: 6.0.1
RoxygenNote: 6.1.1
Encoding: UTF-8
7 changes: 6 additions & 1 deletion R/aParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#' \item{default [any concrete value | \code{expression}]}{See argument of same name.}
#' \item{has.default [\code{logical(1)}]}{Extra flag to really be able to check whether the user passed a default, to avoid troubles with \code{NULL} and \code{NA}.}
#' \item{tunable [\code{logical(1)}]}{See argument of same name.}
#' \item{distinct [\code{logical(1)}]}{See argument of same name.}
#' \item{special.vals [\code{list}]}{See argument of same name.}
#' }
#'
Expand Down Expand Up @@ -75,6 +76,9 @@
#' Defining a parameter to be not-tunable allows to mark arguments like, e.g., \dQuote{verbose} or other purely technical stuff.
#' Note that this flag is most likely not respected by optimizing procedures unless stated otherwise.
#' Default is \code{TRUE} (except for \code{untyped}, \code{function}, \code{character} and \code{characterVector}) which means it is tunable.
#' @param distinct [\code{logical(1)}]\cr
#' Whether sampling with or without replacement should be done for vector params.
#' Default is to sample with replacment (\code{distinct = FALSE}).
#' @param special.vals [\code{list()}]\cr
#' A list of special values the parameter can except which are outside of the defined range.
#' Default is an empty list.
Expand All @@ -89,7 +93,7 @@
NULL

makeParam = function(id, type, learner.param, len = 1L, lower = NULL, upper = NULL, values = NULL, cnames = NULL, allow.inf = FALSE, default,
trafo = NULL, requires = NULL, tunable = TRUE, special.vals = list(), when) {
trafo = NULL, requires = NULL, distinct = FALSE, tunable = TRUE, special.vals = list(), when) {
assertString(id)
assert(
checkCount(len, na.ok = learner.param),
Expand Down Expand Up @@ -160,6 +164,7 @@ makeParam = function(id, type, learner.param, len = 1L, lower = NULL, upper = NU
default = default,
trafo = trafo,
requires = requires,
distinct = distinct,
tunable = tunable,
special.vals = special.vals
)
Expand Down
24 changes: 14 additions & 10 deletions R/makeParamFuns.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ makeNumericParam = function(id, lower = -Inf, upper = Inf, allow.inf = FALSE,
#' @rdname Param
#' @export
makeNumericVectorParam = function(id, len, lower = -Inf, upper = Inf, cnames = NULL,
allow.inf = FALSE, default, trafo = NULL, requires = NULL,
allow.inf = FALSE, default, trafo = NULL, requires = NULL, distinct = FALSE,
tunable = TRUE, special.vals = list()) {
makeParam(id = id, type = "numericvector", learner.param = FALSE, len = len, lower = lower,
upper = upper, cnames = cnames, allow.inf = allow.inf,
default = default, trafo = trafo, requires = requires, tunable = tunable, special.vals = special.vals)
default = default, trafo = trafo, requires = requires, tunable = tunable,
distinct = distinct, special.vals = special.vals)
}

#' @rdname Param
Expand All @@ -30,10 +31,11 @@ makeIntegerParam = function(id, lower = -Inf, upper = Inf, default, trafo = NULL
#' @rdname Param
#' @export
makeIntegerVectorParam = function(id, len, lower = -Inf, upper = Inf, cnames = NULL,
default, trafo = NULL, requires = NULL, tunable = TRUE, special.vals = list()) {
default, trafo = NULL, requires = NULL, tunable = TRUE,
distinct = FALSE, special.vals = list()) {
makeParam(id = id, type = "integervector", learner.param = FALSE, len = len, lower = lower, upper = upper,
cnames = cnames, default = default, trafo = trafo,
requires = requires, tunable = tunable, special.vals = special.vals)
requires = requires, tunable = tunable, distinct = distinct, special.vals = special.vals)
}

#' @rdname Param
Expand All @@ -48,11 +50,11 @@ makeLogicalParam = function(id, default, requires = NULL, tunable = TRUE, specia
#' @rdname Param
#' @export
makeLogicalVectorParam = function(id, len, cnames = NULL, default,
requires = NULL, tunable = TRUE, special.vals = list()) {
requires = NULL, tunable = TRUE, trafo = NULL, special.vals = list()) {
values = list("TRUE" = TRUE, "FALSE" = FALSE)
makeParam(id = id, type = "logicalvector", learner.param = FALSE, len = len,
values = values, cnames = cnames, default = default,
trafo = NULL, requires = requires, tunable = tunable, special.vals = special.vals)
trafo = trafo, requires = requires, tunable = tunable, special.vals = special.vals)
}

#' @rdname Param
Expand All @@ -67,11 +69,12 @@ makeDiscreteParam = function(id, values, trafo = NULL, default,
#' @rdname Param
#' @export
makeDiscreteVectorParam = function(id, len, values, default, requires = NULL,
tunable = TRUE, special.vals = list()) {
tunable = TRUE, distinct = FALSE, special.vals = list()) {

makeParam(id = id, type = "discretevector", learner.param = FALSE, len = len,
values = values, default = default,
trafo = NULL, requires = requires, tunable = tunable, special.vals = special.vals)
trafo = NULL, requires = requires, tunable = tunable,
distinct = distinct, special.vals = special.vals)
}

#' @rdname Param
Expand Down Expand Up @@ -103,10 +106,11 @@ makeCharacterParam = function(id, default, requires = NULL, special.vals = list(
#' @rdname Param
#' @export
makeCharacterVectorParam = function(id, len, cnames = NULL, default,
requires = NULL, special.vals = list()) {
requires = NULL, distinct = FALSE, special.vals = list()) {

makeParam(id = id, type = "charactervector", learner.param = FALSE, len = len,
cnames = cnames, default = default,
trafo = NULL, requires = requires, tunable = FALSE, special.vals = special.vals)
trafo = NULL, requires = requires, tunable = FALSE,
distinct = distinct, special.vals = special.vals)
}

6 changes: 5 additions & 1 deletion R/sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ sampleValue.Param = function(par, discrete.names = FALSE, trafo = FALSE) {
} else if (isLogicalTypeString(type)) {
x = sample(c(TRUE, FALSE), par$len, replace = TRUE)
} else if (isDiscreteTypeString(type, FALSE)) {
x = sample(names(par$values), par$len, replace = TRUE)
if (isTRUE(par$distinct)) {
x = sample(names(par$values), par$len, replace = FALSE)
} else {
x = sample(names(par$values), par$len, replace = TRUE)
}
if (!discrete.names) {
x = if (type == "discretevector")
par$values[x]
Expand Down
18 changes: 8 additions & 10 deletions man/LearnerParam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/OptPath.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions man/Param.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/addOptPathEl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/as.data.frame.OptPathDF.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/filterParams.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/generateDesign.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathBestIndex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathCol.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathCols.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathDOB.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathEOL.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathEl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathErrorMessages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathExecTimes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathLength.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathParetoFront.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathX.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/getOptPathY.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/isFeasible.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/isRequiresOk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/makeParamSet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading