-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathripsFiltration.R
68 lines (61 loc) · 2.12 KB
/
ripsFiltration.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
67
68
ripsFiltration <- function(
X, maxdimension, maxscale, dist = "euclidean", library = "GUDHI",
printProgress = FALSE) {
if (!is.numeric(X) && !is.data.frame(X)) {
stop("X should be a matrix of coordinates")
}
if (!is.numeric(maxdimension) ||
length(maxdimension) != 1 || maxdimension < 0) {
stop("maxdimension should be a nonnegative integer")
}
if (!is.numeric(maxscale) || length(maxscale) != 1) {
stop("maxscale should be a number")
}
if (dist != "euclidean" && dist != "arbitrary") {
stop ("dist should be either 'euclidean' or 'arbitrary'")
}
if (library == "gudhi" || library == "Gudhi") {
library <- "GUDHI"
}
if (library == "dionysus" || library == "DIONYSUS") {
library <- "Dionysus"
}
if (library == "D2") {
library <- "D2"
}
if (library != "GUDHI" && library != "Dionysus" && library != "D2") {
stop("library should be a string: either 'GUDHI' or 'Dionysus'")
}
if (!is.logical(printProgress)) {
stop("printProgress should be logical")
}
if (dist == "arbitrary" && library == "GUDHI") {
library <- "Dionysus"
}
X <- as.matrix(X)
max_num_pairs <- 5000 # to be added as an option
# in 32bit architectures Dionysus L2 doesn't work
#ripsOut <- RipsDiag(X = X, maxdimension = maxdimension,
# maxscale = maxscale, dist = dist, library = library,
# location = location, printProgress = printProgress)
if (dist == "euclidean" && library != "GUDHI" &&
.Machine[["sizeof.pointer"]] != 8) {
ripsOut <- RipsFiltration(
X = as.matrix(dist(X)), maxdimension = maxdimension,
maxscale = maxscale, dist = "arbitrary", library = library,
printProgress = printProgress)
} else {
ripsOut <- RipsFiltration(
X = X, maxdimension = maxdimension, maxscale = maxscale, dist = dist,
library = library, printProgress = printProgress)
}
if (dist == "euclidean") {
out <- list(
"cmplx" = ripsOut[[1]], "values" = ripsOut[[2]], "increasing" = TRUE,
"coordinates" = X)
} else {
out <- list(
"cmplx" = ripsOut[[1]], "values" = ripsOut[[2]], "increasing" = TRUE)
}
return (out)
}