I currently have a list of persistent diagrams with the following structure -
str(result)
List of 19
$ :List of 2
..$ DiagGrid1:List of 4
..$ DiagGrid2:List of 4
i.e. 19 tuples of Diagrams which correspond to 19 .csv files containing two classes of curves (Approach and Retract). I would like to create a 38x38 distance matrix with the bottleneck() function -
bottleneck(result[[1]]$DiagGrid1$diagram, result[[1]]$DiagGrid1$diagram)
for all 19 list elements and the tuple combinations between them. Unfortunately, I can't get the for() loop correctly, so I'm wondering if someone could point me in the correct direction or just give general advice on this.
Thanks in any case.
The bottleneck() function can be found in the TDA library. For the loop itself, I have tried the following -
num_elements <- length(result)
distance_matrix <- matrix(0, nrow = num_elements * 2, ncol = num_elements * 2)
for (i in 1:num_elements) {
for (j in 1:num_elements) {
diag_grid1_i <- result[[i]]$DiagGrid1$diagram
diag_grid2_i <- result[[i]]$DiagGrid2$diagram
diag_grid1_j <- result[[j]]$DiagGrid1$diagram
diag_grid2_j <- result[[j]]$DiagGrid2$diagram
distance_matrix[i, j] <- bottleneck(diag_grid1_i, diag_grid2_j)
distance_matrix[i + num_elements, j + num_elements] <- bottleneck(diag_grid1_j, diag_grid2_i)
}
}
The output of dput(result[1:2]) is too long and crashed the site on my side but I can provide this, if that helps.
str(result[[1]]$DiagGrid1)
List of 4
$ diagram : 'diagram' num [1:1494, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:3] "dimension" "Birth" "Death"
..- attr(*, "maxdimension")= num 1
..- attr(*, "scale")= num [1:2] 6.63e-05 3.21e-04
..- attr(*, "call")= language gridDiag(X = matrices$X, FUN = knnDE, lim = cbind(Xlim, Ylim), by = by, sublevel = TRUE, library = "Dionysus| __truncated__ ...
$ birthLocation: num [1:1494, 1:2] 160.8 160.8 0 0 26.7 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : NULL
$ deathLocation: num [1:1494, 1:2] 13.8 160.8 13.2 0 145.3 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : NULL
$ cycleLocation:List of 1494
..$ : num[0 , 0 , 1:2]
..$ : num [1:2, 1, 1:2] 160.8 160.8 -12.4 -12
..$ : num [1:2, 1, 1:2] 0 158 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 0 0 -12.4 -12.3
..$ : num [1:2, 1, 1:2] 26.65 147.75 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 27 26.65 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 28 27 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 26.3 26.65 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 27.65 28 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 25.3 26.3 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 27.35 27 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 26 26.3 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 25.65 26 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 29.35 28.05 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 24.95 25.25 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 29.05 29.35 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 28.35 28.05 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 28.7 29.05 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 32.45 29.35 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 29.7 29.35 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 31.45 29.7 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 30.05 29.7 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 33.85 32.45 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 31.1 31.45 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 30.75 31.1 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 30.45 30.75 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 32.15 32.45 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 24.65 24.95 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 31.8 31.45 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 34.15 33.85 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 33.5 33.85 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 35.2 34.15 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 33.15 33.5 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 34.5 34.2 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 35.55 35.2 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 34.85 34.5 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 32.8 32.5 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 36.55 35.6 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 35.85 35.6 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 36.9 36.55 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 36.2 36.55 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 24.4 24.6 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 37.95 36.9 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 38.65 37.95 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 40 38.65 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 37.25 36.9 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 37.55 37.25 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 39.3 38.65 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 24.1 24.4 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 38.3 38.65 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 41.35 40 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 38.95 39.3 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 40.35 40 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 41 40.35 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 40.65 41 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 42.35 41.35 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 39.65 39.3 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 43.05 42.35 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 41.7 41.35 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 42.7 43.05 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 42 42.35 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 44 43.05 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 43.7 44 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 47.1 44 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 43.35 43.05 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 44.4 44.05 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 23.8 24.05 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 45.75 44.4 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 45.1 45.75 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 45.45 45.75 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 48.8 47.1 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 44.75 44.4 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 46.8 47.1 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 48.5 48.8 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 48.1 48.5 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 46.45 46.8 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 46.1 45.75 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 47.8 48.1 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 49.1 48.8 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 49.85 49.1 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 47.45 47.15 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 50.15 49.85 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 49.5 49.15 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 51.15 50.2 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 50.5 50.2 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 23.5 23.75 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 54.2 51.15 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 51.5 51.15 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 50.8 51.15 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 51.85 51.5 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 52.85 51.85 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 52.15 51.85 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 23.2 23.5 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 55.25 54.2 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 53.2 52.85 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 52.5 52.85 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 53.5 53.2 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 55.9 55.25 -7.45 -7.45
..$ : num [1:2, 1, 1:2] 54.9 55.2 -7.45 -7.45
.. [list output truncated]
Basically I need to loop through result[[1]] to result[[19]] and consider all tuples of DiagGrid1, DiagGrid2.