## 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, 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$diag[,1]==1)
plot(XX, col=2, main="Representative loop of grid points")
for (i in 1:length(one))
{
points(Diag2$birth[one[i],], pch=15, cex=3, col=i)
points(Diag2$death[one[i],], pch=17, cex=3, col=i)
points(Diag2$cycleLocation[[one[i]]], pch=19, cex=1, col=i)
}
Run the code above in your browser using DataLab