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

Disable threading, tag hyperpars #93

Merged
merged 1 commit into from
Feb 6, 2021
Merged
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
8 changes: 3 additions & 5 deletions R/FilterCMIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ FilterCMIM = R6Class("FilterCMIM",
#' @description Create a FilterCMIM object.
initialize = function() {
param_set = ParamSet$new(list(
ParamInt$new("threads", lower = 0L, default = 0L)
ParamInt$new("threads", lower = 0L, default = 0L, tags = "threads")
))
param_set$values = list(threads = 1L)

super$initialize(
id = "cmim",
Expand All @@ -40,10 +41,7 @@ FilterCMIM = R6Class("FilterCMIM",

private = list(
.calculate = function(task, nfeat) {
threads = self$param_set$values$threads %??% 0L
X = task$data(cols = task$feature_names)
Y = task$truth()
reencode_praznik_score(praznik::CMIM(X = X, Y = Y, k = nfeat, threads = threads))
call_praznik(self, task, praznik::CMIM)
}
)
)
Expand Down
8 changes: 3 additions & 5 deletions R/FilterDISR.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ FilterDISR = R6Class("FilterDISR",
#' @description Create a FilterDISR object.
initialize = function() {
param_set = ParamSet$new(list(
ParamInt$new("threads", lower = 0L, default = 0L)
ParamInt$new("threads", lower = 0L, default = 0L, tags = "threads")
))
param_set$values = list(threads = 1L)

super$initialize(
id = "disr",
Expand All @@ -40,10 +41,7 @@ FilterDISR = R6Class("FilterDISR",

private = list(
.calculate = function(task, nfeat) {
threads = self$param_set$values$threads %??% 0L
X = task$data(cols = task$feature_names)
Y = task$truth()
reencode_praznik_score(praznik::DISR(X = X, Y = Y, k = nfeat, threads = threads))
call_praznik(self, task, praznik::DISR)
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion R/FilterInformationGain.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FilterInformationGain = R6Class("FilterInformationGain",
default = "infogain"),
ParamLgl$new("equal", default = FALSE),
ParamLgl$new("discIntegers", default = TRUE),
ParamInt$new("threads", lower = 0L, default = 1L)
ParamInt$new("threads", lower = 1L, default = 1L, tags = "threads")
))

super$initialize(
Expand Down
8 changes: 3 additions & 5 deletions R/FilterJMI.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ FilterJMI = R6Class("FilterJMI",
#' @description Create a FilterJMI object.
initialize = function() {
param_set = ParamSet$new(list(
ParamInt$new("threads", lower = 0L, default = 0L)
ParamInt$new("threads", lower = 0L, default = 0L, tags = "threads")
))
param_set$values = list(threads = 1L)

super$initialize(
id = "jmi",
Expand All @@ -40,10 +41,7 @@ FilterJMI = R6Class("FilterJMI",

private = list(
.calculate = function(task, nfeat) {
threads = self$param_set$values$threads %??% 0L
X = task$data(cols = task$feature_names)
Y = task$truth()
reencode_praznik_score(praznik::JMI(X = X, Y = Y, k = nfeat, threads = threads))
call_praznik(self, task, praznik::JMI)
}
)
)
Expand Down
8 changes: 3 additions & 5 deletions R/FilterJMIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ FilterJMIM = R6Class("FilterJMIM",
initialize = function() {

param_set = ParamSet$new(list(
ParamInt$new("threads", lower = 0L, default = 0L)
ParamInt$new("threads", lower = 0L, default = 0L, tags = "threads")
))
param_set$values = list(threads = 1L)
super$initialize(
id = "jmim",
task_type = c("classif", "regr"),
Expand All @@ -40,10 +41,7 @@ FilterJMIM = R6Class("FilterJMIM",

private = list(
.calculate = function(task, nfeat) {
threads = self$param_set$values$threads %??% 0L
X = task$data(cols = task$feature_names)
Y = task$truth()
reencode_praznik_score(praznik::JMIM(X = X, Y = Y, k = nfeat, threads = threads))
call_praznik(self, task, praznik::JMIM)
}
)
)
Expand Down
8 changes: 3 additions & 5 deletions R/FilterMIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ FilterMIM = R6Class("FilterMIM",
#' @description Create a FilterMIM object.
initialize = function() {
param_set = ParamSet$new(list(
ParamInt$new("threads", lower = 0L, default = 0L)
ParamInt$new("threads", lower = 0L, default = 0L, tags = "threads")
))
param_set$values = list(threads = 1L)

super$initialize(
id = "mim",
Expand All @@ -40,10 +41,7 @@ FilterMIM = R6Class("FilterMIM",

private = list(
.calculate = function(task, nfeat) {
threads = self$param_set$values$threads %??% 0L
X = task$data(cols = task$feature_names)
Y = task$truth()
reencode_praznik_score(praznik::MIM(X = X, Y = Y, k = nfeat, threads = threads))
call_praznik(self, task, praznik::MIM)
}
)
)
Expand Down
8 changes: 3 additions & 5 deletions R/FilterMRMR.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ FilterMRMR = R6Class("FilterMRMR",
#' @description Create a FilterMRMR object.
initialize = function() {
param_set = ParamSet$new(list(
ParamInt$new("threads", lower = 0L, default = 0L)
ParamInt$new("threads", lower = 0L, default = 0L, tags = "threads")
))
param_set$values = list(threads = 1L)

super$initialize(
id = "mrmr",
Expand All @@ -40,10 +41,7 @@ FilterMRMR = R6Class("FilterMRMR",

private = list(
.calculate = function(task, nfeat) {
threads = self$param_set$values$threads %??% 0L
X = task$data(cols = task$feature_names)
Y = task$truth()
reencode_praznik_score(praznik::MRMR(X = X, Y = Y, k = nfeat, threads = threads))
call_praznik(self, task, praznik::MRMR)
}
)
)
Expand Down
8 changes: 3 additions & 5 deletions R/FilterNJMIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ FilterNJMIM = R6Class("FilterNJMIM",
#' @description Create a FilterNJMIM object.
initialize = function() {
param_set = ParamSet$new(list(
ParamInt$new("threads", lower = 0L, default = 0L)
ParamInt$new("threads", lower = 0L, default = 0L, tags = "threads")
))
param_set$values = list(threads = 1L)
super$initialize(
id = "njmim",
task_type = c("classif", "regr"),
Expand All @@ -39,10 +40,7 @@ FilterNJMIM = R6Class("FilterNJMIM",

private = list(
.calculate = function(task, nfeat) {
threads = self$param_set$values$threads %??% 0L
X = task$data(cols = task$feature_names)
Y = task$truth()
reencode_praznik_score(praznik::NJMIM(X = X, Y = Y, k = nfeat, threads = threads))
call_praznik(self, task, praznik::NJMIM)
}
)
)
Expand Down
11 changes: 8 additions & 3 deletions R/helper.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
reencode_praznik_score = function(x) {
scores = x$score
set_names(seq(from = 1, to = 0, length.out = length(scores)), names(scores))
call_praznik = function(self, task, fun) {
selection = invoke(fun,
X = task$data(cols = task$feature_names),
Y = task$truth(),
.args = self$param_set$get_values()
)$selection

set_names(seq(from = 1, to = 0, length.out = length(selection)), names(selection))
}
4 changes: 4 additions & 0 deletions man-roxygen/details_praznik.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
#' As the scores calculated by the \CRANpkg{praznik} package are not monotone due
#' to the greedy forward fashion, the returned scores simply reflect the selection order:
#' `1`, `(k-1)/k`, ..., `1/k` where `k` is the number of selected features.
#'
#' Threading is disabled by default (hyperparameter `threads` is set to 1).
#' Set to a number `>= 2` to enable threading, or to `0` for auto-detecting the number
#' of available cores.
4 changes: 4 additions & 0 deletions man/mlr_filters_cmim.Rd

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

4 changes: 4 additions & 0 deletions man/mlr_filters_disr.Rd

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

4 changes: 4 additions & 0 deletions man/mlr_filters_jmi.Rd

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

4 changes: 4 additions & 0 deletions man/mlr_filters_jmim.Rd

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

4 changes: 4 additions & 0 deletions man/mlr_filters_mim.Rd

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

4 changes: 4 additions & 0 deletions man/mlr_filters_mrmr.Rd

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

4 changes: 4 additions & 0 deletions man/mlr_filters_njmim.Rd

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