-
Notifications
You must be signed in to change notification settings - Fork 6
add parameter to control output class #46
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
0a24c0a
2aec1c7
8173108
f5848a3
9ccc3e9
3404896
ae14d77
31b346a
c41c26d
a3373bf
690d329
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,22 +18,23 @@ | |
| #' @param ... other relevant parameters | ||
| #' @rdname cubical | ||
| #' @export cubical | ||
| #' @return `PHom` object | ||
| #' @return `"PHom"` or `"persistence"` object | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could have the documentation here link to the documentation of |
||
| #' @examples | ||
| #' | ||
| #' # 2-dim example | ||
| #' dataset <- rnorm(10 ^ 2) | ||
| #' dim(dataset) <- rep(10, 2) | ||
| #' cubical_hom2 <- cubical(dataset) | ||
| #' ( cubical_hom2 <- cubical(dataset) ) | ||
| #' | ||
| #' # 3-dim example | ||
| #' dataset <- rnorm(8 ^ 3) | ||
| #' dim(dataset) <- rep(8, 3) | ||
| #' cubical_hom3 <- cubical(dataset) | ||
| #' ( cubical_hom3 <- cubical(dataset) ) | ||
| #' | ||
| #' # 4-dim example | ||
| #' dataset <- rnorm(5 ^ 4) | ||
| #' dim(dataset) <- rep(5, 4) | ||
| #' ( cubical_hom4 <- cubical(dataset) ) | ||
| # Notes: | ||
| # - figure out format from `dataset` | ||
| # - return_format will be "df" (opinionated) w/ additional "PHom" S3 class | ||
|
|
@@ -47,9 +48,18 @@ cubical <- function(dataset, ...) { | |
| #' @param threshold maximum simplicial complex diameter to explore | ||
| #' @param method either `"lj"` (for Link Join) or `"cp"` (for Compute Pairs); | ||
| #' see Kaji et al. (2020) <https://arxiv.org/abs/2005.12692> for details | ||
| #' @param return_class class of output object; either `"PHom"` (default; legacy) | ||
| #' or `"persistence"` (from the | ||
| #' **[phutil](https://cran.r-project.org/package=phutil)** package) | ||
| #' @export cubical.array | ||
| #' @export | ||
| cubical.array <- function(dataset, threshold = 9999, method = "lj", ...) { | ||
| cubical.array <- function( | ||
| dataset, | ||
| threshold = 9999, | ||
| method = "lj", | ||
| return_class = c("PHom", "persistence"), | ||
| ... | ||
| ) { | ||
| # ensure valid arguments passed | ||
| validate_params_cub(threshold = threshold, | ||
| method = method) | ||
|
|
@@ -103,7 +113,16 @@ cubical.array <- function(dataset, threshold = 9999, method = "lj", ...) { | |
| } | ||
|
|
||
| # convert data frame to a PHom object | ||
| ans <- new_PHom(ans) | ||
| ans <- switch( | ||
| match.arg(return_class), | ||
| PHom = new_PHom(ans), | ||
| persistence = as_persistence( | ||
| ans, | ||
| engine = "ripserr::cubical", | ||
| filtration = "cubical", | ||
| parameters = list(threshold = threshold, method = method) | ||
| ) | ||
| ) | ||
|
|
||
| # return | ||
| return(ans) | ||
|
|
@@ -125,4 +144,4 @@ cubical.matrix <- function(dataset, ...) { | |
|
|
||
| # return | ||
| return(ans) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,11 +27,12 @@ | |
| #' <doi:10.1527/tjsai.D-G72>. Persistent homology of the resulting matrix is | ||
| #' then calculated. | ||
| #' | ||
| #' @importFrom phutil as_persistence | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to call
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. Feel free to make that change!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, i'm on it. |
||
| #' @param dataset object on which to calculate persistent homology | ||
| #' @param ... other relevant parameters | ||
| #' @rdname vietoris_rips | ||
| #' @export vietoris_rips | ||
| #' @return `PHom` object | ||
| #' @return `"PHom"` or `"persistence"` object | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On this and the above comment, i lean toward non-duplication of hyperlinks, and i believe (or at least intended) that the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On reflection, i'm with you. |
||
| #' @examples | ||
| #' | ||
| #' # create a 2-d point cloud of a circle (100 points) | ||
|
|
@@ -40,7 +41,7 @@ | |
| #' pt.cloud <- cbind(cos(rand.angle), sin(rand.angle)) | ||
| #' | ||
| #' # calculate persistent homology (num.pts by 3 numeric matrix) | ||
| #' pers.hom <- vietoris_rips(pt.cloud) | ||
| #' ( pers.hom <- vietoris_rips(pt.cloud) ) | ||
| # Notes: | ||
| # - figure out format from `dataset` | ||
| # - return_format will be "df" (opinionated) w/ additional "PHom" S3 class | ||
|
|
@@ -62,13 +63,16 @@ vietoris_rips.data.frame <- function(dataset, ...) { | |
| return(ans) | ||
| } | ||
|
|
||
| #' @rdname vietoris_rips | ||
| #' @param max_dim maximum dimension of persistent homology features to be | ||
| #' calculated | ||
| #' @param dim deprecated; passed to `max_dim` or ignored if `max_dim` is | ||
| #' specified | ||
| #' @param threshold maximum simplicial complex diameter to explore | ||
| #' @param p prime field in which to calculate persistent homology | ||
| #' @rdname vietoris_rips | ||
| #' @param return_class class of output object; either `"PHom"` (default; legacy) | ||
| #' or `"persistence"` (from the | ||
| #' **[phutil](https://cran.r-project.org/package=phutil)** package) | ||
| #' @export vietoris_rips.matrix | ||
| #' @export | ||
| vietoris_rips.matrix <- function( | ||
|
|
@@ -77,11 +81,23 @@ vietoris_rips.matrix <- function( | |
| threshold = -1, | ||
| p = 2L, | ||
| dim = NULL, | ||
| return_class = c("PHom", "persistence"), | ||
| ... | ||
| ) { | ||
|
|
||
| # shortcut for special case (only 1 row should return empty PHom) | ||
| if (nrow(dataset) == 1L) return(new_PHom()) | ||
| if (nrow(dataset) == 1L) { | ||
| return(switch( | ||
| match.arg(return_class), | ||
| PHom = new_PHom(), | ||
| persistence = as_persistence( | ||
| matrix(NA_real_, nrow = 0L, ncol = 3L), | ||
| engine = "ripserr::vietoris_rips", | ||
| filtration = "Vietoris-Rips", | ||
| parameters = list(max_dim = max_dim, threshold = threshold, p = p) | ||
| ) | ||
| )) | ||
| } | ||
|
|
||
| # handle `dim` if passed | ||
| if (! is.null(dim)) { | ||
|
|
@@ -111,7 +127,16 @@ vietoris_rips.matrix <- function( | |
| ans <- ripser_cpp_dist(dataset, max_dim, threshold, 1., p) | ||
|
|
||
| # coerce to 'PHom' class | ||
| ans <- new_PHom(ripser_ans_to_df(ans)) | ||
| ans <- switch( | ||
| match.arg(return_class), | ||
| PHom = new_PHom(ripser_ans_to_df(ans)), | ||
| persistence = as_persistence( | ||
| ans, | ||
| engine = "ripserr::vietoris_rips", | ||
| filtration = "Vietoris-Rips", | ||
| parameters = list(max_dim = max_dim, threshold = threshold, p = p) | ||
| ) | ||
| ) | ||
|
|
||
| # return | ||
| return(ans) | ||
|
|
@@ -126,6 +151,7 @@ vietoris_rips.dist <- function( | |
| threshold = -1, | ||
| p = 2L, | ||
| dim = NULL, | ||
| return_class = c("PHom", "persistence"), | ||
| ... | ||
| ) { | ||
|
|
||
|
|
@@ -157,18 +183,26 @@ vietoris_rips.dist <- function( | |
| ans <- ripser_cpp_dist(dataset, max_dim, threshold, 1., p) | ||
|
|
||
| # coerce to 'PHom' class | ||
| ans <- new_PHom(ripser_ans_to_df(ans)) | ||
| ans <- switch( | ||
| match.arg(return_class), | ||
| PHom = new_PHom(ripser_ans_to_df(ans)), | ||
| persistence = as_persistence( | ||
| ans, | ||
| engine = "ripserr::vietoris_rips", | ||
| filtration = "Vietoris-Rips", | ||
| parameters = list(max_dim = max_dim, threshold = threshold, p = p) | ||
| ) | ||
| ) | ||
|
|
||
| # return | ||
| return(ans) | ||
| } | ||
|
|
||
| #' @aliases vietoris_rips.numeric vietoris_rips.ts | ||
| #' @rdname vietoris_rips | ||
| #' @param data_dim desired end data dimension | ||
| #' @param dim_lag time series lag factor between dimensions | ||
| #' @param sample_lag time series lag factor between samples (rows) | ||
| #' @param method currently only allows `"qa"` (quasi-attractor method) | ||
| #' @rdname vietoris_rips | ||
| #' @export vietoris_rips.numeric | ||
| #' @export | ||
| vietoris_rips.numeric <- function( | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not starting the deprecation right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was that users would get a soft notice (introduction of options), then a soft warning (change of default), then a hard warning (deprecation). But i concede that i err toward being too gradual.