Skip to main content
Biostatistics (Oxford, England) logoLink to Biostatistics (Oxford, England)
. 2019 Feb 8;21(4):709–726. doi: 10.1093/biostatistics/kxy083

Fast nonconvex deconvolution of calcium imaging data

Sean W Jewell 1,, Toby Dylan Hocking 2, Paul Fearnhead 3, Daniela M Witten 4
PMCID: PMC7566556  PMID: 30753436

Summary

Calcium imaging data promises to transform the field of neuroscience by making it possible to record from large populations of neurons simultaneously. However, determining the exact moment in time at which a neuron spikes, from a calcium imaging data set, amounts to a non-trivial deconvolution problem which is of critical importance for downstream analyses. While a number of formulations have been proposed for this task in the recent literature, in this article, we focus on a formulation recently proposed in Jewell and Witten (2018. Exact spike train inference via Inline graphic optimization. The Annals of Applied Statistics12(4), 2457–2482) that can accurately estimate not just the spike rate, but also the specific times at which the neuron spikes. We develop a much faster algorithm that can be used to deconvolve a fluorescence trace of 100 000 timesteps in less than a second. Furthermore, we present a modification to this algorithm that precludes the possibility of a “negative spike”. We demonstrate the performance of this algorithm for spike deconvolution on calcium imaging datasets that were recently released as part of the Inline graphic challenge (http://spikefinder.codeneuro.org/). The algorithm presented in this article was used in the Allen Institute for Brain Science’s “platform paper” to decode neural activity from the Allen Brain Observatory; this is the main scientific paper in which their data resource is presented. Our Inline graphic implementation, along with Inline graphic and Inline graphic wrappers, is publicly available. Inline graphic code is available on Inline graphic and Inline graphic, and Inline graphic wrappers are available on Inline graphic; see https://github.com/jewellsean/FastLZeroSpikeInference.

Keywords: Calcium imaging, Changepoint detection, Neuroscience, Nonconvex optimization

1. Introduction

Due to recent advances in calcium imaging technology, it has become possible to record from large populations of neurons simultaneously in behaving animals (Dombeck and others, 2007; Ahrens and others, 2013; Prevedel and others, 2014). These data result in a fluorescence trace for each neuron.

However, most downstream analyses require not a fluorescence trace, but instead a measure of the neuron’s activity over time. Consequently, a number of unsupervised and—more recently—supervised methods have been developed to infer neural activity on the basis of the fluorescence trace (Yaksi and Friedrich, 2006; Holekamp and others, 2008; Sasaki and others, 2008; Dyer and others, 2010, 2013; Grewe and others, 2010; Vogelstein and others, 2009, 2010; Pnevmatikakis and others, 2013; Deneux and others, 2016; Friedrich and Paninski, 2016; Theis and others, 2016; Friedrich and others, 2017; Jewell and Witten, 2018).

In this article, we make use of a generative model that connects the observed fluorescence trace Inline graphic to the underlying and unobserved calcium concentration Inline graphic, and the unknown spike times (Vogelstein and others, 2010; Friedrich and Paninski, 2016; Friedrich and others, 2017). This model assumes that the observed fluorescence is a noisy version of the underlying calcium, which exponentially decays, unless there is a spike, in which case there is an instantaneous increase in the calcium concentration, as follows:

graphic file with name M13.gif (1.1)

where Inline graphic, and where Inline graphic indicates the presence of a spike at the Inline graphicth timestep. At most timesteps Inline graphic, corresponding to no spike, and the calcium will decay exponentially at a rate governed by the parameter Inline graphic, which is assumed known. For simplicity, in what follows, we assume that the intercept Inline graphic is equal to zero. However, this is easy to relax; see Section 2.4 for a straight-forward extension, and Section 3 for practical considerations. Moreover, we set Inline graphic equal to one, since the problems we will solve are scale-invariant. That is, the value of Inline graphic does not affect the scientific conclusions.

Under the additional assumption that the errors Inline graphic are normally distributed, model (1.1) suggests estimating the concentration by solving the following constrained Inline graphic optimization problem

graphic file with name M24.gif (1.2)

where Inline graphic is a non-negative tuning parameter that controls the tradeoff between how closely the calcium concentration matches the fluorescence trace, Inline graphic, and the number of non-zero spikes, Inline graphic. The solution to this optimization problem directly provides an estimate for the spike times; that is, if Inline graphic, then we infer a spike at time Inline graphic. We note that this problem is over-parameterized, in the sense that knowing Inline graphic determines Inline graphic.

While (1.2) follows from the biological process described in (1.1), the Inline graphic penalty makes the problem nonconvex and thus seemingly intractable. Consequently, rather than solving (1.2), prior approaches have solved a convex relaxation to (1.2) (Vogelstein and others, 2010; Friedrich and Paninski, 2016; Friedrich and others, 2017), where the Inline graphic penalty is replaced by an Inline graphic penalty.

In recent work, Jewell and Witten (2018) showed that it is possible to efficiently solve the related nonconvex optimization problem

graphic file with name M35.gif (1.3)

obtained by removing the positivity constraint, Inline graphic, from (1.2). The positivity constraint enforces the biological property that a firing neuron can only cause the calcium concentration to increase. Nonetheless, despite the slight loss in physical interpretability caused by the omission of the positivity constraint, Jewell and Witten (2018) showed that solving (1.3) leads to improved performance over existing deconvolution approaches that perform a convex relaxation of (1.2). In particular, the method of Jewell and Witten (2018) provides an accurate estimate of the specific timesteps at which a neuron fires.

Unfortunately, the algorithm proposed in Jewell and Witten (2018) for solving (1.3) is too slow to conveniently run on large-scale data. For traces of 100 000 timesteps, the implementation runs in a few minutes for a single value of the tuning parameter Inline graphic; in practice the user must apply the algorithm over a fine grid of values of Inline graphic, leading potentially to hours of computation time for a single trace. Furthermore, a single experiment could result in hundreds or thousands of fluorescence traces (Ahrens and others, 2013; Vladimirov and others, 2014).

In this article, we develop a fast algorithm for solving problem (1.3); for traces of 100 000 timesteps our implementation runs in less than a second. Furthermore, this new algorithm can easily accommodate the positivity constraint that was omitted from (1.3); in other words, we can directly solve problem (1.2). Additionally, we exploit ideas from Haynes and others (2017) to efficiently “choose” good values of Inline graphic; that is, values of Inline graphic where the solution to (1.3) changes.

The algorithm we develop to solve (1.2) was used to obtain the key scientific results in the Allen Institute’s main scientific paper from the Allen Brain Observatory (de Vries and others, 2018). Additionally, the Allen Institute for Brain Science recently released an update to their software development kit that provides users with the output from our algorithm for close to 60 000 neurons during different experimental conditions.

In what follows, we introduce our new algorithm for solving (1.2) and (1.3) in Section 2. We compare its performance in Section 3 to a convex relaxation of (1.2) on a number of calcium imaging datasets that were recently released as part of the Inline graphic challenge (http://spikefinder.codeneuro.org/). We close with a discussion in Section 4.

2. A fast functional pruning algorithm for solving problems (1.3) and (1.2)

2.1. A review of Jewell and Witten (2018)

Jewell and Witten (2018) point out that the Inline graphic optimization problem (1.3) is equivalent to a changepoint detection problem,

graphic file with name M43.gif (2.4)

where

graphic file with name M44.gif (2.5)

In problem (2.4), we select the optimal changepoints Inline graphic and the number of changepoints Inline graphic such that the cost of segmenting the data into Inline graphic exponentially decaying regions is minimal, where (2.5) is the cost associated with the region that spans the Inline graphicth to Inline graphicth timesteps. Problems (2.4) and (1.3) are equivalent in the sense that Inline graphic and all other Inline graphic.

To solve the changepoint problem, Jewell and Witten (2018) exploit a simple recursion (Jackson and others, 2005),

graphic file with name M52.gif (2.6)

where Inline graphic is the optimal cost of segmenting the data Inline graphic, and where we define Inline graphic. This results in an algorithm with computational complexity Inline graphic, which can be substantially improved by noticing that the minimization on the right hand side of (2.6) can be performed over a smaller set Inline graphic without sacrificing the global optimum (Killick and others, 2012); details are provided in Jewell and Witten (2018). As mentioned in the introduction, the algorithm runs in a few minutes for traces of length 100 000, and yields the global optimum to (1.3). We note that the recursion (2.6) does not naturally lead to an algorithm to solve (1.2); this is discussed in further detail in Section 2.3.

2.2. Functional pruning for solving (1.3)

2.2.1. Motivation for functional pruning.

In order to motivate the potential for a much faster algorithm for solving (1.3) than the one proposed in Jewell and Witten (2018), consider Figure 1a.

Fig. 1.

Fig. 1.

Algorithm 1: (a) motivation and (b) example. (a) A simple example to show that there are only a few possible values for the most recent changepoint before timestep 40. We consider solving for the most recent changepoint, given data Inline graphic, for each possible value of the calcium concentration at the Inline graphicth timestep, Inline graphic. For each possible value of Inline graphic, we display the estimated calcium concentration going back in time to the most recent changepoint before timestep 40. The colors indicate the time of the most recent changepoint. In this example, there are only three possibilities for the most recent changepoint: Inline graphic. For example, Inline graphic, and Inline graphic. (b) Evolution of Inline graphic and Inline graphic for Example 1. The left-hand panels display the functions Inline graphic and Inline graphic, and the right-hand panels show the function Inline graphic, which is the minimum of those two functions. Rows index the timesteps, Inline graphic. The functions are colored based on the timestep of the most recent changepoint, that is, the value of Inline graphic corresponding to Inline graphic. Top: When Inline graphic, Inline graphic; this corresponds to the region Inline graphic. Center: When Inline graphic, Inline graphic is the minimum of two quantities: Inline graphic, which corresponds to the most recent changepoint being at timestep zero, and Inline graphic, which corresponds to the most recent changepoint being at timestep one. These two functions are shown on the left-hand side, and Inline graphic) is shown on the right-hand side. Bottom: When Inline graphic, Inline graphic is calculated similarly; see Example 1 for additional details.

In this figure, we are interested in determining the optimal cost of segmenting the data up to time Inline graphic, that is, calculating Inline graphic in (2.6). Instead of directly applying the recursion (2.6), we consider a slightly different question: What is the optimal most recent changepoint before the 40th timestep, conditional on, the unknown calcium concentration Inline graphic? Given the previously stored values Inline graphic, and the data Inline graphic, it is straightforward to calculate the best most recent changepoint Inline graphic, as Inline graphic, for any value of the calcium concentration Inline graphic.

Figure 1a displays the most recent changepoint Inline graphic as a function of Inline graphic. We observe that regardless of the value of the calcium at the current timestep—and consequently, regardless of the fluorescence values Inline graphicthe only possible times for the most recent changepoint before the 40th timestep are 20, 37, and 39; that is, Inline graphic for all possible Inline graphic.

However, the algorithm proposed in Jewell and Witten (2018) does not exploit the fact that 20, 37, and 39 are the only possible times for the most recent changepoint before the 40th timestep: the minimization in (2.6) is performed over the set Inline graphic, or else over a slightly smaller set Inline graphic using ideas from Killick and others (2012). This suggests that by viewing the cost of segmenting the data up until the Inline graphicth timestep as a function of the calcium at the Inline graphicth timestep, we could potentially develop an algorithm that is much faster than the one in Jewell and Witten (2018) in that it would only require performing the minimization in (2.6) over Inline graphic. The idea of using this type of conditioning was first suggested by Rigaill (2015) and Maidstone and others (2017), albeit to speed up algorithms for detecting changepoints in a different class of models.

2.2.2. The functional pruning algorithm.

To begin, we substitute the cost function Inline graphic into the recursion (2.6), in order to obtain

graphic file with name M102.gif (2.7)

where

graphic file with name M103.gif (2.8)

and

graphic file with name M104.gif (2.9)

In words, Inline graphic is the cost of partitioning the data up until time Inline graphic, given that the most recent changepoint was at time Inline graphic, and the calcium at the Inline graphicth timestep equals Inline graphic. Inline graphic is the optimal cost of partitioning the data up until time Inline graphic, given that the calcium at the Inline graphicth timestep equals Inline graphic.

The following proposition will prove useful in what follows.

Proposition 1

For Inline graphic defined in (2.9), the following recursion holds:

Proposition 1 (2.10)

The proof of Proposition 1 is in Appendix S1 of the supplementary material available at Biostatistics online. The recursion in (2.10) encompasses two possibilities: either there is a changepoint at the Inline graphicst timestep, and we must determine the optimal cost up to that time, Inline graphic, or there is no changepoint at the Inline graphicst timestep, Inline graphic. The recursion in (2.10) is reminiscent of (2.6), and raises the following question: can we use (2.10) as the basis for a recursive algorithm for solving the problem of interest, (1.3)? At first, it appears almost hopeless, since the recursion (2.10) involves a function of Inline graphic, a real-valued parameter. However, as we will see, it turns out that Inline graphic and Inline graphic are simple functions of Inline graphic that are easy to analytically manipulate.

Observe that, by definition (2.9), the optimal cost Inline graphic takes the form

graphic file with name M125.gif (2.11)

where Inline graphic; this is the set of values for the calcium at the Inline graphicth timestep such that the most recent changepoint occurred at time Inline graphic. Furthermore, by inspection of (2.8), we see that Inline graphic is itself a quadratic function of Inline graphic for all Inline graphic. Thus, Inline graphic is in fact piecewise quadratic. This means that in order to efficiently store the function Inline graphic, we must simply keep track of the regions Inline graphic, as well as the three coefficients (constant, linear, quadratic) that define the quadratic function corresponding to each region. We will now present a small toy example illustrating how the recursion (2.10) can be used to build up optimal cost functions, each of which is piecewise quadratic.

Example 1

Consider the simple dataset Inline graphic with Inline graphic and Inline graphic. We start with Inline graphic, which is just a quadratic centered around Inline graphic,

Example 1

Then, at the next time point, we form Inline graphic based on (2.10),

Example 1

Again, using the recursion (2.10) we obtain the next optimal cost function,

Example 1

We note that Inline graphic is defined over just Inline graphic and Inline graphic. This example is displayed in Figure 1b.

Although we have shown how to efficiently build optimal cost functions Inline graphic from Inline graphic, it remains to establish that these cost functions can be used to determine the optimal changepoints, that is, the values of Inline graphic that solve (1.3). These can be obtained by finding the value of Inline graphic that satisfies

graphic file with name M151.gif (2.12)

for Inline graphic until Inline graphic is obtained. Full details are provided in Algorithm 1. To summarize, we have developed a recursive algorithm for solving (1.3) using the recursions in Proposition 1.

Algorithm 1:

Algorithm 1:

A functional pruning algorithm for solving (1.3)

Example 2

“Example 1 revisited”

We return to Example 1 to illustrate how (2.12) can be used to determine the optimal changepoints. In the interest of simplicity, we assume that Inline graphic; in other words, we have observed all of the data. Then, Inline graphic, where

Example 2

Therefore, the most recent changepoint is Inline graphic. In fact, since the most recent changepoint is at timestep 0, we say that there are no changepoints.

Algorithm 1 is an instance of the class of functional pruning algorithms proposed in Maidstone and others (2017).

2.2.3. Computational time of functional pruning.

We saw in Example 1 that Proposition 1 can lead to a recursive algorithm for solving the problem of interest (1.3). At first glance, since Inline graphic is piecewise quadratic with Inline graphic regions (2.11), and our recursive algorithm requires computing Inline graphic, it appears that a total of Inline graphic operations must be performed in order to deconvolve a fluorescence trace of length Inline graphic. Critically, however, this is not the case. This is because, in practice, Inline graphic is piecewise quadratic with substantially fewer than Inline graphic regions, as we saw in Figure 1a. To see this, recall from (2.11) that the Inline graphicth region up to timestep Inline graphic is defined as Inline graphic. However, if Inline graphic is the empty set—that is, if there is no Inline graphic such that Inline graphic—then Inline graphic is, in fact, not a function of the Inline graphicth region.

In practice, Inline graphic will often be the empty set. For instance, see Figure 1a. We note that in this example, at timestep Inline graphic, the optimal cost function is only a function of three regions,

graphic file with name M175.gif

In a similar way, in Example 1, we saw that Inline graphic was a function of two regions.

Therefore, though its worst-case performance is upper-bounded by Inline graphic, in practice, Algorithm 1 is typically much faster than this. In Appendix S6 of the supplementary material available at Biostatistics online, we show that the maximum number of regions, Inline graphic, is a small fraction of Inline graphic; for Inline graphic, fewer than 30 regions are required.

Furthermore, by slightly modifying Theorem 6.1 of Maidstone and others (2017), we can show that Algorithm 1 is no worse than the algorithm proposed in Jewell and Witten (2018). In fact, as shown in Figure 2, Algorithm 1 is typically up to a thousand times faster than that of Jewell and Witten (2018) on a fluorescence trace of length 100 000. In simulations, our Inline graphic implementation of Algorithm 1 runs in less than one second on traces of length 100 000.

Fig. 2.

Fig. 2.

Timing comparisons between three algorithms for solving (1.2) and (1.3) with Inline graphic. Functional pruning approach used in Algorithm 1 and Algorithm S8.1 of the supplementary material available at Biostatistics online (purple), and two algorithms from Jewell and Witten (2018): one based on recursion (2.6) (Optimal partitioning), and one based on an improvement to (2.6) that makes use of ideas from Killick and others (2012) (Inequality pruning). Fifty sample datasets are simulated according to (1.1) with coefficient Inline graphic, decay parameter Inline graphic, normal errors Inline graphic, Poisson distributed spikes Inline graphic where Inline graphic, and initial calcium value Inline graphic. Standard errors are on average Inline graphic of the average computation time. Panels correspond to different values of Inline graphic. Timing results were obtained on an Intel Xeon E5-2620 2.0 GHz processor.

2.3. An efficient algorithm to solve the constrained problem (1.2)

As stated in the introduction, our main interest is to solve (1.2) for the global optimum. Problem (1.2) differs from problem (1.3) in that there is an additional constraint that enforces biological reality: firing neurons can only cause an increase, but not a decrease, in the calcium concentration. The algorithm in Jewell and Witten (2018) cannot be used to solve (1.2), because it relies on the recursion in (2.6), which does not allow for any dependence in the calcium concentration before and after a changepoint. Thus, at the time of this writing, there are no algorithms available to efficiently solve (1.2) for the global optimum.

In this section, we utilize a simple modification, due to Hocking and others (2017), to the functional recursion (2.10) that ensures that the constraint Inline graphic is satisfied. First, recall from (2.10) that Inline graphic, where we take the minimum over two terms, which result from adding an additional point Inline graphic to the current segment, Inline graphic, and adding a new candidate changepoint at Inline graphic and starting a new segment at the Inline graphicth timestep, Inline graphic.

In the latter case, if there is a spike at the Inline graphicth timestep, then in order to enforce the positivity constraint, Inline graphic, the term Inline graphic in (2.10) needs to be modified to Inline graphic Therefore, we replace (2.10) with

graphic file with name M202.gif (2.13)

and we replace (2.8) with

graphic file with name M203.gif (2.14)

We note that this is a slight abuse of notation since Inline graphic and Inline graphic take on different definitions depending on the optimization problem ((1.2) or (1.3)). Equations (2.13) and (2.14) can be used to develop an efficient recursive algorithm to solve problem (1.2). Details of the algorithm itself are included in Appendix S2 of the supplementary material available at Biostatistics online. A continuation of Example 1 that solves (1.2) is included in Appendix S5 of the supplementary material available at Biostatistics online. Figure 2 shows the running time of solving (1.2).

2.4. Solving (1.1) for non-zero intercept Inline graphic

Thus far, we have considered (1.1) with Inline graphic. To accommodate the possibility of nonzero baseline calcium, we consider the problem

graphic file with name M208.gif (2.15)

Instead of directly solving (2.15) with respect to Inline graphic, we consider a fine grid of values for Inline graphic, and solve (1.2) with Inline graphic using Algorithm S8.1 of the supplementary material available at Biostatistics online, for each value of Inline graphic considered. The solution to (2.15) is the set Inline graphic corresponding to the value of Inline graphic that led to the smallest value of the objective, over all values of Inline graphic considered.

2.5. Solving (1.1) with additional spike constraints

The methods used to solve (1.2) and (1.3) can also be used to solve the related nonconvex problem

graphic file with name M216.gif (2.16)

proposed in Friedrich and others (2017). In Appendix S4 of the supplementary material available at Biostatistics online, we examine this proposal more closely. Remarkably, we show that Algorithm S8.1 of the supplementary material available at Biostatistics online can be generalized to solve

graphic file with name M217.gif (2.17)

exactly! We note that this is equivalent to (2.16) by taking Inline graphic.

3. Real data experiments

In this section, we illustrate the performance of the solution to (1.2) for spike deconvolution across a number of datasets, which were aggregated as part of the recent Inline graphic challenge (http://spikefinder.codeneuro.org/). Each dataset consists of both calcium and electrophysiological recordings for a single cell. As part of the Inline graphic challenge, all data recordings were standardized by resampling to 100 Hz and linear trends were removed from the calcium trace via preprocessing steps described in Theis and others (2016).

Throughout this section, due to computation considerations, the solutions to (1.2) and (1.3) are obtained using slight modifications of Algorithm 1 and Algorithm S8.1 of the supplementary material available at Biostatistics online. These modifications are described in Appendix S3.1 of the supplementary material available at Biostatistics online. Additionally, since the Inline graphic data removed linear trends from the raw calcium trace, we do not estimate Inline graphic in (1.1). Instead, we set Inline graphic; our empirical results suggest that estimation of Inline graphic may not be necessary.

In our experiments, we will treat the spikes ascertained using electrophysiological recording as the “ground truth”, and will quantify the ability of spike deconvolution algorithms to recover these ground truth spikes on the basis of the calcium recordings. The data sets differ in terms of the choice of calcium indicator (GCaMP5, GCaMP6, jRCAMP, jRGECO, OGB), scanning technology (AOD, galvo, and resonant), and circuit under investigation (V1 and retina).

Throughout this section, we compare our proposal (1.2) to a recent approach from the literature that employs an Inline graphic (convex) relaxation to (1.2),

graphic file with name M226.gif (3.18)

proposed by Friedrich and Paninski (2016) and Friedrich and others (2017). Friedrich and others (2017) developed a very fast algorithm to solve (3.18); in simulated examples their algorithm solves (3.18) approximately 40–60Inline graphic faster than Algorithm 1 and 40–900Inline graphic faster than Algorithm S8.1 of the supplementary material available at Biostatistics online. This is not surprising, since (3.18) is a convex problem, whereas (1.2) and (1.3) are nonconvex problems. Moreover, in practical applications, Algorithm 1 and Algorithm S8.1 of the supplementary material available at Biostatistics online are often fast enough. Indeed, de Vries and others (2018) uses Algorithm S8.1 of the supplementary material available at Biostatistics online to deconvolve traces from nearly 60 000 neurons.

Since the solution to (3.18) often results in many small non-zero elements of Inline graphic, we consider post-thresholding. That is, given Inline graphic that solve (3.18), and a threshold Inline graphic, we set Inline graphic; in other words, we conclude that a spike is present only if Inline graphic.

In Section 3.1, we compare our proposed approach (1.2) to (3.18) on data from the Inline graphic challenge. We describe our experimental approach in Section 3.1.1. Section 3.1.2 illustrates these methods for a single cell, and in Section 3.1.3, we examine results for all datasets considered in the Inline graphic challenge. In Section 3.2, we illustrate on a real-data example that solving (1.2) gives superior estimates than solving (1.3). In Section 3.3, we compare the estimated increase in calcium due to a spike (using (1.2)) to the actual number of recorded spikes (based on the ground truth electrophysiological recordings).

Inline graphic code to reproduce all experiments is available on GitHub at https://github.com/jewellsean/fast-nonconvex-experiments.

3.1. Comparison of (1.2) to (3.18) on data from the Inline graphic challenge

3.1.1. Description of methods for Sections 3.1.23.1.3.

We now describe the methods that will be used in Sections 3.1.23.1.3. Our main objective is to accurately estimate the times at which spikes occur. Thus, we use two measures that directly compare two spike trains, both of which have been used extensively in the neuroscience literature (Quiroga and Panzeri, 2009; Reinagel and Reid, 2000; Gerstner and others, 2014): (i) van Rossum distance with timescale parameter Inline graphic (van Rossum, 2001; Houghton and Kreuz, 2012) and (ii) Victor-Purpura distance with cost parameter Inline graphic (Victor and Purpura, 1997, 1996). We also use an additional measure: (iii) the correlation between two downsampled spike trains; details of this measure are provided in Theis and others (2016). As we will see, measures (i) and (ii) are sensitive to the timing of spikes, whereas measure (iii) is somewhat insensitive to the timing of the spikes, and instead quantifies the similarity between the spike rates.

To analyze the performances of the proposals (1.2) and (3.18) over a single fluorescence trace, we take a training/test set approach. Given a fluorescence trace of length Inline graphic, the first Inline graphic timesteps are used in the training set, and the remainder are used for the test set. We solve (1.2) and (3.18) for a range of values of the tuning parameter Inline graphic on the training set; in the case of (3.18) we also use a range of threshold values Inline graphic.

For all tuning parameter values considered, we apply the three measures mentioned earlier to the estimated and true spike trains, and select the tuning parameter values that optimize these measures on the training set. We then solve (1.2) and (3.18) on the test set with the selected values of the tuning parameters, and evaluate test set performance.

As pointed out by Pachitariu and others (2018), estimating the decay rate Inline graphic in (1.1) is difficult. Therefore, as in Pachitariu and others (2018), we categorize calcium indicators into three groups based on their decay properties. As in Vogelstein and others (2010), within each calcium indicator rate category, we set Inline graphic, where Inline graphic is 1 / (frame rate), and Inline graphic is a time-scale parameter based on the category, defined as

graphic file with name M248.gif

For example, in Figure 3, GCaMP6f is classified as a fast indicator and the data is recorded at 100Hz. Therefore, we take Inline graphic.

Fig. 3.

Fig. 3.

Illustrative example for cell 13, GCaMP6f, V1, from Chen and others (2013) after preprocessing; see Theis and others (2016). Different spike measures are displayed in each row. Left: Performances of the post-thresholded solution to (3.18) and the solution to (1.2). Right: The cell’s fluorescence trace is displayed in grey. The estimated spikes on the test set from the “best” choice of the tuning parameter Inline graphic, as determined by either van Rossum, Victor-Purpura, or a correlation-based measure on the training set, are displayed under the fluorescence trace. The true spike times, as determined using electrophysiological recording, are shown in black. The colors in the left-hand panels correspond to the colors in the right-hand panel.

In practice, users typically do not have the benefit of a training set to select the tuning parameter value Inline graphic to solve (1.2) or (1.3). Therefore, we recommend using the procedure proposed in de Vries and others (2018), which selects Inline graphic based on the firing rate, decay rate Inline graphic, and estimated signal-to-noise ratio.

3.1.2. Results for a single cell.

In Figure 3, we illustrate this procedure for cell 13, GCaMP6f, V1, from Chen and others (2013). Each row corresponds to one of the measures described in Section 3.1.1. The left column displays these measures on the training set, for the solution to (1.2) with different values of Inline graphic, and for the post-thresholded solution to (3.18) with different values of Inline graphic and Inline graphic. The right column shows the fluorescence trace along with the estimated spikes, on the test set, using tuning parameters selected on the training set.

There are a number of important observations to draw from Figure 3. As measured by van Rossum and Victor-Purpura, the estimated spikes from (1.2) are much more accurate than those estimated (and post-thresholded) using the convex relaxation (3.18). This agrees with our visual inspection of the right hand panel: the estimated spikes from problem (1.2) more closely match the number and timings of the true spikes than those estimated from problem (3.18).

In contrast, if performance is measured by correlation, then the estimated spikes obtained from (3.18) result in slightly better performance than the estimated spikes from (1.2). However, in the training set there are 75 true spikes, whereas (3.18) outperforms (1.2) when approximately 200 spikes are estimated. Therefore, selecting the tuning parameter for (3.18) based on correlation leads to a substantial overestimate of the number of spikes, and therefore, poor overall accuracy in the number and timing of the spikes. This pattern has been observed in other Inline graphic regularization problems (Zou, 2006; Maidstone and others, 2018), and persists across cells in the Inline graphic data (results not shown).

To summarize, when van Rossum and Victor-Purpura distance are used to evaluate performance, our proposal (1.2) substantially outperforms the approach in (3.18). When performance is evaluated using correlation, the performance of (3.18) is slightly better than that of (1.2); however, this better performance is achieved when far too many spikes are estimated, indicating that correlation is a poor choice for quantifying the accuracy of spike detection.

3.1.3. Results for all datasets in the Inline graphic challenge.

In this section, we examine the performance of the solutions to (1.2) and (3.18) on all datasets collected as part of the Inline graphic challenge. For the ten datasets included in this challenge, Table S1 of the supplementary material available at Biostatistics online tabulates the calcium indicator; circuit; publishing authors; average, minimum, and maximum fluorescence trace length; the number of cells measured; and the time-scale classification. In total, there are 174 traces, each of which contains fewer than 100,000 timesteps. We analyze these 174 cells as described in Section 3.1.1.

Figure 4a compares the test set performance, with respect to the van Rossum, Victor-Purpura, and correlation measures, for each of the 174 cells. As measured by the van Rossum and Victor-Purpura distance, the solution to (1.2) outperforms the solution to (3.18). However, under the correlation measure, the solution to (3.18) achieves higher correlations than the solution to (1.2). These results are consistent with those on a single cell presented in Section 3.1.2, where it was shown that van Rossum and Victor-Purpura accurately estimate spike times, whereas correlation yields a cruder measure of spike rate and encourages overestimation of the number of spikes.

Fig. 4.

Fig. 4.

Results for all datasets in the Inline graphic challenge. (a) Optimal van Rossum, Victor-Purpura, and correlation measures for our proposal, (1.2), and a competing proposal, (3.18). Small values of the van Rossum and Victor-Purpura measures suggest accurate estimation of the timing and number of spikes, whereas a large value of the correlation measure suggests accurate estimation of the spike rate, though perhaps an overestimate of the number of spikes. Each dot represents the performance of (1.2) and (3.18) on a single cell, for each of the 174 cells. Cells are colored based on the dataset from which they were obtained (see Table S1 of the supplementary material available at Biostatistics online). (b) Large increases in the estimated spike magnitude, Inline graphic, are associated with more true spikes, as measured by electrophysiology, at the Inline graphicth timestep. For each cell, we transform the spike magnitudes into percentiles, and then compare the percentile of Inline graphic to the true number of spikes within a 0.1 second window of Inline graphic. Left: For each cell in each of the ten datasets, we display each timestep for which a spike is estimated to occur; however, to avoid overplotting, hexagonal bins are used to represent points covered by the hexagon; darker colors indicate more points. The black curve represents the loess fit across all of the points. Right: Loess curves along with Inline graphic confidence intervals for each dataset. Cells are colored based on the dataset from which they were obtained (see Table S1 of the supplementary material available at Biostatistics online). Details are provided in Section 3.3.

3.2. The solution to (1.2) outperforms the solution to (1.3)

As mentioned earlier, in this article, we have developed not only an algorithm for solving (1.3) that is much faster than the algorithm proposed in Jewell and Witten (2018), but also an algorithm for solving (1.2), which cannot be solved using techniques from Jewell and Witten (2018). By incorporating the fact that a firing neuron causes an increase, but never a decrease, in the calcium concentration, the estimated spikes from problem (1.2) are closer to the ground truth spikes than the estimated spikes from (1.3). In practice, the solutions to (1.2) and (1.3) are typically quite similar; however, the solution to (1.2) benefits from greater interpretability. See Appendix S8 of the supplementary material available at Biostatistics online for an example.

3.3. Comparison of the estimated spike magnitudes from (1.2) to the true number of spikes.

The data from the Inline graphic challenge was resampled to 100 Hz before we downloaded it. At this sampling frequency, since one timestep is just Inline graphicth of a second, there are very few timesteps with more than one true spike. Nonetheless, for instances where there is more than one spike in a single timestep, we wish to ask the question: Do larger values of the estimated spike magnitudes, Inline graphic, correspond to more true spikes (as measured by electrophysiology) in the Inline graphicth timestep?

Figure 4b investigates whether there is a relationship between the estimated spike magnitude Inline graphic and the number of spikes measured by electrophysiology at the Inline graphicth timestep. Because the estimated spike magnitude of Inline graphic is not directly comparable across cells, for each cell we transform the magnitudes into percentiles. We then compare the percentile of Inline graphic to the true number of spikes within a 0.1 second window of Inline graphic. Figure 4b displays the percentiles and the number of spikes across all 174 traces on a test set; tuning parameters were chosen to optimize the van Rossum distance on a training set. The left panel displays a loess curve fit to all ten datasets, and the right panel shows the loess curves along with Inline graphic confidence intervals for each dataset. As expected, a larger value of Inline graphic is associated with more spikes in the ground truth data.

4. Discussion

Determining the times at which a neuron fires from a calcium imaging dataset is a challenging and important problem. In this article, we build upon the nonconvex approach for spike deconvolution proposed in Jewell and Witten (2018). Though Jewell and Witten (2018) proposed a tractable algorithm for solving the nonconvex problem, it is prohibitively slow to run on large populations of neurons for which long recordings are available. The algorithm proposed in this paper solves the optimization problem of Jewell and Witten (2018) for fluorescence traces of 100 000 timesteps in less than a second. Moreover, Algorithm S8.1 of the supplementary material available at Biostatistics online overcomes a limitation of Jewell and Witten (2018) by avoiding “negative” spikes; that is, a decrease in the calcium concentration due to a spike. We show that these algorithms have excellent performance, relative to existing convex relaxations, as quantified by the van Rossum and Victor-Purpura measures, on datasets collected as part of the Inline graphic challenge (http://spikefinder.codeneuro.org/). Moreover, Algorithm S8.1 of the supplementary material available at Biostatistics online was recently used to decode data from nearly Inline graphic neurons in the Allen Institute for Brain Science’s “platform paper” for the Allen Brain Observatory (de Vries and others, 2018).

In this article, we assume that the calcium concentration decays exponentially according to a first-order auto-regressive model. Although this is typically a good approximation, there are datasets for which—due to different experimental conditions—spike times estimated from (1.2) and (1.3) are systematically biased due to model misspecification. In future work, we propose to extend the functional pruning framework to more general calcium models.

In this article, we focus on developing point estimates of the times at which a neuron spikes. However, it is also of interest to propagate uncertainty from the deconvolution procedure to downstream analyses that rely on the spike times. It remains an open question to define the notion of confidence associated with a set of estimated spikes.

Supplementary Material

kxy083_Supplementary_Data

Acknowledgments

We thank Michael Buice, Peter Ledochowitsch, and Michael Oliver at the Allen Institute for Brain Science and Ilana Witten at Princeton for helpful conversations. Conflict of Interest: None declared.

Funding

S.J. received funding from the Natural Sciences and Engineering Research Council of Canada. T.D.H. is partially supported by the Natural Sciences and Engineering Research Council of Canada (RGPGR 448167-2013), and by Canadian Institutes of Health Research (EP1-120608 and EP1-120609). This work was partially supported by Engineering and Physical Sciences Research Council Grant EP/N031938/1 to P.F., and National Science Foundation CAREER DMS-1252624, National Institutes of Health grants DP5OD009145, R01DA047869, and R01EB026908, and a Simons Investigator Award in Mathematical Modeling of Living Systems to D.W.

References

  1. Ahrens M. B., Orger M. B., Robson D. N., Li J. M. and Keller P. J. (2013). Whole-brain functional imaging at cellular resolution using light-sheet microscopy. Nature Methods 10, 413–420. [DOI] [PubMed] [Google Scholar]
  2. Chen T.-W., Wardill T. J., Sun Y., Pulver S. R., Renninger S. L., Baohan A., Schreiter E. R., Kerr R. A., Orger M. B., Jayaraman V.. and others (2013). Ultrasensitive fluorescent proteins for imaging neuronal activity. Nature 499, 295–300. [DOI] [PMC free article] [PubMed] [Google Scholar]
  3. de Vries S. E. J., Lecoq J., Buice M. A., Groblewski P. A., Ocker G. K., Oliver M., Feng D., Cain N., Ledochowitsch P., Millman D.. and others (2018). A large-scale, standardized physiological survey reveals higher order coding throughout the mouse visual cortex. bioRxiv:359513. doi: 10.1101/359513. [DOI] [PMC free article] [PubMed] [Google Scholar]
  4. Deneux T., Kaszas A., Szalay G., Katona G., Lakner T., Grinvald A., Rózsa B. and Vanzetta I. (2016). Accurate spike estimation from noisy calcium signals for ultrafast three-dimensional imaging of large neuronal populations in vivo. Nature Communications 7, 12190. [DOI] [PMC free article] [PubMed] [Google Scholar]
  5. Dombeck D. A., Khabbaz A. N., Collman F., Adelman T. L. and Tank D. W. (2007). Imaging large-scale neural activity with cellular resolution in awake, mobile mice. Neuron 56, 43–57. [DOI] [PMC free article] [PubMed] [Google Scholar]
  6. Dyer E. L., Duarte M. F., Johnson D. H. and Baraniuk R. G. (2010). Recovering spikes from noisy neuronal calcium signals via structured sparse approximation. In: Vigneron V., Zarzoso V., Moreau E., Gribonval R. and Vincent E. (editors), Latent Variable Analysis and Signal Separation. Berlin, Heidelberg: Springer Berlin Heidelberg, pp. 604–611. [Google Scholar]
  7. Dyer E. L., Studer C., Robinson J. T. and Baraniuk R. G. (2013). A robust and efficient method to recover neural events from noisy and corrupted data. In: Neural Engineering (NER), 2013 6th International IEEE/EMBS Conference on IEEE. San Diego, CA, USA: IEEE, pp. 593–596. [Google Scholar]
  8. Friedrich J. and Paninski L. (2016). Fast active set methods for online spike inference from calcium imaging. In: Lee D.D., Sugiyama M., Luxburg U.V., Guyon I. and Garnett R. (editors), Advances In Neural Information Processing Systems. Barcelona, Spain: Curran Associates, Inc., pp. 1984–1992. [Google Scholar]
  9. Friedrich J., Zhou P. and Paninski L. (2017). Fast online deconvolution of calcium imaging data. PLoS Computational Biology 13, e1005423. [DOI] [PMC free article] [PubMed] [Google Scholar]
  10. Gerstner W., Kistler W. M., Naud R. and Paninski L. (2014). Neuronal Dynamics: From Single Neurons to Networks and Models of Cognition. Cambridge: Cambridge University Press. [Google Scholar]
  11. Grewe B. F., Langer D., Kasper H., Kampa B. M. and Helmchen F. (2010). High-speed in vivo calcium imaging reveals neuronal network activity with near-millisecond precision. Nature Methods 7, 399–405. [DOI] [PubMed] [Google Scholar]
  12. Haynes K., Eckley I. A. and Fearnhead P. (2017). Computationally efficient changepoint detection for a range of penalties. Journal of Computational and Graphical Statistics 26, 134–143. [Google Scholar]
  13. Hocking T. D., Rigaill G., Fearnhead P. and Bourque G. (2017). A log-linear time algorithm for constrained changepoint detection. arXiv preprint arXiv:1703.03352. [Google Scholar]
  14. Holekamp T. F., Turaga D. and Holy T. E. (2008). Fast three-dimensional fluorescence imaging of activity in neural populations by objective-coupled planar illumination microscopy. Neuron 57, 661–672. [DOI] [PubMed] [Google Scholar]
  15. Houghton C. and Kreuz T. (2012). On the efficient calculation of van rossum distances. Network: Computation in Neural Systems 23, 48–58. [DOI] [PubMed] [Google Scholar]
  16. Jackson B., Scargle J. D., Barnes D., Arabhi S., Alt A., Gioumousis P., Gwin E., Sangtrakulcharoen P., Tan L. and Tsai T. T. (2005). An algorithm for optimal partitioning of data on an interval. IEEE Signal Processing Letters 12, 105–108. [Google Scholar]
  17. Jewell S. and Witten D. (2018). Exact spike train inference via Inline graphic optimization. The Annals of Applied Statistics 12, 2457–2482. [DOI] [PMC free article] [PubMed] [Google Scholar]
  18. Killick R., Fearnhead P. and Eckley I. A. (2012). Optimal detection of changepoints with a linear computational cost. Journal of the American Statistical Association 107, 1590–1598. [Google Scholar]
  19. Maidstone R., Fearnhead P. and Letchford A. (2018). Detecting changes in slope with an Inline graphic penalty. Journal of Computational and Graphical Statistics, doi: 10.1080/10618600.2018.1512868. [DOI] [Google Scholar]
  20. Maidstone R., Hocking T., Rigaill G. and Fearnhead P. (2017). On optimal multiple changepoint algorithms for large data. Statistics and Computing 27, 519–533. [DOI] [PMC free article] [PubMed] [Google Scholar]
  21. Pachitariu M., Stringer C. and Harris K. D. (2018). Robustness of spike deconvolution for calcium imaging of neural spiking. Journal of Neuroscience 38, 7976–7985. [DOI] [PMC free article] [PubMed] [Google Scholar]
  22. Pnevmatikakis E. A., Merel J., Pakman A. and Paninski L. (2013). Bayesian spike inference from calcium imaging data. In: Signals, Systems and Computers, 2013 Asilomar Conference on IEEE. pp. 349–353. doi: 10.1109/ACSSC.2013.6810293. [DOI] [Google Scholar]
  23. Prevedel R., Yoon Y.-G., Hoffmann M., Pak N., Wetzstein G., Kato S., Schrödel T., Raskar R., Zimmer M., Boyden E. S.. and others (2014). Simultaneous whole-animal 3D imaging of neuronal activity using light-field microscopy. Nature Methods 11, 727–730. [DOI] [PMC free article] [PubMed] [Google Scholar]
  24. Quiroga R. Q. and Panzeri S. (2009). Extracting information from neuronal populations: information theory and decoding approaches. Nature Reviews Neuroscience 10, 173. [DOI] [PubMed] [Google Scholar]
  25. Reinagel P. and Reid R. C. (2000). Temporal coding of visual information in the thalamus. Journal of Neuroscience 20, 5392–5400. [DOI] [PMC free article] [PubMed] [Google Scholar]
  26. Rigaill G. (2015). A pruned dynamic programming algorithm to recover the best segmentations with 1 to k_max change-points. Journal de la Société Française de Statistique 156, 180–205. [Google Scholar]
  27. Sasaki T., Takahashi N., Matsuki N. and Ikegaya Y. (2008). Fast and accurate detection of action potentials from somatic calcium fluctuations. Journal of Neurophysiology 100, 1668–1676. [DOI] [PubMed] [Google Scholar]
  28. Theis L., Berens P., Froudarakis E., Reimer J., Rosón M. R., Baden T., Euler T., Tolias A. S. and Bethge M. (2016). Benchmarking spike rate inference in population calcium imaging. Neuron 90, 471–482. [DOI] [PMC free article] [PubMed] [Google Scholar]
  29. van Rossum M. C. (2001). A novel spike distance. Neural Computation 13, 751–763. [DOI] [PubMed] [Google Scholar]
  30. Victor J. D. and Purpura K. P. (1996). Nature and precision of temporal coding in visual cortex: a metric-space analysis. Journal of Neurophysiology 76, 1310–1326. [DOI] [PubMed] [Google Scholar]
  31. Victor J. D. and Purpura K. P. (1997). Metric-space analysis of spike trains: theory, algorithms and application. Network: Computation in Neural Systems 8, 127–164. [Google Scholar]
  32. Vladimirov N., Mu Y., Kawashima T., Bennett D. V., Yang C.-T., Looger L. L., Keller P. J., Freeman J. and Ahrens M. B. (2014). Light-sheet functional imaging in fictively behaving zebrafish. Nature Methods 11, 883. [DOI] [PubMed] [Google Scholar]
  33. Vogelstein J. T., Packer A. M., Machado T. A., Sippy T., Babadi B., Yuste R. and Paninski L. (2010). Fast nonnegative deconvolution for spike train inference from population calcium imaging. Journal of Neurophysiology 104, 3691–3704. [DOI] [PMC free article] [PubMed] [Google Scholar]
  34. Vogelstein J. T., Watson B. O., Packer A. M., Yuste R., Jedynak B. and Paninski L. (2009). Spike inference from calcium imaging using sequential monte carlo methods. Biophysical Journal 97, 636–655. [DOI] [PMC free article] [PubMed] [Google Scholar]
  35. Yaksi E. and Friedrich R. W. (2006). Reconstruction of firing rate changes across neuronal populations by temporally deconvolved ca2+ imaging. Nature Methods 3, 377–383. [DOI] [PubMed] [Google Scholar]
  36. Zou H. (2006). The adaptive lasso and its oracle properties. Journal of the American Statistical Association 101, 1418–1429. [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Supplementary Materials

kxy083_Supplementary_Data

Articles from Biostatistics (Oxford, England) are provided here courtesy of Oxford University Press

RESOURCES