Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
4db7cfc
first upload on HiwiBranch
awinterstetter Jun 26, 2025
4f4716c
27.06.2025 - 16:35
awinterstetter Jun 27, 2025
b5eb4dd
before logger change
awinterstetter Jun 28, 2025
c585791
code aufgeräumt
awinterstetter Jun 29, 2025
e237d8b
private.output implemented
awinterstetter Jun 29, 2025
d4daed6
push before changing train function
awinterstetter Jun 29, 2025
2e7613e
updates in the night
awinterstetter Jun 29, 2025
0289424
final changes sunday
awinterstetter Jun 29, 2025
42f826d
morning changes
awinterstetter Jun 30, 2025
5bd71ce
Änderungen nach Meeting mit Martin
awinterstetter Jun 30, 2025
e581ace
test file 1st upload
awinterstetter Jul 4, 2025
1e03403
Intendation fixed, invisible print, string at the top of each console…
awinterstetter Jul 4, 2025
66f53a8
prediction object print implementiert
awinterstetter Jul 4, 2025
582f2ac
first tests implemented
awinterstetter Jul 4, 2025
22f4b77
output test translated into a loop
awinterstetter Jul 6, 2025
c3e8ca1
collect_multiplicity test implemented
awinterstetter Jul 6, 2025
eee3071
malformed log target test implemented
awinterstetter Jul 6, 2025
d01a2fa
collect_multiplicity Test wurde modifiziert
awinterstetter Jul 6, 2025
554ea1a
changes after meeting with Martin (7.7.)
awinterstetter Jul 7, 2025
e229245
small changes
awinterstetter Jul 7, 2025
faf68a8
changes after meeting
awinterstetter Jul 7, 2025
bd64c52
self§state implemented; test input vs output implemented
awinterstetter Jul 10, 2025
bfadd92
changes Friday Morning
awinterstetter Jul 11, 2025
5e6fbcb
devtools::load_all() fix
awinterstetter Jul 11, 2025
d06ec8f
nach ewig langem rumfixen, geht jetzt devtools::test(...)
awinterstetter Jul 11, 2025
e1692f9
Saturday updates
awinterstetter Jul 12, 2025
dafd8a6
ignire
awinterstetter Jul 13, 2025
8c36fc7
regex test "$data" for task implemented
awinterstetter Jul 13, 2025
0e48999
regex test implemented
awinterstetter Jul 14, 2025
9595990
changes after meeting mit Martin (14.07.2025)
awinterstetter Jul 14, 2025
79e3def
PipeOp Info tests impemented
awinterstetter Jul 18, 2025
18a38fb
expect_printer_output fixed (no more capture_warnings etc.)
awinterstetter Aug 8, 2025
35d3749
pipeopinfo test modified
awinterstetter Aug 9, 2025
e8e6495
PipeOpIsomap changes
awinterstetter Aug 10, 2025
df15662
PipeOp Isomap Predictions vergleichbar mit S4 Algorithmus
awinterstetter Aug 11, 2025
78ecd59
PipeOPIsomap working similar on iris data
awinterstetter Aug 13, 2025
8bfd2fa
tag = "debug" added
awinterstetter Aug 13, 2025
dbcd05b
tag = "debug" added at the appropriate spot
awinterstetter Aug 13, 2025
5d69ec6
c() replaced by list() at multiple instances
awinterstetter Aug 13, 2025
bddb834
capture_warning/capture_messages bei test_that("pattern check") erset…
awinterstetter Aug 13, 2025
85b8de9
redundanten Part entfernt
awinterstetter Aug 13, 2025
3f6034e
tag = "debug" removed, so that tests have no warning
awinterstetter Aug 13, 2025
a6f0d51
test for collect_multiplicity refined
awinterstetter Aug 13, 2025
16e62c1
implemented predict-test in "regex pattern" test and standardized var…
awinterstetter Aug 13, 2025
550bbfd
test update on github
awinterstetter Aug 14, 2025
4b6dc5b
undo test
awinterstetter Aug 14, 2025
ec76f78
MacBook next try
awinterstetter Aug 14, 2025
489bac7
test
awinterstetter Aug 14, 2025
6e3f109
test different PAT
awinterstetter Aug 14, 2025
fda57c0
changes in the documentation
awinterstetter Aug 14, 2025
2a7c707
changes in train and predict function
awinterstetter Aug 15, 2025
3250bf8
test code in attic
awinterstetter Aug 15, 2025
6a89a04
minor changes regarding hyperparameters
awinterstetter Aug 15, 2025
dbd387a
changes in comments and test documentation
awinterstetter Aug 17, 2025
85a5dba
changes in default parameters
awinterstetter Aug 17, 2025
59d46d7
test code changes
awinterstetter Aug 17, 2025
5cb4622
minor changes in "pattern-check"-test
awinterstetter Aug 18, 2025
76189db
pipeop isomap reworked and pipe_op_info test cleaned
awinterstetter Aug 18, 2025
3ca9089
test "original printer overwritten" is fixed
awinterstetter Aug 18, 2025
cea1990
removed test code file
awinterstetter Aug 18, 2025
aa11906
pipeopisomap added in description
awinterstetter Aug 19, 2025
5a090db
skip if not installed rpart
awinterstetter Aug 19, 2025
77c8105
changes in description and global definition for predict and capture.…
awinterstetter Aug 19, 2025
1beeb22
backports replaced by utils
awinterstetter Aug 19, 2025
e8d4ea7
backports completely replaced by utils
awinterstetter Aug 19, 2025
52724b0
first tests implemented for isomap
awinterstetter Aug 20, 2025
333dcaa
devtools::document() ran in repo folder
awinterstetter Aug 21, 2025
f0fa24b
push after devtools::document()
awinterstetter Aug 21, 2025
42a3102
test for isomap implemented
awinterstetter Aug 21, 2025
7134076
update (pls work validity checks)
awinterstetter Aug 21, 2025
90a7795
fixing predict error in isomap
awinterstetter Aug 22, 2025
5f6ee94
removed default = NULL
awinterstetter Aug 22, 2025
ef2330a
@method predict Graph added in Graph.R
awinterstetter Aug 22, 2025
a274e81
added RANN and RSpectra to suggests in DESCRIPTION
awinterstetter Aug 22, 2025
809bf6e
changes on documentation for PipeOpInfo
awinterstetter Aug 25, 2025
0058a7a
slight changes to pipeopinfo
awinterstetter Aug 25, 2025
014698d
Fixes for hyperparameters get_geod and .mute
awinterstetter Aug 25, 2025
cdb7b60
fix for test
awinterstetter Aug 25, 2025
05a6b29
added isomap tests
awinterstetter Aug 26, 2025
08f70e3
minor changes in tests isomap
awinterstetter Aug 26, 2025
d2542ff
changes in HP so that they refer correctly to the set default
awinterstetter Aug 27, 2025
5643285
changes after meeting with Martin (PipeOpIsomap has dimRed::predict, …
awinterstetter Aug 27, 2025
120eecd
comment out test for mute
awinterstetter Aug 27, 2025
233b1ee
change in feature types in super$initialize
awinterstetter Aug 27, 2025
e25eb83
fixed isomap tests
awinterstetter Sep 18, 2025
b08b048
added example to PipeOpIsomap in documentation
awinterstetter Sep 19, 2025
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
17 changes: 2 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,44 @@
*.swp
doc
Meta

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# pkgdown site
docs/
/Meta/
logger_file
.DS_Store
9 changes: 8 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ Suggests:
future,
htmlwidgets,
ranger,
themis
themis,
lgr,
checkmate,
dimRed,
RSpectra,
RANN
ByteCompile: true
Encoding: UTF-8
Config/testthat/edition: 3
Expand Down Expand Up @@ -159,6 +164,8 @@ Collate:
'PipeOpImputeMode.R'
'PipeOpImputeOOR.R'
'PipeOpImputeSample.R'
'PipeOpInfo.R'
'PipeOpIsomap.R'
'PipeOpKernelPCA.R'
'PipeOpLearner.R'
'PipeOpLearnerCV.R'
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export(PipeOpImputeMedian)
export(PipeOpImputeMode)
export(PipeOpImputeOOR)
export(PipeOpImputeSample)
export(PipeOpInfo)
export(PipeOpIsomap)
export(PipeOpKernelPCA)
export(PipeOpLearner)
export(PipeOpLearnerCV)
Expand Down
1 change: 1 addition & 0 deletions R/Graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ graph_load_namespaces = function(self, info) {


#' @export
#' @method predict Graph
predict.Graph = function(object, newdata, ...) {
if (!object$is_trained) {
stop("Cannot predict, Graph has not been trained yet")
Expand Down
146 changes: 146 additions & 0 deletions R/PipeOpInfo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#' @title Customizable Information Printer
#'
#' @usage NULL
#' @name mlr_pipeops_info
#' @format [`R6Class`][R6::R6Class] object inheriting from [`PipeOp`]
#'
#' @description
#' Given input is printed in a customizable way.
#'
#'
#' @section Construction:
#' ```
#' PipeOpInfo$new(id = "info", collect_multiplicity = FALSE, log_target = "lgr::mlr3/mlr3pipelines::info")
#' ```
#' * `ìd` :: `character(1)`\cr
#' Identifier of resulting object, default "info"
#' * `printer` :: `list` \cr
#' User input, specified printer-functions defined for a new object-classes or used to override their counterparts in the `original_printer`
#' * `collect_multiplicity` :: `logical(1)`\cr
#' If `TRUE`, the input is a [`Multiplicity`] collecting channel. This means, a
#' [`Multiplicity`] input/output, instead of multiple normal inputs/outputs, is accepted and the members are aggregated.
#' * `log_target` :: `character(1)`\cr
#' Specifies how the output is printed, can either be assigned to a logger with a specified level, or can be printer in the
#' format "message", "warning" or "cat". When the log_target is specified as "none", the input will be printed as is.
#' Has either he form <output>::<argument1>::<argument2> for logger output otherwise "message", "warning", "cat" or none.
#'
#' @section Input and Output Channels:
#' `PipeOpInfo` has one input channel called "input", it can take any type of input (*)
#' `PipeOpInfo` has one output channel called "output", it can take any type of output (*)
#'
#' @section State:
#' The `$state` is left empty (`list()`).
#'
#' @section Fields:
#' Fields inherited from `PipeOp`, as well as:
#' * `printer` :: `list`\cr
#' List that contains information on how a specific object-class should be printed to the console.
#' * `log_target` :: `character(1)` \cr
#' Specifies how the printed console output should be displayed to the user.
#'
#' @section Methods:
#' Only methods inherited from [`PipeOp`].
#'
#' @examples
#' library("mlr3")
#' poinfo = po("info")
#' poinfo$train(list(tsk("mtcars")))
#' poinfo$predict(list(tsk("penguins")))
#'
#' @family PipeOps
#' @template seealso_pipeopslist
#' @include PipeOp.R
#' @export
#'
#'

PipeOpInfo = R6Class("PipeOpInfo",
inherit = PipeOp,
public = list(
initialize = function(id = "info", printer = NULL, collect_multiplicity = FALSE, log_target = "lgr::mlr3/mlr3pipelines::info", param_vals = list()) {
assertString(log_target, pattern = "^(cat|none|warning|message|lgr::[^:]+::[^:]+)$")
inouttype = "*"
if (collect_multiplicity) {
inouttype = sprintf("[%s]", inouttype)
}
super$initialize(id, param_vals = param_vals,
input = data.table(name = "input", train = inouttype, predict = inouttype),
output = data.table(name = "output", train = inouttype, predict = inouttype)
#tag = "debug"
)
original_printer = list(
Task = crate(function(x) {
list(task = x, data = x$data()[, 1:min(10, ncol(x$data()))])
}),
Prediction = crate(function(x) {
tryCatch(list(prediction = x, score = x$score()), error = function(e) {list(prediction = x)})
}),
`NULL` = crate(function(x) "NULL"),
default = crate(function(x) x)
)
private$.printer = insert_named(original_printer, printer)
private$.log_target = log_target
}
),
active = list(
printer = function(rhs) {
if (!missing(rhs)) stop("printer is read only.")
private$.printer
},
log_target = function(rhs) {
if (!missing(rhs)) stop("log_target is read only.")
private$.log_target
}
),
private = list(
.printer = NULL,
.log_target = NULL,
.output = function(inputs, stage) {
input_class = class(inputs[[1]])
leftmost_class =
if (any(input_class %in% names(private$.printer))) {
input_class[input_class %in% names(private$.printer)][[1]]
} else {
"default"
}
if (!("default" %in% names(private$.printer))) {
stop("Object-class was not found and no default printer is available.")
}
specific_printer = private$.printer[[leftmost_class]]
log_target_split = strsplit(private$.log_target, "::")[[1]]
stage_string = sprintf("Object passing through PipeOp %s - %s", self$id, stage)
print_string = utils::capture.output({
cat(stage_string, "\n\n")
specific_printer(inputs[[1]])
})
if (log_target_split[[1]] == "lgr") {
logger = lgr::get_logger(log_target_split[[2]])
log_level = log_target_split[[3]]
logger$log(log_level, msg = print_string)
} else if (private$.log_target == "cat") {
cat(paste(print_string, collapse = "\n"))
} else if (private$.log_target == "message") {
message(paste(print_string, collapse = "\n"))
} else if (private$.log_target == "warning") {
warning(paste(print_string, collapse = "\n"))
} else if (private$.log_target == "none") {
} else {
stopf("Invalid log_target '%s'.", log_target)
}
},
.train = function(inputs, stage = "Training") {
self$state = list()
private$.output(inputs, stage)
inputs
},
.predict = function(inputs, stage = "Prediction") {
private$.output(inputs, stage)
inputs
},
.additional_phash_input = function() {
list(printer = self$printer, log_target = self$log_target)
}
)
)

mlr_pipeops$add("info", PipeOpInfo)
105 changes: 105 additions & 0 deletions R/PipeOpIsomap.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#' @title Algorithm for Dimensionality Reduction
#'
#' @usage NULL
#' @name mlr_pipeops_isomap
#' @format [`R6Class`][R6::R6Class] object inheriting from [`PipeOpTaskPreproc`]
#'
#'
#'
#' @section Construction:
#' ```
#' PipeOpIsomap$new(id = "isomap", ...)
#' ```
#'
#' * `ìd` :: `character(1)`\cr
#' Identifier of resulting object, default `"isomap"`
#' * `param_vals` :: named `list`\cr
#' List of hyperparameter settings, overwriting the hyperparameter settings that would otherwise be set during construction. Default `list()`.
#'
#' @section Input and Output Channels:
#' Input and output channels are inherited from [`PipeOpTaskPreproc`].
#'
#' The output is the input [`Task`][mlr3::Task] with the data projected on the lower dimension.
#'
#' @section State:
#'
#' @section Parameters:
#' The parameters are the parameters inherited from [`PipeOpTaskPreproc`], as well as:
#' * `knn` :: `numeric(1)`\cr
#' The number of nearest neighbors in the graph.
#' Initialized to 50.
#' * `ndim` :: `numeric(1)`\cr
#' The number of embedding dimensions.
#' Initialized to 2.
#' * `get_geod` :: `logical(1)`\cr
#' Determines whether the distance matrix should be kept in the `$state`
#' Initialized to `FALSE`.
#' * `.mute` :: `character`\cr
#' A character vector containing the elements you want to mute during training (c("message", "output")).
#' Initialized to `character(0)`.
#'
#'
#' @section Internals:
#' Applies the Isomap Embedding from the `dimRed`-package.
#'
#' @section Fields:
#' Only fields inherited from `PipeOp`.
#'
#' @section Methods:
#'
#'
#' @examples
#' po = po("isomap")
#' po$train(list(tsk("iris")))[[1]]$data()
#' po$predict(list(tsk("iris")))[[1]]$data()
#'
#'
#' @family PipeOps
#' @template seealso_pipeopslist
#' @include PipeOpTaskPreproc.R
#' @export
#'

PipeOpIsomap = R6Class("PipeOpIsomap",
inherit = PipeOpTaskPreproc,
public = list(
initialize = function(id = "isomap", param_vals = list()) {
ps = ps(
knn = p_int(default = 50, lower = 1, upper = Inf, tags = c("train", "isomap")),
ndim = p_int(default = 2, lower = 1, upper = Inf, tags = c("train", "isomap")),
get_geod = p_lgl(default = FALSE, tags = c("train", "isomap")),
.mute = p_uty(init = c("message", "output"), tags = c("train", "isomap"))
)
super$initialize(id = id, param_set = ps, param_vals = param_vals, packages = c("dimRed", "stats"))
}
),
private = list(
.train_dt = function(dt, levels, target) {
embed_result = mlr3misc::invoke(.f = dimRed::embed, .data = dt, .method = "Isomap", .args = self$param_set$get_values(tags = "isomap"))
self$state = list(embed_result = embed_result)
embed_result@data@data
},
.predict_dt = function(dt, levels) {
dimRed::predict(self$state$embed_result, as.data.frame(dt))@data
}
)
)

mlr_pipeops$add("isomap", PipeOpIsomap)

# po = po("isomap", .mute = "message")
# po$param_set$get_values(tags = "train")


# po$train(list(tsk("iris")))[[1]]$data()
# po$predict(list(tsk("iris")))[[1]]$data()

# po$train(list(tsk("mtcars")))
# po$predict(list(tsk("mtcars")))[[1]]$data()

# emb2 <- embed(iris[1:4], "Isomap", .mute = NULL, knn = 25)
# emb3 <- predict(emb2, iris[1:4])

# po = po("isomap", knn = 20, ndim = 2, get_geod = TRUE)
# plot(po$train(list(tsk("mtcars")))[[1]]$data()[,2:3])

2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ register_mlr3 = function() {
x$pipeops$valid_tags = unique(c(x$pipeops$valid_tags,
c("abstract", "meta", "missings", "feature selection", "imbalanced data",
"data transform", "target transform", "ensemble", "robustify", "learner", "encode",
"multiplicity")))
"multiplicity", "debug")))
x$pipeops$properties = c("validation", "internal_tuning")
}

Expand Down
2 changes: 2 additions & 0 deletions man/PipeOp.Rd

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

2 changes: 2 additions & 0 deletions man/PipeOpEncodePL.Rd

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

2 changes: 2 additions & 0 deletions man/PipeOpEnsemble.Rd

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

2 changes: 2 additions & 0 deletions man/PipeOpImpute.Rd

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

Loading
Loading