diff --git a/projects/project_populationvector/Makefile b/projects/project_populationvector/Makefile new file mode 100644 index 0000000..6422eb4 --- /dev/null +++ b/projects/project_populationvector/Makefile @@ -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 diff --git a/projects/project_populationvector/code/generatedata.py b/projects/project_populationvector/code/generatedata.py new file mode 100644 index 0000000..dfe1829 --- /dev/null +++ b/projects/project_populationvector/code/generatedata.py @@ -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}) + diff --git a/projects/project_populationvector/population01.mat b/projects/project_populationvector/population01.mat new file mode 100644 index 0000000..9a0f13d Binary files /dev/null and b/projects/project_populationvector/population01.mat differ diff --git a/projects/project_populationvector/population02.mat b/projects/project_populationvector/population02.mat new file mode 100644 index 0000000..296aa5b Binary files /dev/null and b/projects/project_populationvector/population02.mat differ diff --git a/projects/project_populationvector/population03.mat b/projects/project_populationvector/population03.mat new file mode 100644 index 0000000..56dd9dd Binary files /dev/null and b/projects/project_populationvector/population03.mat differ diff --git a/projects/project_populationvector/population04.mat b/projects/project_populationvector/population04.mat new file mode 100644 index 0000000..c0c92ec Binary files /dev/null and b/projects/project_populationvector/population04.mat differ diff --git a/projects/project_populationvector/population05.mat b/projects/project_populationvector/population05.mat new file mode 100644 index 0000000..63118d3 Binary files /dev/null and b/projects/project_populationvector/population05.mat differ diff --git a/projects/project_populationvector/population06.mat b/projects/project_populationvector/population06.mat new file mode 100644 index 0000000..4700426 Binary files /dev/null and b/projects/project_populationvector/population06.mat differ diff --git a/projects/project_populationvector/population07.mat b/projects/project_populationvector/population07.mat new file mode 100644 index 0000000..2724a28 Binary files /dev/null and b/projects/project_populationvector/population07.mat differ diff --git a/projects/project_populationvector/population08.mat b/projects/project_populationvector/population08.mat new file mode 100644 index 0000000..2d3177c Binary files /dev/null and b/projects/project_populationvector/population08.mat differ diff --git a/projects/project_populationvector/population09.mat b/projects/project_populationvector/population09.mat new file mode 100644 index 0000000..77430b2 Binary files /dev/null and b/projects/project_populationvector/population09.mat differ diff --git a/projects/project_populationvector/population10.mat b/projects/project_populationvector/population10.mat new file mode 100644 index 0000000..fcdc0ff Binary files /dev/null and b/projects/project_populationvector/population10.mat differ diff --git a/projects/project_populationvector/population11.mat b/projects/project_populationvector/population11.mat new file mode 100644 index 0000000..6ff0dfe Binary files /dev/null and b/projects/project_populationvector/population11.mat differ diff --git a/projects/project_populationvector/population12.mat b/projects/project_populationvector/population12.mat new file mode 100644 index 0000000..43e27b6 Binary files /dev/null and b/projects/project_populationvector/population12.mat differ diff --git a/projects/project_populationvector/population13.mat b/projects/project_populationvector/population13.mat new file mode 100644 index 0000000..ecb0f09 Binary files /dev/null and b/projects/project_populationvector/population13.mat differ diff --git a/projects/project_populationvector/population14.mat b/projects/project_populationvector/population14.mat new file mode 100644 index 0000000..1a648d9 Binary files /dev/null and b/projects/project_populationvector/population14.mat differ diff --git a/projects/project_populationvector/population15.mat b/projects/project_populationvector/population15.mat new file mode 100644 index 0000000..1d9dfd7 Binary files /dev/null and b/projects/project_populationvector/population15.mat differ diff --git a/projects/project_populationvector/population16.mat b/projects/project_populationvector/population16.mat new file mode 100644 index 0000000..f91f0bc Binary files /dev/null and b/projects/project_populationvector/population16.mat differ diff --git a/projects/project_populationvector/population17.mat b/projects/project_populationvector/population17.mat new file mode 100644 index 0000000..7b861b9 Binary files /dev/null and b/projects/project_populationvector/population17.mat differ diff --git a/projects/project_populationvector/population18.mat b/projects/project_populationvector/population18.mat new file mode 100644 index 0000000..24b6789 Binary files /dev/null and b/projects/project_populationvector/population18.mat differ diff --git a/projects/project_populationvector/population19.mat b/projects/project_populationvector/population19.mat new file mode 100644 index 0000000..e377d6d Binary files /dev/null and b/projects/project_populationvector/population19.mat differ diff --git a/projects/project_populationvector/population20.mat b/projects/project_populationvector/population20.mat new file mode 100644 index 0000000..b8f030b Binary files /dev/null and b/projects/project_populationvector/population20.mat differ diff --git a/projects/project_populationvector/population21.mat b/projects/project_populationvector/population21.mat new file mode 100644 index 0000000..aee3a8e Binary files /dev/null and b/projects/project_populationvector/population21.mat differ diff --git a/projects/project_populationvector/population22.mat b/projects/project_populationvector/population22.mat new file mode 100644 index 0000000..1d4e8a2 Binary files /dev/null and b/projects/project_populationvector/population22.mat differ diff --git a/projects/project_populationvector/population23.mat b/projects/project_populationvector/population23.mat new file mode 100644 index 0000000..c495d7e Binary files /dev/null and b/projects/project_populationvector/population23.mat differ diff --git a/projects/project_populationvector/population24.mat b/projects/project_populationvector/population24.mat new file mode 100644 index 0000000..66ae79d Binary files /dev/null and b/projects/project_populationvector/population24.mat differ diff --git a/projects/project_populationvector/population25.mat b/projects/project_populationvector/population25.mat new file mode 100644 index 0000000..42d9628 Binary files /dev/null and b/projects/project_populationvector/population25.mat differ diff --git a/projects/project_populationvector/population26.mat b/projects/project_populationvector/population26.mat new file mode 100644 index 0000000..c55f7b7 Binary files /dev/null and b/projects/project_populationvector/population26.mat differ diff --git a/projects/project_populationvector/population27.mat b/projects/project_populationvector/population27.mat new file mode 100644 index 0000000..c7da744 Binary files /dev/null and b/projects/project_populationvector/population27.mat differ diff --git a/projects/project_populationvector/population28.mat b/projects/project_populationvector/population28.mat new file mode 100644 index 0000000..67a75dc Binary files /dev/null and b/projects/project_populationvector/population28.mat differ diff --git a/projects/project_populationvector/population29.mat b/projects/project_populationvector/population29.mat new file mode 100644 index 0000000..985b69f Binary files /dev/null and b/projects/project_populationvector/population29.mat differ diff --git a/projects/project_populationvector/population30.mat b/projects/project_populationvector/population30.mat new file mode 100644 index 0000000..a577ed0 Binary files /dev/null and b/projects/project_populationvector/population30.mat differ diff --git a/projects/project_populationvector/population31.mat b/projects/project_populationvector/population31.mat new file mode 100644 index 0000000..a2b34d3 Binary files /dev/null and b/projects/project_populationvector/population31.mat differ diff --git a/projects/project_populationvector/population32.mat b/projects/project_populationvector/population32.mat new file mode 100644 index 0000000..ec19c8d Binary files /dev/null and b/projects/project_populationvector/population32.mat differ diff --git a/projects/project_populationvector/population33.mat b/projects/project_populationvector/population33.mat new file mode 100644 index 0000000..89b4f5a Binary files /dev/null and b/projects/project_populationvector/population33.mat differ diff --git a/projects/project_populationvector/population34.mat b/projects/project_populationvector/population34.mat new file mode 100644 index 0000000..02f71b2 Binary files /dev/null and b/projects/project_populationvector/population34.mat differ diff --git a/projects/project_populationvector/population35.mat b/projects/project_populationvector/population35.mat new file mode 100644 index 0000000..b808ade Binary files /dev/null and b/projects/project_populationvector/population35.mat differ diff --git a/projects/project_populationvector/population36.mat b/projects/project_populationvector/population36.mat new file mode 100644 index 0000000..e7002d2 Binary files /dev/null and b/projects/project_populationvector/population36.mat differ diff --git a/projects/project_populationvector/population37.mat b/projects/project_populationvector/population37.mat new file mode 100644 index 0000000..134b039 Binary files /dev/null and b/projects/project_populationvector/population37.mat differ diff --git a/projects/project_populationvector/population38.mat b/projects/project_populationvector/population38.mat new file mode 100644 index 0000000..6dd2440 Binary files /dev/null and b/projects/project_populationvector/population38.mat differ diff --git a/projects/project_populationvector/population39.mat b/projects/project_populationvector/population39.mat new file mode 100644 index 0000000..2da24a9 Binary files /dev/null and b/projects/project_populationvector/population39.mat differ diff --git a/projects/project_populationvector/population40.mat b/projects/project_populationvector/population40.mat new file mode 100644 index 0000000..5c8e851 Binary files /dev/null and b/projects/project_populationvector/population40.mat differ diff --git a/projects/project_populationvector/population41.mat b/projects/project_populationvector/population41.mat new file mode 100644 index 0000000..00113a6 Binary files /dev/null and b/projects/project_populationvector/population41.mat differ diff --git a/projects/project_populationvector/population42.mat b/projects/project_populationvector/population42.mat new file mode 100644 index 0000000..7dcdc17 Binary files /dev/null and b/projects/project_populationvector/population42.mat differ diff --git a/projects/project_populationvector/population43.mat b/projects/project_populationvector/population43.mat new file mode 100644 index 0000000..41bcbbf Binary files /dev/null and b/projects/project_populationvector/population43.mat differ diff --git a/projects/project_populationvector/population44.mat b/projects/project_populationvector/population44.mat new file mode 100644 index 0000000..dccb595 Binary files /dev/null and b/projects/project_populationvector/population44.mat differ diff --git a/projects/project_populationvector/population45.mat b/projects/project_populationvector/population45.mat new file mode 100644 index 0000000..3adc406 Binary files /dev/null and b/projects/project_populationvector/population45.mat differ diff --git a/projects/project_populationvector/population46.mat b/projects/project_populationvector/population46.mat new file mode 100644 index 0000000..28c0e86 Binary files /dev/null and b/projects/project_populationvector/population46.mat differ diff --git a/projects/project_populationvector/population47.mat b/projects/project_populationvector/population47.mat new file mode 100644 index 0000000..7904341 Binary files /dev/null and b/projects/project_populationvector/population47.mat differ diff --git a/projects/project_populationvector/population48.mat b/projects/project_populationvector/population48.mat new file mode 100644 index 0000000..bc226f6 Binary files /dev/null and b/projects/project_populationvector/population48.mat differ diff --git a/projects/project_populationvector/population49.mat b/projects/project_populationvector/population49.mat new file mode 100644 index 0000000..86c9094 Binary files /dev/null and b/projects/project_populationvector/population49.mat differ diff --git a/projects/project_populationvector/population50.mat b/projects/project_populationvector/population50.mat new file mode 100644 index 0000000..1143e45 Binary files /dev/null and b/projects/project_populationvector/population50.mat differ diff --git a/projects/project_populationvector/populationvector.tex b/projects/project_populationvector/populationvector.tex new file mode 100644 index 0000000..5cd87df --- /dev/null +++ b/projects/project_populationvector/populationvector.tex @@ -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=tmin)&(times<=tmax)))/(tmax-tmin); +end +rate = mean(rates); +end diff --git a/projects/project_populationvector/solution/populationvector.m b/projects/project_populationvector/solution/populationvector.m new file mode 100644 index 0000000..829e07d --- /dev/null +++ b/projects/project_populationvector/solution/populationvector.m @@ -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 diff --git a/projects/project_populationvector/solution/spikeraster.m b/projects/project_populationvector/solution/spikeraster.m new file mode 100644 index 0000000..4eb1b8b --- /dev/null +++ b/projects/project_populationvector/solution/spikeraster.m @@ -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 + diff --git a/projects/project_populationvector/unit1.mat b/projects/project_populationvector/unit1.mat new file mode 100644 index 0000000..4964818 Binary files /dev/null and b/projects/project_populationvector/unit1.mat differ diff --git a/projects/project_populationvector/unit2.mat b/projects/project_populationvector/unit2.mat new file mode 100644 index 0000000..66cef43 Binary files /dev/null and b/projects/project_populationvector/unit2.mat differ diff --git a/projects/project_populationvector/unit3.mat b/projects/project_populationvector/unit3.mat new file mode 100644 index 0000000..b2d77d9 Binary files /dev/null and b/projects/project_populationvector/unit3.mat differ diff --git a/projects/project_populationvector/unit4.mat b/projects/project_populationvector/unit4.mat new file mode 100644 index 0000000..722a17a Binary files /dev/null and b/projects/project_populationvector/unit4.mat differ diff --git a/projects/project_populationvector/unit5.mat b/projects/project_populationvector/unit5.mat new file mode 100644 index 0000000..630c0e2 Binary files /dev/null and b/projects/project_populationvector/unit5.mat differ diff --git a/projects/project_populationvector/unit6.mat b/projects/project_populationvector/unit6.mat new file mode 100644 index 0000000..242d5d3 Binary files /dev/null and b/projects/project_populationvector/unit6.mat differ