-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathTaskGeneratorSimplex.R
66 lines (61 loc) · 1.94 KB
/
TaskGeneratorSimplex.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#' @title Simplex Classification Task Generator
#'
#' @name mlr_task_generators_simplex
#' @include TaskGenerator.R
#'
#' @description
#' A [TaskGenerator] for the simplex task in [mlbench::mlbench.simplex()].
#'
#' Note that the generator implemented in \CRANpkg{mlbench} returns
#' fewer samples than requested.
#'
#' @templateVar id simplex
#' @template task_generator
#'
#' @template seealso_task_generator
#' @export
#' @examples
#' generator = tgen("simplex")
#' plot(generator, n = 200)
#'
#' task = generator$generate(200)
#' str(task$data())
TaskGeneratorSimplex = R6Class("TaskGeneratorSimplex",
inherit = TaskGenerator,
public = list(
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
center = p_lgl(default = TRUE),
d = p_int(1L, default = 3L),
sd = p_dbl(0, default = 0.1),
sides = p_int(1L, default = 1L)
)
super$initialize(id = "simplex", "classif", "mlbench", ps,
label = "Simplex Classification", man = "mlr3::mlr_task_generators_simplex")
},
#' @description
#' Creates a simple plot of generated data.
#' @param n (`integer(1)`)\cr
#' Number of samples to draw for the plot. Default is 200.
#' @param pch (`integer(1)`)\cr
#' Point char. Passed to [plot()].
#' @param ... (any)\cr
#' Additional arguments passed to [plot()].
plot = function(n = 200L, pch = 19L, ...) {
plot(private$.generate_obj(n), pch = pch, ...)
}
),
private = list(
.generate_obj = function(n) {
invoke(mlbench::mlbench.simplex, n = n, .args = self$param_set$values, .opts = allow_partial_matching)
},
.generate = function(n) {
obj = private$.generate_obj(n)
TaskClassif$new(sprintf("%s_%i", self$id, n), convert_mlbench(obj), target = "y")
}
)
)
#' @include mlr_task_generators.R
mlr_task_generators$add("simplex", function() TaskGeneratorSimplex$new())