Skip to content

chore: use air format #104

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
^Meta$
^README\.Rmd$
^README\.html$
^[\.]?air\.toml$
^\.Renviron$
^\.Rproj\.user$
^\.ccache$
Expand Down
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.3.9008
hooks:
- id: style-files
args: [--style_pkg=styler.mlr, --style_fun=mlr_style]
additional_dependencies:
- mlr-org/styler.mlr
- id: roxygenize
additional_dependencies:
- ClusterR
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClust.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
#' # get a specific learner from mlr_learners:
#' learner = lrn("clust.kmeans")
#' print(learner)
LearnerClust = R6Class("LearnerClust",
LearnerClust = R6Class(
"LearnerClust",
inherit = Learner,
public = list(
#' @field assignments (`NULL` | `vector()`)\cr
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustAffinityPropagation.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustAP = R6Class("LearnerClustAP",
LearnerClustAP = R6Class(
"LearnerClustAP",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
6 changes: 4 additions & 2 deletions R/LearnerClustAgnes.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustAgnes = R6Class("LearnerClustAgnes",
LearnerClustAgnes = R6Class(
"LearnerClustAgnes",
inherit = LearnerClust,
public = list(
#' @description
Expand Down Expand Up @@ -66,7 +67,8 @@ LearnerClustAgnes = R6Class("LearnerClustAgnes",
private = list(
.train = function(task) {
pv = self$param_set$get_values(tags = "train")
m = invoke(cluster::agnes,
m = invoke(
cluster::agnes,
x = task$data(),
diss = FALSE,
.args = remove_named(pv, "k")
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustBICO.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustBICO = R6Class("LearnerClustBICO",
LearnerClustBICO = R6Class(
"LearnerClustBICO",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustBIRCH.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustBIRCH = R6Class("LearnerClustBIRCH",
LearnerClustBIRCH = R6Class(
"LearnerClustBIRCH",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
25 changes: 14 additions & 11 deletions R/LearnerClustCMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,32 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustCMeans = R6Class("LearnerClustCMeans",
LearnerClustCMeans = R6Class(
"LearnerClustCMeans",
inherit = LearnerClust,
public = list(
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
centers = p_uty(
tags = c("required", "train"), custom_check = check_centers
),
centers = p_uty(tags = c("required", "train"), custom_check = check_centers),
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(1, default = 2, tags = "train"),
rate.par = p_dbl(0, 1, tags = "train", depends = quote(method == "ufcl")),
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
} else {
"`weights` must be positive numeric vector or a single positive number"
}
})),
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
} else {
"`weights` must be positive numeric vector or a single positive number"
}
})
),
control = p_uty(tags = "train")
)

Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustCobweb.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustCobweb = R6Class("LearnerClustCobweb",
LearnerClustCobweb = R6Class(
"LearnerClustCobweb",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustDBSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustDBSCAN = R6Class("LearnerClustDBSCAN",
LearnerClustDBSCAN = R6Class(
"LearnerClustDBSCAN",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
39 changes: 24 additions & 15 deletions R/LearnerClustDBSCANfpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustDBSCANfpc = R6Class("LearnerClustDBSCANfpc",
LearnerClustDBSCANfpc = R6Class(
"LearnerClustDBSCANfpc",
inherit = LearnerClust,
public = list(
#' @description
Expand All @@ -27,20 +28,28 @@ 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(default = FALSE, tags = "train", custom_check = crate(function(x) {
if (test_flag(x) || test_int(x, lower = 0L, upper = 2L)) {
TRUE
} else {
"`showplot` need to be either logical or integer between 0 and 2"
}
})),
countmode = p_uty(default = NULL, tags = "train", custom_check = crate(function(x) {
if (test_integer(x, null.ok = TRUE)) {
TRUE
} else {
"`countmode` need to be NULL or vector of integers"
}
}))
showplot = p_uty(
default = FALSE,
tags = "train",
custom_check = crate(function(x) {
if (test_flag(x) || test_int(x, lower = 0L, upper = 2L)) {
TRUE
} else {
"`showplot` need to be either logical or integer between 0 and 2"
}
})
),
countmode = p_uty(
default = NULL,
tags = "train",
custom_check = crate(function(x) {
if (test_integer(x, null.ok = TRUE)) {
TRUE
} else {
"`countmode` need to be NULL or vector of integers"
}
})
)
)

param_set$set_values(MinPts = 5L, scale = FALSE, seeds = TRUE, showplot = FALSE, countmode = NULL)
Expand Down
6 changes: 4 additions & 2 deletions R/LearnerClustDiana.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustDiana = R6Class("LearnerClustDiana",
LearnerClustDiana = R6Class(
"LearnerClustDiana",
inherit = LearnerClust,
public = list(
#' @description
Expand Down Expand Up @@ -47,7 +48,8 @@ LearnerClustDiana = R6Class("LearnerClustDiana",
private = list(
.train = function(task) {
pv = self$param_set$get_values(tags = "train")
m = invoke(cluster::diana,
m = invoke(
cluster::diana,
x = task$data(),
diss = FALSE,
.args = remove_named(pv, "k")
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustEM.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustEM = R6Class("LearnerClustEM",
LearnerClustEM = R6Class(
"LearnerClustEM",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustFanny.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustFanny = R6Class("LearnerClustFanny",
LearnerClustFanny = R6Class(
"LearnerClustFanny",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustFarthestFirst.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustFarthestFirst = R6Class("LearnerClustFF",
LearnerClustFarthestFirst = R6Class(
"LearnerClustFF",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
16 changes: 10 additions & 6 deletions R/LearnerClustFeatureless.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustFeatureless = R6Class("LearnerClustFeatureless",
LearnerClustFeatureless = R6Class(
"LearnerClustFeatureless",
inherit = LearnerClust,
public = list(
#' @description
Expand Down Expand Up @@ -68,11 +69,14 @@ LearnerClustFeatureless = R6Class("LearnerClustFeatureless",

# reorder rows so that the max probability corresponds to
# the selected partition in `partition`
prob = do.call(rbind, map(seq_along(partition), function(i) {
x = prob[i, , drop = TRUE]
pos = which_max(x)
if (pos == i) x else append(x[-pos], x[pos], after = partition[i] - 1L)
}))
prob = do.call(
rbind,
map(seq_along(partition), function(i) {
x = prob[i, , drop = TRUE]
pos = which_max(x)
if (pos == i) x else append(x[-pos], x[pos], after = partition[i] - 1L)
})
)
}

PredictionClust$new(task = task, partition = partition, prob = prob)
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustHDBSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustHDBSCAN = R6Class("LearnerClustHDBSCAN",
LearnerClustHDBSCAN = R6Class(
"LearnerClustHDBSCAN",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
9 changes: 6 additions & 3 deletions R/LearnerClustHclust.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustHclust = R6Class("LearnerClustHclust",
LearnerClustHclust = R6Class(
"LearnerClustHclust",
inherit = LearnerClust,
public = list(
#' @description
Expand Down Expand Up @@ -56,12 +57,14 @@ LearnerClustHclust = R6Class("LearnerClustHclust",
private = list(
.train = function(task) {
pv = self$param_set$get_values(tags = "train")
dist = invoke(stats::dist,
dist = invoke(
stats::dist,
x = task$data(),
method = pv$d %??% "euclidean",
.args = self$param_set$get_values(tags = c("train", "dist"))
)
m = invoke(stats::hclust,
m = invoke(
stats::hclust,
d = dist,
.args = self$param_set$get_values(tags = c("train", "hclust"))
)
Expand Down
18 changes: 13 additions & 5 deletions R/LearnerClustKKMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustKKMeans = R6Class("LearnerClustKKMeans",
LearnerClustKKMeans = R6Class(
"LearnerClustKKMeans",
inherit = LearnerClust,
public = list(
#' @description
Expand All @@ -33,10 +34,15 @@ LearnerClustKKMeans = R6Class("LearnerClustKKMeans",
tags = "train"
),
sigma = p_dbl(
0, tags = "train", depends = quote(kernel %in% c("rbfdot", "anovadot", "besseldot", "laplacedot"))
0,
tags = "train",
depends = quote(kernel %in% c("rbfdot", "anovadot", "besseldot", "laplacedot"))
),
degree = p_int(
1L, default = 3L, tags = "train", depends = quote(kernel %in% c("polydot", "anovadot", "besseldot"))
1L,
default = 3L,
tags = "train",
depends = quote(kernel %in% c("polydot", "anovadot", "besseldot"))
),
scale = p_dbl(0, default = 1, tags = "train", depends = quote(kernel %in% c("polydot", "tanhdot"))),
offset = p_dbl(default = 1, tags = "train", depends = quote(kernel %in% c("polydot", "tanhdot"))),
Expand Down Expand Up @@ -83,11 +89,13 @@ LearnerClustKKMeans = R6Class("LearnerClustKKMeans",
# kernel product between each new datapoint and itself: rows are identical
d_xx = matrix(
rep(diag(kernlab::kernelMatrix(K, as.matrix(data))), each = ncol(d_xc)),
ncol = ncol(d_xc), byrow = TRUE
ncol = ncol(d_xc),
byrow = TRUE
)
# kernel product between each center and itself: columns are identical
d_cc = matrix(
rep(diag(kernlab::kernelMatrix(K, as.matrix(c))), each = nrow(d_xc)), nrow = nrow(d_xc)
rep(diag(kernlab::kernelMatrix(K, as.matrix(c))), each = nrow(d_xc)),
nrow = nrow(d_xc)
)
# this is the squared kernel distance to the centers
d2 = d_xx + d_cc - 2 * d_xc
Expand Down
7 changes: 5 additions & 2 deletions R/LearnerClustKMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustKMeans = R6Class("LearnerClustKMeans",
LearnerClustKMeans = R6Class(
"LearnerClustKMeans",
inherit = LearnerClust,
public = list(
#' @description
Expand All @@ -28,7 +29,9 @@ LearnerClustKMeans = R6Class("LearnerClustKMeans",
centers = p_uty(tags = c("required", "train"), custom_check = check_centers),
iter.max = p_int(1L, default = 10L, tags = "train"),
algorithm = p_fct(
levels = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen"), default = "Hartigan-Wong", tags = "train"
levels = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen"),
default = "Hartigan-Wong",
tags = "train"
),
nstart = p_int(1L, default = 1L, tags = "train"),
trace = p_int(0L, default = 0L, tags = "train")
Expand Down
3 changes: 2 additions & 1 deletion R/LearnerClustMclust.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#' @export
#' @template seealso_learner
#' @template example
LearnerClustMclust = R6Class("LearnerClustMclust",
LearnerClustMclust = R6Class(
"LearnerClustMclust",
inherit = LearnerClust,
public = list(
#' @description
Expand Down
Loading