{"title": "Fast Active Set Methods for Online Spike Inference from Calcium Imaging", "book": "Advances in Neural Information Processing Systems", "page_first": 1984, "page_last": 1992, "abstract": "Fluorescent calcium indicators are a popular means for observing the spiking activity of large neuronal populations. Unfortunately, extracting the spike train of each neuron from raw fluorescence calcium imaging data is a nontrivial problem. We present a fast online active set method to solve this sparse nonnegative deconvolution problem. Importantly, the algorithm progresses through each time series sequentially from beginning to end, thus enabling real-time online spike inference during the imaging session. Our algorithm is a generalization of the pool adjacent violators algorithm (PAVA) for isotonic regression and inherits its linear-time computational complexity. We gain remarkable increases in processing speed:  more than one order of magnitude compared to currently employed state of the art convex solvers relying on interior point methods. Our method can exploit warm starts; therefore optimizing model hyperparameters only requires a handful of passes through the data. The algorithm enables real-time simultaneous deconvolution of $O(10^5)$ traces of whole-brain zebrafish imaging data on a laptop.", "full_text": "Fast Active Set Methods for\n\nOnline Spike Inference from Calcium Imaging\n\n1Grossman Center and Department of Statistics, Columbia University, New York, NY\n\nJohannes Friedrich1,2, Liam Paninski1\n\n2Janelia Research Campus, Ashburn, VA\n\nj.friedrich@columbia.edu, liam@stat.columbia.edu\n\nAbstract\n\nFluorescent calcium indicators are a popular means for observing the spiking ac-\ntivity of large neuronal populations. Unfortunately, extracting the spike train of\neach neuron from raw \ufb02uorescence calcium imaging data is a nontrivial problem.\nWe present a fast online active set method to solve this sparse nonnegative decon-\nvolution problem. Importantly, the algorithm progresses through each time series\nsequentially from beginning to end, thus enabling real-time online spike inference\nduring the imaging session. Our algorithm is a generalization of the pool adjacent\nviolators algorithm (PAVA) for isotonic regression and inherits its linear-time com-\nputational complexity. We gain remarkable increases in processing speed: more\nthan one order of magnitude compared to currently employed state of the art convex\nsolvers relying on interior point methods. Our method can exploit warm starts;\ntherefore optimizing model hyperparameters only requires a handful of passes\nthrough the data. The algorithm enables real-time simultaneous deconvolution of\nO(105) traces of whole-brain zebra\ufb01sh imaging data on a laptop.\n\nIntroduction\n\n1\nCalcium imaging has become one of the most widely used techniques for recording activity from\nneural populations in vivo [1]. The basic principle of calcium imaging is that neural action potentials\n(or spikes), the point process signal of interest, each induce an optically measurable transient response\nin calcium dynamics. The nontrivial problem to extract the spike train of each neuron from a raw\n\ufb02uorescence trace has been addressed with several different approaches, including template matching\n[2] and linear deconvolution [3, 4], which are outperformed by sparse nonnegative deconvolution\n[5]. The latter can be interpreted as the MAP estimate under a generative model (linear convolution\nplus noise; Fig. 1), whereas fully Bayesian methods [6, 7] can provide some further improvements,\nbut are more computationally expensive. Supervised methods trained on simultaneously-recorded\nelectrophysiological and imaging data [8, 9] have also recently achieved state of the art results, but\nare more black-box in nature.\nThe methods above are typically applied to imaging data of\ufb02ine, after the experiment is complete;\nhowever, there is a need for accurate and fast real-time processing to enable closed-loop experiments, a\npowerful strategy for causal investigation of neural circuitry [10]. In particular, observing and feeding\nback the effects of circuit interventions on physiologically relevant timescales will be valuable for\ndirectly testing whether inferred models of dynamics, connectivity, and causation are accurate in vivo,\nand recent experimental advances [11, 12] are now enabling work in this direction. Brain-computer\ninterfaces (BCIs) also rely on real-time estimates of neural activity. Whereas most BCI systems rely\non electrical recordings, BCIs have been driven by optical signals too [13], providing new insight\ninto how neurons change their activity during learning on a \ufb01ner spatial scale than possible with\nintracortical electrodes. Finally, adaptive experimental design approaches [14, 15, 16] also rely on\nonline estimates of neural activity.\n\n30th Conference on Neural Information Processing Systems (NIPS 2016), Barcelona, Spain.\n\n\fFigure 1: Generative autoregressive model for calcium dynamics. Spike train s gets \ufb01ltered to produce calcium\ntrace c; here we used p = 2 as order of the AR process. Added noise yields the observed \ufb02uorescence y.\n\nEven in cases where we do not require the strict timing/latency constraints of real-time processing,\nwe still need methods that scale to large data sets as for example in whole-brain imaging of larval\nzebra\ufb01sh [17, 18]. A further demand for scalability stems from the fact that the deconvolution\nproblem is solved in the inner loop of constrained nonnegative matrix factorization (CNMF) [19], the\ncurrent state of the art for simultaneous denoising, deconvolution, and demixing of spatiotemporal\ncalcium imaging data.\nIn this paper we address the pressing need for scalable online spike inference methods. We build\non the success of framing spike inference as a sparse nonnegative deconvolution problem. Current\nalgorithms employ interior point methods to solve the ensuing optimization problem and are fast\nenough to process hundreds of neurons in about the same time as the recording [5], but will not scale\nto currently obtained larger data sets such as whole-brain zebra\ufb01sh imaging. Furthermore, these\ninterior point methods scale linearly, but they cannot be warm started, i.e. be initialized with the\nsolution from a previous iteration to gain speed-ups, and do not run online.\nWe noted a close connection between the MAP problem and isotonic regression, which \ufb01ts data\nby a monotone piecewise constant function. A classic isotonic regression algorithm is the pool\nadjacent violators algorithm (PAVA) [20, 21], which sweeps through the data looking for violations\nof the monotonicity constraint. When it \ufb01nds one, it adjusts the estimate to the best possible \ufb01t with\nconstraints, which amounts to pooling data points with the same \ufb01tted value. During the sweep\nadjacent pools that violate the constraints are merged. We generalized PAVA to derive an Online\nActive Set method to Infer Spikes (OASIS) that yields speed-ups in processing time by at least one\norder of magnitude compared to interior point methods on both simulated and real data. Further,\nOASIS can be warm-started, which is useful in the inner loop of CNMF, and also when adjusting\nmodel hyperparameters, as we show below. Importantly, OASIS is not only much faster, but operates\nin an online fashion, progressing through the \ufb02uorescence time series sequentially from beginning to\nend. The advances in speed paired with the inherently online fashion of the algorithm enable true\nreal-time online spike inference during the imaging session, with the potential to signi\ufb01cantly impact\nexperimental paradigms. We expect our algorithm to be a useful tool for the neuroscience community,\nto enable new experiments that online access to spike timings affords and to be of interest in other\n\ufb01elds, such as physics and quantitative \ufb01nance, that deal with jump diffusion processes.\nThe rest of this paper is organized as follows: Section 2 introduces the autoregressive model for\ncalcium dynamics. In Section 3 we derive our active set method for the sparse nonnegative deconvo-\nlution problem for the simple case of AR(1) dynamics and generalize it to arbitrary AR(p) processes\nin the Supplementary Material. We further use the problem\u2019s dual formulation to adjust the sparsity\nlevel in a principled way (following [19]), and describe methods for \ufb01tting model hyperparameters\nincluding the coef\ufb01cients of the AR process. In Section 4 we show some results on simulated as well\nas real data. Finally, in Section 5 we conclude with possible further extensions.\n\n2 Autoregressive model for calcium dynamics\nWe assume we observe the \ufb02uorescence signal for T timesteps, and denote by st the number of spikes\nthat the neuron \ufb01red at the t-th timestep, t = 1, ..., T , cf. Figure 1. We approximate the calcium\nconcentration dynamics c using a stable autoregressive process of order p (AR(p)) where p is a small\npositive integer, usually p = 1 or 2,\n\nct =\n\n\u03b3ict\u2212i + st.\n\np(cid:88)\n\ni=1\n\n2\n\nThe observed \ufb02uorescence y \u2208 RT is related to the calcium concentration as [5, 6, 7]:\n\nyt = a ct + \u0001t,\n\n\u0001t \u223c N (0, \u03c32)\n\n(1)\n\n(2)\n\n0150300Time012Fluorescencescy\fwhere a is a nonnegative scalar and the noise is assumed to be i.i.d. zero mean Gaussian with variance\n\u03c32. For the remainder we assume units such that a = 1 without loss of generality. The parameters \u03b3i\nand \u03c3 can be estimated from the autocovariance function and the power spectral density (PSD) of\ny respectively [19]. The autocovariance approach assumes that the spiking signal s comes from a\nhomogeneous Poisson process and in practice often gives a crude estimate of \u03b3i. We will improve on\nthis below (Fig. 3) by \ufb01tting the AR coef\ufb01cients directly, which leads to better estimates, particularly\nwhen the spikes have some signi\ufb01cant autocorrelation.\nThe goal of calcium deconvolution is to extract an estimate of the neural activity s from the vector of\nobservations y. As discussed in [5, 19], this leads to the following nonnegative LASSO problem for\nestimating the calcium concentration:\n\nminimize\n\nc\n\n1\n\n2(cid:107)c \u2212 y(cid:107)2 + \u03bb(cid:107)s(cid:107)1\n\nsubject to s = Gc \u2265 0\n\nwhere the (cid:96)1 penalty enforces sparsity of the neural activity and the lower triangular matrix G is\nde\ufb01ned as:\n\n\uf8eb\uf8ec\uf8ec\uf8ed 1\n\nG =\n\n0\n0\n1\n\n. . .\n. . .\n. . .\n\n0\n\u2212\u03b31\n1\n\u2212\u03b32 \u2212\u03b31\n...\n. . .\n. . .\n. . . \u2212\u03b32 \u2212\u03b31\n\n. . .\n\n0\n\n\uf8f6\uf8f7\uf8f7\uf8f8\n\n0\n0\n0\n\n...\n\n1\n\n(3)\n\n(4)\n\nFollowing the approach in [5] the spike signal s is relaxed from nonnegative integers to arbitrary\nnonnegative values.\n\n3 Derivation of the active set algorithm\nThe optimization problem (3) could be solved using generic convex program solvers. Here we derive\nthe much faster Online Active Set method to Infer Spikes (OASIS).\n\n3.1 Online Active Set method to Infer Spikes (OASIS)\nFor simplicity we consider \ufb01rst the AR(1) model and defer the cumbersome general case p > 1 to the\nSupplementary Material. We begin by inserting the de\ufb01nition of s (Eq. 3, skipping the index of \u03b3 for\na single AR coef\ufb01cient). Using that s is constrained to be nonnegative yields for the sparsity penalty\n\nGk,tct = \u03bb\n\n(1 \u2212 \u03b3 + \u03b3\u03b4tT )ct =\n\n\u00b5tct = \u00b5(cid:62)c\n\n(5)\n\nT(cid:88)\n\nt=1\n\nT(cid:88)\n\nt=1\n\nT(cid:88)\n\nT(cid:88)\n\nt=1\n\nk=1\n\n\u03bb(cid:107)s(cid:107)1 = \u03bb1(cid:62)s = \u03bb\nT(cid:88)\n(ct \u2212 yt)2 +\n\nminimize\n\n1\n2\n\nc\n\nt=1\n\nT(cid:88)\n\nt=1\n\nwith \u00b5t := \u03bb(1 \u2212 \u03b3 + \u03b3\u03b4tT ) (with \u03b4 denoting Kronecker\u2019s delta) by noting that the sum of the last\ncolumn of G is 1, whereas all other columns sum to (1 \u2212 \u03b3). Now the problem\n\n\u00b5tct\n\nsubject to ct+1 \u2265 \u03b3ct \u2265 0 \u2200t\n\n(6)\n\nshares some similarity to isotonic regression with the constraint ct+1 \u2265 ct. However, our constraint\nct+1 \u2265 \u03b3ct bounds the rate of decay instead of enforcing monotonicity. We generalize PAVA to\nhandle the additional factor \u03b3. The algorithm is based on the following: For an optimal solution, if\nyt < \u03b3yt\u22121, then the constraint becomes active and holds with equality, ct = \u03b3ct\u22121. (Supposing\nthe opposite, i.e. ct > \u03b3ct\u22121, we could move ct\u22121 and ct by some small \u0001 to decreases the objective\nwithout violating the constraints, yielding a proof by contradiction.)\nWe \ufb01rst present the algorithm in a way that conveys its core ideas, then improve the algorithm\u2019s\nef\ufb01ciency by introducing \u201cpools\u201d of variables (adjacent ct values) which are updated simultaneously.\nWe introduce temporary values c(cid:48) and initialize them to the unconstrained least squares solution,\nc(cid:48) = y \u2212 \u00b5. Initially all constraints are in the \u201cpassive set\u201d and possible violations are \ufb01xed by\nsubsequently adding the respective constraints to the \u201cactive set.\u201d Starting at t = 2 one moves\nforward until a violation of the constraint c(cid:48)\n\u03c4\u22121 at some time \u03c4 is detected (Fig. 2A). Now\nthe constraint is added to the active set and enforced by setting c(cid:48)\n\u03c4\u22121. Updating the two\n\u03c4\u22121 + \u00b5\u03c4 \u03b3c(cid:48)\n\u03c4\u22121 yields an\ntime steps by minimizing 1\n\u03c4\u22121. However, this updated value can violate the constraint c(cid:48)\nupdated value c(cid:48)\n\u03c4\u22121 \u2265 \u03b3c(cid:48)\n\u03c4\u22122 and we\nneed to update c(cid:48)\n\u03c4\u22122 as well, etc., until we have backtracked some \u2206t steps to time \u02c6t = \u03c4 \u2212 \u2206t\n\n\u03c4 = \u03b3c(cid:48)\n\u03c4\u22121)2 + \u00b5\u03c4\u22121c(cid:48)\n\n2 (y\u03c4\u22121 \u2212 c(cid:48)\n\n2 (y\u03c4 \u2212 \u03b3c(cid:48)\n\n\u03c4 \u2265 \u03b3c(cid:48)\n\n\u03c4\u22121)2 + 1\n\n3\n\n\fA\n\nmove forward \u0017\n\nB\n\ntrack back \u0013\n\nC\n\nmove forward \u0013\n\nD\n\nmove forward \u0013\n\nE\n\nmove forward \u0017\n\nF\n\ntrack back \u0017\n\nG\n\ntrack back \u0013\n\nH\n\nmove forward \u0013\n\nI\n\ntrack back \u0013\n\n. . .\n\nFigure 2: Illustration of OASIS for an AR(1) process (see Supplementary Video). Red lines depict true spike\ntimes. The shaded background shows how the time points are gathered in pools. The pool currently under\nconsideration is indicated by the blue crosses. A constraint violation is encountered for the second time step (A)\nleading to backtracking and merging (B). The algorithm proceeds moving forward (C-E) until the next violation\noccurs (E) and triggers backtracking and merging (F-G) as long as constraints are violated. When the most\nrecent spike time has been reached (G) the algorithm proceeds forward again (H). The process continues until\nthe end of the series has been reached (I). The solution is obtained and pools span the inter-spike-intervals.\n\n\u02c6t \u2265 \u03b3c(cid:48)\nwhere the constraint c(cid:48)\n\u02c6t\u22121 is already valid. At most one needs to backtrack to the most recent\nspike, because c(cid:48)\n> \u03b3c(cid:48)\n\u02c6t\u22121 at spike times \u02c6t (Eq. 1). (Because such delays could be too long for some\n\u02c6t\ninteresting closed loop experiments, we show in the Supplementary Material how well the method\nperforms if backtracking is limited to just few frames.) Solving\n\n\u2206t(cid:88)\n\nt=0\n\n(\u03b3tc(cid:48)\n\n\u2206t(cid:88)\n\u02c6t \u2212 yt+\u02c6t)2 +\n(cid:80)\u2206t\n(cid:80)\u2206t\nt=0(yt+\u02c6t \u2212 \u00b5t+\u02c6t)\u03b3t\n\nt=0\n\nt=0 \u03b32t\n= \u03b3tc(cid:48)\n\n\u00b5t+\u02c6t\u03b3tc(cid:48)\n\n\u02c6t\n\n(7)\n\n(8)\n\nminimize\n\n1\n2\nby setting the derivative to zero yields\nc(cid:48)\n\u02c6t =\n\nc(cid:48)\n\u02c6t\n\n\u02c6t+t\n\n1:\u2206t+1(y\u2212\u00b5)\u02c6t:\u03c4\n\u02c6t could be expressed in the more familiar regression form as h(cid:62)\nh(cid:62)\n1:\u2206t+1h1:\u2206t+1\n\nand the next values are updated according to c(cid:48)\n\u02c6t for t = 1, ..., \u2206t. (Along the way it is worth\nnoting that, because a spike induces a calcium response described by kernel h with components\nh1+t = \u03b3t, c(cid:48)\n, where\nwe used the notation vi:j to describe a vector formed by components i to j of v.) Now one moves\nforward again (Fig. 2C-E) until detection of the next violation (Fig. 2E), backtracks again to the most\nrecent spike (Fig. 2G), etc. Once the end of the time series is reached (Fig. 2I) we have found the\noptimal solution and set c = c(cid:48).\nIn a worst case situation a constraint violation is encountered at every step of the forward sweep\n2 \u2212 1 updates\nand an O(T 2) algorithm. In order to obtain a more ef\ufb01cient algorithm we introduce pools which are\ntuples of the form (vi, wi, ti, li) with value vi, weight wi, event time ti and pool length li. Initially\nthere is a pool (yt \u2212 \u00b5t, 1, t, 1) for each time step t. During backtracking pools get combined and only\nthe \ufb01rst value vi = c(cid:48)\nti is explicitly considered, while the other values are merely de\ufb01ned implicitly\nvia ct+1 = \u03b3ct. The constraint ct+1 \u2265 \u03b3ct translates to vi+1 \u2265 \u03b3livi as the criterion determining\nwhether pools need to be combined. The introduced weights allow ef\ufb01cient value updates whenever\npools are merged by avoiding recalculating the sums in equation (8). Values are updated according to\n\nthrough the series. Updating all t values up to time t yields overall(cid:80)T\n\nt=2 t = T (T +1)\n\nwhere the denominator is the new weight of the pool and the pool lengths are summed\n\nvi \u2190\n\nwivi + \u03b3liwi+1vi+1\n\nwi + \u03b32liwi+1\n\nwi \u2190 wi + \u03b32liwi+1\nli \u2190 li + li+1.\n\n4\n\n(9)\n\n(10)\n(11)\n\n\fWhenever pools i and i + 1 are merged, former pool i + 1 is removed and the succeeding pool\nindices decreased by 1. It is easy to prove by induction that the updates according to equations\n(9-11) guarantee that equation (8) holds for all values (see Supplementary Material) without having to\nexplicitly calculate it. The latter would be expensive for long pools, whereas merging two pools has\nO(1) complexity independent of the pool lengths. With pooling the considered worst case situation\nresults in a single pool that is updated at every step forward, yielding O(T ) complexity. Analogous\nto PAVA, the updates solve equation (6) not just greedily but optimally. The \ufb01nal algorithm is\nsummarized in Algorithm 1 and illustrated in Figure 2 as well as in the Supplementary Video.\n\ni=1 \u2190 {(yt \u2212 \u03bb(1 \u2212 \u03b3 + \u03b3\u03b4tT ), 1, t, 1)}T\n\nwhile i < |P| and vi+1 \u2265 \u03b3li vi do i \u2190 i + 1\nif i == |P| then break\nwhile i > 0 and vi+1 < \u03b3li vi do\n\nAlgorithm 1 Fast online deconvolution algorithm for AR(1) processes with positive jumps\nRequire: data y, decay factor \u03b3, regularization parameter \u03bb\n1: initialize pools as P = {(vi, wi, ti, li)}T\n2: while i < |P| do\n3:\n4:\n5:\n6:\n7:\n8:\n9:\n10: for (v, w, t, l) in P do\n11:\n12: return c\n\ni \u2190 i + 1\nfor \u03c4 = 0, ..., l \u2212 1 do ct+\u03c4 \u2190 \u03b3\u03c4 max(0, v)\n\nPi \u2190(cid:16) wivi+\u03b3li wi+1vi+1\n\nremove Pi+1\ni \u2190 i \u2212 1\n\n, wi + \u03b32li wi+1, ti, li + li+1\n\nwi+\u03b32li wi+1\n\n(cid:17)\n\nt=1 and let i \u2190 1\n\n(cid:46) iterate until end\n(cid:46) move forward\n\n(cid:46) track back\n(cid:46) Eqs. (9-11)\n\n(cid:46) construct solution for all t\n(cid:46) enforce ct \u2265 0 via max\n\n3.2 Dual formulation with hard noise constraint\nThe formulation above contains a troublesome free sparsity parameter \u03bb (implicit in \u00b5). A more\nrobust deconvolution approach eliminates it by inclusion of the residual sum of squares (RSS) as a\nhard constraint and not as a penalty term in the objective function [19]. The expected RSS satis\ufb01es\n(cid:104)(cid:107)c \u2212 y(cid:107)2(cid:105) = \u03c32T and by the law of large numbers (cid:107)c \u2212 y(cid:107)2 \u2248 \u03c32T with high probability, leading\nto the constrained problem\n(12)\n\nminimize\n\nsubject to s = Gc \u2265 0\n\nand (cid:107)c \u2212 y(cid:107)2 \u2264 \u03c32T.\n\n(cid:107)s(cid:107)1\n\nc\n\n(As noted above, we estimate \u03c3 using the power spectral estimator described in [19].) We will solve\nthis problem by increasing \u03bb in the dual formulation until the noise constraint is tight. We start with\nsome small \u03bb, e.g. \u03bb = 0, to obtain a \ufb01rst partitioning into pools P, cf. Figure 3A below. From\nequations (8-10) (and see also S11) along with the de\ufb01nition of \u00b5 (Eq. 5) it follows that given the\nsolution (vi, wi, ti, li), where\n\nvi =\n\n(cid:80)li\u22121\n(cid:80)li\u22121\nt=0 (yti+t \u2212 \u00b5ti+t)\u03b3t\nt=0 \u03b32t\n(cid:80)li\u22121\ni, w(cid:48)\ni, l(cid:48)\ni, t(cid:48)\nt=0 (1 \u2212 \u03b3 + \u03b3\u03b4ti+t,T )\u03b3t\n\ni) for \u03bb + \u2206\u03bb is\n\n=\n\nwi\n\nv(cid:48)\ni = vi \u2212 \u2206\u03bb\n\nfor some \u03bb, the solution (v(cid:48)\n\n(cid:80)li\u22121\nt=0 (yti+t \u2212 \u03bb(1 \u2212 \u03b3 + \u03b3\u03b4ti+t,T ))\u03b3t\n\nwi\n\n= vi \u2212 \u2206\u03bb\n\n1 \u2212 \u03b3li(1 \u2212 \u03b4iz)\n\nwi\n\n(13)\n\nwhere z = |P| is the index of the last pool and because pools are updated independently we make\nthe approximation that no changes in the pool structure occur. Inserting equation (13) into the noise\nconstraint (Eq. 12) results in\n\nz(cid:88)\n\nli\u22121(cid:88)\n\n(cid:18)(cid:18)\n\ni=1\n\nt=0\n\n1 \u2212 \u03b3li(1 \u2212 \u03b4iz)\n\nvi \u2212 \u2206\u03bb\n\nwi\n\u2212\u03b2+\u221a\u03b22\u22124\u03b1\u0001\n\n(cid:19)\n\n(cid:19)2\nwith \u03b1 =(cid:80)\n\n\u03b3t \u2212 yti+t\n\nand \u0001 =(cid:80)\n\nand solving the quadratic equation yields \u2206\u03bb =\n\ni,t \u03c72\n\nit \u2212 \u03c32T where \u03beit = 1\u2212\u03b3li (1\u2212\u03b4iz)\n\nwi\n\n2\u03b1\n\ni,t \u03be2\n\u03b3t and \u03c7it = yti+t \u2212 vi\u03b3t.\n\n= \u03c32T\n\n(14)\n\nit, \u03b2 = 2(cid:80)\n\ni,t \u03c7it\u03beit\n\n5\n\n\fA\n\nB\n\nC\n\nD\n\nE\n\nF\n\nrun Alg. 1\n\nrun Alg. 1\n\nrun Alg. 1\n\nIterate B \u2013 E\n\n\u223c3 iterations\nto converge\n\n...\n\nFigure 3: Optimizing sparsity parameter \u03bb and AR coef\ufb01cient \u03b3. (A) Running the active set method, with\nconservatively small estimate of \u03b3, yields an initial denoised estimate (blue) of the data (yellow) roughly\ncapturing the truth (red). We also report the correlation between the deconvolved estimate and true spike train\nas direct measure for the accuracy of spike train inference. (B) Updating sparsity parameter \u03bb according to\nEq. (14) such that RSS = \u03c32T (left) shifts the current estimate downward (right, blue). (C) Running the active\nset method enforces the constraints again and is fast due to warm-starting. (D) Updating \u03b3 by minimizing the\npolynomial function RSS(\u03b3) and (E) running the warm-started active set method completes one iteration, which\nyields already a decent \ufb01t. (F) A few more iterations improve the solution further and the obtained estimate is\nhardly distinguishable from the one obtained with known true \u03b3 (turquoise dashed on top of blue solid line).\nNote that determining \u03b3 based on the autocovariance (purple) yields a crude solution that even misses spikes (at\n24.6 s and 46.5 s).\n\nThe solution \u2206\u03bb provides a good approximate proposal step for updating the pool values vi (using\nEq. 13). Since this update proposal is only approximate it can give rise to violated constraints (e.g.,\nnegative values of vi). To satisfy all constraints Algorithm 1 is run to update the pool structure, cf.\n(cid:48) instead of the\nFigure 3C, but with a warm start: we initialize with the current set of merely z pools P\nT pools for a cold start (Alg. 1, line 1). This step returns a set of vi values that satisfy the constraints\nand may merge pools (i.e., delete spikes); then the procedure (update \u03bb then rerun the warm-started\nAlgorithm 1) can be iterated until no further pools need to be merged, at which point the procedure\nhas converged. In practice this leads to an increasing sequence of \u03bb values (corresponding to an\nincreasingly sparse set of spikes), and no pool-split (i.e., add-spike) moves are necessary1.\nThis warm-starting approach brings major speed bene\ufb01ts: after the residual is updated following a\n\u03bb update, the computational cost of the algorithm is linear in the number of pools z, hence warm\nstarting drastically reduces computational costs from k1T to k2z with proportionality constants k1\nand k2: if no pool boundary updates are needed then after warm starting the algorithm only needs to\npass once through all pools to verify that no constraint is violated, whereas a cold start might involve\na couple passes over the data to update pools, so k2 is typically signi\ufb01cantly smaller than k1, and z is\ntypically much smaller than T (especially in sparsely-spiking regimes).\n\n3.3 Optimizing the AR coef\ufb01cient\nThus far the parameter \u03b3 has been known or been estimated based on the autocovariance function.\nWe can improve upon this estimate by optimizing \u03b3 as well, which is illustrated in Figure 3. After\nupdating \u03bb followed by running Algorithm 1, we perform a coordinate descent step in \u03b3 that minimizes\nthe RSS, cf. Figure 3D. The RSS as a function of \u03b3 is a high order polynomial, cf. equation (8), and\nwe need to settle for numerical solutions. We used Brent\u2019s method [22] with bounds 0 \u2264 \u03b3 < 1. One\niteration consists now of steps B-E in Figure 3, while for known \u03b3 only B-C were necessary.\n\n1Note that it is possible to cheaply detect any violations of the KKT conditions in a candidate solution; if\nsuch a violation is detected, the corresponding pool could be split and the warm-started Algorithm 1 run locally\nnear the detected violations. However, as we noted, due to the increasing \u03bb sequence we did not \ufb01nd this step to\nbe necessary in the examples examined here.\n\n6\n\n02Correlation:0.734TruthEstimateData0\u03bb\u2217\u03bb\u03c32TRSS\u03bb\u221202Correlation:0.75302FluorescenceCorrelation:0.767\u03b3\u2217\u03b3\u03c32TRSS\u03b3\u221202Correlation:0.77702Correlation:0.79110203040Time[s]02Correlation:0.849true\u03b3\u03b3fromautocovariance\fA\n\nB\n\nC\n\nD\n\nE\n\nFigure 4: OASIS produces the same high quality results as convex solvers at least an order of magnitude faster.\n(A) Raw and inferred traces for simulated AR(1) data, (B) simulated AR(2) and (C) real data from [29] modeled\nas AR(2) process. OASIS solves equation (3) exactly for AR(1) and just approximately for AR(2) processes,\nnevertheless well extracting spikes. (D) Computation time for simulated AR(1) data with given \u03bb (blue circles,\nEq. 3) or inference with hard noise constraint (green x, Eq. 12). GUROBI failed on the noise constrained\nproblem. (E) Computation time for simulated AR(2) data.\n\n4 Results\n\n4.1 Benchmarking OASIS\n\nWe generated datasets of 20 \ufb02uorescence traces each for p = 1 and 2 with a duration of 100 s at\na framerate of 30 Hz, such that T = 3,000 frames. The spiking signal came from a homogeneous\nPoisson process. We used \u03b3 = 0.95, \u03c3 = 0.3 for the AR(1) model and \u03b31 = 1.7, \u03b32 = \u22120.712,\n\u03c3 = 1 for the AR(2) model. Figures 4A-C are reassuring that our suggested (dual) active set method\nyields indeed the same results as other convex solvers for an AR(1) process and that spikes are\nextracted well. For an AR(2) process OASIS is greedy and yields good results that are similar to the\none obtained with convex solvers (lower panels in Fig. 4B and C), with virtually identical denoised\n\ufb02uorescence traces (upper panels). An exact fast (primal) active set method method for this case is\npresented in the extended journal version of this paper [23].\nFigures 4D,E report the computation time (\u00b1SEM) averaged over all 20 traces and ten runs per trace\non a MacBook Pro with Intel Core i5 2.7 GHz CPU. We compared the run time of our algorithm\nto a variety of state of the art convex solvers that can all be conveniently called from the convex\noptimization toolbox CVXPY [24]: embedded conic solver (ECOS, [25]), MOSEK [26], splitting\nconic solver (SCS, [27]) and GUROBI [28]. With given sparsity parameter \u03bb (Eq. 3) OASIS is about\ntwo magnitudes faster than any other method for an AR(1) process (Fig. 4D, blue disks) and more\nthan one magnitude for an AR(2) process (Fig. 4E). Whereas the other solvers take almost the same\ntime for the noise constrained problem (Eq. 12, Fig. 4D,E, green x), our method takes about three\ntimes longer to \ufb01nd the value of the dual variable \u03bb compared to the formulation where the residual is\npart of the objective; nevertheless it still outperforms the other algorithms by a huge margin.\nWe also ran the algorithms on longer traces of length T = 30,000 frames, con\ufb01rming that OASIS\nscales linearly with T . Our active set method maintained its lead by 1-2 orders of magnitude in\ncomputing time. Further, compared to our active set method the other algorithms required at least an\norder of magnitude more RAM, con\ufb01rming that OASIS is not only faster but much more memory\nef\ufb01cient. Indeed, because OASIS can run in online mode the memory footprint can be O(1), instead\nof O(T ).\nWe veri\ufb01ed these results on real data as well. Running OASIS with the hard noise constraint and\np = 2 on the GCaMP6s dataset collected at 60 Hz from [29] took 0.101 \u00b1 0.005 s per trace, whereas\nthe fastest other methods required 2.37 \u00b1 0.12 s. Figure 4C shows the real data together with the\ninferred denoised and deconvolved traces as well as the true spike times, which were obtained by\nsimultaneous electrophysiological recordings [29].\nWe also extracted each neuron\u2019s \ufb02uorescence activity using CNMF from an unpublished whole-brain\nzebra\ufb01sh imaging dataset from the M. Ahrens lab. Running OASIS with hard noise constraint and\n\n7\n\n02Fluor.OASISCVXPYTruthData0255001Activity06Fluor.030Time[s]01Activity030Time[s]OASISECOSMOSEKSCSGUROBI00.51.0Time[s]O.E.M.S.G.0.010.11OASISECOSMOSEKSCSGUROBISolver012Time[s]O.E.M.S.G.0.010.11\fp = 1 (chosen because the calcium onset was fast compared to the acquisition rate of 2 Hz) on 10,000\ntraces out of a total of 91,478 suspected neurons took 81.5 s whereas ECOS, the fastest competitor,\nneeded 2,818.1 s. For all neurons we would hence expect 745 s for OASIS, which is below the 1,500 s\nrecording duration, and over 25,780 s for ECOS and other candidates.\n\n4.2 Hyperparameter optimization\nWe have shown that we can solve equation (3) and equation (12) faster than interior point methods.\nThe AR coef\ufb01ent \u03b3 was either known or estimated based on the autocorrelation in the above analyses.\nThe latter approach assumes that the spiking signal comes from a homogeneous Poisson process,\nwhich does not generally hold for realistic data. Therefore we were interested in optimizing not\nonly the sparsity parameter \u03bb, but also the AR(1) coef\ufb01ent \u03b3. To illustrate the optimization of both,\nwe generated a \ufb02uorescence trace with spiking signal from an inhomogeneous Poisson process\nwith sinusoidal instantaneous \ufb01ring rate (Fig. 3), thus mimicking realistic data. We conservatively\ninitialized \u03b3 to a small value of 0.9. The value obtained based on the autocorrelation was 0.9792\nand larger than the true value of 0.95. The left panels in Figures 3B and D illustrate the update of\n\u03bb from the previous value \u03bb\u2212 to \u03bb\u2217 by solving a quadratic equation analytically (Eq. 14) and the\nupdate of \u03b3 by numerical minimization of a high order polynomial respectively. Note that after\nmerely one iteration (Fig. 3E) a good solution is obtained and after three iterations the solution is\nvirtually identical to the one obtained when the true value of \u03b3 has been provided (Fig. 3F). This\nholds not only visually, but also when judged by the correlation between deconvolved activity and\nground truth spike train, which was 0.869 compared to merely 0.773 if \u03b3 was obtained based on the\nautocorrelation. The optimization was robust to the initial value of \u03b3, as long as it was positive and\nnot, or only marginally, greater than the true value. The value obtained based on the autocorrelation\nwas considerably greater and partitioned the time series into pools in a way that missed entire spikes.\nA quanti\ufb01cation of the computing time for hyperparameter optimization as well as means to reduce it\nare presented in the extended journal version [23].\n\n5 Conclusions\nWe presented an online active set method for spike inference from calcium imaging data. We assumed\nthat the forward model to generate a \ufb02uorescence trace from a spike train is linear-Gaussian. Future\nwork will extend the method to nonlinear models [30] incorporating saturation effects and a noise\nvariance that increases with the mean \ufb02uorescence to better resemble the Poissonian statistics of\nphoton counts. In the Supplementary Material we already extend our mathematical formulation to\ninclude weights for each time point as a \ufb01rst step in this direction.\nFurther development, contained in the extended journal version [23], includes and optimizes an\nexplicit \ufb02uorescence baseline. It also provides means to speed up the optimization of model hyperpa-\nrameters, including the added baseline. It presents an exact and fast (primal) active set method for\nAR(p > 1) processes and more general calcium response kernels. A further extension is to add the\nconstraint that positive spikes need to be larger than some minimal value, which renders the problem\nnon-convex. A minor modi\ufb01cation to our algorithm enables it to \ufb01nd an (approximate) solution of this\nnon-convex problem, which can be marginally better than the solution obtained with (cid:96)1 regularizer.\n\nAcknowledgments\n\nWe would like to thank Misha Ahrens and Yu Mu for providing whole-brain imaging data of larval\nzebra\ufb01sh. We thank John Cunningham for fruitful discussions and Scott Linderman as well as Daniel\nSoudry for valuable comments on the manuscript.\nFunding for this research was provided by Swiss National Science Foundation Research Award\nP300P2_158428, Simons Foundation Global Brain Research Awards 325171 and 365002, ARO\nMURI W911NF-12-1-0594, NIH BRAIN Initiative R01 EB22913 and R21 EY027592, DARPA\nN66001- 15-C-4032 (SIMPLEX), and a Google Faculty Research award; in addition, this work\nwas supported by the Intelligence Advanced Research Projects Activity (IARPA) via Department of\nInterior/ Interior Business Center (DoI/IBC) contract number D16PC00003. The U.S. Government\nis authorized to reproduce and distribute reprints for Governmental purposes notwithstanding any\ncopyright annotation thereon. Disclaimer: The views and conclusions contained herein are those\nof the authors and should not be interpreted as necessarily representing the of\ufb01cial policies or\nendorsements, either expressed or implied, of IARPA, DoI/IBC, or the U.S. Government.\n\n8\n\n\fReferences\n[1] C Grienberger and C Konnerth. Imaging calcium in neurons. Neuron, 73(5):862\u2013885, 2012.\n[2] B F Grewe, D Langer, H Kasper, B M Kampa, and F Helmchen. High-speed in vivo calcium imaging\n\nreveals neuronal network activity with near-millisecond precision. Nat Methods, 7(5):399\u2013405, 2010.\n\n[3] E Yaksi and R W Friedrich. Reconstruction of \ufb01ring rate changes across neuronal populations by temporally\n\ndeconvolved Ca2+ imaging. Nat Methods, 3(5):377\u2013383, 2006.\n\n[4] T F Holekamp, D Turaga, and T E Holy. Fast three-dimensional \ufb02uorescence imaging of activity in neural\n\npopulations by objective-coupled planar illumination microscopy. Neuron, 57(5):661\u2013672, 2008.\n\n[5] J T Vogelstein et al. Fast nonnegative deconvolution for spike train inference from population calcium\n\nimaging. J Neurophysiol, 104(6):3691\u20133704, 2010.\n\n[6] J T Vogelstein, B O Watson, A M Packer, R Yuste, B Jedynak, and L Paninski. Spike inference from\n\ncalcium imaging using sequential monte carlo methods. Biophys J, 97(2):636\u2013655, 2009.\n\n[7] E A Pnevmatikakis, J Merel, A Pakman, and L Paninski. Bayesian spike inference from calcium imaging\n\ndata. Asilomar Conference on Signals, Systems and Computers, 2013.\n\n[8] T Sasaki, N Takahashi, N Matsuki, and Y Ikegaya. Fast and accurate detection of action potentials from\n\nsomatic calcium \ufb02uctuations. J Neurophysiol, 100(3):1668\u20131676, 2008.\n\n[9] L Theis et al. Benchmarking spike rate inference in population calcium imaging. Neuron, 90(3):471\u2013482,\n\n2016.\n\n[10] L Grosenick, J H Marshel, and K Deisseroth. Closed-loop and activity-guided optogenetic control. Neuron,\n\n86(1):106\u2013139, 2015.\n\n[11] J P Rickgauer, K Deisseroth, and D W Tank. Simultaneous cellular-resolution optical perturbation and\n\nimaging of place cell \ufb01ring \ufb01elds. Nat Neurosci, 17(12):1816\u20131824, 2014.\n\n[12] A M Packer, L E Russell, H WP Dalgleish, and M H\u00e4usser. Simultaneous all-optical manipulation and\n\nrecording of neural circuit activity with cellular resolution in vivo. Nat Methods, 12(2):140\u2013146, 2015.\n\n[13] K B Clancy, A C Koralek, R M Costa, D E Feldman, and J M Carmena. Volitional modulation of optically\n\nrecorded calcium signals during neuroprosthetic learning. Nat Neurosci, 17(6):807\u2013809, 2014.\n\n[14] J Lewi, R Butera, and L Paninski. Sequential optimal design of neurophysiology experiments. Neural\n\nComput, 21(3):619\u2013687, 2009.\n\n[15] M Park and J W Pillow. Bayesian active learning with localized priors for fast receptive \ufb01eld characteriza-\n\ntion. In Adv Neural Inf Process Syst, pages 2348\u20132356, 2012.\n\n[16] B Shababo, B Paige, A Pakman, and L Paninski. Bayesian inference and online experimental design for\n\nmapping neural microcircuits. In Adv Neural Inf Process Syst, pages 1304\u20131312, 2013.\n\n[17] M B Ahrens, M B Orger, D N Robson, J M Li, and P J Keller. Whole-brain functional imaging at cellular\n\nresolution using light-sheet microscopy. Nat Methods, 10(5):413\u2013420, 2013.\n\n[18] N Vladimirov et al. Light-sheet functional imaging in \ufb01ctively behaving zebra\ufb01sh. Nat Methods, 2014.\n[19] E A Pnevmatikakis et al. Simultaneous denoising, deconvolution, and demixing of calcium imaging data.\n\nNeuron, 89(2):285\u2013299, 2016.\n\n[20] M Ayer et al. An empirical distribution function for sampling with incomplete information. Ann Math Stat,\n\n26(4):641\u2013647, 1955.\n\n[21] R E Barlow, D J Bartholomew, JM Bremner, and H D Brunk. Statistical inference under order restrictions:\n\nThe theory and application of isotonic regression. Wiley New York, 1972.\n\n[22] R P Brent. Algorithms for Minimization Without Derivatives. Courier Corporation, 1973.\n[23] J Friedrich, P Zhou, and L Paninski. Fast active set methods for online deconvolution of calcium imaging\n\ndata. arXiv, 1609.00639, 2016.\n\n[24] S Diamond and S Boyd. CVXPY: A Python-embedded modeling language for convex optimization. J\n\nMach Learn Res, 17(83):1\u20135, 2016.\n\n[25] A Domahidi, E Chu, and S Boyd. ECOS: An SOCP solver for embedded systems. In European Control\n\nConference (ECC), pages 3071\u20133076, 2013.\n\n[26] E D Andersen and K D Andersen. The MOSEK interior point optimizer for linear programming: an\nIn High performance optimization, pages 197\u2013232.\n\nimplementation of the homogeneous algorithm.\nSpringer, 2000.\n\n[27] B O\u2019Donoghue, E Chu, N Parikh, and S Boyd. Conic optimization via operator splitting and homogeneous\n\nself-dual embedding. J Optim Theory Appl, pages 1\u201327, 2016.\n\n[28] Gurobi Optimization Inc. Gurobi optimizer reference manual, 2015.\n[29] T-W Chen et al. Ultrasensitive \ufb02uorescent proteins for imaging neuronal activity. Nature, 499(7458):295\u2013\n\n300, 2013.\n\n[30] T A Pologruto, R Yasuda, and K Svoboda. Monitoring neural activity and [Ca2+] with genetically encoded\n\nCa2+ indicators. J Neurosci, 24(43):9572\u20139579, 2004.\n\n9\n\n\f", "award": [], "sourceid": 1069, "authors": [{"given_name": "Johannes", "family_name": "Friedrich", "institution": "Columbia University"}, {"given_name": "Liam", "family_name": "Paninski", "institution": "Columbia University"}]}