## Distance Function Diagram and Kernel Density Diagram
# input data
n <- 300
XX <- circleUnif(n)
## Ranges of the grid
Xlim <- c(-1.8, 1.8)
Ylim <- c(-1.6, 1.6)
lim <- cbind(Xlim, Ylim)
by <- 0.05
h <- .3 #bandwidth for the function kde
#Distance Function Diagram of the sublevel sets
Diag1 <- gridDiag(XX, distFct, lim = lim, by = by, sublevel = TRUE,
printProgress = TRUE)
#Kernel Density Diagram of the superlevel sets
Diag2 <- gridDiag(XX, kde, lim = lim, by = by, sublevel = FALSE,
library = "Dionysus", location = TRUE, printProgress = TRUE, h = h)
#plot
par(mfrow = c(2, 2))
plot(XX, cex = 0.5, pch = 19)
title(main = "Data")
plot(Diag1[["diagram"]])
title(main = "Distance Function Diagram")
plot(Diag2[["diagram"]])
title(main = "Density Persistence Diagram")
one <- which(Diag2[["diagram"]][, 1] == 1)
plot(XX, col = 2, main = "Representative loop of grid points")
for (i in seq(along = one)) {
points(Diag2[["birthLocation"]][one[i], , drop = FALSE], pch = 15, cex = 3,
col = i)
points(Diag2[["deathLocation"]][one[i], , drop = FALSE], pch = 17, cex = 3,
col = i)
for (j in seq_len(dim(Diag2[["cycleLocation"]][[one[i]]])[1])) {
lines(Diag2[["cycleLocation"]][[one[i]]][j, , ], pch = 19, cex = 1, col = i)
}
}
Run the code above in your browser using DataLab