Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export(isRequiresOk)
export(isSpecialValue)
export(isVector)
export(isVectorTypeString)
export(makeCharacterLearnerParam)
export(makeCharacterLearnerVectorParam)
export(makeCharacterParam)
export(makeCharacterVectorParam)
export(makeDiscreteLearnerParam)
Expand Down
3 changes: 1 addition & 2 deletions R/aParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
#' Defining a parameter to be not-tunable allows to mark arguments like, e.g., \dQuote{verbose} or
#' other purely technical stuff, and allows them to be excluded from later automatic optimization
#' procedures that would try to consider all available parameters.
#' Default is \code{TRUE} (except for \code{untyped}, \code{function}, \code{character} and
#' \code{characterVector}) which means it is tunable.
#' Default is \code{TRUE}, which means it is tunable.
#' @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 Down
4 changes: 2 additions & 2 deletions R/convertDiscrete.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ discreteValueToName = function(par, x) {
return(NA_character_)
assertClass(par, "Param")
assertChoice(par$type, c("discrete", "discretevector"))
if (par$type == "discretevector" && length(x) != par$len)
if (par$type == "discretevector" && isTRUE(length(x) != par$len))
stopf("Length of x must be %i!", par$len)
ns = names(par$values)
getIndex = function(values, v) {
Expand All @@ -65,6 +65,6 @@ discreteValueToName = function(par, x) {
if (par$type == "discrete") {
ns[getIndex(par$values, x)]
} else if (par$type == "discretevector") {
ns[sapply(x, getIndex, values = par$values)]
vcapply(x, function(app x) ns[getIndex(x, values = par$values)])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nice thing about sapply is that it gives list() in case of length(x) == 0, which would match quite nicely with the actual default being list(). When the related BBmisc issue gets fixed, this will result in the most natural printout. vcapply will give character(0) when x is list(), which is a deviation from the behaviour of the other "vector" types (which always show logical(0), numeric(0) etc. depending on their type).

Not going to say much about the syntax error here.

Copy link
Member

@jakob-r jakob-r Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the typo. But in the documentation we say that the output is a character vector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I didn't consider the other points from which discreteValueToName gets called. I'd still say the printout of a discreteVectorLearnerParam with default list() shouldn't have character(0) in it.

}
}
20 changes: 19 additions & 1 deletion R/makeLearnerParamFuns.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ makeLogicalLearnerParam = function(id, default, when = "train", requires = NULL,
makeLogicalVectorLearnerParam = function(id, len = as.integer(NA), default, when = "train",
requires = NULL, tunable = TRUE, special.vals = list()) {
values = list("TRUE" = TRUE, "FALSE" = FALSE)
makeParam(id = id, type = "logicalvector", learner.param = TRUE, len = len,values = values,
makeParam(id = id, type = "logicalvector", learner.param = TRUE, len = len, values = values,
default = default, requires = requires, tunable = tunable, special.vals = special.vals, when = when)
}

Expand All @@ -83,3 +83,21 @@ makeFunctionLearnerParam = function(id, default, when = "train", requires = NULL
}


#' @rdname LearnerParam
#' @export
makeCharacterLearnerParam = function(id, default, when = "train", requires = NULL, tunable = TRUE,
special.vals = list()) {
makeParam(id = id, type = "character", learner.param = TRUE,
default = default, requires = requires, tunable = tunable, special.vals = special.vals, when = when)
}

#' @rdname LearnerParam
#' @export
makeCharacterLearnerVectorParam = function(id, len = as.integer(NA), default, when = "train",
requires = NULL, tunable = TRUE, special.vals = list()) {

makeParam(id = id, type = "charactervector", learner.param = TRUE, len = len,
default = default, requires = requires, tunable = tunable, special.vals = special.vals, when = when)
}


14 changes: 8 additions & 6 deletions R/makeParamFuns.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ makeDiscreteVectorParam = function(id, len, values, default, requires = NULL,

#' @rdname Param
#' @export
makeFunctionParam = function(id, default = default, requires = NULL, special.vals = list()) {
makeFunctionParam = function(id, default = default, requires = NULL, tunable = TRUE,
special.vals = list()) {
makeParam(id = id, type = "function", learner.param = FALSE,
values = NULL, default = default, trafo = NULL,
requires = requires, tunable = FALSE, special.vals = special.vals)
requires = requires, tunable = tunable, special.vals = special.vals)
}

#FIXME: what happens if NA is later used for untyped params? because we might interpret this as
Expand All @@ -94,19 +95,20 @@ makeUntypedParam = function(id, default, requires = NULL, tunable = TRUE, specia

#' @rdname Param
#' @export
makeCharacterParam = function(id, default, requires = NULL, special.vals = list()) {
makeCharacterParam = function(id, default, requires = NULL, tunable = TRUE,
special.vals = list()) {
makeParam(id = id, type = "character", learner.param = FALSE,
default = default, trafo = NULL,
requires = requires, tunable = FALSE, special.vals = special.vals)
requires = requires, tunable = tunable, special.vals = special.vals)
}

#' @rdname Param
#' @export
makeCharacterVectorParam = function(id, len, cnames = NULL, default,
requires = NULL, special.vals = list()) {
requires = NULL, tunable = TRUE, 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 = tunable, special.vals = special.vals)
}

12 changes: 10 additions & 2 deletions man/LearnerParam.Rd

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

10 changes: 5 additions & 5 deletions man/Param.Rd

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

3 changes: 3 additions & 0 deletions tests/testthat/test_Param.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ test_that("param print works", {
expect_output(print(p), "99")
p = makeUntypedParam(id = "x", default = c(99, 99))
expect_output(print(p), "untyped")
p = makeDiscreteVectorLearnerParam("test",
default = list(), values = c("a", "b", "c"), len = NA)
expect_output(print(p), "discretevector")
})

test_that("normal (not learner) vec param cannot have NA lengths", {
Expand Down