peekxc / Mapper

R package for computing the Mapper construction from Topological Data Analysis
http://peekxc.github.io/Mapper/
Other
6 stars 6 forks source link

draft cover plot methods #9

Open corybrunson opened 5 years ago

corybrunson commented 5 years ago

Occasionally i become uncertain about what my covers are actually doing, and it's takes a while to inspect them via .$interval_bounds() and .$level_sets, for example. It seems natural to want some methods to quickly visualize a cover, with or without the lensed data overlaid. These methods aren't very elegant, but they can very quickly reveal problems with a cover that cause unexpected and otherwise opaque problems for the nerve construction. What do you think? (I've only written a method for FixedIntervalCover.) I ran the following chunks after installing the current version of this inspect branch:

library(Mapper)

# data: uniform sample from the 2-sphere
s2 <- array(stats::rnorm(720 * (2 + 1)), dim = c(720, 2 + 1))
van <- which(apply(s2, 1, norm, "2") == 0)
for (i in van) {
  while (norm(s2[i, ], "2") == 0) {
    s2[i, ] <- stats::rnorm(2 + 1)
  }
}
s2 <- sweep(s2, 1, apply(s2, 1, norm, "2"), FUN = "/")
# data: initialize mapper
m <- MapperRef$new(X = s2)

# lens: project to the first coordinate
f_s2 <- s2[, 1, drop = FALSE]
m$filter <- f_s2
# cover: 5 fixed-length intervals with 50% overlap
c_s2 <- FixedIntervalCover$new(number_intervals = 5, percent_overlap = 50)
c_s2$construct_cover(filter = m$filter)
m$cover <- c_s2
hist(m$filter(), xlim = c(-1.2, 1.2))
m$cover$plot(m$filter, add=TRUE, lwd=2)


# lens: project to the first two coordinates
f_s2 <- s2[, 1:2]
m$filter <- f_s2
# cover: 5-by-5 fixed-length intervals with 40% overlap
c_s2 <- FixedIntervalCover$new(number_intervals = 5, percent_overlap = 40)
c_s2$construct_cover(filter = m$filter)
m$cover <- c_s2
m$cover$plot(m$filter, border = "#00000077")

plot(f_s2, pch = 19, cex = .5)
m$cover$plot(m$filter, border = "#00000077", index = "(3 4)", add = TRUE)

Created on 2019-08-11 by the reprex package (v0.2.1)