In [1]:
require(fastcluster)
library(TDAmapper)
library(devtools)
library(igraph)
In [15]:
# sample points from two intertwined spirals
set.seed("1")
t <- runif(100, min=1, max=6.3) # theta
X <- data.frame( x = c( t*cos(t), -t*cos(t) ), y = c( t*sin(t), -t*sin(t) ) )
d <- dist(X)
plot(X[,1], X[,2])
X
In [9]:
filter <- X[,2] # height projection
num_intervals <- 10
percent_overlap <- 50
num_bins_when_clustering <- 10
m3 <- mapper1D(
distance_matrix = d,
filter_values = filter,
# num_intervals = 10, # use default
# percent_overlap = 50, # use default
# num_bins_when_clustering = 10 # use default
)
g3 <- graph.adjacency(m3$adjacency, mode="undirected")
plot(g3, layout = layout.auto(g3) )
In [10]:
# parametrize a trefoil knot
n <- 100
t <- 2*pi*(1:n)/n
X <- data.frame(x = sin(t)+2*sin(2*t),
y = cos(t)-2*cos(2*t),
z = -sin(3*t))
f <- X
library(rgl)
plot3d(X$x, X$y, X$z)
In [13]:
# use the github version so that vertices stay on the canvas
library(devtools)
devtools::install_github("christophergandrud/networkD3")
library(networkD3)
In [14]:
# parametrize a trefoil knot
n <- 100
t <- 2*pi*(1:n)/n
X <- data.frame(x = sin(t)+2*sin(2*t),
y = cos(t)-2*cos(2*t),
z = -sin(3*t))
f <- X
m5 <- mapper(dist(X), f, c(3,3,3), c(30,30,30), 5)
g5 <- graph.adjacency(m5$adjacency, mode="undirected")
plot(g5, layout = layout.auto(g5) )
tkplot(g5)
# create data frames for vertices and edges with the right variable names
MapperNodes <- mapperVertices(m5, 1:dim(f)[1] )
MapperLinks <- mapperEdges(m5)
# interactive plot
forceNetwork(Nodes = MapperNodes, Links = MapperLinks,
Source = "Linksource", Target = "Linktarget",
Value = "Linkvalue", NodeID = "Nodename",
Group = "Nodegroup", opacity = 0.8,
linkDistance = 10, charge = -400)
In [ ]: