Skip to content

Implementing KNN referencing and a backup referencing mechanism for common_reference#4412

Open
zzhmark wants to merge 3 commits intoSpikeInterface:mainfrom
zzhmark:main
Open

Implementing KNN referencing and a backup referencing mechanism for common_reference#4412
zzhmark wants to merge 3 commits intoSpikeInterface:mainfrom
zzhmark:main

Conversation

@zzhmark
Copy link
Contributor

@zzhmark zzhmark commented Feb 26, 2026

PR based on this issue: #4193

The new features are designed for ungrouped local referencing.

Changes in parameters:

  • reference: include knn as an option
  • backup_reference: allowing global, single and knn (local is unstable) to take effect when local referencing cannot get enough #channels, default as global
  • nneighbors: used for knn referencing, i.e. #channels nearby used for referencing
  • backup_thr: when #channel found locally is below this, turn to backup_reference, default as 1, i.e. no channel found. (we may also consider None to force explicit assignment)

Changes in workflow:

  • Verification in parameters. Since reference and backup_reference both need preprocessing, all the elif are turned as if.
  • Removing assertion of no local reference found as it would be judged dynamically.
  • Add knn preprocessing in init (similar to local).
  • Changing the ungrouped part in get_traces.
    • Defining each reference method as local functions to call.
    • In local, setup if else to choose backup when #channels not meeting the requirement.

zzhmark and others added 3 commits February 26, 2026 16:25
backup reference for local reference when local channels too few; knn can be more robust than local as it ensures the # of reference channels
@zzhmark
Copy link
Contributor Author

zzhmark commented Feb 26, 2026

Here is an example ephys data I used for testing to see the differences. KNN is working better than global. The backup mechanism is verified by setting the local radius as (50, 51) (no channel would be found) and its backup method is global, so backup car is getting the same result as the global car, and it's different from the proper local car (50,200).

probe raw global car knn car local car backup car (global)

@alejoe91
Copy link
Member

Hi @zzhmark

If I'm reading the implementation correctly, you are not discarding channels within the inner radius when computing nearest neighbors. I think this is the wrong behavior: if you rereference to closed-by channels, spiking signals will be essentially killed.
I think that we should still use the local radii, and keep the knn as backend when no channels are found. I think that was the original idea from #4193: to fix the case when local finds no channels. How does that sound?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants