Skip to content

Commit

Permalink
refactor: change the order of paradox args (#53)
Browse files Browse the repository at this point in the history
* refactor: rename ps var to param_set

* refactor: same order for lower and upper in p_int and p_dbl w/ omitting argument name
  • Loading branch information
m-muecke authored Feb 8, 2024
1 parent 9186eb0 commit 12eb820
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 136 deletions.
14 changes: 12 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ repos:
- mlr-org/styler.mlr
- id: roxygenize
additional_dependencies:
- ClusterR
- LPCM
- R6
- RWeka
- apcluster
- backports
- checkmate
- clue
- fpc
- cluster
- data.table
- dbscan
- e1071
- fpc
- kernlab
- mclust
- mlbench
- mlr3
- mlr3misc
- paradox
- R6
# codemeta must be above use-tidy-description when both are used
- id: use-tidy-description
- id: readme-rmd-rendered
Expand Down
12 changes: 6 additions & 6 deletions R/LearnerClustAffinityPropagation.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ LearnerClustAP = R6Class("LearnerClustAP",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
param_set = ps(
s = p_uty(tags = c("required", "train")),
p = p_uty(default = NA, tags = "train", custom_check = crate(function(x) check_numeric(x))),
q = p_dbl(lower = 0, upper = 1, tags = "train"),
maxits = p_int(lower = 1L, default = 1000L, tags = "train"),
convits = p_int(lower = 1L, default = 100L, tags = "train"),
lam = p_dbl(lower = 0.5, upper = 1, default = 0.9, tags = "train"),
q = p_dbl(0, 1, tags = "train"),
maxits = p_int(1L, default = 1000L, tags = "train"),
convits = p_int(1L, default = 100L, tags = "train"),
lam = p_dbl(0.5, 1, default = 0.9, tags = "train"),
includeSim = p_lgl(default = FALSE, tags = "train"),
details = p_lgl(default = FALSE, tags = "train"),
nonoise = p_lgl(default = FALSE, tags = "train"),
Expand All @@ -41,7 +41,7 @@ LearnerClustAP = R6Class("LearnerClustAP",
id = "clust.ap",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
param_set = param_set,
properties = c("partitional", "exclusive", "complete"),
packages = "apcluster",
man = "mlr3cluster::mlr_learners_clust.ap",
Expand Down
12 changes: 6 additions & 6 deletions R/LearnerClustAgnes.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ LearnerClustAgnes = R6Class("LearnerClustAgnes",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
param_set = ps(
metric = p_fct(default = "euclidean", levels = c("euclidean", "manhattan"), tags = "train"),
stand = p_lgl(default = FALSE, tags = "train"),
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"),
trace.lev = p_int(0L, default = 0L, tags = "train"),
k = p_int(1L, default = 2L, tags = "predict"),
par.method = p_uty(tags = "train", custom_check = crate(function(x) {
if (!(test_numeric(x) || test_list(x))) {
return("`par.method` needs to be a numeric vector")
Expand All @@ -44,15 +44,15 @@ LearnerClustAgnes = R6Class("LearnerClustAgnes",
)

# param deps
ps$add_dep("par.method", "method", CondAnyOf$new(c("flexible", "gaverage")))
param_set$add_dep("par.method", "method", CondAnyOf$new(c("flexible", "gaverage")))

ps$set_values(k = 2L)
param_set$set_values(k = 2L)

super$initialize(
id = "clust.agnes",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
param_set = param_set,
properties = c("hierarchical", "exclusive", "complete"),
packages = "cluster",
man = "mlr3cluster::mlr_learners_clust.agnes",
Expand Down
14 changes: 7 additions & 7 deletions R/LearnerClustCMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ LearnerClustCMeans = R6Class("LearnerClustCMeans",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
param_set = ps(
centers = p_uty(
tags = c("required", "train"), default = 2L, custom_check = crate(check_centers)
),
iter.max = p_int(lower = 1L, default = 100L, tags = "train"),
iter.max = p_int(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 = 1, default = 2, tags = "train"),
rate.par = p_dbl(lower = 0, upper = 1, tags = "train"),
m = p_dbl(1, default = 2, tags = "train"),
rate.par = p_dbl(0, 1, tags = "train"),
weights = p_uty(default = 1L, tags = "train", custom_check = crate(function(x) {
if (test_numeric(x) && all(x > 0) || check_count(x, positive = TRUE)) {
TRUE
Expand All @@ -42,15 +42,15 @@ LearnerClustCMeans = R6Class("LearnerClustCMeans",
control = p_uty(tags = "train")
)
# add deps
ps$add_dep("rate.par", "method", CondEqual$new("ufcl"))
param_set$add_dep("rate.par", "method", CondEqual$new("ufcl"))

ps$set_values(centers = 2L)
param_set$set_values(centers = 2L)

super$initialize(
id = "clust.cmeans",
feature_types = c("logical", "integer", "numeric"),
predict_types = c("partition", "prob"),
param_set = ps,
param_set = param_set,
properties = c("partitional", "fuzzy", "complete"),
packages = "e1071",
man = "mlr3cluster::mlr_learners_clust.cmeans",
Expand Down
10 changes: 5 additions & 5 deletions R/LearnerClustCobweb.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ LearnerClustCobweb = R6Class("LearnerClustCobweb",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
A = p_dbl(default = 1, lower = 0, tags = "train"),
C = p_dbl(default = 0.002, lower = 0, tags = "train"),
S = p_int(default = 42L, lower = 1L, tags = "train")
param_set = ps(
A = p_dbl(0, default = 1, tags = "train"),
C = p_dbl(0, default = 0.002, tags = "train"),
S = p_int(1L, default = 42L, tags = "train")
)

super$initialize(
id = "clust.cobweb",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
param_set = param_set,
properties = c("partitional", "exclusive", "complete"),
packages = "RWeka",
man = "mlr3cluster::mlr_learners_clust.cobweb",
Expand Down
14 changes: 7 additions & 7 deletions R/LearnerClustDBSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ LearnerClustDBSCAN = R6Class("LearnerClustDBSCAN",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
eps = p_dbl(lower = 0, tags = c("required", "train")),
minPts = p_int(lower = 0L, default = 5L, tags = "train"),
param_set = ps(
eps = p_dbl(0, tags = c("required", "train")),
minPts = p_int(0L, default = 5L, tags = "train"),
borderPoints = p_lgl(default = TRUE, tags = "train"),
weights = p_uty(tags = "train", custom_check = crate(function(x) check_numeric(x))),
search = p_fct(levels = c("kdtree", "linear", "dist"), default = "kdtree", tags = "train"),
bucketSize = p_int(lower = 1L, default = 10L, tags = "train"),
bucketSize = p_int(1L, default = 10L, tags = "train"),
splitRule = p_fct(
levels = c("STD", "MIDPT", "FAIR", "SL_MIDPT", "SL_FAIR", "SUGGEST"), default = "SUGGEST", tags = "train"
),
approx = p_dbl(default = 0, tags = "train")
)
# add deps
ps$add_dep("bucketSize", "search", CondEqual$new("kdtree"))
ps$add_dep("splitRule", "search", CondEqual$new("kdtree"))
param_set$add_dep("bucketSize", "search", CondEqual$new("kdtree"))
param_set$add_dep("splitRule", "search", CondEqual$new("kdtree"))

super$initialize(
id = "clust.dbscan",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
param_set = param_set,
properties = c("partitional", "exclusive", "complete"),
packages = "dbscan",
man = "mlr3cluster::mlr_learners_clust.dbscan",
Expand Down
4 changes: 2 additions & 2 deletions R/LearnerClustDBSCANfpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ LearnerClustDBSCANfpc = R6Class("LearnerClustDBSCANfpc",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
eps = p_dbl(lower = 0, tags = c("required", "train")),
MinPts = p_int(lower = 0L, default = 5L, tags = "train"),
eps = p_dbl(0, tags = c("required", "train")),
MinPts = p_int(0L, default = 5L, tags = "train"),
scale = p_lgl(default = FALSE, tags = "train"),
method = p_fct(levels = c("hybrid", "raw", "dist"), tags = "train"),
seeds = p_lgl(default = TRUE, tags = "train"),
Expand Down
10 changes: 5 additions & 5 deletions R/LearnerClustDiana.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ LearnerClustDiana = R6Class("LearnerClustDiana",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
param_set = ps(
metric = p_fct(default = "euclidean", levels = c("euclidean", "manhattan"), tags = "train"),
stand = p_lgl(default = FALSE, tags = "train"),
trace.lev = p_int(lower = 0L, default = 0L, tags = "train"),
k = p_int(lower = 1L, default = 2L, tags = "predict")
trace.lev = p_int(0L, default = 0L, tags = "train"),
k = p_int(1L, default = 2L, tags = "predict")
)
ps$set_values(k = 2L)
param_set$set_values(k = 2L)

super$initialize(
id = "clust.diana",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
param_set = param_set,
properties = c("hierarchical", "exclusive", "complete"),
packages = "cluster",
man = "mlr3cluster::mlr_learners_clust.diana",
Expand Down
24 changes: 12 additions & 12 deletions R/LearnerClustEM.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ LearnerClustEM = R6Class("LearnerClustEM",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
I = p_int(default = 100L, lower = 1L, tags = "train"),
ll_cv = p_dbl(default = 1e-6, lower = 1e-6, tags = "train"),
ll_iter = p_dbl(default = 1e-6, lower = 1e-6, tags = "train"),
M = p_dbl(default = 1e-6, lower = 1e-6, tags = "train"),
max = p_int(default = -1L, lower = -1L, tags = "train"),
N = p_int(default = -1L, lower = -1L, tags = "train"),
num_slots = p_int(default = 1L, lower = 1L, tags = "train"),
S = p_int(default = 100L, lower = 0L, tags = "train"),
X = p_int(default = 10L, lower = 1L, tags = "train"),
K = p_int(default = 10L, lower = 1L, tags = "train"),
param_set = ps(
I = p_int(1L, default = 100L, tags = "train"),
ll_cv = p_dbl(1e-6, default = 1e-6, tags = "train"),
ll_iter = p_dbl(1e-6, default = 1e-6, tags = "train"),
M = p_dbl(1e-6, default = 1e-6, tags = "train"),
max = p_int(-1L, default = -1L, tags = "train"),
N = p_int(-1L, default = -1L, tags = "train"),
num_slots = p_int(1L, default = 1L, tags = "train"),
S = p_int(0L, default = 100L, tags = "train"),
X = p_int(1L, default = 10L, tags = "train"),
K = p_int(1L, default = 10L, tags = "train"),
V = p_lgl(default = FALSE, tags = "train"),
output_debug_info = p_lgl(default = FALSE, tags = "train")
)
Expand All @@ -40,7 +40,7 @@ LearnerClustEM = R6Class("LearnerClustEM",
id = "clust.em",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
param_set = param_set,
properties = c("partitional", "exclusive", "complete"),
packages = "RWeka",
man = "mlr3cluster::mlr_learners_clust.em",
Expand Down
16 changes: 8 additions & 8 deletions R/LearnerClustFanny.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ LearnerClustFanny = R6Class("LearnerClustFanny",
#' @description
#' 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")),
memb.exp = p_dbl(lower = 1, default = 2, tags = "train"),
param_set = ps(
k = p_int(1L, default = 2L, tags = c("required", "train")),
memb.exp = p_dbl(1, default = 2, tags = "train"),
metric = p_fct(default = "euclidean", levels = c("euclidean", "manhattan", "SqEuclidean"), tags = "train"),
stand = p_lgl(default = FALSE, tags = "train"),
maxit = p_int(lower = 0L, default = 500L, tags = "train"),
tol = p_dbl(lower = 0, default = 1e-15, tags = "train"),
trace.lev = p_int(lower = 0L, default = 0L, tags = "train")
maxit = p_int(0L, default = 500L, tags = "train"),
tol = p_dbl(0, default = 1e-15, tags = "train"),
trace.lev = p_int(0L, default = 0L, tags = "train")
)
ps$set_values(k = 2L)
param_set$set_values(k = 2L)

super$initialize(
id = "clust.fanny",
feature_types = c("logical", "integer", "numeric"),
predict_types = c("partition", "prob"),
param_set = ps,
param_set = param_set,
properties = c("partitional", "fuzzy", "complete"),
packages = "cluster",
man = "mlr3cluster::mlr_learners_clust.fanny",
Expand Down
8 changes: 4 additions & 4 deletions R/LearnerClustFarthestFirst.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ LearnerClustFarthestFirst = R6Class("LearnerClustFF",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
N = p_int(default = 2L, lower = 1L, tags = "train"),
S = p_int(default = 1L, lower = 1L, tags = "train"),
param_set = ps(
N = p_int(1L, default = 2L, tags = "train"),
S = p_int(1L, default = 1L, tags = "train"),
output_debug_info = p_lgl(default = FALSE, tags = "train")
)

super$initialize(
id = "clust.ff",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
param_set = param_set,
properties = c("partitional", "exclusive", "complete"),
packages = "RWeka",
man = "mlr3cluster::mlr_learners_clust.ff",
Expand Down
8 changes: 3 additions & 5 deletions R/LearnerClustFeatureless.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ LearnerClustFeatureless = R6Class("LearnerClustFeatureless",
#' @description
#' 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"))
)
ps$set_values(num_clusters = 1L)
param_set = ps(num_clusters = p_int(1L, default = 1L, tags = c("required", "train", "predict")))
param_set$set_values(num_clusters = 1L)

super$initialize(
id = "clust.featureless",
feature_types = c("logical", "integer", "numeric"),
predict_types = c("partition", "prob"),
param_set = ps,
param_set = param_set,
properties = c("partitional", "exclusive", "complete", "missings"),
man = "mlr3cluster::mlr_learners_clust.featureless",
label = "Featureless Clustering"
Expand Down
10 changes: 5 additions & 5 deletions R/LearnerClustHclust.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LearnerClustHclust = R6Class("LearnerClustHclust",
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
param_set = ps(
method = p_fct(
default = "complete",
levels = c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", "median", "centroid"),
Expand All @@ -34,18 +34,18 @@ LearnerClustHclust = R6Class("LearnerClustHclust",
diag = p_lgl(default = FALSE, tags = c("train", "dist")),
upper = p_lgl(default = FALSE, tags = c("train", "dist")),
p = p_dbl(default = 2, tags = c("train", "dist")),
k = p_int(lower = 1L, default = 2L, tags = "predict")
k = p_int(1L, default = 2L, tags = "predict")
)

# param deps
ps$add_dep("p", "distmethod", CondAnyOf$new("minkowski"))
ps$set_values(k = 2L, distmethod = "euclidean")
param_set$add_dep("p", "distmethod", CondAnyOf$new("minkowski"))
param_set$set_values(k = 2L, distmethod = "euclidean")

super$initialize(
id = "clust.hclust",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
param_set = param_set,
properties = c("hierarchical", "exclusive", "complete"),
packages = "stats",
man = "mlr3cluster::mlr_learners_clust.hclust",
Expand Down
Loading

0 comments on commit 12eb820

Please sign in to comment.