Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Add check for missing index parameter to BallCover.R #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yaraskaf
Copy link

In developing some additional cover options (as discussed in #7), I noticed that level sets were being constructed multiple times per Mapper construction for the BallCover but not the FixedIntervalCover.

This seems to be because FixedIntervalCover only constructs self$level_sets when the index parameter is missing or null (i.e. when the cover is initially constructed). BallCover does not check whether index is null before constructing self$level_sets, so the computation may be performed more than once.

Addition of this check for null/missing speeds up BallCover considerably without affecting the level sets or complex that is generated.

For example, using data and filter

library(Mapper)

data("noisy_circle", package = "Mapper")
X = noisy_circle

left_pt <- X[which.min(X[, 1]),]
f_X <- matrix(apply(X, 1, function(pt) (pt - left_pt)[1]))

I ran the following code using the current version of the master branch of Mapper:

ptm <- proc.time()
base_m <- MapperRef$new(X)$
  use_filter(filter = f_X)$
  use_cover(cover="ball", epsilon=0.01)$
  use_distance_measure(measure="euclidean")$
  construct_k_skeleton(k=1L)
proc.time()-ptm
>#   user  system elapsed
     2.09    0.05    2.14

Then I ran the same code after loading the current version of this ballcover_optimization branch:

library(devtools)
load_all()

ptm <- proc.time()
opt_m <- MapperRef$new(X)$
  use_filter(filter = f_X)$
  use_cover(cover="ball", epsilon=0.01)$
  use_distance_measure(measure="euclidean")$
  construct_k_skeleton(k=1L)
proc.time()-ptm
>#   user  system elapsed
     0.23    0.00    0.19

And compared the resulting complexes and level sets:

base_levelsets <- base_m$cover$level_sets
base_complex <- base_m$simplicial_complex

optimized_levelsets <- opt_m$cover$level_sets
optimized_complex <- opt_m$simplicial_complex

expect_equal(base_complex, optimized_complex)
expect_identical(base_levelsets, optimized_levelsets)

Checking for null/missing index reduces the number of times the cover constructs self$level_sets, speeding up the cover.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant