-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtest_unit_plot.py
More file actions
117 lines (110 loc) · 3.26 KB
/
test_unit_plot.py
File metadata and controls
117 lines (110 loc) · 3.26 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import unittest
import networkx as nx
import numpy as np
from tdamapper.clustering import TrivialClustering
from tdamapper.core import MapperAlgorithm
from tdamapper.cover import BallCover
from tdamapper.plot import MapperLayoutInteractive, MapperLayoutStatic, MapperPlot
class TestMapperPlot(unittest.TestCase):
def test_two_connected_clusters(self):
data = [
np.array([0.0, 1.0]),
np.array([1.0, 0.0]),
np.array([0.0, 0.0]),
np.array([1.0, 1.0]),
]
mp = MapperAlgorithm(
cover=BallCover(1.1, metric="euclidean"), clustering=TrivialClustering()
)
g = mp.fit_transform(data, data)
mp_plot1 = MapperPlot(g, dim=2, seed=123, iterations=10)
mp_plot1.plot_plotly(
colors=data,
agg=np.nanmax,
width=200,
height=200,
title="example",
cmap="jet",
)
mp_plot2 = MapperPlot(g, dim=3, seed=123, iterations=10)
fig2 = mp_plot2.plot_plotly(
colors=data,
agg=np.nanmax,
width=200,
height=200,
title="example",
cmap="jet",
)
mp_plot2.plot_plotly_update(
fig2,
colors=data,
agg=np.nanmin,
width=300,
height=300,
title="example-updated",
cmap="viridis",
)
mp_plot3 = MapperPlot(g, dim=2)
mp_plot3.plot_matplotlib(width=300, height=300, colors=data)
mp_plot3.plot_pyvis(
width=512,
height=512,
colors=data,
output_file="network.html",
)
def test_empty_graph(self):
empty_graph = nx.Graph()
mapper_plot = MapperPlot(empty_graph, dim=2)
mapper_plot.plot_matplotlib(colors=[])
mapper_plot.plot_plotly(colors=[])
mapper_plot.plot_pyvis(colors=[], output_file="tmp.html")
def test_two_connected_clusters_deprecated(self):
data = [
np.array([0.0, 1.0]),
np.array([1.0, 0.0]),
np.array([0.0, 0.0]),
np.array([1.0, 1.0]),
]
mp = MapperAlgorithm(
cover=BallCover(1.1, metric="euclidean"), clustering=TrivialClustering()
)
g = mp.fit_transform(data, data)
mp_plot1 = MapperLayoutInteractive(
g,
dim=2,
colors=data,
seed=123,
iterations=10,
agg=np.nanmax,
width=200,
height=200,
title="example",
cmap="jet",
)
mp_plot1.plot()
mp_plot2 = MapperLayoutInteractive(
g,
dim=3,
colors=data,
seed=123,
iterations=10,
agg=np.nanmax,
width=200,
height=200,
title="example",
cmap="jet",
)
mp_plot2.plot()
mp_plot2.update(
colors=data,
seed=124,
iterations=15,
agg=np.nanmin,
width=300,
height=300,
title="example-updated",
cmap="viridis",
)
mp_plot2.plot()
mp_plot3 = MapperLayoutStatic(g, colors=data, dim=2)
mp_plot3.plot()