Matlab Code for Spike Interval Distances Between Spike Trains

Christina Behrend: ceb48@duke.edu


main cost-based metrics page
algorithm page for cost-based metrics

Matlab code for Spike Interval Metric

function [d,scr]=spkd_int_post(tli,tlj,cost,tsamp) % % d=spkd(tli,tlj,cost) calculates the "spike interval" distance % (Victor & Purpura 1996) for a single cost % % input variables % tli: vector spike times for first spike train % tlj: vector spike times for second spike train % cost: cost per unit time to move a spike % tsamp: the length of the entire interval % calculates distance between two spike trains in the spike interval metric % by a continuum modification of the sellers algorithm % end conditions: the first and last ISI are expanded as needed to minimize % the total cost % Original Copyright (c) 1999 by Daniel Reich and Jonathan Victor. % Translated to Matlab by Christina Behrend from FORTRAN code by Jonathan Victor. nspi=length(tli); % number of spike times in train 1 nspj=length(tlj); % number of spike times in train 2 ni = nspi+1; % number of intervals in train 1 nj = nspj+1; % number of intervals in train 2 scr=zeros(ni+1,nj+1); % define calculation for a cost of zero if cost==0 d=abs(nspi-nspj); return end % INITIALIZE MARGINS WITH COST OF ADDING A SPIKE scr(:,1)=(0:ni)'; scr(1,:)=(0:nj); for i = 1:ni if (i == 1) && (i == ni) di = tsamp; elseif (i == 1) && (i < ni) di = tli(i); elseif (i > 1) && (i == ni) di = tsamp-tli(i-1); elseif (i > 1) && (i < ni) di = tli(i)-tli(i-1); end iend = 0; if ((i == 1) || (i == ni)) iend = 1; end for j = 1:nj if (j == 1) && (j == nj) dj = tsamp; elseif (j == 1) && (j < nj) dj = tlj(j); elseif (j > 1) && (j == nj) dj = tsamp-tlj(j-1); elseif (j > 1) && (j < nj) dj = tlj(j)-tlj(j-1); end dist = abs(di-dj); jend = 0; if ((j == 1) || (j == nj)) jend = 1; end if (iend == 1) && (jend == 1) dist = 0; elseif (iend == 1) dist = max(0,di-dj); elseif (jend == 1) dist = max(0,dj-di); end scr(i+1,j+1)=min([scr(i,j+1)+1 scr(i+1,j)+1 scr(i,j)+cost*dist]); end end d = scr(ni+1,nj+1);