-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMake_figs2.py
187 lines (141 loc) · 6.62 KB
/
Make_figs2.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# ============================================================================================================
# Make_figs2.py -- Generates the figures with the data produced by
# 3-Neuromodulation_and_plasticity_Activity_vs_Learning_rate.py
#
# Ref: Pedrosa V and Clopath C (2017) The Role of Neuromodulators in Cortical Plasticity.
# A Computational Perspective. Front. Synaptic Neurosci. 8:38. doi: 10.3389/fnsyn.2016.00038
# -----------------------------------------------------------------------
#
# Author: Victor Pedrosa <v.pedrosa15@imperial.ac.uk>
# Imperial College London, London, UK - Dec 2016
# ============================================================================================================
# ------------------------------------- Import modules -------------------------------------------------------
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})
import os
import numpy as np
from matplotlib.gridspec import GridSpec
plt.rc('xtick', labelsize=17)
plt.rc('ytick', labelsize=17)
Dir = 'Data_Activity_vs_Learning_rate/'
# ================================================================================================================
# Plot the synaptic weights for small and large learning rates
# ================================================================================================================
# Files with the data to be loaded
f1 = 'Syn_weights_all_trials_learning_rate=00.0100_activity=01.0000.npy'
f2 = 'Syn_weights_all_trials_learning_rate=00.0200_activity=01.0000.npy'
# Create the figure
fig = plt.figure(num=2,figsize=(10, 4), dpi=100, facecolor='w')
gs1 = GridSpec(1, 2)
# ----------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------
# Plot the weights for small alpha and large alpha
# Load the initial and the final weights
n = -1
W0 = np.load(Dir+f1)[:,0]
W1 = np.load(Dir+f1)[:,n] # small alpha
W2 = np.load(Dir+f2)[:,n] # large alpha
# Redefine the weights as a weighted sum of the synaptic weights and re-scale it
W0_in = W0
sigma = .5
for i in range(10):
NormDist = 1./np.sum(np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)]))
InputWeights = NormDist*np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)])
W0[:,i] = np.dot(W0_in,InputWeights)
W0 = np.mean(W0,axis=0)
W0 = W0/np.max(W0)
W1_in = W1
sigma = .5
for i in range(10):
NormDist = 1./np.sum(np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)]))
InputWeights = NormDist*np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)])
W1[:,i] = np.dot(W1_in,InputWeights)
for i in range(W1.shape[0]):
W1[i] = W1[i]/np.max(W1[i])
W2_in = W2
sigma = .5
for i in range(10):
NormDist = 1./np.sum(np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)]))
InputWeights = NormDist*np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)])
W2[:,i] = np.dot(W2_in,InputWeights)
for i in range(W2.shape[0]):
W2[i] = W2[i]/np.max(W2[i])
# Calculate the mean weight over all the trials
W1_mean = np.mean(W1,axis=0)
W2_mean = np.mean(W2,axis=0)
# Plot the weights (initial and final)
xdata = np.arange(1,11,1)
ax1 = plt.subplot(gs1[0, 0])
plt.xlabel('Input',fontsize='20')
plt.ylabel('Synaptic Weight', fontsize='20')
plt.xlim((1,10))
plt.ylim((0,1.01))
color = 'r'
plt.plot(xdata,W0,color='k',label='Initial',lw=2)
plt.plot(xdata,W1_mean,color=color,label=r'Small $\alpha$',lw=2)
color = 'b'
plt.plot(xdata,W2_mean,color=color,label=r'Large $\alpha$',lw=2)
plt.legend(fontsize=10,loc=0)
# ================================================================================================================
# ================================================================================================================
# ================================================================================================================
# Plot the synaptic weights for small and large values of presynaptic activity
# ================================================================================================================
f1 = 'Syn_weights_all_trials_learning_rate=00.0200_activity=01.0000.npy'
f2 = 'Syn_weights_all_trials_learning_rate=00.0200_activity=10.0000.npy'
# ----------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------
# Plot the weights for small nu and large nu
# Load the initial and the final weights
n = -1
W0 = np.load(Dir+f1)[:,0,:10]
W1 = np.load(Dir+f1)[:,n,:10]
W2 = np.load(Dir+f2)[:,n,:10]
# Redefine the weights as a weighted sum of the synaptic weights and re-scale it
W0_in = W0
sigma = .5
for i in range(10):
NormDist = 1./np.sum(np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)]))
InputWeights = NormDist*np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)])
W0[:,i] = np.dot(W0_in,InputWeights)
W0 = np.mean(W0,axis=0)
W0 = W0/np.max(W0)
W1_in = W1
sigma = .5
for i in range(10):
NormDist = 1./np.sum(np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)]))
InputWeights = NormDist*np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)])
W1[:,i] = np.dot(W1_in,InputWeights)
for i in range(W1.shape[0]):
W1[i] = W1[i]/np.max(W1[i])
W2_in = W2
sigma = .5
for i in range(10):
NormDist = 1./np.sum(np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)]))
InputWeights = NormDist*np.array([np.exp(-(x-i)**2/((2.*sigma)**2)) for x in range(10)])
W2[:,i] = np.dot(W2_in,InputWeights)
for i in range(W2.shape[0]):
W2[i] = W2[i]/np.max(W2[i])
# Calculate the mean weight over all the trials
W1_mean = np.mean(W1,axis=0)
W1_sd = np.std(W1,axis=0)
W2_mean = np.mean(W2,axis=0)
W2_sd = np.std(W2,axis=0)
# Plot the weights (initial and final)
xdata = np.arange(1,11,1)
ax1 = plt.subplot(gs1[0, 1])
plt.xlabel('Input',fontsize='20')
plt.ylabel('Synaptic Weight', fontsize='20')
plt.xlim((1,10))
plt.ylim((0,1.01))
color = 'r'
plt.plot(xdata,W0,color='k',label='Initial',lw=2)
plt.plot(xdata,W1_mean,color=color,label=r'Small $\nu$',lw=2)
color = 'b'
plt.plot(xdata,W2_mean,color=color,label=r'Large $\nu$',lw=2)
plt.legend(fontsize=10,loc=0)
# ----------------------------------------------------------------------------------------------------------------
# Choose the directory and save the figures
plt.savefig('Figures/Fig2_Receptive_field_plasticity_Activity_vs_Learning_rate.png',dpi=300)
plt.show()