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 2 years 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

@h-mayorquin I'm taking another look at this and it seems in good shape. Maybe we should add an option to the compare_* function to select the matching strategy?

alejoe91 avatar May 10 '24 12:05 alejoe91

@samuelgarcia @h-mayorquin let's move forward woth this!

alejoe91 avatar Sep 25 '24 08:09 alejoe91

@samuelgarcia @h-mayorquin let's move forward woth this!

What would be missing to move forward?

h-mayorquin avatar Oct 08 '24 21:10 h-mayorquin

@h-mayorquin cleaned up a bit and exposed the option at the comparison level. @h-mayorquin can you check? in particular, the implementation of the agreement_matrix here

Also added some simple tests to check that the two agreement methods return the same matches.

alejoe91 avatar Feb 03 '25 12:02 alejoe91

Strange that the docs never finished. This is ready on my side.

h-mayorquin avatar Feb 04 '25 21:02 h-mayorquin