finished solution for population vector

This commit is contained in:
Jan Benda 2017-01-24 12:14:13 +01:00
parent 0501b89444
commit 2fa3bdd38d
3 changed files with 94 additions and 1 deletions
projects/project_populationvector

View File

@ -55,6 +55,8 @@
\texttt{spikes} variables of the \texttt{population*.mat} files. \texttt{spikes} variables of the \texttt{population*.mat} files.
The \texttt{angle} variable holds the angle of the presented bar. The \texttt{angle} variable holds the angle of the presented bar.
NOTE: the orientation is angle plu 90 degree!!!!!!
\begin{parts} \begin{parts}
\part Illustrate the spiking activity of the V1 cells in response \part Illustrate the spiking activity of the V1 cells in response
to different orientation angles of the bars by means of spike to different orientation angles of the bars by means of spike
@ -97,6 +99,9 @@
\end{parts} \end{parts}
\end{questions} \end{questions}
NOTE: change data generation such that the phase variable is indeed
the maximum response and not the minumum!
\end{document} \end{document}
gains and angles of the 6 neurons: gains and angles of the 6 neurons:

View File

@ -16,6 +16,7 @@ end
close all close all
cosine = @(p,xdata)0.5*p(1).*(1.0-cos(2.0*pi*(xdata/180.0-p(2)))); cosine = @(p,xdata)0.5*p(1).*(1.0-cos(2.0*pi*(xdata/180.0-p(2))));
files = dir('../unit*.mat'); files = dir('../unit*.mat');
phases = zeros(length(files), 1);
figure() figure()
for j = 1:length(files) for j = 1:length(files)
file = files(j); file = files(j);
@ -31,7 +32,11 @@ for j = 1:length(files)
p0 = [mr, angles(maxi)/180.0-0.5]; p0 = [mr, angles(maxi)/180.0-0.5];
%p = p0; %p = p0;
p = lsqcurvefit(cosine, p0, angles, rates'); p = lsqcurvefit(cosine, p0, angles, rates');
phase = p(2)*180.0 phase = p(2)*180.0 + 90.0;
if phase > 180.0
phase = phase - 180.0;
end
phases(j) = phase;
subplot(2, 3, j); subplot(2, 3, j);
plot(angles, rates, 'b'); plot(angles, rates, 'b');
hold on; hold on;
@ -41,3 +46,73 @@ for j = 1:length(files)
ylim([0.0 50.0]) ylim([0.0 50.0])
title(sprintf('unit %d', j)) title(sprintf('unit %d', j))
end end
%% read out:
a = load('../population04.mat');
spikes = a.spikes;
angle = a.angle;
unitphases = a.phases*180.0 + 90.0;
unitphases(unitphases>180.0) = unitphases(unitphases>180.0) - 180.0;
figure();
subplot(1, 3, 1);
angleestimates1 = zeros(size(spikes, 2), 1);
angleestimates2 = zeros(size(spikes, 2), 1);
for j = 1:size(spikes, 2)
rates = zeros(size(spikes, 1), 1);
for k = 1:size(spikes, 1)
r = firingrate(spikes(k, j), 0.0, 0.2);
rates(k) = r;
end
[x, inx] = sort(phases);
plot(phases(inx), rates(inx), '-o');
hold on;
angleestimates1(j) = popvecangle(phases, rates);
[m, i] = max(rates);
angleestimates2(j) = phases(i);
end
hold off;
subplot(1, 3, 2);
hist(angleestimates1);
subplot(1, 3, 3);
hist(angleestimates2);
angle
mean(angleestimates1)
mean(angleestimates2)
%% read out robustness:
files = dir('../population*.mat');
angles = zeros(length(files), 1);
e1m = zeros(length(files), 1);
e1s = zeros(length(files), 1);
e2m = zeros(length(files), 1);
e2s = zeros(length(files), 1);
for i = 1:length(files)
file = files(i);
a = load(strcat('../', file.name));
spikes = a.spikes;
angle = a.angle;
angleestimates1 = zeros(size(spikes, 2), 1);
angleestimates2 = zeros(size(spikes, 2), 1);
for j = 1:size(spikes, 2)
rates = zeros(size(spikes, 1), 1);
for k = 1:size(spikes, 1)
r = firingrate(spikes(k, j), 0.0, 0.2);
rates(k) = r;
end
angleestimates1(j) = popvecangle(phases, rates);
[m, inx] = max(rates);
angleestimates2(j) = phases(inx);
end
angles(i) = angle;
e1m(i) = mean(angleestimates1);
e1s(i) = std(angleestimates1);
e2m(i) = mean(angleestimates2);
e2s(i) = std(angleestimates2);
end
figure();
subplot(1, 2, 1);
scatter(angles, e1m);
subplot(1, 2, 2);
scatter(angles, e2m);

View File

@ -0,0 +1,13 @@
function angle = popvecangle(phases, rates)
% estimate population vector
vecs = zeros(2, length(phases));
norm = sum(rates);
vecs(1, :) = rates.*cos(2*pi*phases/180.0)/norm;
vecs(2, :) = rates.*sin(2*pi*phases/180.0)/norm;
mvec = mean(vecs, 2);
angle = atan2(mvec(2), mvec(1));
angle = angle/2/pi*180.0;
if angle < 0
angle = angle + 180.0;
end
end