Fortran Code for Spike Time and Spike Interval Distances Between Spike Trains

Jonathan D. Victor: jdvicto@med.cornell.edu

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

Spike Time Metric

SUBROUTINE SPKD(NSPI,TLI,NSPJ,TLJ,SCR,NSPIMX,COST,D) C C CALCULATES DISTANCE BETWEEN TWO SPIKE TRAINS C IN THE SPIKE TIME METRIC BY A CONTINUUM C MODIFICATION OF THE SELLERS ALGORITHM C C INPUT VARIABLES: C NSPI: NUMBER OF SPIKES IN TRAIN I C TLI: LIST OF SPIKE TIMES IN TRAIN I C NSPJ: NUMBER OF SPIKES IN TRAIN J C TLJ: LIST OF SPIKE TIMES IN TRAIN J C SCR: SCRATCH ARRAY -- NOTE THAT DIMENSION STARTS AT 0 C NSPIMX: FOR ADJUSTABLE DIMENSIONS C COST: THE COST PER UNIT TIME TO MOVE A SPIKE C C D: THE DISTANCE C DIMENSION SCR(0:NSPIMX,0:NSPIMX) DIMENSION TLI(NSPIMX) DIMENSION TLJ(NSPIMX) C C INITIALIZE MARGINS WITH COST OF ADDING A SPIKE C DO 1 I=0,NSPI 1 SCR(I,0)=I DO 2 J=0,NSPJ 2 SCR(0,J)=J IF ((NSPI .EQ. 0) .OR. (NSPJ .EQ. 0)) GO TO 100 C C THE HEART OF THE ALGORITHM C DO 10 I=1,NSPI DO 10 J=1,NSPJ 10 SCR(I,J)=AMIN1(SCR(I-1,J)+1,SCR(I,J-1)+1, 1SCR(I-1,J-1)+COST*ABS(TLI(I)-TLJ(J))) 100 D=SCR(NSPI,NSPJ) RETURN END

Spike Interval Metric

SUBROUTINE SPKD3(NSPI,TLI,NSPJ,TLJ,SCR,NSPIMX,COST,TSAMP,D) C C CALCULATES DISTANCE BETWEEN TWO SPIKE TRAINS C IN THE SPIKE INTERVAL METRIC BY A CONTINUUM C MODIFICATION OF THE SELLERS ALGORITHM C C END CONDITIONS: THE FIRST AND LAST ISI ARE EXPANDED AS NEEDED C TO MINIMIZE TOTAL COST C C INPUT VARIABLES: C NSPI: NUMBER OF SPIKES IN TRAIN I C TLI: LIST OF SPIKE TIMES IN TRAIN I C NSPJ: NUMBER OF SPIKES IN TRAIN J C TLJ: LIST OF SPIKE TIMES IN TRAIN J C SCR: SCRATCH ARRAY -- NOTE THAT DIMENSION STARTS AT 0 C NSPIMX: FOR ADJUSTABLE DIMENSIONS C COST: THE COST PER UNIT TIME TO MOVE A SPIKE C TSAMP: THE LENGTH OF THE ENTIRE INTERVAL C DIMENSION SCR(0:NSPIMX+1,0:NSPIMX+1) DIMENSION TLI(NSPIMX) DIMENSION TLJ(NSPIMX) C C INITIALIZE MARGINS WITH COST OF ADDING AN INTERVAL C C THIS IS A BIT CLUMSY, SINCE ONE MUST ALWAYS HAVE C AT LEAST ONE INTERVAL C NI=NSPI+1 !NUMBER OF INTERVALS NJ=NSPJ+1 DO 1 I=0,NI 1 SCR(I,0)=I DO 2 J=0,NJ 2 SCR(0,J)=J C C THE HEART OF THE ALGORITHM C DO 10 I=1,NI IF ((I .EQ. 1) .AND. (I .EQ. NI)) DI=TSAMP IF ((I .EQ. 1) .AND. (I .LT. NI)) DI=TLI(I) IF ((I .GT. 1) .AND. (I .EQ. NI)) DI=TSAMP-TLI(I-1) IF ((I .GT. 1) .AND. (I .LT. NI)) DI=TLI(I)-TLI(I-1) DO 10 J=1,NJ IF ((J .EQ. 1) .AND. (J .EQ. NJ)) DJ=TSAMP IF ((J .EQ. 1) .AND. (J .LT. NJ)) DJ=TLJ(J) IF ((J .GT. 1) .AND. (J .EQ. NJ)) DJ=TSAMP-TLJ(J-1) IF ((J .GT. 1) .AND. (J .LT. NJ)) DJ=TLJ(J)-TLJ(J-1) C DIST=ABS(DI-DJ) C C LOOK FOR SPECIAL CASES AT THE ENDS C IEND=0 IF ((I .EQ. 1) .OR. (I .EQ. NI)) IEND=1 JEND=0 IF ((J .EQ. 1) .OR. (J .EQ. NJ)) JEND=1 IF ((IEND .EQ. 0) .AND. (JEND .EQ. 0)) GO TO 10 IF (IEND .EQ. 1) DIST=AMAX1(0.,DI-DJ) !CAN EXPAND AN END INTERVAL IF (JEND .EQ. 1) DIST=AMAX1(0.,DJ-DI) !CAN EXPAND AN END INTERVAL IF ((IEND .EQ. 1) .AND. (JEND .EQ. 1)) DIST=0. 10 SCR(I,J)=AMIN1(SCR(I-1,J)+1,SCR(I,J-1)+1,SCR(I-1,J-1)+COST*DIST) C D=SCR(NI,NJ) C RETURN END