Skip to content

diagram method does not check column names #51

@corybrunson

Description

@corybrunson

diagram objects may be produced with deaths before births, in which case the Death column precedes the Birth column. This is not currently checked by as_persistence.diagram(), producing the buggy behavior below.

library(phutil)

# sublevel sets (conventional)
( d <- TDA::gridDiag(FUNvalues = volcano) )
#> $diagram
#>       dimension Birth Death
#>  [1,]         0    94   195
#>  [2,]         0   148   168
#>  [3,]         0   100   110
#>  [4,]         0   107   117
#>  [5,]         0   103   110
#>  [6,]         0    97   101
#>  [7,]         0   111   115
#>  [8,]         0   101   104
#>  [9,]         0   104   107
#> [10,]         0   105   107
#> [11,]         0   107   108
#> [12,]         0   100   101
#> [13,]         0    99   100
#> [14,]         1   124   195
#> [15,]         1   176   180
#> [16,]         1   166   170
#> [17,]         1   168   170
#> [18,]         1   107   108
#> [19,]         1   180   181
( p <- as_persistence(d) )
#> 
#> ── Persistence Data ────────────────────────────────────────────────────────────
#> ℹ There are 13 and 6 pairs in dimensions 0 and 1 respectively.
#> ℹ Computed from a Grid filtration using `TDA::gridDiag()`.
#> ℹ With the following parameters: FUNvalues = volcano.
p$pairs
#> [[1]]
#>       [,1] [,2]
#>  [1,]   94  195
#>  [2,]  148  168
#>  [3,]  100  110
#>  [4,]  107  117
#>  [5,]  103  110
#>  [6,]   97  101
#>  [7,]  111  115
#>  [8,]  101  104
#>  [9,]  104  107
#> [10,]  105  107
#> [11,]  107  108
#> [12,]  100  101
#> [13,]   99  100
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]  124  195
#> [2,]  176  180
#> [3,]  166  170
#> [4,]  168  170
#> [5,]  107  108
#> [6,]  180  181

# superlevel sets (unconventional)
( d <- TDA::gridDiag(FUNvalues = volcano, sublevel = FALSE) )
#> $diagram
#>      dimension Death Birth
#> [1,]         0    94   195
#> [2,]         0   166   170
#> [3,]         0   176   180
#> [4,]         0   168   170
#> [5,]         0   114   115
#> [6,]         0   107   108
#> [7,]         0   180   181
#> [8,]         1   148   168
( p <- as_persistence(d) )
#> 
#> ── Persistence Data ────────────────────────────────────────────────────────────
#> ℹ There are 7 and 1 pairs in dimensions 0 and 1 respectively.
#> ℹ Computed from a Grid filtration using `TDA::gridDiag()`.
#> ℹ With the following parameters: FUNvalues = volcano and sublevel = FALSE.
p$pairs
#> [[1]]
#>      [,1] [,2]
#> [1,]   94  195
#> [2,]  166  170
#> [3,]  176  180
#> [4,]  168  170
#> [5,]  114  115
#> [6,]  107  108
#> [7,]  180  181
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]  148  168

Created on 2025-10-26 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions