Reference position-free, stable region-free, drift-invariant templates
In a drifting recording, a naive average of templates does not make sense. Rather, one should shift the template's component waveforms to account for the drift before averaging.
To do this, we will compute a template on virtual channels. Let the probe
consist of
E.g., for NP1, the virtual probe looks like:
.
.
.
o o
o o
o o virtual
o o padding
o o
___ o o ____
o o
o o
.
.
.
o o central
o o probe
.
.
.
o o
___ o o ____
o o
o o
o o virtual
o o padding
o o
o o
.
.
.
Each unit's spikes will be shifted to land inside the central
probe before averaging. Then, during deconvolution, a probe-
length portion (i.e.,
If the drift is rigid, picking channels like this works; if nonrigid, then we are assuming that the nonrigidity is negligible at the scale of individual units (<200um diameter), which is fair enough and not worth trying to avoid, and anyway is it even true that individual templates would get "bent" when the brain bends?
Concretely, here is the algorithm for computing the free template for a single unit. This is a thorough and conceptual description with justifications, with formal notation describing the exact computations.
Probe notation (idealized probe without missing channels, there is a note below about extending to the realistic case):
- Number of channels
$C$ , consisting of$P$ pitch groups, so that each pitch has$C/P$ channels.
Parameters:
-
$B$ , the number of superresolution bins in the central pitch; equivalently can be parameterized by the bin spacing$h=\Delta/B$ . - Binning mode: either by displacement estimate (mode "p"), by the z position (mode "z"), or a practical mixture of both (mode "hybrid"). More on this below.
Inputs:
- A drift estimate
$p$ , which here we treat as a function$p(t,z)$ giving the drift at time$t$ and depth$z$ . - Spike times and (unregistered) depths
$t_1,...,t_m$ and$z_1,...,z_m$ for a particular unit. - Waveforms
$w_1,...,w_m$ for this unit, extracted on all channels, so that$w_i$ is$T\times C$ .
Define:
- Let
$p_i=p(t_i,z_i)$ and$\bar{p}$ be the average of these. - Registered depths
$r_i = z_i - p(t_i,z_i)$ for this unit. - The unit's registered location
$\bar{r}$ , which is the mean or better yet median of$r_1,...,r_m$ . - The unit's implied "virtual position" trace
$v(t) = \bar{r} + p(t, \bar{r})$ . - The floor division
$\lfloor a/b \rfloor$ , which is the largest integer such that$b \lfloor a/b \rfloor \leq a$ .
Now, for each spike, we must do two things:
- Figure out how many pitches to shift the waveform before
averaging it with other waveforms
- This signed integer quantity is called
$k_i$ and must be determined for each spike.
- This signed integer quantity is called
- Assign the spike to a superres bin, which determines the
groups of spikes that will be averaged together
- This integer bin identity is called
$b_i$ and must be determined for each spike. (1) handles the large scale (bigger than a pitch) component of the drift, and (2) handles the sub-pitch part.
- This integer bin identity is called
Depending on the binning mode, we will change how this is done.
First, what are they?
- In mode "z", each spike's localization alone determines where we think it
is relative to the unit: the number of pitches
$k_i$ is the integer part of$z_i - \bar{r}$ mod the pitch, and the bin identities are determined from the remainder. - In mode "p", the drift estimate alone determines the above: the number
of pitches
$k_i$ is the integer part of$p_i - \bar{p}$ mod the pitch, and the bin identity is chosen based on the remainder. - Mode "hybrid" seeks a middle ground, generalizing the previous "stable
region" approach. First, the recording is divided into several "stable
regions", which are just determined by binning the drift estimate mod
the pitch. Then,
$k_i$ is exactly this drift bin identity, which is the same as setting$k_i$ as in mode "p". The superres bin ids are then determined by binning$z_i - k_i\Delta$ -- which is the residual of$z$ modulo which drift-bin we are in.
Formally, how are
- Modes "z" and "p":
- If mode is "z", let
$o_i=z_i-\bar{r}$ . If mode is "p", let$o_i=p_i-\bar{p}$ . - Let
$k_i = \lfloor (o_i + \Delta/2) / \Delta\rfloor$ - Let
$s_i = o_i - k_i\Delta$ be the remaining sub-pitch drift, and note$s_i\geq0$ by construction. -
$b_i$ is obtained as$\lfloor (s_i + h/2) / h\rfloor$ .
- If mode is "z", let
- Mode "hybrid":
- Let
$k_i = \lfloor (p_i - \bar{p} + \Delta/2) / \Delta\rfloor$ - Let
$s_i = z_i - \bar{r} - k_i\Delta$ and$b_i=\lfloor (s_i + h/2) / h\rfloor$ . - Note that here, the bin ids are signed and may include values
outside
${0,...,B - 1}$ .
- Let
Mode "p" is useful when the depth estimate is noisy and the drift estimate is good; mode "z" is useful when the depth estimate is good and the drift estimate is noisy.
The downside to using mode "z" is that we may unnecessarily shift and misassign superres bins for units with noisy locations, but this is done at random so is in some sense "unbiased". The downside to mode "p" is that we unnecessarily shift and misassign superres bins when the drift estimate is bad, and this could introduce a systemic error since drift failures tend to be correlated through time -- so, this can lead to bias.
Mode "hybrid" goes for a middle ground, where the drift estimate is
fairly good with <1 pitch length
"hybrid" mode is practical, since it uses information from the drift
estimate but hedges this by allowing for some unmodeled drift, without
suffering from the noise issue that mode "z" suffers from when deciding
Assume now that we have chosen
For each occupied bin
For each waveform, we want to pad to the full
where here the pad operation
Then the template is simply computed as the missing-value aware average
of the padded waveforms
- In practice, we have missing channels and the probe is not a perfect set of repeating units; the narrative above ignored this for clarity. We can handle this, but I haven't written it down yet.
- Usually we want denoised templates -- so we need to keep track of the number of spikes that make it into each virtual channel to make sure we compute our per-channel SNR right. Other than that things are the same.