corybrunson / plt

R interface & extension to an adapted Persistence Landscapes Toolbox
https://corybrunson.github.io/plt
GNU General Public License v3.0
0 stars 2 forks source link

Difference in the plot of pl_mean() #3

Open a1danbryant opened 3 months ago

a1danbryant commented 3 months ago

This issue came up when trying to plot the result of pl_mean().

By including/excluding the line 'pd<-as.persistence(pd)' we get different results from plotting the output of pl_mean(). The landscape() function has as_persistence() nested inside of it, so this might be an issue of whether or not as_persistence() is being called. The format of 'pd' (the persistence data), generated from the TDA package's alpha complex in this instance, might be relevant as the "read_me" file utilizes ripserr's vietoris-ripps complex to create the persistence data, and seems to operate as expected without calling as_persistence() (and instead just landscape()).

Below is an example of the difference we see when plotting the result from pl_mean().

library(reprex)
#> Warning: package 'reprex' was built under R version 4.3.3
library(plt)
library(TDA)
#> Warning: package 'TDA' was built under R version 4.3.3
#> 
#> Attaching package: 'TDA'
#> The following object is masked from 'package:plt':
#> 
#>     landscape
library(tdaunif)
#> Warning: package 'tdaunif' was built under R version 4.3.3

set.seed(3942)

#correct pl_mean output
pl_list1 <- c()
for (i in seq(6)) {
  pc <- sample_lemniscate_gerono(60, sd = 0.05)
  pd <- alphaComplexDiag(pc, maxdimension = 1)$diagram
  pd[,2] <- sqrt(pd[,2])
  pd[,3] <- sqrt(pd[,3])
  pd <- as_persistence(pd)
  pl <- landscape(pd, degree = 1, xby = .01)
  pl_list1 <- c(pl_list1, pl)
}
#> Error in landscape(pd, degree = 1, xby = 0.01): unused arguments (degree = 1, xby = 0.01)

avg_pl1 <- pl_mean(pl_list1)
#> Error in as.environment(NULL): using 'as.environment(NULL)' is defunct
plot(avg_pl1)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'avg_pl1' not found

#incorrect pl_mean output
pl_list2 <- c()
for (i in seq(6)) {
  pc <- sample_lemniscate_gerono(60, sd = 0.05)
  pd <- alphaComplexDiag(pc, maxdimension = 1)$diagram
  pd[,2] <- sqrt(pd[,2])
  pd[,3] <- sqrt(pd[,3])
  #pd <- as_persistence(pd)
  pl <- landscape(pd, degree = 1, xby = .01)
  pl_list2 <- c(pl_list2, pl)
}
#> Error in landscape(pd, degree = 1, xby = 0.01): unused arguments (degree = 1, xby = 0.01)

avg_pl2 <- pl_mean(pl_list2)
#> Error in as.environment(NULL): using 'as.environment(NULL)' is defunct
plot(avg_pl2) 
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'avg_pl2' not found

Created on 2024-07-25 with reprex v2.1.1

corybrunson commented 3 months ago

Thanks @a1danbryant for raising the issue. It looks like the reprex was corrupted by a conflict between TDA::landscape() and plt::landscape(). This might eventually mean that {plt} should use a different name for this function, e.g. pl() or pl_construct(). In the meantime, you can avoid the conflict by attaching {TDA} package before {plt}, so that the latter masks the former. Or you could try using the {conflicted} package for more explicit control over conflicting object names.

Please edit the reprex (or create a new one in a comment) and i'll come back to this!