-
Notifications
You must be signed in to change notification settings - Fork 2
/
ACL_mutualinfo.m
96 lines (70 loc) · 2.17 KB
/
ACL_mutualinfo.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
function f = ACL_ca_mutualinfo(peaks_time, pos, dim, varargin)
%finds mutual info for a bunch of cells
tic
if size(varargin)==0
psize = 1.000; %some REAL ratio of pixels to cm -- 3.5 for wilson, 2.5 for disterhoft linear, 1.000 for eyeblink
else
psize = varargin;
end
if size(pos,2) > size(pos,1)
pos = pos';
end
if size(peaks_time,2) > size(peaks_time,1)
peaks_time = peaks_time';
end
mutinfo = NaN(2, size(peaks_time,2));
pos(:,3) = 1;
velthreshold = 8;
vel = ca_velocity(pos);
goodvel = find(vel(1,:)>=velthreshold);
goodtime = pos(goodvel, 1);
goodpos = pos(goodvel,:);
%mintime = vel(2,1);
%maxtime = vel(2,end);
numunits = size(peaks_time,2);
for k=1:numunits
want = find(peaks_time(:,k)>0);
currspikes = pos(want,1);
highspeedspikes = [];
% [c indexmin] = (min(abs(curr_peaks(k,:)-mintime))); %
% [c indexmax] = (min(abs(peaks_time(k,:)-maxtime))); %
% currspikes = curr_peaks(k,indexmin:indexmax);
for i=1:length(currspikes) %finding if in good vel
[minValue,closestIndex] = min(abs(currspikes(i)-goodtime));
if minValue <= 1/7.5 %if spike is within 1 second of moving. no idea if good time
highspeedspikes(end+1) = currspikes(i);
end;
end
%gets direction
fwd = [];
bwd = [];
for z = 1:length(highspeedspikes)
[minValue,closestIndex] = min(abs(pos(:,1)-highspeedspikes(z)));
if pos(max(closestIndex-7, 1),2)-pos(min(closestIndex+7,length(pos)),2)>0
fwd(end+1) = highspeedspikes(z);
else
bwd(end+1) = highspeedspikes(z);
end
end
%subplot(ceil(sqrt(numunits)),ceil(sqrt(numunits)), k)
set(0,'DefaultFigureVisible', 'off');
%fr = ACL_ca_firingrate(currspikes, pos);
% if fr > .01 && length(fwd)>0
if length(fwd)>0
goodpos(:,3) = 1;
[rate totspikes totstime colorbar spikeprob occprob] = normalizePosData(fwd,goodpos,dim, psize);
mutinfo(1, k) = mutualinfo([spikeprob', occprob']);
else
mutinfo(1, k) = NaN;
end
if length(bwd)>0
% if fr > .01 && length(bwd)>0
goodpos(:,3) = 1;
[rate totspikes totstime colorbar spikeprob occprob] = normalizePosData(bwd,goodpos,dim, psize);
mutinfo(2, k) = mutualinfo([spikeprob', occprob']);
else
mutinfo(2, k) = NaN;
end
end
f = mutinfo';
toc