Calculate sums, scalar multiples, absolute values, means, inner products, extrema, and moments of persistent landscapes. These operations arise from the Hilbert space structure on persistence landscapes (Bubenik, 2015).

pl_add(pl1, pl2)

pl_sum(pl_list)

pl_scale(pl, mult)

pl_abs(pl)

pl_diff(pl_list)

pl_mean(pl_list)

pl_var(pl_list, p = 2)

pl_sd(pl_list, p = 2)

pl_inner(pl1, pl2)

pl_min(pl, level = 1L)

pl_max(pl, level = 1L)

pl_range(pl, level = 1L)

pl_vmin(pl, level = pl_num_levels(pl))

pl_vmax(pl, level = pl_num_levels(pl))

pl_vrange(pl, level = pl_num_levels(pl))

pl_moment(pl, p = 1L, center = 0, level = 1L)

pl_vmoment(pl, p = 1L, center = 0, level = pl_num_levels(pl))

Arguments

pl1, pl2

Persistence landscapes.

pl_list

A list of persistence landscapes.

pl

Persistence landscapes.

mult

Double; a real-valued scale factor.

p

Positive integer or infinity; the power used to compute a norm or moment.

level

Positive integer; the level of the persistence landscape (up to) whose moment to calculate. This value is internally decreased by 1L to prevent off-by-one errors when passing to C++ code.

center

Double; where to center the moment.

Value

A persistence landscape (an object of S4 class 'Rcpp_PersistenceLandscape'), a list of persistence landscapes, a real number, or a vector of real numbers.

Details

These functions are prefixed pl_*() to help users access them via tab-completion. Some take their names from the underlying S4 class methods and are only provided to enable composition via pipes: add, scale, abs, inner, min (minimum), max (maximum), and moment; range combines min and max. Others mimic classic R functions to handle lists of persistence landscapes: sum, diff, mean, var, and sd. Finally, some are vectorizations of the preceding: vmin, vmax, vrange, and vmoment.

See also

Rcpp_PersistenceLandscape-methods for prefix and infix syntax.

algebra, analysis, inference for other landscape functions.

Examples


# scale a landscape
x <- tdaunif::sample_torus_tube(40, 2.5)
pd <- ripserr::vietoris_rips(x, dim = 1L, threshold = 2)
#> Warning: `dim` parameter has been deprecated; use `max_dim` instead.
pl <- landscape(pd, degree = 1, exact = FALSE, xmax = 2.5, xby = 0.1)
print(pl$getInternal()[2, , ])
#>       [,1]       [,2]
#>  [1,]  0.0 0.00000000
#>  [2,]  0.1 0.00000000
#>  [3,]  0.2 0.00000000
#>  [4,]  0.3 0.00000000
#>  [5,]  0.4 0.00000000
#>  [6,]  0.5 0.00000000
#>  [7,]  0.6 0.00000000
#>  [8,]  0.7 0.05167421
#>  [9,]  0.8 0.04113183
#> [10,]  0.9 0.00000000
#> [11,]  1.0 0.00000000
#> [12,]  1.1 0.00000000
#> [13,]  1.2 0.00000000
#> [14,]  1.3 0.00000000
#> [15,]  1.4 0.00000000
#> [16,]  1.5 0.00000000
#> [17,]  1.6 0.00000000
#> [18,]  1.7 0.00000000
#> [19,]  1.8 0.00000000
#> [20,]  1.9 0.00000000
#> [21,]  2.0 0.00000000
#> [22,]  2.1 0.00000000
#> [23,]  2.2 0.00000000
#> [24,]  2.3 0.00000000
#> [25,]  2.4 0.00000000
#> [26,]  2.5 0.00000000
print(pl$scale(0.5)$getInternal()[2, , ])
#>       [,1]       [,2]
#>  [1,]  0.0 0.00000000
#>  [2,]  0.1 0.00000000
#>  [3,]  0.2 0.00000000
#>  [4,]  0.3 0.00000000
#>  [5,]  0.4 0.00000000
#>  [6,]  0.5 0.00000000
#>  [7,]  0.6 0.00000000
#>  [8,]  0.7 0.02583710
#>  [9,]  0.8 0.02056591
#> [10,]  0.9 0.00000000
#> [11,]  1.0 0.00000000
#> [12,]  1.1 0.00000000
#> [13,]  1.2 0.00000000
#> [14,]  1.3 0.00000000
#> [15,]  1.4 0.00000000
#> [16,]  1.5 0.00000000
#> [17,]  1.6 0.00000000
#> [18,]  1.7 0.00000000
#> [19,]  1.8 0.00000000
#> [20,]  1.9 0.00000000
#> [21,]  2.0 0.00000000
#> [22,]  2.1 0.00000000
#> [23,]  2.2 0.00000000
#> [24,]  2.3 0.00000000
#> [25,]  2.4 0.00000000
#> [26,]  2.5 0.00000000

# create two landscapes from the same sampling distribution
x <- tdaunif::sample_torus_tube(40, 2.5)
y <- tdaunif::sample_torus_tube(40, 2.5)
x_pd <- ripserr::vietoris_rips(x, dim = 1, threshold = 2)
#> Warning: `dim` parameter has been deprecated; use `max_dim` instead.
y_pd <- ripserr::vietoris_rips(y, dim = 1, threshold = 2)
#> Warning: `dim` parameter has been deprecated; use `max_dim` instead.
x_pl <- landscape(x_pd, degree = 1, exact = FALSE, xmax = 2.5, xby = 0.1)
y_pl <- landscape(y_pd, degree = 1, exact = FALSE, xmax = 2.5, xby = 0.1)

# compare landscapes and calculate mean landscape
print(x_pl$getInternal())
#> , , 1
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [2,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [3,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [4,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [5,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [6,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [7,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [8,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#>      [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [2,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [3,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [4,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [5,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [6,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [7,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [8,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6]        [,7]         [,8]       [,9]
#> [1,]    0    0    0    0    0    0 0.050136363 0.1415052864 0.04424601
#> [2,]    0    0    0    0    0    0 0.009642749 0.0016243337 0.04150529
#> [3,]    0    0    0    0    0    0 0.000000000 0.0005088148 0.04056985
#> [4,]    0    0    0    0    0    0 0.000000000 0.0000000000 0.00000000
#> [5,]    0    0    0    0    0    0 0.000000000 0.0000000000 0.00000000
#> [6,]    0    0    0    0    0    0 0.000000000 0.0000000000 0.00000000
#> [7,]    0    0    0    0    0    0 0.000000000 0.0000000000 0.00000000
#> [8,]    0    0    0    0    0    0 0.000000000 0.0000000000 0.00000000
#>           [,10] [,11] [,12]      [,13] [,14] [,15] [,16] [,17] [,18] [,19]
#> [1,] 0.02227656     0     0 0.05048058     0     0     0     0     0     0
#> [2,] 0.00000000     0     0 0.00000000     0     0     0     0     0     0
#> [3,] 0.00000000     0     0 0.00000000     0     0     0     0     0     0
#> [4,] 0.00000000     0     0 0.00000000     0     0     0     0     0     0
#> [5,] 0.00000000     0     0 0.00000000     0     0     0     0     0     0
#> [6,] 0.00000000     0     0 0.00000000     0     0     0     0     0     0
#> [7,] 0.00000000     0     0 0.00000000     0     0     0     0     0     0
#> [8,] 0.00000000     0     0 0.00000000     0     0     0     0     0     0
#>      [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,]     0     0     0     0     0     0     0
#> [2,]     0     0     0     0     0     0     0
#> [3,]     0     0     0     0     0     0     0
#> [4,]     0     0     0     0     0     0     0
#> [5,]     0     0     0     0     0     0     0
#> [6,]     0     0     0     0     0     0     0
#> [7,]     0     0     0     0     0     0     0
#> [8,]     0     0     0     0     0     0     0
#> 
print(y_pl$getInternal())
#> , , 1
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [2,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [3,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [4,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [5,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [6,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [7,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#>      [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [2,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [3,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [4,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [5,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [6,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [7,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3] [,4] [,5]       [,6]        [,7]        [,8]        [,9]
#> [1,]    0    0    0    0    0 0.03722113 0.137221129 0.095184528 0.004993068
#> [2,]    0    0    0    0    0 0.00000000 0.013504139 0.080211838 0.000000000
#> [3,]    0    0    0    0    0 0.00000000 0.004595203 0.039436042 0.000000000
#> [4,]    0    0    0    0    0 0.00000000 0.000000000 0.032114568 0.000000000
#> [5,]    0    0    0    0    0 0.00000000 0.000000000 0.008034788 0.000000000
#> [6,]    0    0    0    0    0 0.00000000 0.000000000 0.000000000 0.000000000
#> [7,]    0    0    0    0    0 0.00000000 0.000000000 0.000000000 0.000000000
#>      [,10]      [,11]     [,12]    [,13]      [,14] [,15] [,16] [,17] [,18]
#> [1,]     0 0.07482755 0.1748276 0.185926 0.08592595     0     0     0     0
#> [2,]     0 0.00000000 0.0000000 0.000000 0.00000000     0     0     0     0
#> [3,]     0 0.00000000 0.0000000 0.000000 0.00000000     0     0     0     0
#> [4,]     0 0.00000000 0.0000000 0.000000 0.00000000     0     0     0     0
#> [5,]     0 0.00000000 0.0000000 0.000000 0.00000000     0     0     0     0
#> [6,]     0 0.00000000 0.0000000 0.000000 0.00000000     0     0     0     0
#> [7,]     0 0.00000000 0.0000000 0.000000 0.00000000     0     0     0     0
#>      [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,]     0     0     0     0     0     0     0     0
#> [2,]     0     0     0     0     0     0     0     0
#> [3,]     0     0     0     0     0     0     0     0
#> [4,]     0     0     0     0     0     0     0     0
#> [5,]     0     0     0     0     0     0     0     0
#> [6,]     0     0     0     0     0     0     0     0
#> [7,]     0     0     0     0     0     0     0     0
#> 
print(pl_mean(list(x_pl, y_pl))$getInternal())
#> , , 1
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [2,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [3,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [4,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [5,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [6,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [7,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#> [8,]    0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8   0.9     1   1.1   1.2   1.3
#>      [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [2,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [3,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [4,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [5,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [6,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [7,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> [8,]   1.4   1.5   1.6   1.7   1.8   1.9     2   2.1   2.2   2.3   2.4   2.5
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3] [,4] [,5]       [,6]        [,7]        [,8]       [,9]
#> [1,]    0    0    0    0    0 0.01861056 0.093678746 0.118344907 0.02461954
#> [2,]    0    0    0    0    0 0.00000000 0.011573444 0.040918086 0.02075264
#> [3,]    0    0    0    0    0 0.00000000 0.002297601 0.019972428 0.02028493
#> [4,]    0    0    0    0    0 0.00000000 0.000000000 0.016057284 0.00000000
#> [5,]    0    0    0    0    0 0.00000000 0.000000000 0.004017394 0.00000000
#> [6,]    0    0    0    0    0 0.00000000 0.000000000 0.000000000 0.00000000
#> [7,]    0    0    0    0    0 0.00000000 0.000000000 0.000000000 0.00000000
#> [8,]    0    0    0    0    0 0.00000000 0.000000000 0.000000000 0.00000000
#>           [,10]      [,11]      [,12]     [,13]      [,14] [,15] [,16] [,17]
#> [1,] 0.01113828 0.03741378 0.08741378 0.1182033 0.04296298     0     0     0
#> [2,] 0.00000000 0.00000000 0.00000000 0.0000000 0.00000000     0     0     0
#> [3,] 0.00000000 0.00000000 0.00000000 0.0000000 0.00000000     0     0     0
#> [4,] 0.00000000 0.00000000 0.00000000 0.0000000 0.00000000     0     0     0
#> [5,] 0.00000000 0.00000000 0.00000000 0.0000000 0.00000000     0     0     0
#> [6,] 0.00000000 0.00000000 0.00000000 0.0000000 0.00000000     0     0     0
#> [7,] 0.00000000 0.00000000 0.00000000 0.0000000 0.00000000     0     0     0
#> [8,] 0.00000000 0.00000000 0.00000000 0.0000000 0.00000000     0     0     0
#>      [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,]     0     0     0     0     0     0     0     0     0
#> [2,]     0     0     0     0     0     0     0     0     0
#> [3,]     0     0     0     0     0     0     0     0     0
#> [4,]     0     0     0     0     0     0     0     0     0
#> [5,]     0     0     0     0     0     0     0     0     0
#> [6,]     0     0     0     0     0     0     0     0     0
#> [7,]     0     0     0     0     0     0     0     0     0
#> [8,]     0     0     0     0     0     0     0     0     0
#> 

if (FALSE) {

set.seed(492869L)

# compute landscape for a large sample
pt <- tdaunif::sample_torus_tube(1000, 5)
pd <- ripserr::vietoris_rips(pt, dim = 2, threshold = 2)
pl <- landscape(pd, degree = 1, exact = FALSE, xby = 0.1, xmin = 0, xmax = 2)

# compute landscapes for a large sample of small samples
pl_list <- c()
for (i in seq(100)) {
  pti <- tdaunif::sample_torus_tube(100, 5)
  pdi <- ripserr::vietoris_rips(pti, dim = 2, threshold = 2)
  pli <- landscape(pdi, degree = 1, exact = FALSE, xby = 0.1, xmin = 0, xmax = 2)
  pl_list <- c(pl_list, pli)
}

# compute the mean landscape
pl_avg <- pl_mean(pl_list)

# compute the distance between the landscapes
pl_diff <- pl$add(pl_avg$scale(-1))
print(pl_inner(pl_diff, pl_diff))

}