-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtda_entropy.py
111 lines (52 loc) · 1.32 KB
/
tda_entropy.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
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
import numpy as np
import ripser
import matplotlib.pyplot as plt
import random
from persim.persistent_entropy import *
from scipy import stats
#
# Construct normal data
#
mu = .50; sigma = .250;
l1 = [];
for i in range(10):
# d1 = np.random.random(mu, sigma, (50,2));
d1 = np.random.normal(mu, sigma, (50,2));
l1.append(d1);
#
# Construct uniform point cloud
#
l2 = [];
for i in range(10):
d2 = np.random.random((50,2));
l2.append(d2);
#
# Plot the normal and unfirom point clouds
#
plt.scatter(d1[:,0], d1[:,1], label='Normal');
plt.scatter(d2[:,0], d2[:,1], label='Uniform');
plt.axis('equal');
plt.legend();
# plt.show();
#
# Generate persistence diagrams for normal/uniform distributions
#
p = 0;
diagrams_d1 = [];
diagrams_d2 = [];
for i in range(len(l1)):
diagrams_d1.append(ripser.ripser(l1[i])['dgms'][p]);
diagrams_d2.append(ripser.ripser(l2[i])['dgms'][p]);
#
# Compute persistent entropy for each persistence diagram
#
entropy_d1 = persistent_entropy(diagrams_d1);
entropy_d2 = persistent_entropy(diagrams_d2);
#
# Perform Mann-Whitney Test
# • H0: geometry of the point clouds is the same
# • Ha: point cloud geometries are different
#
np.random.seed(10);
stats.mannwhitneyu(entropy_d1, entropy_d2);
# MannwhitneyuResult(statistic=13.0, pvalue=0.00579535854433471)