Skip to content

Commit

Permalink
a required parameter can not have a default.
Browse files Browse the repository at this point in the history
  • Loading branch information
mb706 committed Jan 14, 2024
1 parent f18628c commit 9c7fafd
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions R/LearnerClustAffinityPropagation.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ LearnerClustAP = R6Class("LearnerClustAP",
initialize = function() {
ps = ps(
s = p_uty(tags = c("required", "train")),
p = p_uty(custom_check = function(x) {
p = p_uty(custom_check = crate(function(x) {
if (test_numeric(x)) {
return(TRUE)
} else {
stop("`p` needs to be a numeric vector")
}
}, default = NA, tags = "train"),
}), default = NA, tags = "train"),
q = p_dbl(lower = 0L, upper = 1L, tags = "train"),
maxits = p_int(lower = 1L, default = 1000L, tags = "train"),
convits = p_int(lower = 1L, default = 100L, tags = "train"),
Expand Down
4 changes: 2 additions & 2 deletions R/LearnerClustAgnes.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LearnerClustAgnes = R6Class("LearnerClustAgnes",
method = p_fct(default = "average", levels = c("average", "single", "complete", "ward", "weighted", "flexible", "gaverage"), tags = "train"),
trace.lev = p_int(lower = 0L, default = 0L, tags = "train"),
k = p_int(lower = 1L, default = 2L, tags = "predict"),
par.method = p_uty(tags = "train", custom_check = function(x) {
par.method = p_uty(tags = "train", custom_check = crate(function(x) {
if (test_numeric(x) || test_list(x)) {
if (length(x) %in% c(1L, 3L, 4L)) {
return(TRUE)
Expand All @@ -36,7 +36,7 @@ LearnerClustAgnes = R6Class("LearnerClustAgnes",
} else {
stop("`par.method` needs to be a numeric vector")
}
})
}))
)

# param deps
Expand Down
10 changes: 5 additions & 5 deletions R/LearnerClustCMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ LearnerClustCMeans = R6Class("LearnerClustCMeans",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
centers = p_uty(tags = c("required", "train"), default = 2L,
custom_check = function(x) {
centers = p_uty(tags = c("required", "train"),
custom_check = crate(function(x) {
if (test_data_frame(x)) {
return(TRUE)
} else if (test_int(x)) {
assert_true(x >= 1L)
} else {
return("`centers` must be integer or data.frame with initial cluster centers")
}
}
})
),
iter.max = p_int(lower = 1L, default = 100L, tags = "train"),
verbose = p_lgl(default = FALSE, tags = "train"),
dist = p_fct(levels = c("euclidean", "manhattan"), default = "euclidean", tags = "train"),
method = p_fct(levels = c("cmeans", "ufcl"), default = "cmeans", tags = "train"),
m = p_dbl(lower = 1L, default = 2L, tags = "train"),
rate.par = p_dbl(lower = 0L, upper = 1L, tags = "train"),
weights = p_uty(default = 1L, custom_check = function(x) {
weights = p_uty(default = 1L, custom_check = crate(function(x) {
if (test_numeric(x)) {
if (sum(sign(x)) == length(x)) {
return(TRUE)
Expand All @@ -52,7 +52,7 @@ LearnerClustCMeans = R6Class("LearnerClustCMeans",
} else {
return("`weights` must be positive numeric vector or a single positive number")
}
},
}),
tags = "train"),
control = p_uty(tags = "train")
)
Expand Down
4 changes: 2 additions & 2 deletions R/LearnerClustDBSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ LearnerClustDBSCAN = R6Class("LearnerClustDBSCAN",
eps = p_dbl(lower = 0L, tags = c("required", "train")),
minPts = p_int(lower = 0L, default = 5L, tags = "train"),
borderPoints = p_lgl(default = TRUE, tags = "train"),
weights = p_uty(custom_check = function(x) {
weights = p_uty(custom_check = crate(function(x) {
if (test_numeric(x)) {
return(TRUE)
} else {
stop("`weights` need to be a numeric vector")
}
}, tags = "train"),
}), tags = "train"),
search = p_fct(levels = c("kdtree", "linear", "dist"), default = "kdtree", tags = "train"),
bucketSize = p_int(lower = 1L, default = 10L, tags = "train"),
splitRule = p_fct(levels = c("STD", "MIDPT", "FAIR", "SL_MIDPT", "SL_FAIR", "SUGGEST"), default = "SUGGEST", tags = "train"),
Expand Down
8 changes: 4 additions & 4 deletions R/LearnerClustDBSCANfpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ LearnerClustDBSCANfpc = R6Class("LearnerClustDBSCANfpc",
scale = p_lgl(default = FALSE, tags = "train"),
method = p_fct(levels = c("hybrid", "raw", "dist"), tags = "train"),
seeds = p_lgl(default = TRUE, tags = "train"),
showplot = p_uty(custom_check = function(x) {
showplot = p_uty(custom_check = crate(function(x) {
if (test_flag(x)) {
return(TRUE)
} else if (test_int(x, lower = 0, upper = 2)) {
return(TRUE)
} else {
stop("`showplot` need to be either logical or integer between 0 and 2")
}
}, default = FALSE, tags = "train"),
countmode = p_uty(custom_check = function(x) {
}), default = FALSE, tags = "train"),
countmode = p_uty(custom_check = crate(function(x) {
if (test_integer(x)) {
return(TRUE)
} else if (test_null(x)) {
return(TRUE)
} else {
stop("`countmode` need to be NULL or vector of integers")
}
}, default = NULL, tags = "train")
}), default = NULL, tags = "train")
)

param_set$values = list(MinPts = 5L, scale = FALSE, seeds = TRUE,
Expand Down
2 changes: 1 addition & 1 deletion R/LearnerClustFanny.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LearnerClustFanny = R6Class("LearnerClustFanny",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
k = p_int(lower = 1L, default = 2L, tags = c("required", "train")),
k = p_int(lower = 1L, tags = c("required", "train")),
memb.exp = p_dbl(lower = 1L, default = 2L, tags = "train"),
metric = p_fct(default = "euclidean", levels = c("euclidean", "manhattan", "SqEuclidean"), tags = "train"),
stand = p_lgl(default = FALSE, tags = "train"),
Expand Down
2 changes: 1 addition & 1 deletion R/LearnerClustFeatureless.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LearnerClustFeatureless = R6Class("LearnerClustFeatureless",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
num_clusters = p_int(lower = 1L, default = 1L, tags = c("required", "train", "predict"))
num_clusters = p_int(lower = 1L, tags = c("required", "train", "predict"))
)
ps$values = list(num_clusters = 1L)

Expand Down
6 changes: 3 additions & 3 deletions R/LearnerClustKKMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ LearnerClustKKMeans = R6Class("LearnerClustKKMeans",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
centers = p_uty(tags = c("required", "train"), default = 2L,
custom_check = function(x) {
centers = p_uty(tags = c("required", "train"),
custom_check = crate(function(x) {
if (test_data_frame(x)) {
return(TRUE)
} else if (test_int(x)) {
assert_true(x >= 1L)
} else {
return("`centers` must be integer or data.frame with initial cluster centers")
}
}
})
),
kernel = p_fct(default = "rbfdot",
levels = c( "vanilladot", "polydot", "rbfdot", "tanhdot", "laplacedot", "besseldot", "anovadot", "splinedot"),
Expand Down
6 changes: 3 additions & 3 deletions R/LearnerClustKMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ LearnerClustKMeans = R6Class("LearnerClustKMeans",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
centers = p_uty(tags = c("required", "train"), default = 2L,
custom_check = function(x) {
centers = p_uty(tags = c("required", "train"),
custom_check = crate(function(x) {
if (test_data_frame(x)) {
return(TRUE)
} else if (test_int(x)) {
assert_true(x >= 1L)
} else {
return("`centers` must be integer or data.frame with initial cluster centers")
}
}
})
),
iter.max = p_int(lower = 1L, default = 10L, tags = c("train")),
algorithm = p_fct(levels = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen"), default = "Hartigan-Wong", tags = c("train")),
Expand Down
24 changes: 12 additions & 12 deletions R/LearnerClustMclust.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,48 @@ LearnerClustMclust = R6Class("LearnerClustMclust",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
G = p_uty(default = c(1:9), custom_check = function(x) {
G = p_uty(default = c(1:9), custom_check = crate(function(x) {
if (test_numeric(x)) {
return(TRUE)
} else {
stop("`G` need to be a numeric vector")
}
}, tags = "train"),
modelNames = p_uty(custom_check = function(x) {
}), tags = "train"),
modelNames = p_uty(custom_check = crate(function(x) {
if (test_character(x)) {
return(TRUE)
} else {
stop("`modelNames` need to be a character vector")
}
}, tags = "train"),
prior = p_uty(custom_check = function(x) {
}), tags = "train"),
prior = p_uty(custom_check = crate(function(x) {
if (test_list(x)) {
return(TRUE)
} else {
stop("`prior` need to be a list")
}
}, tags = "train"),
control = p_uty(default = mclust::emControl(), custom_check = function(x) {
}), tags = "train"),
control = p_uty(default = mclust::emControl(), custom_check = crate(function(x) {
if (test_list(x)) {
return(TRUE)
} else {
stop("`control` need to be a list of control parameters for EM")
}
}, tags = "train"),
initialization = p_uty(custom_check = function(x) {
}), tags = "train"),
initialization = p_uty(custom_check = crate(function(x) {
if (test_list(x)) {
return(TRUE)
} else {
stop("`initialization` need to be a list of initialization components")
}
}, tags = "train"),
x = p_uty(custom_check = function(x) {
}), tags = "train"),
x = p_uty(custom_check = crate(function(x) {
if (test_class(x, "mclustBIC")) {
return(TRUE)
} else {
stop("`x` need to be an object of class 'mclustBIC'")
}
}, tags = "train")
}), tags = "train")
)

super$initialize(
Expand Down
8 changes: 4 additions & 4 deletions R/LearnerClustMeanShift.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ LearnerClustMeanShift = R6Class("LearnerClustMeanShift",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
h = p_uty(custom_check = function(x) {
h = p_uty(custom_check = crate(function(x) {
if (test_numeric(x) || test_int(x)) {
return(TRUE)
} else {
return("`h` must be either integer or numeric vector")
}
}, tags = "train"),
subset = p_uty(custom_check = function(x) {
}), tags = "train"),
subset = p_uty(custom_check = crate(function(x) {
if (test_numeric(x)) {
return(TRUE)
} else {
return("`subset` must be a numeric vector")
}
}, tags = "train"),
}), tags = "train"),
scaled = p_int(lower = 0L, default = 1, tags = "train"),
iter = p_int(lower = 1L, default = 200L, tags = "train"),
thr = p_dbl(default = 0.01, tags = "train")
Expand Down
6 changes: 3 additions & 3 deletions R/LearnerClustPAM.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ LearnerClustPAM = R6Class("LearnerClustPAM",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
k = p_int(lower = 1L, default = 2L, tags = c("required", "train")),
k = p_int(lower = 1L, tags = c("required", "train")),
metric = p_fct(levels = c("euclidian", "manhattan"), tags = "train"),
medoids = p_uty(default = NULL, tags = "train",
custom_check = function(x) {
custom_check = custom(function(x) {
if (test_integerish(x)) {
return(TRUE)
} else if (test_null(x)) {
return(TRUE)
} else {
stop("`medoids` needs to be either `NULL` or vector with row indices!")
}
}
})
),
stand = p_lgl(default = FALSE, tags = "train"),
do.swap = p_lgl(default = TRUE, tags = "train"),
Expand Down

0 comments on commit 9c7fafd

Please sign in to comment.