Export, and create and manipulate objects of, the PersistenceLandscape' C++ class.

# S3 method for Rcpp_PersistenceLandscape
summary(object, ...)

# S3 method for summary.Rcpp_PersistenceLandscape
print(x, digits = max(1L, getOption("digits") - 3L), ...)

# S3 method for Rcpp_PersistenceLandscape
as.vector(x, mode = "any")

# S3 method for Rcpp_PersistenceLandscape
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

Arguments

object

an object for which a summary is desired.

...

additional arguments affecting the summary produced.

x

a result of the default method of summary().

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

mode

character string naming an atomic mode or "list" or "expression" or (except for vector) "any". Currently, is.vector() allows any type (see typeof) for mode, and when mode is not "any", is.vector(x, mode) is almost the same as typeof(x) == mode.

row.names

NULL or a character vector giving the row names for the data frame. Missing values are not allowed.

optional

logical. If TRUE, setting row names and converting column names (to syntactic names: see make.names) is optional. Note that all of R's base package as.data.frame() methods use optional only for column names treatment, basically with the meaning of data.frame(*, check.names = !optional). See also the make.names argument of the matrix method.

Details

The C++ class 'PersistenceLandscape' is exposed as the S4 class 'Rcpp_PersistenceLandscape' via the RCPP_MODULE() macro provided by Rcpp. See https://github.com/coatless-r-n-d/rcpp-modules-student for an introduction. New objects should be created from persistence data (diagrams) using landscape().

Fields

new

Constructor.

exact

Representation of the underlying PL.

min_x

Infimum (left endpoint) of the support of a discrete PL.

max_x

Supremum (right endpoint) of the support of a discrete PL.

dx

Resolution of the representation of a discrete PL.

See also

landscape() for the R wrapper.

Examples


# double matrix
pl <- new(
  PersistenceLandscape,
  cbind(c(0, 0, 1, 2), c(1.5, 2.5, 3.5, 4.5)),
  TRUE,
  0, 10, .01
)
pl$isExact()
#> [1] TRUE
pl$xMin()
#> [1] 0
pl$xMax()
#> [1] 10
pl$xBy()
#> [1] 0.01
pl$getInternal()
#> [[1]]
#>       [,1] [,2]
#>  [1,] -Inf 0.00
#>  [2,] 0.00 0.00
#>  [3,] 1.25 1.25
#>  [4,] 1.75 0.75
#>  [5,] 2.25 1.25
#>  [6,] 2.75 0.75
#>  [7,] 3.25 1.25
#>  [8,] 4.50 0.00
#>  [9,]  Inf 0.00
#> 
#> [[2]]
#>       [,1] [,2]
#>  [1,] -Inf 0.00
#>  [2,] 0.00 0.00
#>  [3,] 0.75 0.75
#>  [4,] 1.25 0.25
#>  [5,] 1.75 0.75
#>  [6,] 2.25 0.25
#>  [7,] 2.75 0.75
#>  [8,] 3.50 0.00
#>  [9,]  Inf 0.00
#> 
#> [[3]]
#>      [,1] [,2]
#> [1,] -Inf 0.00
#> [2,] 1.00 0.00
#> [3,] 1.25 0.25
#> [4,] 1.50 0.00
#> [5,] 2.00 0.00
#> [6,] 2.25 0.25
#> [7,] 2.50 0.00
#> [8,]  Inf 0.00
#> 
print(pl)
#> Persistence landscape (exact format) of 3 levels over (0,10)
summary(pl)
#> Internal representation:  exact 
#> Number of levels:  3 
#> Representation limits: ( 0 , 4.5 ) 
#> Landscape range: ( 0 , 1.25 ) 
#> Magnitude:  4.187 
#> Integral:   5.25 

dim(pl$discretize()$getInternal())
#> [1]    3 1001    2
length(as.vector(pl))
#> [1] 3003
as.data.frame(pl)
#>     level    x   fx
#> 1.1     1 -Inf 0.00
#> 1.2     1 0.00 0.00
#> 1.3     1 1.25 1.25
#> 1.4     1 1.75 0.75
#> 1.5     1 2.25 1.25
#> 1.6     1 2.75 0.75
#> 1.7     1 3.25 1.25
#> 1.8     1 4.50 0.00
#> 1.9     1  Inf 0.00
#> 2.1     2 -Inf 0.00
#> 2.2     2 0.00 0.00
#> 2.3     2 0.75 0.75
#> 2.4     2 1.25 0.25
#> 2.5     2 1.75 0.75
#> 2.6     2 2.25 0.25
#> 2.7     2 2.75 0.75
#> 2.8     2 3.50 0.00
#> 2.9     2  Inf 0.00
#> 3.1     3 -Inf 0.00
#> 3.2     3 1.00 0.00
#> 3.3     3 1.25 0.25
#> 3.4     3 1.50 0.00
#> 3.5     3 2.00 0.00
#> 3.6     3 2.25 0.25
#> 3.7     3 2.50 0.00
#> 3.8     3  Inf 0.00

pl2 <- pl$scale(2)
pl2$getInternal()
#> [[1]]
#>       [,1] [,2]
#>  [1,] -Inf  0.0
#>  [2,] 0.00  0.0
#>  [3,] 1.25  2.5
#>  [4,] 1.75  1.5
#>  [5,] 2.25  2.5
#>  [6,] 2.75  1.5
#>  [7,] 3.25  2.5
#>  [8,] 4.50  0.0
#>  [9,]  Inf  0.0
#> 
#> [[2]]
#>       [,1] [,2]
#>  [1,] -Inf  0.0
#>  [2,] 0.00  0.0
#>  [3,] 0.75  1.5
#>  [4,] 1.25  0.5
#>  [5,] 1.75  1.5
#>  [6,] 2.25  0.5
#>  [7,] 2.75  1.5
#>  [8,] 3.50  0.0
#>  [9,]  Inf  0.0
#> 
#> [[3]]
#>      [,1] [,2]
#> [1,] -Inf  0.0
#> [2,] 1.00  0.0
#> [3,] 1.25  0.5
#> [4,] 1.50  0.0
#> [5,] 2.00  0.0
#> [6,] 2.25  0.5
#> [7,] 2.50  0.0
#> [8,]  Inf  0.0
#> 
pl3 <- pl$add(pl2)
pl3$getInternal()
#> [[1]]
#>       [,1] [,2]
#>  [1,] -Inf 0.00
#>  [2,] 0.00 0.00
#>  [3,] 1.25 3.75
#>  [4,] 1.75 2.25
#>  [5,] 2.25 3.75
#>  [6,] 2.75 2.25
#>  [7,] 3.25 3.75
#>  [8,] 4.50 0.00
#>  [9,]  Inf 0.00
#> 
#> [[2]]
#>       [,1] [,2]
#>  [1,] -Inf 0.00
#>  [2,] 0.00 0.00
#>  [3,] 0.75 2.25
#>  [4,] 1.25 0.75
#>  [5,] 1.75 2.25
#>  [6,] 2.25 0.75
#>  [7,] 2.75 2.25
#>  [8,] 3.50 0.00
#>  [9,]  Inf 0.00
#> 
#> [[3]]
#>      [,1] [,2]
#> [1,] -Inf 0.00
#> [2,] 1.00 0.00
#> [3,] 1.25 0.75
#> [4,] 1.50 0.00
#> [5,] 2.00 0.00
#> [6,] 2.25 0.75
#> [7,] 2.50 0.00
#> [8,]  Inf 0.00
#> 

# integer matrix
pl <- new(
  PersistenceLandscape,
  cbind(c(0L, 0L, 1L, 2L), c(2L, 3L, 4L, 5L)),
  TRUE,
  0, 10, .01
)
pl$getInternal()
#> [[1]]
#>       [,1] [,2]
#>  [1,] -Inf  0.0
#>  [2,]  0.0  0.0
#>  [3,]  1.5  1.5
#>  [4,]  2.0  1.0
#>  [5,]  2.5  1.5
#>  [6,]  3.0  1.0
#>  [7,]  3.5  1.5
#>  [8,]  5.0  0.0
#>  [9,]  Inf  0.0
#> 
#> [[2]]
#>       [,1] [,2]
#>  [1,] -Inf  0.0
#>  [2,]  0.0  0.0
#>  [3,]  1.0  1.0
#>  [4,]  1.5  0.5
#>  [5,]  2.0  1.0
#>  [6,]  2.5  0.5
#>  [7,]  3.0  1.0
#>  [8,]  4.0  0.0
#>  [9,]  Inf  0.0
#> 
#> [[3]]
#>      [,1] [,2]
#> [1,] -Inf  0.0
#> [2,]  1.0  0.0
#> [3,]  1.5  0.5
#> [4,]  2.0  0.0
#> [5,]  2.5  0.5
#> [6,]  3.0  0.0
#> [7,]  Inf  0.0
#> 
print(pl)
#> Persistence landscape (exact format) of 3 levels over (0,10)

# discrete landscape
pl <- new(
  PersistenceLandscape,
  cbind(c(0, 0, 1, 2), c(1.5, 2.5, 3.5, 4.5)),
  FALSE,
  0, 5, .5
)
pl$xBy()
#> [1] 0.5
pl$getInternal()
#> , , 1
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [2,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [3,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [4,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,]    0  0.5  1.0  1.0  1.0  1.0  1.0    1  0.5     0     0
#> [2,]    0  0.5  0.5  0.5  0.5  0.5  0.5    0  0.0     0     0
#> [3,]    0  0.0  0.0  0.0  0.0  0.0  0.0    0  0.0     0     0
#> [4,]    0  0.0  0.0  0.0  0.0  0.0  0.0    0  0.0     0     0
#> 
print(pl)
#> Persistence landscape (discrete format) of 4 levels over (0,5)

dim(pl$discretize()$getInternal())
#> Warning: PL is already discrete.
#> [1]  4 11  2
length(as.vector(pl))
#> Warning: PL is already discrete.
#> [1] 44
as.data.frame(pl)
#>      level   x  fx
#> 1.1      1 0.0 0.0
#> 1.2      1 0.5 0.5
#> 1.3      1 1.0 1.0
#> 1.4      1 1.5 1.0
#> 2.1      2 2.0 1.0
#> 2.2      2 2.5 1.0
#> 2.3      2 3.0 1.0
#> 2.4      2 3.5 1.0
#> 3.1      3 4.0 0.5
#> 3.2      3 4.5 0.0
#> 3.3      3 5.0 0.0
#> 3.4      3 0.0 0.0
#> 4.1      4 0.5 0.5
#> 4.2      4 1.0 0.5
#> 4.3      4 1.5 0.5
#> 4.4      4 2.0 0.5
#> 5.1      5 2.5 0.5
#> 5.2      5 3.0 0.5
#> 5.3      5 3.5 0.0
#> 5.4      5 4.0 0.0
#> 6.1      6 4.5 0.0
#> 6.2      6 5.0 0.0
#> 6.3      6 0.0 0.0
#> 6.4      6 0.5 0.0
#> 7.1      7 1.0 0.0
#> 7.2      7 1.5 0.0
#> 7.3      7 2.0 0.0
#> 7.4      7 2.5 0.0
#> 8.1      8 3.0 0.0
#> 8.2      8 3.5 0.0
#> 8.3      8 4.0 0.0
#> 8.4      8 4.5 0.0
#> 9.1      9 5.0 0.0
#> 9.2      9 0.0 0.0
#> 9.3      9 0.5 0.0
#> 9.4      9 1.0 0.0
#> 10.1    10 1.5 0.0
#> 10.2    10 2.0 0.0
#> 10.3    10 2.5 0.0
#> 10.4    10 3.0 0.0
#> 11.1    11 3.5 0.0
#> 11.2    11 4.0 0.0
#> 11.3    11 4.5 0.0
#> 11.4    11 5.0 0.0

pl2 <- pl$scale(2)
pl2$isExact()
#> [1] FALSE
pl2$xBy()
#> [1] 0.5
pl2$getInternal()
#> , , 1
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [2,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [3,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [4,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,]    0    1    2    2    2    2    2    2    1     0     0
#> [2,]    0    1    1    1    1    1    1    0    0     0     0
#> [3,]    0    0    0    0    0    0    0    0    0     0     0
#> [4,]    0    0    0    0    0    0    0    0    0     0     0
#> 
show(pl2)
#> Persistence landscape (discrete format) of 4 levels over (0,5)

(pl3 <- pl$add(pl2))
#> Persistence landscape (discrete format) of 4 levels over (0,5)
pl3$getInternal()
#> , , 1
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [2,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [3,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> [4,]    0  0.5    1  1.5    2  2.5    3  3.5    4   4.5     5
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,]    0  1.5  3.0  3.0  3.0  3.0  3.0    3  1.5     0     0
#> [2,]    0  1.5  1.5  1.5  1.5  1.5  1.5    0  0.0     0     0
#> [3,]    0  0.0  0.0  0.0  0.0  0.0  0.0    0  0.0     0     0
#> [4,]    0  0.0  0.0  0.0  0.0  0.0  0.0    0  0.0     0     0
#> 
pl3$xBy()
#> [1] 0.5