Skip to content

Instantly share code, notes, and snippets.

@chiral
Created April 4, 2014 04:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiral/9967948 to your computer and use it in GitHub Desktop.
Save chiral/9967948 to your computer and use it in GitHub Desktop.
Test program for "pHom" package which can calculate persistent homologies in R
library(phom)
library(scatterplot3d)
N <- 20
R <- 25
r <- 10
sd <- 1
ts <- seq(0,2*pi,pi/N)
ps <- seq(0,2*pi,pi/N)
x<-y<-z<-c()
for (t in ts) for (p in ps) {
x <- c(x,R*cos(t)+r*cos(p)*cos(t))
y <- c(y,R*sin(t)+r*cos(p)*sin(t))
z <- c(z,r*sin(p))
}
par(mfcol=c(1,2))
scatterplot3d(x,y,z,type="l")
N1 <- length(ts)
rn <- function() rnorm(N1*N1,0,sd)
scatterplot3d(x+rn(),
y+rn(),
z+rn(),
type="p",pch=20)
print("Please enter key for next graphs.")
readline()
par(mfcol=c(1,2))
max_dim <- 2
max_f <- 5
intervals <- pHom(cbind(x,y,z), max_dim, max_f)
plotBarcodeDiagram(intervals, 0, max_f, title="b0")
plotBarcodeDiagram(intervals, 1, max_f, title="b1")
print("Please enter key for next graphs.")
readline()
par(mfcol=c(1,1))
#plotBarcodeDiagram(intervals, 2, max_f)
plotPersistenceDiagram(intervals, max_dim, max_f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment