Skip to content

Allow for concatenated mode in get_some_projections and compute_pc_metrics - #3670

Merged
alejoe91 merged 2 commits into
SpikeInterface:mainfrom
chrishalcrow:fix-concatenate-mode
Feb 5, 2025
Merged

Allow for concatenated mode in get_some_projections and compute_pc_metrics#3670
alejoe91 merged 2 commits into
SpikeInterface:mainfrom
chrishalcrow:fix-concatenate-mode

Conversation

@chrishalcrow

Copy link
Copy Markdown
Member

Should fix #3653

Fixes bug where get_some_projections and compute_pc_metrics couldn't extract pcas when they were computed in concatenated mode. Fixing this allows pca quality metrics to be computed too.

Added a test which used to fail, and now passes.

Harder to test if this definitely works. Here's some evidence: it's code which computes the quality metrics in concatenated mode (with 20 components) and in non-concatenated mode (with 5x4=20 components), then computes the metrics. We wouldn't expect the results to be equal, but would expect them to be highly correlated, which they seem to be!

import numpy as np
import spikeinterface.full as si

rec, sort = si.generate_ground_truth_recording()

sa_1 = si.create_sorting_analyzer(recording=rec, sorting=sort, folder="my_sa", format="binary_folder", overwrite=True, sparse=False, seed=1205)

sa_1.compute({
    "noise_levels": {},
    "random_spikes": {'seed': 1205},
    "waveforms": {},
    "templates": {},
    "principal_components": {"mode": 'concatenated', "n_components": 20},
    "quality_metrics": {"metric_names": ["d_prime","silhouette", "nearest_neighbor"]}
})

sa_2 = si.create_sorting_analyzer(recording=rec, sorting=sort, folder="my_sa", format="binary_folder", overwrite=True, sparse=False)

sa_2.compute({
    "noise_levels": {},
    "random_spikes": {'seed': 1205},
    "waveforms": {},
    "templates": {},
    "principal_components": {},
    "quality_metrics": {"metric_names": ["d_prime","silhouette", "nearest_neighbor"]}
})

qm_1 = sa_1.get_extension("quality_metrics").get_data()
qm_2 = sa_2.get_extension("quality_metrics").get_data()

dprime_corr = np.corrcoef(x = [ qm_1['d_prime'].values, qm_2['d_prime'].values ])
sil_corr = np.corrcoef(x = [ qm_1['silhouette'].values, qm_2['silhouette'].values ])
nnhit_corr = np.corrcoef(x = [ qm_1['nn_hit_rate'].values, qm_2['nn_hit_rate'].values ])
nnmiss_corr = np.corrcoef(x = [ qm_1['nn_miss_rate'].values, qm_2['nn_miss_rate'].values ])

print(dprime_corr)
print(sil_corr)
print(nnhit_corr)
print(nnmiss_corr)

with output:

dprime_corr:  [[1.         0.99704657]
 [0.99704657 1.        ]]
sil_corr:  [[1.         0.95037167]
 [0.95037167 1.        ]]
nnhit_corr:  [[1.         0.98622277]
 [0.98622277 1.        ]]
nnmiss_corr:  [[1.         0.96420438]
 [0.96420438 1.        ]]

@zm711 zm711 added bug Something isn't working qualitymetrics DEPRECATER: use "metrics" instead Related to qualitymetrics module labels Feb 5, 2025
@alejoe91 alejoe91 added this to the 0.102.0 milestone Feb 5, 2025
@alejoe91
alejoe91 merged commit ca22ba8 into SpikeInterface:main Feb 5, 2025
@chrishalcrow
chrishalcrow deleted the fix-concatenate-mode branch February 5, 2025 15:19
@b-grimaud

Copy link
Copy Markdown
Contributor

Just tested it and it works, thanks !

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

Labels

bug Something isn't working qualitymetrics DEPRECATER: use "metrics" instead Related to qualitymetrics module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PCA quality metrics crash when using "concatenated" mode

4 participants