-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFig-3-accuracy-lesion.py
executable file
·259 lines (225 loc) · 10 KB
/
Fig-3-accuracy-lesion.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright INRIA
# Contributors: Wahiba Taouali ([email protected])
# Nicolas P. Rougier ([email protected])
#
# This software is governed by the CeCILL license under French law and abiding
# by the rules of distribution of free software. You can use, modify and/ or
# redistribute the software under the terms of the CeCILL license as circulated
# by CEA, CNRS and INRIA at the following URL
# http://www.cecill.info/index.en.html.
#
# As a counterpart to the access to the source code and rights to copy, modify
# and redistribute granted by the license, users are provided only with a
# limited warranty and the software's author, the holder of the economic
# rights, and the successive licensors have only limited liability.
#
# In this respect, the user's attention is drawn to the risks associated with
# loading, using, modifying and/or developing or reproducing the software by
# the user in light of its specific status of free software, that may mean that
# it is complicated to manipulate, and that also therefore means that it is
# reserved for developers and experienced professionals having in-depth
# computer knowledge. Users are therefore encouraged to load and test the
# software's suitability as regards their requirements in conditions enabling
# the security of their systems and/or data to be ensured and, more generally,
# to use and operate it in the same conditions as regards security.
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
# -----------------------------------------------------------------------------
import os.path
import itertools
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from matplotlib.patches import Rectangle
import matplotlib.patheffects as PathEffects
import matplotlib
from model import *
from graphics import *
from stimulus import *
from parameters import *
from projections import *
font = {'size' : 18}
matplotlib.rc('font', **font)
# Target positions (rho,theta)
targets = []
targets_rho = [2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20] # -> X
targets_theta = [-45, -30, -15, 0, +15, +30, +45] # -> Y
for i in targets_rho:
for j in targets_theta:
targets.append((i,j))
# Decode function
def decode(Z, xmin=+0.0, xmax=+2.0, ymin=-1.0, ymax=+1.0,):
Y,X = np.mgrid[0:Z.shape[0],0:Z.shape[1]]
X = xmin + X/float(Z.shape[0]-1)*(xmax-xmin)
Y = ymin + Y/float(Z.shape[1]-1)*(ymax-ymin)
Z_sum = Z.sum()
x = (Z*X).sum() / Z_sum
y = (Z*Y).sum() / Z_sum
return x,y
def run(ax, lesion, name, title):
S = np.zeros((len(targets),4))
model = Model()
model.make_lesion(lesion)
if os.path.exists('data/lesion-%s.npy' % name):
S = np.load('data/lesion-%s.npy' % name)
else:
for i,target in enumerate(targets):
rho,theta = target
x_,y_ = polar_to_logpolar(rho/90.0, np.pi*theta/180.0)
x_,y_ = 2*x_, 2*y_-1
model.reset()
model.R = stimulus((rho, theta))
model.run(duration=5*second, dt=5*millisecond, epsilon=0.001)
x,y = decode(model.SC_V)
S[i] = x_, y_, x, y
print 'Target at (%d,%d): %f' % (rho,theta, np.sqrt((x-x_)*(x-x_) + (y-y_)*(y-y_)))
np.save('data/lesion-%s.npy' % name, S)
logpolar_frame(ax)
for i in range(len(S)):
ax.plot([S[i,0],S[i,2]],[S[i,1],S[i,3]], color='k', lw=.5)
ax.scatter(S[:,0], S[:,1], s=35, color='k', marker='o', lw=.5)
ax.scatter(S[:,2], S[:,3], s=35, color='k', marker='o', facecolors='w', lw=.5)
ax.text(0,-1, title, ha="left", va="top", fontsize=18)
if lesion is not None:
position,size = lesion
rho,theta = position
rho,theta = rho/90.0, np.pi*theta/180.0
x,y = polar_to_logpolar(rho,theta)
radius = size/90.0
ax.add_patch(plt.Circle((2*x,2*y-1), radius=radius, ec='k', fc='w', zorder=+10, alpha=.5))
ax.add_patch(plt.Circle((2*x,2*y-1), radius=radius, ec='k', lw=.5, fc='none', zorder=+15))
#plt.show()
if 0:
for j in [1, 5, 25, 50, 100, 250, 500]:
lesion_size = 10
lesion_rho = 5
lesion_theta= -15
rho = 5
theta = 0
model = Model()
make_lesion(model, [(lesion_rho,lesion_theta), lesion_size])
dt = 0.01
model.run(t=j*dt, dt=dt, S = [ [(rho,theta), 1.0, 1.0] ] )
fig = plt.figure(figsize=(8,6), facecolor='w')
ax1 = plt.subplot(111, aspect=1)
logpolar_frame(ax1)
logpolar_imshow(ax1, model.SCv)
rho,theta = lesion_rho/90.0, np.pi*lesion_theta/180.0
x,y = logpolar(rho,theta)
radius = lesion_size/90.0
ax1.add_patch(plt.Circle((2*x,2*y-1), radius=radius, ec='k', fc='w', zorder=+10, alpha=.5))
ax1.add_patch(plt.Circle((2*x,2*y-1), radius=radius, ec='k', fc='none', zorder=+15))
plt.savefig('lesion-after-%03d.pdf' % j)
# plt.show()
# Error histograms
if 1:
import matplotlib
matplotlib.rcParams['xtick.major.width'] = .5
matplotlib.rcParams['ytick.major.width'] = .5
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'
fig = plt.figure(figsize=(10,12))
fig.patch.set_color('w')
G = gridspec.GridSpec(3, 2)
G.update(left=0.07, right=0.95, wspace=0.2, hspace=0.2, bottom=0.05,top=0.95)
# Intact model
ax = plt.subplot(G[0, 0], aspect=1)
run(ax, None, "None", "Intact model")
ax.text(0.0, 1.0, 'a', va='top', ha='right',
transform=ax.transAxes, fontsize=20, fontweight='bold')
# Lesioned model
ax = plt.subplot(G[0, 1], aspect=1)
run(ax, [(5,0),12], "(5,0)", "Lesioned model")
ax.text(0.0, 1.0, 'b', va='top', ha='right',
transform=ax.transAxes, fontsize=20, fontweight='bold')
red = (1,.25,.25)
blue = (.25,.25,1)
# Horizontal errors
ax = plt.subplot(G[1, 0:])
ax.set_axisbelow(True)
ax.spines['right'].set_color('none')
ax.spines['left'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
S = np.load('data/lesion-None.npy').reshape(11,7,4)
D = np.sqrt( (S[...,2]-S[...,0])**2 + (S[...,3]-S[...,1])**2)
X = np.array(targets_rho)
M = np.mean(D, axis=1) * 100
E = np.std(D,axis=1) * 100
ax.bar(X-0.5, M, .5, yerr=E, label='Intact model', color=blue, edgecolor='w', ecolor=blue)
print M, np.mean(M) ,np.std(M)
S = np.load('data/lesion-(5,0).npy').reshape(11,7,4)
D = np.sqrt( (S[...,2]-S[...,0])**2 + (S[...,3]-S[...,1])**2)
X = np.array(targets_rho)
M = np.mean(D, axis=1) * 100
E = np.std(D,axis=1) * 100
c = (1,.75,.75)
ax.bar(X, M, .5, yerr=E, label='Lesioned model', color=red, edgecolor='w', ecolor=red)
plt.ylim(0,25)
plt.xlim(0,21)
plt.xticks([0,10,15,20], [u"0°",u"10°",u"15°",u"20°"])
plt.yticks([0,5,10,15,20], [u"0%",u"5%",u"10%",u"15%",u"20%"])
ax.grid(which='major', axis='y', linewidth=0.75, linestyle='-', color='0.5',zorder=-10)
#[t.set_color('0.5') for t in ax.xaxis.get_ticklabels()]
#[t.set_color('0.5') for t in ax.yaxis.get_ticklabels()]
[t.set_alpha(0.0) for t in ax.yaxis.get_ticklines()]
ax.legend(frameon=False, fontsize=15)
plt.text(0, 21, "Mean encoding error along rosto-caudal axis",
va='bottom',ha='left',color='k', fontsize=18)
ax.annotate("Lesion site",
xy=(5, 0), xycoords='data',
xytext=(5, -2.5), textcoords='data', ha='center',
arrowprops=dict(arrowstyle="->", color="k"))
ax.text(0.0, 1.0, 'c', va='top', ha='right',
transform=ax.transAxes, fontsize=20, fontweight='bold')
# Vertical errors
ax = plt.subplot(G[2, 0:])
ax.set_axisbelow(True)
ax.spines['right'].set_color('none')
ax.spines['left'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
S = np.load('data/lesion-None.npy').reshape(11,7,4)
D = np.sqrt( (S[...,2]-S[...,0])**2 + (S[...,3]-S[...,1])**2)
X = np.array(targets_theta)
M = np.mean(D, axis=0) * 100
E = np.std(D, axis=0) * 100
ax.bar(X-2.5, M, 2.5, yerr=E, label='Intact model', color=blue, edgecolor='w', ecolor=blue)
print M, np.mean(M) ,np.std(M)
S = np.load('data/lesion-(5,0).npy').reshape(11,7,4)
D = np.sqrt( (S[...,2]-S[...,0])**2 + (S[...,3]-S[...,1])**2)
X = np.array(targets_theta)
M = np.mean(D, axis=0) * 100
E = np.std(D, axis=0) * 100
ax.bar(X, M, 2.5, yerr=E, label='Lesioned model', color=red, edgecolor='w', ecolor=red)
plt.xlim(-50,50)
plt.xticks([-45,-30,-15,+15,+30,+45],
[u"-45°",u"-30°",u"-15°", u"15°", u"30°", u"45°"])
plt.ylim(0,25)
plt.yticks([0,5,10,15,20], [u"0%",u"5%",u"10%",u"15%",u"20%"])
#ax.grid(which='major', axis='y', linewidth=0.75, linestyle='-', color='1.',zorder=-10)
ax.grid(which='major', axis='y', linewidth=0.75, linestyle='-', color='0.5',zorder=-10)
#[t.set_color('0.5') for t in ax.xaxis.get_ticklabels()]
#[t.set_color('0.5') for t in ax.yaxis.get_ticklabels()]
[t.set_alpha(0.0) for t in ax.yaxis.get_ticklines()]
ax.legend(frameon=False, fontsize=15)
plt.text(-50, 21, "Mean encoding error along vertical axis",
va='bottom',ha='left',color='k', fontsize=18)
ax.annotate("Lesion site",
xy=(0, 0), xycoords='data',
xytext=(0, -2.5), textcoords='data', ha='center',
arrowprops=dict(arrowstyle="->", color="k"))
ax.text(0.0, 1.0, 'd', va='top', ha='right',
transform=ax.transAxes, fontsize=20, fontweight='bold')
plt.savefig("figures/Fig-3.pdf")
#plt.tight_layout()
plt.savefig("figures/Fig-3.eps",format='eps', dpi=1000)
plt.show()