Day 09
Day 9 in 2015: Handles topic and collection of open tasks
Please download today's script for the handles topic as a pdf or Word file!
As there is often not enough time during the course to deal with the more interesting and demanding tasks, this can be done on the last regular course day. In some cases, the programming concepts learnt in the meantime also open up other solutions than on the actual course day. It can therefore also be useful for people who have already worked on a task to look at it again.
Here is a collection of the tasks still open for many course participants:
Please complete at least T7H2. From the other tasks, choose the ones that interest you the most.
T7H2)[CellRespMat.mat] contains responses from 20 nerve cells in the retina whose activity was recorded in an experiment and stored in this 3D matrix. The first dimension of the 3D matrix corresponds to the 20 cells, the second to time (500 time steps of 1 ms each) and the third dimension to the stimulus presentation (192 presentations of the same stimulus). E.g.: r=CellRespMat(5,100,45) is the 100th time step of the response of cell 5 at the 45th stimulus presentation. For each time step, each cell responds with 0 (no spike) or 1 (spike). The cells respond to 192 light stimuli (patterns on the screen) that moved to the left or right with equal probability. The direction of the respective movement stimulus is stored in a vector:[sigma.mat](-1 means left, 1 means right).
- Look at the data in the Array Editor or as a graphic. To do this, you must reduce the data to 2D matrices. The squeeze command turns a "slice" of a 3D matrix into a real 2D matrix, e.g. M=squeeze(CellRespMat(5,:,:)); contains all time points of all presentations of cell 5.
- Consider a suitable way of storing the measurement data together with the associated stimulation by using cell arrays or structures to make it easier to handle the data.
- Hints:
-
- The way you organise data is always a matter of taste - there is not just one right or best solution).
- sparse() only works for 2D matrices!
T5H3) [spikedata_short.mat] is an intracellular measurement of the membrane potential of a leech neuron. Ten responses of this cell to the same stimulus were recorded, a current pulse whose time course (in nA) is stored in the simultaneously stored vector stimulus .
- Write a script to view all the response traces together with the time course of the stimulus (this can also be one after the other).
- Set a threshold "by eye" to find the action potentials.
- Caution: there is an artefact in the response trace at the end of each current pulse. We do not want to recognise this as an action potential.
**T5H4) Write a function that receives the matrix with the measurement data from the last task (T5H3) and a threshold value as input arguments and returns a vector of how many spikes were triggered in the individual runs as output. (The difficulty with this task is that leech spikes have a temporal length of several milliseconds but should only be counted once).
T7H3) (corresponds approximately to T4H5, can be modified by your own solution)
A circle (which is actually a 360-angle) is created with Matlab as follows:
degrad = pi/180;
w=0:1:360;
si=sin(w*degrad);
co=cos(w*degrad);
plot(co,si)
If you try this out, this circle looks pretty much like an egg. axis equal makes the axes square, so it's nicer to look at.
A closed line like this circle can be filled with a colour using the fill(x,y,farbdef) command. Colours are defined either with the abbreviation also used for the plot command (e.g. y for yellow etc) or with the help of RGB coding.
- Create a structure that contains all relevant information for the various circles (or other n-corners).
- Draw a square, a 3-corner, a 7-corner and a 25-corner in the same way.
- Try out how to change the size and direction of these figures.
- *) You only have to change the programme slightly to draw a five-pointed star in one go. How?
**T7H4) Starry sky (corresponds approximately to T4H6): You want to draw a pretty colourful filled starry sky with different sized colourful filled stars (or optionally other N vertices) with different numbers of vertices against a dark blue background.
- a) Think of a structure in which you can store all the relevant information about your stars.
- b) Draw the starry sky with several stars of different colours.
- c) Embellish your starry sky so that it fills the entire screen. (Use the help to find out how to do this).
- d) Draw your stars in random places in the sky.
- e) You can use the starry sky as a kind of screensaver.
-
- At first the stars are coloured as described above.
- Then, after a short pause, the stars turn yellow in random order.
- When all the stars are yellow, they return to their original colour in random order.
- This colour change is repeated until the user cancels the program.
- f) Save the sequence of your celestial phenomena in a file using a meaningful structure. Write a programme that repeats the sky show in the same way.
- ***g) Make sure that the different stars do not overlap.
T8H2) In neuroscience, it is a common approach to consider the time of occurrence of individual action potentials as unimportant and only look at the spike rate (i.e. the number of action potentials occurring in a given time window). If the occurrence of individual spikes is then to be simulated, this is done with a random process, the so-called Poisson process. A Poisson process has the property that at each time step it is decided independently of all other time steps whether an event occurs or not. For example, if a neuron fires at 10 spikes/s and a sampling rate of 1000Hz is used, the probability of a spike occurring at each time step is 1%.
a) Write a function that receives a spike rate, the sampling rate and the length of the desired simulated response trace as input values and returns a vector with the simulated responses of the neuron.
b) Extend your function so that it does not receive a fixed value for the spike rate as input, but a vector that specifies the spike rate for each point in time of the response to be simulated (the length then no longer needs to be passed, it results from the length of the vector of spike rates).
T8H3) The Poisson process is the simplest conceivable neuron model and cannot explain many properties of biological nerve cells. A somewhat more realistic (but still very simple) model for action potential responses of a neuron is the integrate-and-fire neuron model. It is a differential equation model that describes the temporal change of the membrane voltage in combination with a threshold that determines the timing of the triggering of action potentials.
The demo programme [intfire.m] shows how an integrate-and-fire neuron model reacts to an external input current.
a) How does the model neuron react to other injected currents?
- Try making the pulse stronger or weaker.
- Make the pulse longer or shorter.
- What is the shortest pulse at which a spike is triggered?
- How does the model react to a sinusoidal stimulus?
b) What effect do the parameters have?
- What is the effect of the time constant?
- What effects does the firing threshold have?
- What happens if you start from a different membrane potential value?
c) How does noise affect the responses?
- Expand the model by adding the following to the integration at each time step tau_bin*randn during the integration. This step is intended to simulate the fact that nerve cells do not always respond in exactly the same way to the same stimulus.
- Run the simulation several times. How do the results change?
- Introduce a new parameter that scales the size of the noise and try out its effect.
- Modify the extended integrate-and-fire script to a function that returns the number of spikes generated but has no graphical output.
- Write a script that calls the new integrate-and-fire function 100 times and plots a histogram of the spike counts that occur.
**T8H4)Write a program that determines a sigmoid function for a given set of measurements that minimises the mean square distance to the measurements.
Test this function by creating artificial data in which a sigmoid function is superimposed with noise.
T6H3) In a psychophysical experiment, three different tones are to be played to a test animal in random order, but each tone is to occur exactly 5 times. We don't worry about generating the tones for now, but simply call them condition 1, 2 and 3.
Think of an algorithm that puts the stimulus conditions in the right order and implement it in a programme.
Test the programme by running it several times. Does it always do what it is supposed to? Are the results the same every time?
Extend your programme so that it puts N (any number) stimuli, which are to be played M times (i.e. any number of times), into a sequence.
Tip: Use the repmat function for this task. This generates a large matrix by repeating a smaller one several times. For example, B = repmat(A,2,5) creates a matrix B that contains a total of 10 copies of the matrix A, whereby A is arranged twice below each other and five times next to each other.(B therefore has twice the number of rows and five times the number of columns of A.)
T6H4) The measured values of an apparatus are not perfectly noise-free, even without a biological preparation. In order to estimate the device noise, 100 measurements with the same stimulus [stimulus1khz.mat] were carried out in the electrophysiology practical course for the apparatus with a model cell (an electronic circuit that reproduces the membrane properties of a nerve cell) and the responses were saved as a matrix under[responses1khz.mat].
- Look at any single measurement together with the stimulus (according to task T5C3).
- Calculate and plot the time course of the response averaged over the 100 measurements in a new graph window.
- Calculate and plot the mean value and the standard deviation of the last 300ms for each measurement (averaging over time) in a new graph window. Is there a tendency? Are there any outliers?
- Calculate and output as text output in the command window: Are the mean value and / or standard deviation different before, during and after the stimulation?
T6H5) (For those interested in mathematics) Measurement data often look quite complicated at first. On closer examination, it sometimes turns out that they originate from two overlapping distributions. For example, the distributions of the heights of men and women overlap (because there are women who are taller than many men).
Imagine you are given the task of inferring gender from height and you know the distributions of heights. The "maximum likelihood" principle is often used for such tasks: Tap the distribution with the higher probability for the given value. This idea can be used to determine a threshold value below which you should tap the distribution with the smaller mean value. This threshold value is the intersection value of the distributions.
- Generate two random numbers from different normal distributions, one with a mean of 5 and a standard deviation of 2, the other with a mean of 3 and a standard deviation of 1.
- Using the probability density formula introduced yesterday, calculate the probabilities for each of the two random numbers that they come from one or the other distribution.
- Extend this programme for two vectors of random numbers from the above distributions.
- Calculate the proportion of random numbers that would be assigned to the wrong distribution according to the maximum likelihood principle.
- Look at the two distributions graphically. Where should you draw the line?
- Vary the mean values and standard deviations of the two distributions. When are there more and when fewer errors?
**T6H6) (For those interested in maths) Extend the last task to a function which, given two mean values and two standard deviations, outputs the value at which you should draw the boundary in order to separate the distributions optimally.
** T4H7) (To be used in the next task) You have the task of catching 10 male and 10 female great tits, blackbirds and robins, ringing them and determining their weight.
- Write a function that does this work for you and returns a table containing the ring number (in ascending order from 1 to 60), the bird species, sex and weight for each of the 60 birds. Use a numerical code (e.g. great tit=1, blackbird=2, robin=3), which is precisely documented in the programme's commentary.
- You can "catch" the birds with the following function[birdcatch.m], which starts with[species,female,weight]=vogelfang and lets random birds flutter into the net. (You do not need to understand this function yet, just use it; we will discuss it on the next day of the course).
- Return values:
-
- Species is a character string,
- Female is a truth value to indicate the sex,
- weight is a number (in grams)
- If you catch a bird that you do not need for your statistics, release it without recording its data.
*T5H5) Use your own solution to exercise T4H7 (or alternatively the sample solution bird_table_insa.m) to create a matrix of captured birds. Sort them so that first the blackbirds, then the robins and finally the tits are listed in the matrix, with the males and then the females within each of these groups. The animals of one species and one sex should be sorted by weight.