if(require("TDAstats") & require("igraph"))
{
# simulate data from the unit circle and calculate
# its diagram
df <- TDAstats::circle2d[sample(1:100,25),]
diag <- TDAstats::calculate_homology(df,
dim = 1,
threshold = 2)
# get minimum death radius of any data cluster
min_death_H0 <-
min(diag[which(diag[,1] == 0),3L])
# get birth and death radius of the loop
loop_birth <- as.numeric(diag[nrow(diag),2L])
loop_death <- as.numeric(diag[nrow(diag),3L])
# compute VR graphs at radii half of
# min_death_H0 and the mean of loop_birth and
# loop_death, returning clusters
graphs <- vr_graphs(X = df,eps =
c(0.5*min_death_H0,(loop_birth + loop_death)/2))
# verify that there are 25 clusters for the smaller radius
length(graphs$graphs[[1]]$clusters)
}
Run the code above in your browser using DataLab