-
Notifications
You must be signed in to change notification settings - Fork 1
/
binned_selectivity.m
76 lines (69 loc) · 2 KB
/
binned_selectivity.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
function [mean_sel, std_sel, all_sel] = binned_selectivity(op, od, mask, nbins)
%BINNED_SELECTIVITY Calculate average orientation selectivity in OD bins.
%
% [mean_sel, std_sel, all_sel] = binned_selectivity(op, od, mask, nbins)
%
% Takes the same input as pinwod. Calculates the average OP selectivity in each
% of the OD bins defined in pinwod. Returns the mean and standard deviation of
% each bin, as well as all the selectivity values.
%
% See also:
% pinwod
% Input validation and defaults
if nargin < 2
error('At least two inputs are required.');
end
if nargin < 3
mask = true(size(op));
end
if nargin < 4
nbins = 5;
end
% Convert OP to selectivity
op = abs(op);
% Mask
op(~mask) = nan;
od(~mask) = nan;
% Split the OD map into positive and negative sections
od_pos = od;
od_pos(od <= 0) = nan;
od_neg = od;
od_neg(od > 0) = nan;
% Divide the two OD map parts into nbins quantiles
% Positive
if nbins == 2
q = quantile(od_pos(:), 2);
q = q(1);
else
q = quantile(od_pos(:), nbins-1);
end
bin_od_pos = nan(size(od_pos));
bin_od_pos(od_pos < q(1)) = nbins;
for k = 2:nbins-1
bin_od_pos(od_pos < q(k) & od_pos > q(k-1)) = nbins - k + 1;
end
bin_od_pos(od_pos > q(nbins-1)) = 1;
% Negative
if nbins == 2
q = quantile(od_neg(:), 2);
q = q(1);
else
q = quantile(od_neg(:), nbins-1);
end
bin_od_neg = nan(size(od_neg));
bin_od_neg(od_neg < q(1)) = nbins;
for k = 2:nbins-1
bin_od_neg(od_neg < q(k) & od_neg > q(k-1)) = nbins - k + 1;
end
bin_od_neg(od_neg > q(nbins-1)) = 1;
% Calculate average selectivity in OD quantiles
mean_sel = nan(nbins,1);
std_sel = nan(nbins,1);
all_sel = cell(nbins,1);
for j = 1:nbins
% bin_od_pos => 1 (centre), n (border)
% bin_od_neg => n (centre), 1 (border)
mean_sel(j) = mean([op(bin_od_pos == j); op(bin_od_neg == (nbins-j+1))]);
std_sel(j) = std([op(bin_od_pos == j); op(bin_od_neg == (nbins-j+1))])/sqrt(length([op(bin_od_pos == j); op(bin_od_neg == (nbins-j+1))]));
all_sel{j} = [op(bin_od_pos == j); op(bin_od_neg == (nbins-j+1))];
end