-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlotRank.m
322 lines (239 loc) · 9.93 KB
/
PlotRank.m
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
function PlotRank(varargin)
load('CuratedCells.mat');
myFig = figure();
set(gcf,'color','white')
plotNormal(Base)
mh = uimenu(myFig,'Label','Plot');
% For the main plot
main = uimenu(mh,'Label','Normal rank','checked','off','callback',{@keydown_callback,Base,'normal'});
% For the alternative plot
alt = uimenu(mh,'Label','By AC slope');
corr = uimenu(alt,'Label','Correlated','checked','off','callback',{@keydown_callback,Base,'alt','corr'});
hm = uimenu(alt,'Label','Half-matched','checked','off','callback',{@keydown_callback,Base,'alt','hm'});
ac = uimenu(alt,'Label','Anticorrelated','checked','off','callback',{@keydown_callback,Base,'alt','ac'});
end
function plotNormal(Base)
for d = [1,2];
nCells = length(Base(d).Cells);
dxLengths = zeros(1,nCells);
for j = 1:nCells;
dxLengths(j) = length(Base(d).Cells(j).Dx);
end
dxL = min(dxLengths);
if d == 1;
rankData.lowDensity = zeros(nCells,dxL);
elseif d == 4;
rankData.highDensity = zeros(nCells,dxL);
end
correlatedRank = zeros(nCells,dxL);
halfmatchedRank = zeros(nCells,dxL);
anticorrelatedRank = zeros(nCells,dxL);
for cell = 1:nCells;
%% First we compute the rank order for each cell
% Extract and normalize data
correlatedResponse = Base(d).Cells(cell).correlatedResponse;
halfmatchedResponse = Base(d).Cells(cell).halfmatchedResponse;
anticorrelatedResponse = Base(d).Cells(cell).anticorrelatedResponse;
[cRank,cIndex] = sort(correlatedResponse,'descend');
hmRank = halfmatchedResponse(cIndex);
acRank = anticorrelatedResponse(cIndex);
Dx = Base(d).Cells(cell).Dx;
if cell == 33;
a = 3;
end
% Resample disparity values
newDx = linspace(min(Dx),max(Dx),dxL);
cRank2 = interp1(Dx,cRank,newDx);
hmRank2 = interp1(Dx,hmRank,newDx);
acRank2 = interp1(Dx,acRank,newDx);
% Not quite sure how to handle the max and min values.
maxC = max([acRank2,hmRank2,cRank2]); minC = min([acRank2,hmRank2,cRank2]);
correlatedRank(cell,:) = (cRank2-minC)/(maxC-minC);
halfmatchedRank(cell,:) = (hmRank2-minC)/(maxC-minC);
anticorrelatedRank(cell,:) = (acRank2-minC)/(maxC-minC);
end
rank = 1:9;
if d == 1;
subCount = 1;
maxSub = 2;
elseif d == 4;
subCount = 2;
maxSub = 2;
else
subCount = 3;
maxSub = 3;
end
subplot(1,maxSub,subCount);
corrRank = mean(correlatedRank); hmRank = mean(halfmatchedRank); acRank = mean(anticorrelatedRank);
N = size(correlatedRank,1);
corrSEM = std(correlatedRank)/sqrt(N); hmSEM = std(halfmatchedRank)/sqrt(N); acSEM = std(anticorrelatedRank)/sqrt(N);
hold off;
E1=errorbar(rank,corrRank,corrSEM*1.96);
set(E1,'color',[0.8,0.1,0.1],'marker','o','markerfacecolor',[0.8,0.1,0.1], ...
'linestyle',':','markersize',10,'linewidth',3);
hold on;
E2=errorbar(rank,hmRank,hmSEM*1.96);
set(E2,'color',[0.1,0.1,0.8],'marker','o','markerfacecolor',[0.1,0.1,0.8], ...
'linestyle',':','markersize',10,'linewidth',3);
E3=errorbar(rank,acRank,acSEM*1.96);
set(E3,'color',[0,0,0],'marker','o','markerfacecolor',[0,0,0], ...
'linestyle',':','markersize',10,'linewidth',3);
xlabel('Rank','fontsize',20);
ylabel('Mean normalized response','fontsize',20);
leg = legend('Correlated','Half-matched','Anti-correlated');
set(leg,'fontsize',14);
set(gca,'fontsize',18,'ytick',0:0.25:1);
title(['Density: ',num2str(Base(d).density),' %'],'fontsize',22);
ylim([0,1]);
end
end
function plotAlt(Base,type)
for d = [1,2];
nCells = length(Base(d).Cells);
dxLengths = zeros(1,nCells);
for j = 1:nCells;
dxLengths(j) = length(Base(d).Cells(j).Dx);
end
dxL = min(dxLengths);
if d == 1;
rankData.lowDensity = zeros(nCells,dxL);
elseif d == 4;
rankData.highDensity = zeros(nCells,dxL);
end
acSlopes = cat(1,Base(d).Cells.regAc);
acSlopes = acSlopes(:,2);
q50 = quantile(acSlopes,0.5);
q33 = quantile(acSlopes,1/3);
q66 = quantile(acSlopes,2/3);
nLower = sum(acSlopes < q33);
nUpper = sum(acSlopes > q66);
lowerPlotRank = zeros(nLower,dxL);
upperPlotRank = zeros(nUpper,dxL);
lowerCell = 0; upperCell = 0;
for cell = 1:nCells;
%% First we compute the rank order for each cell
% Extract and normalize data
correlatedResponse = Base(d).Cells(cell).correlatedResponse;
halfmatchedResponse = Base(d).Cells(cell).halfmatchedResponse;
anticorrelatedResponse = Base(d).Cells(cell).anticorrelatedResponse;
[cRank,cIndex] = sort(correlatedResponse,'descend');
hmRank = halfmatchedResponse(cIndex);
acRank = anticorrelatedResponse(cIndex);
Dx = Base(d).Cells(cell).Dx;
% Resample disparity values
newDx = linspace(min(Dx),max(Dx),dxL);
cRank2 = interp1(Dx,cRank,newDx);
hmRank2 = interp1(Dx,hmRank,newDx);
acRank2 = interp1(Dx,acRank,newDx);
maxC = max([acRank2,hmRank2,cRank2]); minC = min([acRank2,hmRank2,cRank2]);
acSlope = Base(d).Cells(cell).regAc(2);
if acSlope > q66;
upperCell = upperCell+1;
switch type
case 'corr'
upperPlotRank(upperCell,:) = (cRank2-minC)/(maxC-minC);
case 'hm'
upperPlotRank(upperCell,:) = (hmRank2-minC)/(maxC-minC);
case 'ac'
upperPlotRank(upperCell,:) = (acRank2-minC)/(maxC-minC);
end
elseif acSlope < q33
lowerCell = lowerCell+1;
switch type
case 'corr'
lowerPlotRank(lowerCell,:) = (cRank2-minC)/(maxC-minC);
case 'hm'
lowerPlotRank(lowerCell,:) = (hmRank2-minC)/(maxC-minC);
case 'ac'
lowerPlotRank(lowerCell,:) = (acRank2-minC)/(maxC-minC);
end
end
end
rank = 1:9;
if d == 1;
subCount = 1;
maxSub = 2;
elseif d == 4;
subCount = 2;
maxSub = 2;
else
subCount = 3;
maxSub = 3;
end
subplot(1,maxSub,subCount); hold on;
upperRank = mean(upperPlotRank);
lowerRank = mean(lowerPlotRank);
N_lower = size(lowerPlotRank,1);
N_upper = size(upperPlotRank,1);
lowerSEM = std(lowerPlotRank)/sqrt(N_lower);
upperSEM = std(upperPlotRank)/sqrt(N_upper);
hold off;
E1=errorbar(rank,lowerRank,lowerSEM*1.96);
set(E1,'color',[0.1,0.1,0.8],'marker','o','markerfacecolor',[0.1,0.1,0.8], ...
'linestyle',':','markersize',10,'linewidth',3);
hold on;
E2=errorbar(rank,upperRank,upperSEM*1.96);
set(E2,'color',[0.8,0.1,0.8],'marker','o','markerfacecolor',[0.8,0.1,0.8], ...
'linestyle',':','markersize',10,'linewidth',3);
leg = legend([E1,E2],'Lower','Upper');
xlabel('Rank','fontsize',20);
ylabel('Mean normalized response','fontsize',20);
set(leg,'fontsize',14);
set(gca,'fontsize',18,'ytick',0:0.25:1);
title(['Density: ',num2str(Base(d).density),' %'],'fontsize',22);
ylim([0,1]);
end
end
function [P,Q] = resampleCell(Cell,K,varargin)
% So what we want to do here:
% Figure out what integers make it so that the length of the
% disparity tuning curve for Cell ends up being K following resampling.
% We're just doing that with a nested loop as the space is so small
N = length(Cell.Dx);
if nargin == 2
multiplier = 1;
else
multiplier = varargin{1};
end
Ps = 1:(25*multiplier);
Qs = 1:(25*multiplier);
for Q = Qs;
for P = Ps;
cost = intCost(N,P,Q,K);
if cost < 0.001;
break
end
end
if cost < 0.001;
break
end
end
if cost >= 0.001
warning('Failed to find a solution; extending the range');
[P,Q] = resampleCell(Cell,K,multiplier+1);
end
end
function cost = intCost(N,P,Q,K)
% Usage: cost = intCost(N,P,Q,K);
% N: Length of array
% P: Numerator to be optimized
% Q: Denominator to be optimized
% K: Desired length
% This function is a stepping stone for figuring out
% how much you have to resample your array in order to
% get the desired size.
cost = sum((K-N*P/Q).^2);
%sprintf('Current cost: %2.f',cost)
end
function keydown_callback(myFig,evt,Base,type,varargin)
if nargin > 4
plotType = varargin{1};
else
plotType = 'none';
end
if strcmp(type,'normal');
plotNormal(Base);
elseif strcmp(type,'alt');
plotAlt(Base,plotType);
end
end