spikeinterface icon indicating copy to clipboard operation
spikeinterface copied to clipboard

Add distance / dot product function for comparing spike train similarity

Open h-mayorquin opened this issue 1 year ago • 3 comments

Hey guys, after this weekend and yesterday and today of frustrations I decided to implement this. This needs some testing so I will put in draft.

Here is the property that I mentioned to you that you can compare to the agreement scores.

The agreement scores are: 1 / ((distance^2 / dot_product) + 1)

As you can see in this graph for the sortngs that @alejoe91 shared with me:

image

So on the left is the agreement scores calculated with the current formula on main, on the right there is the agrement scores calculate with the distance metric function from the PR.

They are not exactly the same. The distance metric penalizes non-matching burstings but as that is a corner case the overall structure is the same.

[EDIT 1] I profiled the function against the make_agreement_scores in main at this point in time 2023 / 11 / 14: Now I compared two sortings 10 hours long with 1000 units each. It takes the function around 3 minutes in this case.

These are the results:

/home/heberto/miniconda3/envs/neuroconv_env/bin/python /home/heberto/development/spikeinterface/bin/dev.py
durations=[36000.0], num_units=1000
function.__name__='make_agreement_scores'
--------------------------------------------------
Mean time over 5 iterations: 212.20 seconds
Mean excluding compliation 156.59 seconds
Std over 5 iterations: 111.38 seconds
Std excluding compliation over: 6.95 seconds
times=['434.61', '151.16', '158.51', '167.12', '149.58']
--------------------------------------------------
function.__name__='compute_distance_matrix'
--------------------------------------------------
Mean time over 5 iterations: 155.84 seconds
Mean excluding compliation 153.47 seconds
Std over 5 iterations: 5.50 seconds
Std excluding compliation over: 3.13 seconds
times=['165.32', '151.88', '158.58', '150.22', '153.20']
--------------------------------------------------
Speedup excluding compilation: 1.02
Speedup including compilation: 1.36

Gist: https://gist.github.com/h-mayorquin/ecc2db36e768b8caf3a3f890b20611ff

h-mayorquin avatar Nov 10 '23 13:11 h-mayorquin