-
Notifications
You must be signed in to change notification settings - Fork 0
/
torus.py
49 lines (41 loc) · 988 Bytes
/
torus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import numpy as np
from mapper.mapper import Mapper
def torus():
u=np.linspace(0,2*np.pi,10)
v=np.linspace(0,2*np.pi,50)
u,v=np.meshgrid(u,v)
a = 2
b = 9
x = (b + a*np.cos(u)) * np.cos(v)
y = (b + a*np.cos(u)) * np.sin(v)
z = a * np.sin(u)
return np.vstack((x.ravel(), y.ravel(), z.ravel())).T
points = torus()
mapper = Mapper(
bins=4,
filter_function='by_coordinate',
coordinate=1,
clustering_function='agglomerative',
linkage="average",
distance=15
)
graph = mapper.fit(points)
mapper.plot_vertices()
mapper.plot_intervals()
mapper.plot_clusters()
mapper.plot_graph()
mapper.plot_graph_in_plane()
mapper.plot_persistence_homology()
# Silhouette score
mapper = Mapper(
bins=4,
filter_function='by_coordinate',
coordinate=1,
)
graph = mapper.fit(points)
mapper.plot_vertices()
mapper.plot_intervals()
mapper.plot_clusters()
mapper.plot_graph()
mapper.plot_graph_in_plane()
mapper.plot_persistence_homology()