-
Notifications
You must be signed in to change notification settings - Fork 0
/
genotypes-tsne
82 lines (60 loc) · 2 KB
/
genotypes-tsne
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
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import offsetbox
import pickle
from sklearn import manifold
loadfile = 'learn_evolve'
iter_1 = 975
iter_2 = 1000
# ---- t-SNE settings ------
perplexity = 10
n_iter = 1000
def upper_tri_masking(A):
m = A.shape[0]
r = np.arange(m)
mask = r[:,None] < r
return A[mask]
plt.rc('text', usetex=True)
font = {'family': 'serif', 'size': 16, 'serif': ['computer modern roman']}
plt.rc('font', **font)
plt.rc('legend', **{'fontsize': 16})
folder = 'save/' + loadfile
J = np.zeros((100, 351)) # 100 organisms (50 iter_1, 50 iter_2) x 351 edges
# -------------------------------- iter_1 ------------------------------
filename = 'save/' + loadfile + '/isings/gen[' + str(iter_1) + ']-isings.pickle'
startstr = 'Loading simulation:' + filename
print(startstr)
isings = pickle.load(open(filename, 'rb'))
orgNum = 0
for I in isings:
J[orgNum, :] = upper_tri_masking(I.J)
orgNum += 1
iter_1_label = 'Gen: ' + str(iter_1)
# ------------------------------- iter_2 --------------------------------
filename = 'save/' + loadfile + '/isings/gen[' + str(iter_2) + ']-isings.pickle'
startstr = 'Loading simulation:' + filename
print(startstr)
isings = pickle.load(open(filename, 'rb'))
for I in isings:
J[orgNum, :] = upper_tri_masking(I.J)
orgNum += 1
iter_2_label = 'Gen: ' + str(iter_2)
# ----------------------------------------------------------------------
print("Computing t-SNE embedding")
tsne = manifold.TSNE(n_components=2, init='pca', random_state=0, perplexity=perplexity, n_iter=n_iter)
J_tsne = tsne.fit_transform(J)
x1 = J_tsne[:50, 0]
y1 = J_tsne[:50, 1]
x2 = J_tsne[50:100, 0]
y2 = J_tsne[50:100, 1]
plt.figure(1)
plt.subplot(111)
plt.scatter(x1, y1, label=iter_1_label)
plt.scatter(x2, y2, marker='+', label=iter_2_label)
plt.legend(loc=2)
titlestr = 'Connectivity t-SNE Projection\n Generation: ' + str(iter_1) + ', ' + str(iter_2)
plt.title(titlestr)
ax = plt.gca()
ax.set_xticklabels([])
plt.show()