def victorDistance(ds, dpathPred='/gspikes', dpathDat="/spikes", cost=.01, searchOffset=20): '''calculate the victor/purpura spike metric between the two spike sets, with the indicated cost''' if not searchOffset: d1 = ds.getSubData(dpathPred).getData()[:,0] d2 = ds.getSubData(dpathDat).getData()[:,0] dist = sc.victorDistance(d1, d2, cost) print dist else: offsets = range(-searchOffset, searchOffset) distances = [] d1 = ds.getSubData(dpathPred).getData()[:,0] d2 = ds.getSubData(dpathDat).getData()[:,0] for i, o in enumerate(offsets): td = d1 + o dist = sc.victorDistance(td, d2, cost) distances.append(dist) mdi = distances.index(min(distances)) print "Offset: %i, Distance: %g" % (offsets[mdi], distances[mdi]) dist = distances[mdi] z = ds.getSubData(dpathDat).getData().shape[0] r = ds.attrib('real_victordist') r = r * z s = dist - r print z, r s = 100 - 100*s / (z-r) print "percentage = %g" % s
def _spikeDistance(e1d, e2d, cost): if cost==0: print "0 cost" d=abs(e1d.shape[0]-e2d.shape[0]) elif cost>=2: print "Inf cost" d=union1d(e1d, e2d).shape[0] elif not (e1d.shape[0] and e2d.shape[0]): print "One sequence empty" d=max(e1d.shape[0], e2d.shape[0]) elif abs(e1d.shape[0]-e2d.shape[0])>3*e1d.shape[0]: print "excessive miss" d=2*abs(e1d.shape[0]-e2d.shape[0]) else: d=sc.victorDistance(e1d, e2d, cost) return d
def randomVictorDistance(ds, dpathPred='/gspikes', dpathDat="/spikes", cost=.01, searchOffset=20): rd = [] d1 = ds.getSubData(dpathPred).getData()[:,0] d2 = ds.getSubData(dpathDat).getData()[:,0] ran = (min(min(d2), min(d1)), max(max(d2), max(d1))) nspikes = d1.shape[0] for j in range(20): offsets = range(-searchOffset, searchOffset) distances = [] d1 = randint(ran[0], ran[1], nspikes) for i, o in enumerate(offsets): td = d1 + o dist = sc.victorDistance(td, d2, cost) distances.append(dist) mdi = distances.index(min(distances)) rd.append(distances[mdi]) rd = array(rd) print "Mean %g, Std %d" % (mean(rd), std(rd))
def calcRealVictorDist(ds, dpathg='/rg', noise=.1, cost=.01): sd = ds.getSubData(dpathg) fs = ds.fs() g = sd.getData()[:,0] match = [] nspikes = [] for i in range(5): evts1 = _gtoSpikes(g, noise, fs) evts2 = _gtoSpikes(g, noise, fs) dist = sc.victorDistance(evts1, evts2, cost) print dist ns = (evts1.shape[0] + evts2.shape[0])/2 m = dist / ns print m match.append(m) m = mean(array(match)) print m ds.setAttrib('real_victordist', m)