AllenInstitute / ecephys_spike_sorting

Modules for processing extracellular electrophysiology data from Neuropixels probes
Other
109 stars 91 forks source link

Error calculating d_prime #54

Open ldclaar opened 4 years ago

ldclaar commented 4 years ago

I'm running into the following error when I run the quality_metrics module (using the master branch) on a dataset I collected:

d_prime = lda_metrics(all_pcs, all_labels, cluster_id) (from line 278 in metrics.py) ValueError: n_components cannot be larger than min(n_features, n_classes - 1).

I've done a little digging and, from what I can tell, it is failing on clusters that do not have any other units_in_range. One way to avoid the problem is to increase the num_channels_to_compare in the quality_metrics_params. Is this a good solution though? I know this will increase the number of neighboring units each cluster is compared to. Another possible solution would be to set a d_prime value (NaN or some high value?) if there are no units_in_range. Does this make sense? I could also be misdiagnosing the problem, any ideas?

jsiegle commented 4 years ago

I think the second option makes the most sense. If there's only one unit on a segment of the probe, LDA and other PCA-based metrics are not defined. I would recommend adding an extra check on line 272 of metrics.py to test if len(units_in_range) > 1.