For this practical lesson about Persistence Homology Inference, we need the TDA R-package.

install.packages("TDA", dependencies=TRUE) 
library(TDA) 

Persistence diagrams for Rips filtration

The ripsDiag() function computes the persistence diagram of the Rips filtration built on top of a point cloud.

The following code generates 60 points from two circles:

Circle1 <- circleUnif(60)
Circle2 <- circleUnif(60, r = 2) + 3
Circles <- rbind(Circle1, Circle2)
plot(Circles, pch = 16, xlab = "",ylab = "")

We specify the limit of the Rips filtration and the max dimension of the homological features we are interested in (0 for components, 1 for loops, 2 for voids, etc.).

maxdimension <- 1    # components and loops
maxscale <- 5        # limit of the filtration

and we generate the persistence diagram using either the C++ library GUDHI (or Dionysus):

Diag <- ripsDiag(X = Circles,
                 maxdimension,
                 maxscale,
                 library = "GUDHI",
                 printProgress = FALSE)
print(Diag[["diagram"]])
##        dimension     Birth       Death
##   [1,]         0 0.0000000 5.000000000
##   [2,]         0 0.0000000 1.248655167
##   [3,]         0 0.0000000 0.681882543
##   [4,]         0 0.0000000 0.626945491
##   [5,]         0 0.0000000 0.605573483
##   [6,]         0 0.0000000 0.558305002
##   [7,]         0 0.0000000 0.503336136
##   [8,]         0 0.0000000 0.454175829
##   [9,]         0 0.0000000 0.420407057
##  [10,]         0 0.0000000 0.419658105
##  [11,]         0 0.0000000 0.370848708
##  [12,]         0 0.0000000 0.364224499
##  [13,]         0 0.0000000 0.351474017
##  [14,]         0 0.0000000 0.345539414
##  [15,]         0 0.0000000 0.335991622
##  [16,]         0 0.0000000 0.334634177
##  [17,]         0 0.0000000 0.326365159
##  [18,]         0 0.0000000 0.323037978
##  [19,]         0 0.0000000 0.315383629
##  [20,]         0 0.0000000 0.310536467
##  [21,]         0 0.0000000 0.310262665
##  [22,]         0 0.0000000 0.299689810
##  [23,]         0 0.0000000 0.299347715
##  [24,]         0 0.0000000 0.281637584
##  [25,]         0 0.0000000 0.280511260
##  [26,]         0 0.0000000 0.267956666
##  [27,]         0 0.0000000 0.262500366
##  [28,]         0 0.0000000 0.252993717
##  [29,]         0 0.0000000 0.234222336
##  [30,]         0 0.0000000 0.232796821
##  [31,]         0 0.0000000 0.231153192
##  [32,]         0 0.0000000 0.220700648
##  [33,]         0 0.0000000 0.206815991
##  [34,]         0 0.0000000 0.205821198
##  [35,]         0 0.0000000 0.193307118
##  [36,]         0 0.0000000 0.186722979
##  [37,]         0 0.0000000 0.185064513
##  [38,]         0 0.0000000 0.182864067
##  [39,]         0 0.0000000 0.174142457
##  [40,]         0 0.0000000 0.173349233
##  [41,]         0 0.0000000 0.165982732
##  [42,]         0 0.0000000 0.165499845
##  [43,]         0 0.0000000 0.162600742
##  [44,]         0 0.0000000 0.158470316
##  [45,]         0 0.0000000 0.156601404
##  [46,]         0 0.0000000 0.154588033
##  [47,]         0 0.0000000 0.151872929
##  [48,]         0 0.0000000 0.143354811
##  [49,]         0 0.0000000 0.142104999
##  [50,]         0 0.0000000 0.136520367
##  [51,]         0 0.0000000 0.130379191
##  [52,]         0 0.0000000 0.129089764
##  [53,]         0 0.0000000 0.127437449
##  [54,]         0 0.0000000 0.126321858
##  [55,]         0 0.0000000 0.123633581
##  [56,]         0 0.0000000 0.115843530
##  [57,]         0 0.0000000 0.111836441
##  [58,]         0 0.0000000 0.109250181
##  [59,]         0 0.0000000 0.105035804
##  [60,]         0 0.0000000 0.103326846
##  [61,]         0 0.0000000 0.097845406
##  [62,]         0 0.0000000 0.096205648
##  [63,]         0 0.0000000 0.093575941
##  [64,]         0 0.0000000 0.090009959
##  [65,]         0 0.0000000 0.089763367
##  [66,]         0 0.0000000 0.087647752
##  [67,]         0 0.0000000 0.085860423
##  [68,]         0 0.0000000 0.080253095
##  [69,]         0 0.0000000 0.078960989
##  [70,]         0 0.0000000 0.070546775
##  [71,]         0 0.0000000 0.068519479
##  [72,]         0 0.0000000 0.066857388
##  [73,]         0 0.0000000 0.066597194
##  [74,]         0 0.0000000 0.066324402
##  [75,]         0 0.0000000 0.065312852
##  [76,]         0 0.0000000 0.058724720
##  [77,]         0 0.0000000 0.058459910
##  [78,]         0 0.0000000 0.058093939
##  [79,]         0 0.0000000 0.057353007
##  [80,]         0 0.0000000 0.056634495
##  [81,]         0 0.0000000 0.055391002
##  [82,]         0 0.0000000 0.054714317
##  [83,]         0 0.0000000 0.053954024
##  [84,]         0 0.0000000 0.053309793
##  [85,]         0 0.0000000 0.051547687
##  [86,]         0 0.0000000 0.046986251
##  [87,]         0 0.0000000 0.046791021
##  [88,]         0 0.0000000 0.044507936
##  [89,]         0 0.0000000 0.042748403
##  [90,]         0 0.0000000 0.041996189
##  [91,]         0 0.0000000 0.035464877
##  [92,]         0 0.0000000 0.034858018
##  [93,]         0 0.0000000 0.033600787
##  [94,]         0 0.0000000 0.032788605
##  [95,]         0 0.0000000 0.032157741
##  [96,]         0 0.0000000 0.032049281
##  [97,]         0 0.0000000 0.026104314
##  [98,]         0 0.0000000 0.025962140
##  [99,]         0 0.0000000 0.023294849
## [100,]         0 0.0000000 0.022391369
## [101,]         0 0.0000000 0.021238881
## [102,]         0 0.0000000 0.019214665
## [103,]         0 0.0000000 0.018691308
## [104,]         0 0.0000000 0.018131942
## [105,]         0 0.0000000 0.018115428
## [106,]         0 0.0000000 0.015066935
## [107,]         0 0.0000000 0.013243244
## [108,]         0 0.0000000 0.012367233
## [109,]         0 0.0000000 0.011430027
## [110,]         0 0.0000000 0.011348145
## [111,]         0 0.0000000 0.011169319
## [112,]         0 0.0000000 0.009955018
## [113,]         0 0.0000000 0.008876962
## [114,]         0 0.0000000 0.007695819
## [115,]         0 0.0000000 0.006985402
## [116,]         0 0.0000000 0.005454312
## [117,]         0 0.0000000 0.004970368
## [118,]         0 0.0000000 0.004721412
## [119,]         0 0.0000000 0.003096041
## [120,]         0 0.0000000 0.001325557
## [121,]         1 0.7037153 3.470094911
## [122,]         1 0.5479865 1.733566397
## [123,]         1 1.2554868 1.257751432
print(summary.diagram(Diag[["diagram"]]))
## Call: 
## ripsDiag(X = Circles, maxdimension = maxdimension, maxscale = maxscale, 
##     library = "GUDHI", printProgress = FALSE)
## 
## Number of features: 
## [1] 123
## 
## Max dimension: 
## [1] 1
## 
## Scale: 
## [1] 0 5

Finally we plot the diagram:

plot(Diag[["diagram"]])

Persistent homology of sublevel and superlevel sets of functions

Download the crater dataset on your laptop and import the data into R:

crater = read.table("./Data/crater.xy")
plot(crater, cex = 0.1,main = "Crater Dataset",xlab = "x",ylab="y")