-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cross-correlation pipe op (#109)
* feat: draft for correlation pipe op * docs: remove some old args * chore: add grid as param * docs: update description for cor * feat: bring tfr to common domain * perf: only reshape function when outside domain * feat: transform to common domain via min max scaling * feat: more changes for cor * tests: simpliy tests for cross-correlation * tests: restructure * refactor: move helpers back since only used in extract * refactor: reuse ncol * fix: missing document * docs: remove stats tag and rebuild readme * tests: test for non matching domain * refactor: revert var rename * docs: update news * tests: more tests * chore: update .Rbuildignore * tests: use expect_identical * docs(cor): missing indent * tests: adding withr for random seed usage * tests: add error message for test * tests: add message for warning * feat: add mlr3pipelines to depends * chore: remove unneeded mlr3 and mlr3pieplines import in tests * fix: still import * docs: some more description * docs: update news
- Loading branch information
Showing
26 changed files
with
270 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#' @title Cross-Correlation of Functional Data | ||
#' @name mlr_pipeops_fda.cor | ||
#' | ||
#' @description | ||
#' Calculates the cross-correlation between two functional vectors using [tf::tf_crosscor()]. | ||
#' Note that it only operates on regular data and that the cross-correlation assumes that each column | ||
#' has the same domain. | ||
#' | ||
#' @section Parameters: | ||
#' The parameters are the parameters inherited from [`PipeOpTaskPreprocSimple`], as well as the following | ||
#' parameters: | ||
#' * `arg` :: `numeric()` \cr | ||
#' Grid to use for the cross-correlation. | ||
#' | ||
#' @export | ||
#' @examples | ||
#' set.seed(1234L) | ||
#' dt = data.table(y = 1:100, x1 = tf::tf_rgp(100L), x2 = tf::tf_rgp(100L)) | ||
#' task = as_task_regr(dt, target = "y") | ||
#' po_cor = po("fda.cor") | ||
#' task_cor = po_cor$train(list(task))[[1L]] | ||
#' task_cor | ||
PipeOpFDACor = R6Class("PipeOpFDACor", | ||
inherit = mlr3pipelines::PipeOpTaskPreprocSimple, | ||
public = list( | ||
#' @description Initializes a new instance of this Class. | ||
#' @param id (`character(1)`)\cr | ||
#' Identifier of resulting object, default `"fda.cor"`. | ||
#' @param param_vals (named `list`)\cr | ||
#' List of hyperparameter settings, overwriting the hyperparameter settings that would | ||
#' otherwise be set during construction. Default `list()`. | ||
initialize = function(id = "fda.cor", param_vals = list()) { | ||
param_set = ps( | ||
arg = p_uty(tags = c("train", "predict"), custom_check = check_numeric) | ||
) | ||
|
||
super$initialize( | ||
id = id, | ||
param_set = param_set, | ||
param_vals = param_vals, | ||
packages = c("mlr3fda", "mlr3pipelines", "tf"), | ||
feature_types = "tfd_reg", | ||
tags = "fda" | ||
) | ||
} | ||
), | ||
private = list( | ||
.transform_dt = function(dt, levels) { | ||
pars = self$param_set$get_values() | ||
|
||
k = ncol(dt) | ||
if (k < 2L) { | ||
warningf("task has less than 2 columns") | ||
return(dt) | ||
} | ||
|
||
nms = names(dt) | ||
res = list() | ||
for (i in 2:k) { | ||
for (j in 1:(i - 1L)) { | ||
x = dt[[i]] | ||
y = dt[[j]] | ||
if (!all(tf::tf_domain(x) == tf::tf_domain(y))) { | ||
stopf("Domain of %s and %s do not match", nms[[j]], nms[[i]]) | ||
} | ||
nm = sprintf("%s_%s_cor", nms[[j]], nms[[i]]) | ||
res[[nm]] = invoke(tf::tf_crosscor, x = x, y = y, .args = pars) | ||
} | ||
} | ||
setDT(res) | ||
} | ||
) | ||
) | ||
|
||
#' @include zzz.R | ||
register_po("fda.cor", PipeOpFDACor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.