compTAG / r-tda

Other
4 stars 6 forks source link

Incorrect diagrams returned from ripsDiag() using distance matrices as input. #31

Open jordans1882 opened 5 years ago

jordans1882 commented 5 years ago

There seems to be a bug in how the ripsDiag() function calculates persistence diagrams when using a distance matrix as input. The following code illustrates this bug:

    sphere_points <- matrix(c(-1, 0,  0, 1, 0, 0, 0, -1, 0,
                               0, 1, 0, 0,  0, -1, 0, 0, 1),
                            nrow = 6, ncol = 3)

    # Use distance matrix for sphere
    diag1 <- ripsDiag(dist(sphere_points), maxdimension = 2,
                      maxscale = 5, dist = "arbitrary")

    # Use distance  matrix
    diag2 <- ripsDiag(sphere_points, maxdimension = 2,
                      maxscale = 5, dist = "euclidean")

diag1$diagram
     dimension Birth    Death
[1,]         0     0 5.000000
[2,]         0     0 1.414214
[3,]         0     0 1.414214
[4,]         0     0 1.414214
[5,]         0     0 1.414214
[6,]         0     0 1.414214

diag2$diagram

     dimension    Birth    Death
[1,]         0 0.000000 5.000000
[2,]         0 0.000000 1.414214
[3,]         0 0.000000 1.414214
[4,]         0 0.000000 1.414214
[5,]         0 0.000000 1.414214
[6,]         0 0.000000 1.414214
[7,]         2 1.414214 2.000000

When using the distance matrix as input, we see that we are unable to find the two-dimensional feature.