-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfiltrationDiag.R
77 lines (70 loc) · 2.53 KB
/
filtrationDiag.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
69
70
71
72
73
74
75
76
77
filtrationDiag <- function(
filtration, maxdimension, library = "GUDHI", location = FALSE,
printProgress = FALSE, diagLimit = NULL) {
if (length(filtration[["cmplx"]]) != length(filtration[["values"]])) {
stop("The length of the simplicial complx should equals the length of the filtration values")
}
if (!is.numeric(maxdimension) ||
length(maxdimension) != 1 || maxdimension < 0) {
stop("maxdimension should be a nonnegative integer")
}
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 for computing persistence diagram should be a string: either 'GUDHI' or 'Dionysus' or 'Dionysus2'")
}
if (!is.logical(location)) {
stop("location should be logical")
}
if (!is.logical(printProgress)) {
stop("printProgress should be logical")
}
if (filtration[["increasing"]] == FALSE) {
filtration[["values"]] <- -filtration[["values"]]
}
filtrationOut <- FiltrationDiag(
filtration = filtration, maxdimension = maxdimension, library = library,
location = location, printProgress = printProgress)
if (location == TRUE) {
BirthLocation <- filtrationOut[[2]][, 1]
DeathLocation <- filtrationOut[[2]][, 2]
if (library == "Dionysus") {
CycleLocation <- filtrationOut[[3]]
}
}
Diag <- filtrationOut[[1]]
if (NROW(Diag) > 0) {
Diag[Diag == Inf] <- ifelse(is.null(diagLimit), Inf, diagLimit)
}
if (filtration[["increasing"]] == FALSE) {
colnames(Diag) <- c("dimension", "Death", "Birth")
Diag[, 2:3] <- -Diag[, 3:2]
} else {
colnames(Diag) <- c("dimension", "Birth", "Death")
}
class(Diag) <- "diagram"
attributes(Diag)[["maxdimension"]] <- max(Diag[, 1])
nonInf <- which(Diag[, 2] != Inf & Diag[, 3] != Inf)
attributes(Diag)[["scale"]] <-
c(min(Diag[nonInf, 2:3]), max(Diag[nonInf, 2:3]))
attributes(Diag)[["call"]] <- match.call()
if (location == FALSE || library == "GUDHI") {
out <- list("diagram" = Diag)
} else if (library == "PHAT") {
out <- list(
"diagram" = Diag, "birthLocation" = BirthLocation,
"deathLocation" = DeathLocation)
} else {
out <- list(
"diagram" = Diag, "birthLocation" = BirthLocation,
"deathLocation" = DeathLocation, "cycleLocation" = CycleLocation)
}
return (out)
}