-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwitness_play.py
64 lines (59 loc) · 2.15 KB
/
witness_play.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
from time import time
import numpy as np
import ilc_data.ilc_loader as ILC
from tda_utils.density_filtration import sort_distances_per_point, indices_for_density_filtration
from tda_utils.witness_complex import *
# Load in ILC data
sct_sparse = ILC.get_sct_var_scale()
dist_mat = ILC.get_dist_mat()
n, d = sct_sparse.shape
print("n = "+str(n))
print("d = "+str(d))
print("shape of dist_mat: "+str(dist_mat.shape))
# Load in distances per point
distances_per_point = np.load("data/ilc_scale_data_distances_per_point.npy")
# time computation of density filtrations
print("Timing computation of density filtrations...")
density_indices = dict()
density_filtrations = dict()
#ks = [1, 5, 10, 50]
ks = [5]
ps = [0.01, 0.05, 0.1, 0.2, 0.5, 1.0]
for k in ks:
for p in ps:
print("\tk = "+str(k)+", p = "+str(p)+":")
start = time()
indices = indices_for_density_filtration(distances_per_point, k, p)
density_indices[(k, p)] = indices
mask = np.zeros(n, dtype=bool)
mask[indices] = True
sqr_mask = np.outer(mask, mask)
density_filtrations[(k, p)] = np.reshape(dist_mat[sqr_mask], (len(indices), len(indices)))
print("\t"+str(time()-start)+" seconds\n")
print("Timing computation of landmarks...")
landmark_indices = dict()
landmark_mats = dict()
pps = [0.05, 0.1, 0.2]
for k in ks:
for p in ps:
for pp in pps:
print("\tk = "+str(k)+", p = "+str(p)+", pp = "+str(pp)+":")
start = time()
landmark_indices[(k, p, pp)], landmark_mats[(k, p, pp)] = choose_landmarks(density_filtrations[(k, p)], pp)
print("\t"+str(time()-start)+" seconds\n")
print("Printing numbers of landmarks...")
for k in ks:
for p in ps:
for pp in pps:
# Number of landmarks completely determined by p, pp
tiny_toople = (p, pp)
toople = (k, p, pp)
print("\tk = "+str(k))
start = time()
landmark_inds = landmark_indices[toople]
dense_inds = density_indices[(k, p)]
true_inds = [dense_inds[ind] for ind in landmark_inds]
to_save = np.vstack([sct_sparse[ind, :] for ind in true_inds])
np.save("data/sample_landmarks_kis"+str(toople)+".npy", to_save)
np.save("data/sample_landmark_indices_kis"+str(toople)+".npy", true_inds)
print("\t"+str(time() - start)+" seconds\n")