-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigure_weights_visualizations.py
55 lines (46 loc) · 1.37 KB
/
figure_weights_visualizations.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
import os
import jax
import jax.numpy as jnp
import matplotlib.pyplot as plt
import numpy as np
from visualizations import plot_eigenvalues
from rnn import RNN2L
jax.config.update("jax_enable_x64", True)
results_dir = 'results'
sigma = 0.3
sigma_mu = 1.0
symmetric_mu = False
symmetric_random = False
net = RNN2L()
os.makedirs(results_dir, exist_ok=True)
# ===== WEIGHTS =====
N0 = 10
P = 10
key = jax.random.PRNGKey(1)
J = net.generate_weights(key,
N0=N0,
P=P,
sigma=sigma,
sigma_mu=sigma_mu,
symmetric_mu=symmetric_mu,
symmetric_random=symmetric_random)
plt.figure(figsize=(6,6))
plt.imshow(J, cmap='plasma');
plt.axis('off');
plt.savefig(os.path.join(results_dir, 'weights.png'), bbox_inches='tight')
plt.savefig(os.path.join(results_dir, 'weights.pdf'), bbox_inches='tight')
# ===== EIGENVALUES =====
N0 = 5
P = 200
key = jax.random.PRNGKey(2)
J = net.generate_weights(key,
N0=N0,
P=P,
sigma=sigma,
sigma_mu=sigma_mu,
symmetric_mu=symmetric_mu,
symmetric_random=symmetric_random)
plot_eigenvalues(J, title=None, color='black')
plt.axis('off')
plt.tight_layout()
plt.savefig(os.path.join(results_dir, 'eigenvalues.pdf'), bbox_inches='tight');