MouseLand / Kilosort

Fast spike sorting with drift correction for up to a thousand channels
https://kilosort.readthedocs.io/en/latest/
GNU General Public License v3.0
469 stars 245 forks source link

mexGetSpikes2 returns a 2-dimensional result in learnTemplates #218

Closed ckemere closed 8 months ago

ckemere commented 4 years ago

I've been dealing with issues related to trying to sort data with not-so great (i.e., lower amplitude and somewhat sparse) firing neurons recorded using Buzsaki-style Neuronexus probes over a long period.

I changed the threshold parameters ops.spkTh = -5, ops.ThPre = 3, and ops.Th = [3, 2] to deal with the fact that I was getting a lot of Batch XX has fewer than Nfilt spikes. errors, and succeeded in getting up to the learnAndSolve8b() function without errors or warnings. However, I discovered that things are now breaking right at the beginning, and it appears to be because mexGetSpikes2 is not returning any spikes.

It revealed an odd bug (?), which is that size(dWU,3) = 1 even though the size returns as 61 8 (which is dimension 2, not 3!). Any thoughts on why mexGetSpikes2 wouldn't return spikes when the initial clustering seems to be working fine?

thanks!

    if ibatch==1
       % only on the first batch, we first get a new set of spikes from the residuals,
       % which in this case is the unmodified data because we start with no templates
        [dWU, cmap] = mexGetSpikes2(Params, dataRAW, wTEMP, iC-1); % CUDA function to get spatiotemporal clips from spike detections
        W = W0(:,ones(1,size(dWU,3)),:); % initialize the low-rank decomposition with standard waves
        Nfilt = size(W,2); % update the number of filters/templates
        nsp(1:Nfilt) = m0; % initialize the number of spikes for new templates with the minimum allowed value, so it doesn't get thrown back out right away
        Params(2) = Nfilt; % update in the CUDA parameters
    end
JoseGuzman commented 4 years ago

The same problem here for a similar issue with very sparse recordings (i.e, low number of spikes) and set ops.minFR very low (1/600). Clustering fails in commit ab9c339873ea988ddd400ddc18315b9282b9d32d (on May 4, 2020). Until commit 48bf2b81d8ad3bece919f358e071520d5b0930e1 everything works OK.

I got tons of 'Batch x has fewer than Nfilt spikes' ` messages and the following error

One or more output arguments not assigned during call to "mexMPnu8".

Error in learnTemplates (line 149)
        mexMPnu8(Params, dataRAW, single(U), single(W), single(mu), iC-1, iW-1, UtU, iList-1, ...

Error in learnAndSolve8b (line 15)
    rez     = learnTemplates(rez, iorder0);

Error in master_kilosort (line 53)
rez = learnAndSolve8b(rez);

In my case, the size of dWU returns:

K>> size(dWU)

ans =

    61    62     0