added opulation vector project
This commit is contained in:
parent
4f3dd321f4
commit
e22e81fa2a
10
projects/project_populationvector/Makefile
Normal file
10
projects/project_populationvector/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
latex:
|
||||
pdflatex *.tex > /dev/null
|
||||
pdflatex *.tex > /dev/null
|
||||
|
||||
clean:
|
||||
rm -rf *.log *.aux *.zip *.out auto
|
||||
rm -f `basename *.tex .tex`.pdf
|
||||
|
||||
zip: latex
|
||||
zip `basename *.tex .tex`.zip *.pdf *.dat *.mat *.m
|
105
projects/project_populationvector/code/generatedata.py
Normal file
105
projects/project_populationvector/code/generatedata.py
Normal file
@ -0,0 +1,105 @@
|
||||
import numpy as np
|
||||
from scipy.io import savemat
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def lifadaptspikes(stimulus, gain=10.0, trials=50, duration=200.0, before=200.0, after=400.0):
|
||||
dt = 0.1
|
||||
s0 = 9.5
|
||||
tau = 10.0
|
||||
D = 1.0
|
||||
taua = 60.0
|
||||
da = 100.0
|
||||
Vth = 10.0
|
||||
n = int((duration+before+after)/dt)
|
||||
delay = 10.0
|
||||
sig = np.zeros(n) + s0
|
||||
n1 = int((before+delay)/dt)
|
||||
n2 = int((before+duration+delay)/dt)
|
||||
sig[n1:n2] += (gain * stimulus - 1.0) * np.exp(-np.arange(n2-n1)*dt/0.4/duration)
|
||||
spikes = []
|
||||
for j in range(trials):
|
||||
noise = np.sqrt(2.0*D/dt)*np.random.randn(n)
|
||||
V = np.random.rand()*Vth
|
||||
A = 0.0
|
||||
s = s0
|
||||
As = np.zeros(n)
|
||||
times = []
|
||||
for k in range(n):
|
||||
As[k] = A
|
||||
V += (-V-A+sig[k]+noise[k])*dt/tau
|
||||
A += (-A)*dt/taua
|
||||
if V >= Vth:
|
||||
V = 0.0
|
||||
A += da/taua
|
||||
times.append(k*dt-before)
|
||||
spikes.append(np.array(times))
|
||||
#plt.plot(np.arange(n)*dt-before, As)
|
||||
#plt.plot(np.arange(n)*dt-before, sig)
|
||||
#return spikes
|
||||
return spikes
|
||||
|
||||
def firingrate(spikes, tmin, tmax):
|
||||
rates = []
|
||||
for st in spikes:
|
||||
times = st[(st>=tmin)&(st<=tmax)]
|
||||
r = len(times)/(tmax-tmin)
|
||||
rates.append(1000.0*r)
|
||||
return np.mean(rates), np.std(rates)
|
||||
|
||||
"""
|
||||
nangles = 12
|
||||
angles = 180.0*np.arange(nangles)/nangles
|
||||
rates = np.zeros(nangles)
|
||||
ratessd = np.zeros(nangles)
|
||||
allspikes = []
|
||||
for k, angle in enumerate(angles):
|
||||
spikes = lifadaptspikes(0.5*(1.0-np.cos(2.0*np.pi*angle/180.0)))
|
||||
rm, rsd = firingrate(spikes, 0.0, 200.0)
|
||||
rates[k] = rm
|
||||
ratessd[k] = rsd
|
||||
allspikes.append(spikes)
|
||||
#plt.subplot(2, 5, k+1)
|
||||
#plt.title('%g' % (angle/2.0/np.pi))
|
||||
#plt.eventplot(spikes, colors=['r'])
|
||||
plt.plot(angles, rates, 'r', lw=2)
|
||||
plt.plot(angles, rates+ratessd, 'b')
|
||||
plt.plot(angles, rates-ratessd, 'b')
|
||||
plt.show()
|
||||
"""
|
||||
|
||||
# tuning curves:
|
||||
nunits = 6
|
||||
unitphases = np.linspace(0.0, 1.0, nunits) + 0.05*np.random.randn(nunits)/float(nunits)
|
||||
unitgains = 15.0 + 5.0*(2.0*np.random.rand(nunits)-1.0)
|
||||
nangles = 12
|
||||
angles = 180.0*np.arange(nangles)/nangles
|
||||
for unit, (phase, gain) in enumerate(zip(unitphases, unitgains)):
|
||||
print '%.1f %.0f' % (gain, phase*180.0)
|
||||
allspikes = []
|
||||
for k, angle in enumerate(angles):
|
||||
spikes = lifadaptspikes(0.5*(1.0-np.cos(2.0*np.pi*(angle/180.0-phase))), gain)
|
||||
allspikes.append(spikes)
|
||||
spikesobj = np.zeros((len(allspikes), len(allspikes[0])), dtype=np.object)
|
||||
for k in range(len(allspikes)):
|
||||
for j in range(len(allspikes[k])):
|
||||
spikesobj[k, j] = 0.001*allspikes[k][j]
|
||||
savemat('unit%d.mat'%(unit+1), mdict={'angles': angles, 'spikes': spikesobj})
|
||||
|
||||
# population activity:
|
||||
nangles = 50
|
||||
angles = 180.0*np.random.rand(nangles)
|
||||
for k, angle in enumerate(angles):
|
||||
print '%.0f' % angle
|
||||
allspikes = []
|
||||
for unit, (phase, gain) in enumerate(zip(unitphases, unitgains)):
|
||||
spikes = lifadaptspikes(0.5*(1.0-np.cos(2.0*np.pi*(angle/180.0-phase))), gain)
|
||||
allspikes.append(spikes)
|
||||
spikesobj = np.zeros((len(allspikes), len(allspikes[0])), dtype=np.object)
|
||||
for i in range(len(allspikes)):
|
||||
for j in range(len(allspikes[i])):
|
||||
spikesobj[i, j] = 0.001*allspikes[i][j]
|
||||
savemat('population%02d.mat'%(k+1), mdict={'spikes': spikesobj,
|
||||
'angle': angle,
|
||||
'phases': unitphases,
|
||||
'gains': unitgains})
|
||||
|
BIN
projects/project_populationvector/population01.mat
Normal file
BIN
projects/project_populationvector/population01.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population02.mat
Normal file
BIN
projects/project_populationvector/population02.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population03.mat
Normal file
BIN
projects/project_populationvector/population03.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population04.mat
Normal file
BIN
projects/project_populationvector/population04.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population05.mat
Normal file
BIN
projects/project_populationvector/population05.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population06.mat
Normal file
BIN
projects/project_populationvector/population06.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population07.mat
Normal file
BIN
projects/project_populationvector/population07.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population08.mat
Normal file
BIN
projects/project_populationvector/population08.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population09.mat
Normal file
BIN
projects/project_populationvector/population09.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population10.mat
Normal file
BIN
projects/project_populationvector/population10.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population11.mat
Normal file
BIN
projects/project_populationvector/population11.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population12.mat
Normal file
BIN
projects/project_populationvector/population12.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population13.mat
Normal file
BIN
projects/project_populationvector/population13.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population14.mat
Normal file
BIN
projects/project_populationvector/population14.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population15.mat
Normal file
BIN
projects/project_populationvector/population15.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population16.mat
Normal file
BIN
projects/project_populationvector/population16.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population17.mat
Normal file
BIN
projects/project_populationvector/population17.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population18.mat
Normal file
BIN
projects/project_populationvector/population18.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population19.mat
Normal file
BIN
projects/project_populationvector/population19.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population20.mat
Normal file
BIN
projects/project_populationvector/population20.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population21.mat
Normal file
BIN
projects/project_populationvector/population21.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population22.mat
Normal file
BIN
projects/project_populationvector/population22.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population23.mat
Normal file
BIN
projects/project_populationvector/population23.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population24.mat
Normal file
BIN
projects/project_populationvector/population24.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population25.mat
Normal file
BIN
projects/project_populationvector/population25.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population26.mat
Normal file
BIN
projects/project_populationvector/population26.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population27.mat
Normal file
BIN
projects/project_populationvector/population27.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population28.mat
Normal file
BIN
projects/project_populationvector/population28.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population29.mat
Normal file
BIN
projects/project_populationvector/population29.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population30.mat
Normal file
BIN
projects/project_populationvector/population30.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population31.mat
Normal file
BIN
projects/project_populationvector/population31.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population32.mat
Normal file
BIN
projects/project_populationvector/population32.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population33.mat
Normal file
BIN
projects/project_populationvector/population33.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population34.mat
Normal file
BIN
projects/project_populationvector/population34.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population35.mat
Normal file
BIN
projects/project_populationvector/population35.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population36.mat
Normal file
BIN
projects/project_populationvector/population36.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population37.mat
Normal file
BIN
projects/project_populationvector/population37.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population38.mat
Normal file
BIN
projects/project_populationvector/population38.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population39.mat
Normal file
BIN
projects/project_populationvector/population39.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population40.mat
Normal file
BIN
projects/project_populationvector/population40.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population41.mat
Normal file
BIN
projects/project_populationvector/population41.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population42.mat
Normal file
BIN
projects/project_populationvector/population42.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population43.mat
Normal file
BIN
projects/project_populationvector/population43.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population44.mat
Normal file
BIN
projects/project_populationvector/population44.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population45.mat
Normal file
BIN
projects/project_populationvector/population45.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population46.mat
Normal file
BIN
projects/project_populationvector/population46.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population47.mat
Normal file
BIN
projects/project_populationvector/population47.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population48.mat
Normal file
BIN
projects/project_populationvector/population48.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population49.mat
Normal file
BIN
projects/project_populationvector/population49.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/population50.mat
Normal file
BIN
projects/project_populationvector/population50.mat
Normal file
Binary file not shown.
99
projects/project_populationvector/populationvector.tex
Normal file
99
projects/project_populationvector/populationvector.tex
Normal file
@ -0,0 +1,99 @@
|
||||
\documentclass[addpoints,11pt]{exam}
|
||||
\usepackage{url}
|
||||
\usepackage{color}
|
||||
\usepackage{hyperref}
|
||||
|
||||
\pagestyle{headandfoot}
|
||||
\runningheadrule
|
||||
\firstpageheadrule
|
||||
\firstpageheader{Scientific Computing}{Project Assignment}{11/05/2014
|
||||
-- 11/06/2014}
|
||||
%\runningheader{Homework 01}{Page \thepage\ of \numpages}{23. October 2014}
|
||||
\firstpagefooter{}{}{}
|
||||
\runningfooter{}{}{}
|
||||
\pointsinmargin
|
||||
\bracketedpoints
|
||||
|
||||
%\printanswers
|
||||
%\shadedsolutions
|
||||
|
||||
|
||||
\begin{document}
|
||||
%%%%%%%%%%%%%%%%%%%%% Submission instructions %%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
\sffamily
|
||||
% \begin{flushright}
|
||||
% \gradetable[h][questions]
|
||||
% \end{flushright}
|
||||
|
||||
\begin{center}
|
||||
\input{../disclaimer.tex}
|
||||
\end{center}
|
||||
|
||||
%%%%%%%%%%%%%% Questions %%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
\begin{questions}
|
||||
\question In the visual cortex V1 orientation sensitive neurons
|
||||
respond to bars in dependence on their orientation.
|
||||
|
||||
How is the orientation of a bar encoded by the activity of a
|
||||
population of orientation sensisitive neurons?
|
||||
|
||||
In an electrophysiological experiment, 6 neurons have been recorded
|
||||
simultaneously. First, the tuning of these neurons was characteried
|
||||
by presenting them bars in a range of 12 orientation angles. Each
|
||||
orientation was presented 50 times. Each of the \texttt{unit*.mat}
|
||||
files contains the responses of one of the neurons. In there,
|
||||
\texttt{angles} is a vector with the orientation angles of the bars
|
||||
in degrees. \texttt{spikes} is a cell array that contains the
|
||||
vectors of spike times for each angle and presentation. The spike
|
||||
times are given in seconds. The stimulation with the bar starts a
|
||||
time $t_0=0$ and ends at time $t_1=200$\,ms.
|
||||
|
||||
Then the population activity of the 6 neurons was measured in
|
||||
response to arbitrarily oriented bars. The responses of the 6
|
||||
neurons to 50 presentation of a bar are stored in the
|
||||
\texttt{spikes} variables of the \texttt{population*.mat} files.
|
||||
The \texttt{angle} variable holds the angle of the presented bar.
|
||||
|
||||
\begin{parts}
|
||||
\part Illustrate the spiking activity of the V1 cells in response
|
||||
to different orientation angles of the bars by means of spike
|
||||
raster plots (of one unit).
|
||||
|
||||
\part Plot the firing rate of each of the 6 neurons as a function
|
||||
of the orientation angle of the bar. As the firing rate compute
|
||||
the number of spikes in the time interval $0<t<200$\,ms divided by
|
||||
200\,ms. The resulting curves are the tuning curves $r(\varphi)$
|
||||
of the neurons.
|
||||
|
||||
\part Fit the function \[ r(\varphi) =
|
||||
g(1-\cos(\varphi-\varphi_0))/2 \] to the measured tuning curves in
|
||||
order to estimated the orientation angle at which the neurons
|
||||
respond strongest. In this function $\varphi_0$ is the position of
|
||||
the peak (really? How exactly is $\varphi_0$ related to the
|
||||
position of the peak? Do you find a better function where
|
||||
$\varphi_0$ is identical with the peak position?) and $g$ is a
|
||||
gain factor that sets the maximum firing rate.
|
||||
|
||||
\part How can the orientation angle of the presented bar be read
|
||||
out from the population activity of the 6 neurons? One is the so
|
||||
called ``population vector''. Think of another (simpler) method.
|
||||
|
||||
Load one of the \texttt{population*.mat} files, illustrate the data,
|
||||
and estimate the orientation angle of the bar by two different methods.
|
||||
|
||||
\part Compare, illustrate and discuss the performance of your two
|
||||
decoding methods.
|
||||
\end{parts}
|
||||
\end{questions}
|
||||
|
||||
\end{document}
|
||||
|
||||
gains and angles of the 6 neurons:
|
||||
|
||||
14.6 0
|
||||
17.1 36
|
||||
17.6 72
|
||||
14.1 107
|
||||
10.7 144
|
||||
11.4 181
|
9
projects/project_populationvector/solution/firingrate.m
Normal file
9
projects/project_populationvector/solution/firingrate.m
Normal file
@ -0,0 +1,9 @@
|
||||
function rate = firingrate(spikes, tmin, tmax)
|
||||
% mean firing rate between tmin and tmax.
|
||||
rates = zeros(length(spikes), 1);
|
||||
for i = 1:length(spikes)
|
||||
times= spikes{i};
|
||||
rates(i) = length(times((times>=tmin)&(times<=tmax)))/(tmax-tmin);
|
||||
end
|
||||
rate = mean(rates);
|
||||
end
|
@ -0,0 +1,43 @@
|
||||
close all
|
||||
files = dir('../unit*.mat');
|
||||
for file = files'
|
||||
a = load(strcat('../', file.name));
|
||||
spikes = a.spikes;
|
||||
angles = a.angles;
|
||||
figure()
|
||||
for k = 1:size(spikes, 1)
|
||||
subplot(3, 4, k)
|
||||
spikeraster(spikes(k,:), -0.2, 0.6);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
%% tuning curves:
|
||||
close all
|
||||
cosine = @(p,xdata)0.5*p(1).*(1.0-cos(2.0*pi*(xdata/180.0-p(2))));
|
||||
files = dir('../unit*.mat');
|
||||
figure()
|
||||
for j = 1:length(files)
|
||||
file = files(j);
|
||||
a = load(strcat('../', file.name));
|
||||
spikes = a.spikes;
|
||||
angles = a.angles;
|
||||
rates = zeros(size(spikes, 1), 1);
|
||||
for k = 1:size(spikes, 1)
|
||||
r = firingrate(spikes(k,:), 0.0, 0.2);
|
||||
rates(k) = r;
|
||||
end
|
||||
[mr, maxi] = max(rates);
|
||||
p0 = [mr, angles(maxi)/180.0-0.5];
|
||||
%p = p0;
|
||||
p = lsqcurvefit(cosine, p0, angles, rates');
|
||||
phase = p(2)*180.0
|
||||
subplot(2, 3, j);
|
||||
plot(angles, rates, 'b');
|
||||
hold on;
|
||||
plot(angles, cosine(p, angles), 'r');
|
||||
hold off;
|
||||
xlim([0.0 180.0])
|
||||
ylim([0.0 50.0])
|
||||
title(sprintf('unit %d', j))
|
||||
end
|
30
projects/project_populationvector/solution/spikeraster.m
Normal file
30
projects/project_populationvector/solution/spikeraster.m
Normal file
@ -0,0 +1,30 @@
|
||||
function spikeraster(spikes, tmin, tmax)
|
||||
% Display a spike raster of the spike times given in spikes.
|
||||
%
|
||||
% spikeraster(spikes, tmax)
|
||||
% spikes: a cell array of vectors of spike times in seconds
|
||||
% tmin: plot spike raster starting at tmin seconds
|
||||
% tmax: plot spike raster upto tmax seconds
|
||||
|
||||
ntrials = length(spikes);
|
||||
for k = 1:ntrials
|
||||
times = spikes{k};
|
||||
times = times((times>=tmin) & (times<=tmax));
|
||||
if tmax < 1.5
|
||||
times = 1000.0*times; % conversion to ms
|
||||
end
|
||||
for i = 1:length( times )
|
||||
line([times(i) times(i)],[k-0.4 k+0.4], 'Color', 'k');
|
||||
end
|
||||
end
|
||||
if (tmax-tmin) < 1.5
|
||||
xlabel('Time [ms]');
|
||||
xlim([1000.0*tmin 1000.0*tmax]);
|
||||
else
|
||||
xlabel('Time [s]');
|
||||
xlim([tmin tmax]);
|
||||
end
|
||||
ylabel('Trials');
|
||||
ylim([0.3 ntrials+0.7 ]);
|
||||
end
|
||||
|
BIN
projects/project_populationvector/unit1.mat
Normal file
BIN
projects/project_populationvector/unit1.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/unit2.mat
Normal file
BIN
projects/project_populationvector/unit2.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/unit3.mat
Normal file
BIN
projects/project_populationvector/unit3.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/unit4.mat
Normal file
BIN
projects/project_populationvector/unit4.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/unit5.mat
Normal file
BIN
projects/project_populationvector/unit5.mat
Normal file
Binary file not shown.
BIN
projects/project_populationvector/unit6.mat
Normal file
BIN
projects/project_populationvector/unit6.mat
Normal file
Binary file not shown.
Reference in New Issue
Block a user