-
-
Notifications
You must be signed in to change notification settings - Fork 405
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
Expression handling #1126
Merged
Merged
Expression handling #1126
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
17fe5e0
initial version of expression-learners
kerschke b56128d
allow expressions within tuning param sets
kerschke 62d6bdb
updated documentation of expression-related files
kerschke 8b20d6f
fixing naming issues
kerschke f85ad87
further doc fixes
kerschke a13c4eb
remove dict argument
kerschke eb9ec14
updating man-pages
kerschke eaea99e
rm dict_template
kerschke 7227a9c
better documentation of expression-related functions
kerschke 00d92f8
removed ParamHelpers:: as it is not necessary
kerschke e0b4728
cleanup; added test
mllg 43e2f4f
removed duplicated PH dep
mllg 8450107
fixes as requested in PR#1126
kerschke d7ca6cf
Merge branch 'master' into expression
mllg 3cfe85d
use setLearnerId in tests
mllg bce6633
fix warnings in tests and r cmd check
mllg d72e6fd
Merge branch 'master' into expression
jakob-r 10d81d5
added assertion for Task
jakob-r 42c92e4
Merge branch 'master' into expression
jakob-r 7eb94f5
Merge remote-tracking branch 'origin/master' into expression
mllg 5144137
Merge branch 'expression' of github.com:mlr-org/mlr into expression
mllg cb5fa80
docs, mini cleanup
mllg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#' @title Evaluates expressions within a learner or parameter set. | ||
#' | ||
#' @description | ||
#' A \code{\link{Learner}} can contain unevaluated \code{\link[base]{expression}s} | ||
#' as value for a hyperparameter. E.g., these expressions are used if the default | ||
#' value depends on the task size or an upper limit for a parameter is given by | ||
#' the number of features in a task. \code{evaluateParamExpressions} allows to | ||
#' evaluate these expressions using a given dictionary, which holds the following | ||
#' information: | ||
#' \itemize{ | ||
#' \item{\code{task}:} the task itself, allowing to access any of its elements. | ||
#' \item{\code{p}:} the number of features in the task | ||
#' \item{\code{n}:} the number of observations in the task | ||
#' \item{\code{type}:} the task type, i.e. "classif", "regr", "surv", "cluster", "costcens" or "multilabel" | ||
#' \item{\code{k}:} the number of classes of the target variable (only available for classification tasks) | ||
#' } | ||
#' Usually the evaluation of the expression is performed automatically, e.g. in | ||
#' \code{\link{train}} or \code{\link{tuneParams}}. Therefore calling | ||
#' \code{evaluateParamExpressions} manually should not be necessary. | ||
#' It is also possible to directly evaluate the expressions of a | ||
#' \code{\link[ParamHelpers]{ParamSet}}, \code{\link[base]{list}} of | ||
#' \code{\link[ParamHelpers]{Param}s} or single \code{\link[ParamHelpers]{Param}s}. | ||
#' For further information on these, please refer to the documentation of the | ||
#' \code{ParamHelpers} package. | ||
#' | ||
#' @param obj [\code{\link{Learner}}]\cr | ||
#' The learner. If you pass a string the learner will be created via | ||
#' \code{\link{makeLearner}}. Expressions within \code{length}, \code{lower} | ||
#' or \code{upper} boundaries, \code{default} or \code{value} will be | ||
#' evaluated using the provided dictionary (\code{dict}). | ||
#' @param dict [\code{environment} | \code{list} | \code{NULL}]\cr | ||
#' Environment or list which will be used for evaluating the variables | ||
#' of expressions within a parameter, parameter set or list of parameters. | ||
#' The default is \code{NULL}. | ||
#' @return [\code{\link{Learner}}]. | ||
#' @export | ||
#' @examples | ||
#' ## (1) evaluation of a learner's hyperparameters | ||
#' task = makeClassifTask(data = iris, target = "Species") | ||
#' dict = getTaskDictionary(task = task) | ||
#' lrn1 = makeLearner("classif.rpart", minsplit = expression(k * p), | ||
#' minbucket = expression(3L + 4L * task$task.desc$has.blocking)) | ||
#' lrn2 = evaluateParamExpressions(obj = lrn1, dict = dict) | ||
#' | ||
#' getHyperPars(lrn1) | ||
#' getHyperPars(lrn2) | ||
#' | ||
#' ## (2) evaluation of a learner's entire parameter set | ||
#' task = makeClassifTask(data = iris, target = "Species") | ||
#' dict = getTaskDictionary(task = task) | ||
#' lrn1 = makeLearner("classif.randomForest") | ||
#' lrn2 = evaluateParamExpressions(obj = lrn1, dict = dict) | ||
#' | ||
#' ## Note the values for parameters 'mtry', 'classwt' and 'cutoff' | ||
#' lrn1$par.set | ||
#' lrn2$par.set | ||
#' | ||
#' ## (3) evaluation of a parameter set | ||
#' task = makeClassifTask(data = iris, target = "Species") | ||
#' dict = getTaskDictionary(task = task) | ||
#' ps1 = makeParamSet( | ||
#' makeNumericParam("C", lower = expression(k), upper = expression(n), trafo = function(x) 2^x), | ||
#' makeDiscreteParam("sigma", values = expression(list(k, p))) | ||
#' ) | ||
#' ps2 = evaluateParamExpressions(obj = ps1, dict = dict) | ||
#' | ||
#' ps1 | ||
#' ps2 | ||
evaluateParamExpressions.Learner = function(obj, dict = NULL) { | ||
obj = checkLearner(obj) | ||
if (hasExpression(obj)) { | ||
assertList(dict, null.ok = TRUE) | ||
obj$par.set = evaluateParamExpressions(obj = obj$par.set, dict = dict) | ||
obj$par.vals = evaluateParamExpressions(obj = obj$par.vals, dict = dict) | ||
} | ||
return(obj) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
dict
should somehow contain information aboutsubset
. The learner only sees the subset task, and probably expects the parameters to behave accordingly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume that the task is already subsetted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subsetting happens in
trainLearner
(e.g.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. I remember... what I don't remember is the motivation behind this though.