Source Code - Measure of directionality L
Matlab code to calculate the directionality measure L between two given spike trains (or between two continuous datasets or between a spike train and a continuous dataset)
For a detailed description of the method please refer to:
Andrzejak RG, Kreuz T:
Characterizing unidirectional couplings between point processes and flows.
Eur Phys Lett 96, 50012 (2011) [PDF].
[Andrzejak_Kreuz_Source_Code.zip] Copyright: Ralph G. Andrzejak, Thomas Kreuz
This zip-file includes all of these files:
In order to understand the following documentation, you should at first read the paper. In case you have questions, please contact ralphandrzejak(at)yahoo.de (see also his webpage).
Below we use the example of the coupled Hindmarsh-Rose dynamics studied in the paper to illustrate the code. In particular we have:
Signal1: A flow of the dynamics X
Signal2: A flow of a replica surrogate of the dynamics X
Signal3: A point process derived from dynamics Y.
All signals are of length 200T (see again the paper for the definition of T). The dynamics X is driving dynamics Y with epsilon = 0.1442. The notation for the following source code parameters corresponds to the one used in the paper.
q: window length
s: step size
W: Theiler window
Q: total duration,
N: Number of windows
k: Number of nearest neighbours
delta_t: sampling step
Remark on time unit convention: The time step between subsequent entries in the Matlab arrays of flow signals corresponds to delta_t. In other words, by going from the element with index i to the element with index i+1, we make a step of delta_t.
Accordingly, the parameters q, s, and Q are specified in units of delta_t. The parameters q, s and multiples thereof can directly be used as array indices, and Q is the length of the flow arrays. Furthermore, the spike times of the point process signals are also specified in units of delta_t and therefore one should use delta_t=1 as input for the function ‘AndrzejakKreuzDpointprocess’ below. Accordingly, the length of the flow signals is 400.000 samples. And the spike times are bounded by 0 and 400.000. N and W are in units of time windows.
To run the code copy: AndrzejakKreuzExampleData.mat,
AndrzejakKreuzExample.m, AndrzejakKreuzL.m, AndrzejakKreuzDflow.m,
AndrzejakKreuzDpointprocess.m, f_SPIKE_ISI_distance_new.m into some directory and call AndrzejakKreuzExample.m Please look through the code and read the following short documentation of the main functions.
A distance matrix from a flow is calculated using:
Here flow is a 1-D vector of length Q containing the sample values of the flow. The output DF is a (N,N) distance matrix. All other parameters are explained above.
A distance matrix from a point process is calculated using
spiketimes is a 1-D vector of containing the times of spikes. The length of the vector is determined by the number of spikes.
dchoice: In the paper we used the ISI distance. With this code you can also use the
SPIKE distance (see references below for more information on these distances.).
Depending on the value of dchoice, you get as output the ISI-distance, the SPIKE- distance or both:
If you set
dchoice=1: DP is a 2-D array of size (N,N) containing the SPIKE distance.
dchoice=2: DP is a 2-D array of size (N,N) containing the ISI distance.
dchoice=2: DP is a 3-D array of size (2,N,N) containing the SPIKE distance in
DP(1,:,:) and the ISI distance in DP(2,:,:).
All other parameters are explained above.
The main function is:
function L = AndrzejakKreuzL(DArray,k,W)
DArray is a 3-D array of size (N,N,ND). It contains ND distance matrices of size (N,N).
In our example we have 3 signals. Accordingly, ND=3. For your own data you can use any number of ND>1 distance matrices (At some point limited by the memory of your computer). You do not have to specify ND. It will be detected automatically from the
size of DArray. The individual distance matrices can be obtained from flows and/or point processes. The order used in our example is arbitrary. Whatever order you choose, it will also be used for the output:
L: a 2-D array of size (ND,ND). In element L(a,b)we have L(a|b). For example L(2,3)contains L(signal2 | signal3) = L(replica surrogate of flow X | point process derived from dynamics Y). The diagonal is set to zero. For the present example, since X is driving Y, we get a high value for L(signal 1 | signal 3) = L(flow X | point process derived from dynamics Y). Lower values are obtained for the other non-diagonal entries.