Skip to content

Update score labels to avoid bad assert - #4888

Open
cwindolf wants to merge 3 commits into
SpikeInterface:mainfrom
cwindolf:score-labels-fix
Open

cwindolf wants to merge 3 commits into
SpikeInterface:mainfrom
cwindolf:score-labels-fix

Conversation

@cwindolf

@cwindolf cwindolf commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Hi!

So, I gather that many have moved on to just using the count matrix for all comparisons, but I am still a devoted user of do_score_labels(). For a long long time, I have had the asserts which check that spikes are only matched once across sortings commented out, because they did not hold with the previous sorting-based implementation. I have added a test which fails on the old version that illustrates the issue. (Note: the same issue, I think, is present in the count matrix, but I am not addressing that here. There is a note about that in the test I added, the count matrix would fail one of the cases if tested.)

I eventually decided to just write a numba loop that makes sure to only match each spike once. It's pretty similar to the one in the count matrix function, with minor changes to ensure unique single matches. I followed the style of that function's numba caching.

I would note: numba is not listed as a dependency in the "comparison" group in pyproject.toml, but I think it is one in practice, since the count matrix uses it too with no Python fallback? I can add that here if helpful.

Wondering if this change feels okay? Is this score labeling used by many? I believe the result should not change except in good ways / edge cases as a result of this implementation.

Thanks!!

…dd a test, and add

a numba version matching the count matrix impl because this would otherwise require a
hot python loop
@cwindolf cwindolf added bug Something isn't working compression Related to data compression comparison Related to comparison module and removed compression Related to data compression labels Oct 21, 2026
lab_st1[ind_st1] = "TP"
lab_st2[ind_st2] = "TP"
mapped_st = sts2[u2][seg_index]
assert np.all(np.diff(sts) >= 0) and np.all(np.diff(mapped_st) >= 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a danger. Is there a good reason to have it?

assert len(np.unique(ind_st2)) == len(ind_st2)
lab_st1[ind_st1] = "TP"
lab_st2[ind_st2] = "TP"
mapped_st = sts2[u2][seg_index]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mapped_st = sts2[u2][seg_index]
mapped_st = sorting2.get_unit_spike_train(u2, seg_index)

We now have a good caching system for spike trains, so we don't need to do the copying trick on lines 677->678, and can directly use this for better readability.

Also mapped_st is a very confusing name.

from numba import jit

@jit(nopython=True, nogil=True)
def compute_pair_match_indices(spike_frames1, spike_frames2, delta_frames):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should generally change the nomenclature from frames to samples to match core spikeinterface language.

@chrishalcrow chrishalcrow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual math/algorithm looks great, and I approve of that.

But this bit of code is very old, and is using language that is out of date with the rest of SpikeInterface (or at least the newer bits of it...). Would be great if we could bring it up to date.

@cwindolf

cwindolf commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you Chris! Will fix that up and let you know. Appreciate your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working comparison Related to comparison module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants