Path storage in the particle filter
Pierre E. Jacob, Lawrence Murray, Sylvain Rubenthaler
Introduction
Consider the problem of filtering in state-space models (Cappé et al, 2005) defined by and for
Here is a hidden Markov chain in some space with initial distribution and transition density . The observations in space are conditionally independent given , with measurement density . For any vector , introduce the notation and .
We denote by the distribution of the path given the observations available at time , from which the filtering distribution of given , denoted by , is a marginal. The bootstrap particle filter (Gordon et al, 1993), described in Algorithm 1, recursively approximates the distributions , and has borne various other sequential Monte Carlo methods (Doucet et al, 2001; Doucet and Johansen, 2011).
In Algorithm 1 the resampling step relies on some distribution on taking normalized weights as parameters.
At each time , Algorithm 1 approximates and by the empirical distributions
It has been shown in Whiteley (2011); Douc et al (2012); van Handel (2009), and in Theorem 7.4.4 in Del Moral (2004) that converges to with under mild conditions on the model laws , and that the Monte Carlo error is constant with respect to . However it is also well-known that the path measures , while converging to with , have a Monte Carlo error typically exploding at least quadratically with the time (Del Moral and Doucet, 2003; Poyiadjis et al, 2011). Indeed the paths quickly coalesce due to the resampling steps, thus providing a poor approximation of the marginal distributions for large values of . In the following we refer to the collection of paths as the ancestry tree, to each (for and ) as a node, to each more specifically as a leaf node, and to paths as branches.
Figure 1 might help to visualise the typical shape of the ancestry tree generated by a particle filter. The time at which all the branches coalesce, denoted by , separates the “trunk” made of a unique branch from to from the “crown” made of all the branches from to . Despite its negative consequence on the estimation of filtering quantities, the particle degeneracy phenomenon results in crowns of small sizes, allowing full trees to be stored at low memory cost. This can be beneficial whenever full paths of the particle filter are required, such as for the conditional sequential Monte Carlo and particle Gibbs algorithms first described in Andrieu et al (2010), studied in Chopin and Singh (2013), and used extensively in Chopin et al (2013) and Lindsten et al (2012). Another instance of sequential Monte Carlo method requiring path storage is presented in Wang et al (2014) in the context of computational biology. In the present article algorithms and results are presented in the filtering terminology, however they immediately extend to any sequential Monte Carlo method for Feynman-Kac models (Del Moral, 2004).
In Section 2 we present an efficient algorithm to store ancestry trees recursively during the run of a particle filter. In Section 3 we present new theoretical results bounding the size of ancestry trees, in order to bound the expected memory requirements of the storage algorithm. Finally the theoretical results and the algorithmic performance are tested numerically in Section 4.
Algorithms
This section introduces a memory-efficient data structure and associated algorithms for storing only those paths with support at time . The algorithms are designed for parallel execution, in keeping with the general parallelisability of other components of sequential Monte Carlo samplers (Lee et al, 2010; Murray, 2013).
Up to time , the particle filter produces particles and ancestors . From , offspring counts are readily obtained (Murray et al, 2013), where represents the number of children at generation of particle . Let represent slots in memory for storing particles. At any time, some of these slots are empty, while others store the nodes of the tree. Let be an ancestry vector, where if is empty or a root node, and otherwise to indicate that the particle in is the parent of the particle in . Let be the offspring vector corresponding to , where indicates that has children. Finally, let give the numbers of the slots in that store the particles of the youngest generation; these are the leaf nodes of the tree.
Basic operations on the tree are its initialisation, the insertion of a new generation of particles, and the pruning of older particles to remove those without a surviving descendent in the youngest generation. These operations are described in Algorithm 2. The descriptions there rely on primitive operations defined in Algorithm 3. The efficient implementation of such primitives is well understood in both serial and parallel contexts, so that they make useful building blocks for the higher-level algorithms.
To begin, the first of the empty slots of the tree are initialised with the first generation of particles as in the init procedure of Algorithm 2. We assume, for now, that is sufficiently large to accommodate all subsequent operations on the tree, but see remarks in Section 2.2 below.
Each new generation is inserted as in the insert procedure of Algorithm 2. The procedure searches for nodes with no offspring in the current generation, and replaces them with the new leaf nodes. The vector is introduced, where is equal to the number of nodes between and with no offspring. Nodes to replace are then located by searching for the increments in . The new generation is inserted at these locations.
Finally, the tree is pruned before the insertion of each new generation , using the prune procedure of Algorithm 2. This requires the offspring vector, , of the new generation. The algorithm determines which of the current leaf nodes have no offspring in the new generation, decrements the offspring counts of their parent nodes, and proceeds recursively up the tree for cases where the parent has no remaining offspring either. Each non-leaf node is considered pruned if , and may be overwritten by future calls to insert.
2 Remarks and improvements
The insert procedure of Algorithm 2 assumes that there are at least free slots in which to place the latest nodes. If this is not true, the buffer can be enlarged by allocating a larger block of memory, copying the contents of the ancestry tree across, and filling the new regions of the and vectors with zeros. Various heuristics can be used to set the new size , aiming to reduce fragmentation and the chance of future increases. Because memory reallocations involve an expensive copy, it is worth increasing more than strictly necessary to postpone additional reallocations. For instance, implementations of the C++ Standard Template Library typically double the storage capacity of a vector that is extended by just one element, anticipating further extensions. A more conservative strategy is to start with a value of equal to a small multiple of , and enlarge by slots whenever necessary. Ultimately, we have not found that the particular enlargement strategy affects execution time a great deal, particularly since, as in the proceeding theoretical results, the size of the ancestry tree crown is independent of , so that the need for reallocations diminishes as increases.
According to the results of Section 3, the expectation of the size of the tree grows linearly with , but this is only due to the trunk. The size of the crown is independent of . It may be possible to improve the algorithms by identifying the nodes along the trunk and storing them separately, as these nodes will never be overwritten by subsequent insertions. Under this modified scheme a separate, single growing trunk needs to be stored but not searched, while the nodes of the crown need to be stored and searched at every time step. The number of nodes in the crown is of constant expectation according to Theorem 3.1 of Section 3. Hence this modification induces a scheme of constant expected computational cost in , which could be relevant in applications where the time horizon is very long, although there will be overhead in identifying the trunk. See Fig. 3(b) in Section 4 for a report on the computational cost of the proposed method. Memory reallocation is also reduced by storing the trunk separately.
We establish in Section 3 that the size of the tree is expected to be bounded by for some constant . The size of the data structure, , must be at least as large as this. We assume that, with a sensible enlargement strategy, it is no more than a constant factor larger than this, so that its expected memory complexity is .
The computational complexity of init is linear in the size of the data structure, . A serial implementation of insert permits a linear prefix sum and search, so that insert is also . In parallel, a linear prefix sum is still achieved (Sengupta et al, 2008), but the search becomes binary searches, logarithmic to the size of the data structure; overall .
For prune, consider the best case, where all particles of the previous generation have an offspring in the new generation. The complexity is then : the algorithm operates on each of the new nodes, but does not traverse the tree further. Now consider the worst case, where only one particle of generation has offspring in the new generation . In this case all but nodes of the existing tree are pruned, so that the complexity is – linear in the size of the data structure, and parellelisable.
Finally, the transform-prefix-sum across the full vector in the insert is redundant. The sum can be truncated once it has reached , as a sufficient number of free slots have then been found. This is simple to achieve in the serial case, but it is not obvious how to achieve it in the parallel case. Heuristic include considering only a subset of at a time and iterating until a sufficient number of free slots are found, and starting the cumulative sum after the last slot that was filled in the previous call to insert. In practice, however, we have observed only negligible variation in execution times when applying such heuristics, and so have chosen to present the simplest version here.
Size of the ancestry tree
From a theoretical point of view, similar random trees have been studied in population genetics Del Moral et al (2009); Möhle (2004) in a setting that corresponds to a state-space model that assigns equal weights to all paths; these results do not apply directly here. In order to bound the expected number of nodes in an ancestry tree, we first study the distance between the final time and the full coalescence time when all the paths merge. Theorem 3.1 proposes a bound on the expectation of , which is independent of and explicit in .
There exists such that for all and for all
Under Assumption 1 the distance to the most recent common ancestor satisfies
for some , which does not depend nor .
The expected number of nodes in the tree can be bounded explicitly in and , as in Theorem 3.2.
We suppose here that . Under Assumption 1 the number of nodes, denoted by at time , satisfies
for some that does not depend on nor .
These results quantify the practical difference between storing all the generated particles (for a deterministic cost of memory units) and storing only the surviving particles (for a random cost expected to be bounded by ).
Assumption 1 is very strong outside compact spaces, and for instance does not even cover the linear-Gaussian case, although the experiments of Section 4 indicate that similar results might hold for non-linear and non-Gaussian cases. The numerical experiments show that the bound is accurate as a function of , so that even if some inequalities used in the proofs appear quite crude, the overall result is precise. However the results do not capture the shape of the tree as a function of , which is why we write the constants and without making their dependency on explicit. Consider for example Theorem 3.1, where can be defined by , as will be proven in Section 3.3. If the bound was sharp as a function of , it would mean that the time to full coalescence increases to infinity when goes to zero. However path degeneracy is expected be more acute for smaller , since more variability in the particle weights is then allowed. The dependency on in is thus not realistic. We believe the bounds could in fact be independent of , by considering as the case corresponding to the largest expectations of and ; a claim not proven here.
Moreover, the proposed proof relies on the multinomial resampling scheme, while most practitioners favour more sophisticated schemes (Carpenter et al, 1999; Liu and Chen, 1998; Kitagawa, 1998; Doucet and Johansen, 2011). Figure 3(a) of Section 4 indicates that similar results hold for these other resampling schemes. There are some obvious counter-examples, for instance when the measurement density is constant, leading to equal weights at each step (equivalently ). Then the results above hold for multinomial resampling but systematic resampling would completely obviate the path degeneracy phenomenon. Describing features of ancestry trees corresponding to general resampling schemes would constitute an interesting avenue of research.
The rest of the section is devoted to proving Theorem 3.1 and Theorem 3.2.
2 From non-uniform weights to uniform weights
We first relate the ancestry process associated with particle filters using multinomial resampling, with the ancestry process associated with the neutral case, where all the weights would be equal to at every time step. To do so we introduce various intermediate processes, starting with the exact multinomial resampling process denoted by , then an approximation represented by which provides an almost sure upper bound and eventually a process counting the number of nodes at generation in the neutral case, for a fixed time horizon .
For each time , define and then as follows. For all in , set . Order the remaining indices of the set into , set and then recursively
Such a function almost surely maps to more unique values than by construction. It can be seen as a mixture of two steps, as described for above, but this time neither step relies on the values of the weights.
We write for the cardinal of the image of a function . In terms of the functions , the full coalescence time can be defined as
with the convention in the event for each , which almost surely satisfies with
Indeed since maps to more unique values than at each time , the quantity , counting the unique ancestors from generation of the particles at time when using the resampling scheme , is almost surely larger than for any , and hence it takes longer to reach the full coalescence time when using compared to .
Following Del Moral et al (2009), Section 4 and Möhle (2004), the sequence is a Markov chain in the filtration with
with the convention . For all , and its transition law verifies
where is the Stirling number of the second kind giving the number of ways of partitioning the set into non empty blocks and where . Note that Eq. (2) is a special case of Eq. (1).
following the same reasoning as for the transition probabilities of . The initial distribution of is not used in the following hence we do not need to specify it. The link between and is explicitly given by
Note that the process is not used in the proof of Theorem 3.1, where we start from again, but is pivotal for the proof of Theorem 3.2.
3 Distance to the most recent common ancestor
where is defined in Eq. (2). In addition we couple and by assuming
(if the two chains are at the same point, then if one of them decreases, the other one decreases too)
and are independent, conditionally upon , .
By construction for all almost surely. Hence with and thus almost surely.
We have, for all , and for all and , ; combining these inequalities we obtain
where . We can now bound this series by expanding into an alternating series and by bounding the alternating series always by one of its partial sums:
which concludes the proof of Theorem 3.1.
4 Number of nodes in the ancestry tree
We now proceed to the proof of Theorem 3.2. Denote by the number of nodes in the crown. The bound on from Theorem 3.1 gives a first crude bound
which is obtained by bounding the size of every generation in the crown by . However we can obtain a better bound, in , by the following arguments.
By expanding into its alternating series and bounding the series by its third partial sum, we obtain
Now for define the function by:
Noting that is concave and using Jensen’s inequality, we obtain
Then there exists independent of such that
The proof of Lemma 1, based on elementary real analysis, is given in Appendix A. Using Lemma 1 and Eq. (8) we obtain Theorem 3.2 with .
Numerical experiments
This section provides numerical experiments to illustrate the results of Section 3 and the efficiency of the algorithms presented in Section 2. The results summarise independent runs, using particles and time steps. For each run, a new synthetic dataset is generated and a different random seed is used. The default resampling scheme is the multinomial scheme, applied at every time step. The algorithms of Section 2 have been implemented in LibBi (Murray, 2013, www.libbi.org), which is used for the numerical results here.
We use the Phytoplankton-Zooplankton (PZ) model described in Jones et al (2010) and Murray et al (2012). Concentrations of phytoplankton and zooplankton , along with the stochastic growth rate of phytoplankton , constitute the hidden state. The state follows the continuous-time dynamics and , with drawn at every integer time . The initial conditions are , . The observations measure with additive log-normal noise, that is . The parameters are set to , , , , and .
To illustrate the efficiency of the procedures presented in Section 2, Fig. 3(b) shows the combined time taken to execute the pruning and insertion algorithms at each time step, for various and . The results suggest that the computational cost is not greatly influenced by , and close to linear with respect to : evidence of a practical implementation with comparable complexity to the particle filter itself.
Conclusion
We have presented a bound on the expected number of nodes in the ancestry tree produced by particle filters. The numerical experiments of Section 4 indicate that the result is accurate, even outside the scope of the assumptions made in the theoretical study, and that the proposed algorithm to store the tree is computationally efficient.
Appendix A Proof of Lemma 1
however this contraction coefficient depends on and a direct use of it yields a bound on that is not in .
Note also that even though goes to , we can focus on the partial sum where , because is essentially bounded by . Indeed note that for we have so that
hence . Therefore we can focus on bounding by . Let us split this sum into partial sums, where the first partial sum is over indices such that , the second is over indices such that , etc. More formally, we introduce such that , , …, , up to where is such that , or equivalently . For instance we take . Thus we have split into partial sums of the form and we are now going to bound each of these partial sum by the same quantity for some that depends only on .
To do so, we consider the time needed by to decrease from a value to a value , with ; we will later take and . Note that for any we have
and note that for any and we have
which is clear upon noticing that as a function of on is concave and thus reaches its minimum in or (and this minimum is greater than , provided ). For any we can check that
by noticing that is concave and that for . Hence for such that , we have
Now suppose that for some we have . Then let us find such that . It is sufficient to find such that
guarantees the inequality . In other words needs less than steps to decrease from to . Summing the terms between and , we obtain
Taking and , we have and thus obtain
with independent of . We have thus bounded the full sum by
for some independent of .