{"id":431,"date":"2021-05-14T12:18:31","date_gmt":"2021-05-14T12:18:31","guid":{"rendered":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/?p=431"},"modified":"2021-05-14T12:53:42","modified_gmt":"2021-05-14T12:53:42","slug":"particle-filters-part-ii","status":"publish","type":"post","link":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/2021\/05\/14\/particle-filters-part-ii\/","title":{"rendered":"Particle Filters (Part II)"},"content":{"rendered":"\n<p><span class=\"has-inline-color has-black-color\">As we saw from the previous blog, the SIS algorithm is degenerate, which simply means that after some observations, relatively small in number, one of the particles achieves a weight close to <span class=\"wp-katex-eq\" data-display=\"false\">1<\/span>. A solution has been proposed to sample the particles at each time observation. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><span class=\"has-inline-color has-black-color\">SIR algorithm<\/span><\/strong><\/h3>\n\n\n\n<p><span class=\"has-inline-color has-black-color\">The SIR (sequential importance resampling) algorithm can be seen as a variant of SIS, but where at each time observation, we resample the paths from a simple multinomial distribution. This means that the particles with the highest weights will be resampled most often, hence we do not waste computational power in continuing the paths with negligible weights. This, however, introduces another problem, called <strong>particle impoverishment<\/strong>, which we shall focus on a bit later. The problem arises from the fact that since particles with large weights are likely to be drawn multiple times during resampling, whereas particles with small weights are not likely to be drawn at all, the diversity of the particles will tend to decrease after a resampling step. To illustrate what happens, we run the SIR algorithm with only <span class=\"wp-katex-eq\" data-display=\"false\">4<\/span> particles and plot them, while observing them being resampled:<\/span><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"644\" height=\"389\" src=\"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-content\/uploads\/sites\/31\/2021\/05\/sir_plot.png\" alt=\"\" class=\"wp-image-435\" srcset=\"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-content\/uploads\/sites\/31\/2021\/05\/sir_plot.png 644w, https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-content\/uploads\/sites\/31\/2021\/05\/sir_plot-300x181.png 300w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><figcaption><span class=\"has-inline-color has-black-color\"><strong>SIR plot: resampling particles<\/strong><\/span><\/figcaption><\/figure><\/div>\n\n\n\n<p><span class=\"has-inline-color has-black-color\">If we look at time <span class=\"wp-katex-eq\" data-display=\"false\">1000<\/span>, we see that two of the paths have not been resampled at all, which means that while they have low weights, we start to lose diversity in the paths. What is more, it seems that we have collapsed onto a single path at time <span class=\"wp-katex-eq\" data-display=\"false\">1000<\/span> onwards, which leaves us with the same issue as with the SIS algorithm. Nevertheless, the algorithm is easy to code, and while it does lead to particle impoverishment, more often than not, it seems to perform within some desirable limits <a rel=\"noreferrer noopener\" href=\"https:\/\/www.stats.ox.ac.uk\/~doucet\/doucet_johansen_tutorialPF2011.pdf\" data-type=\"URL\" data-id=\"https:\/\/www.stats.ox.ac.uk\/~doucet\/doucet_johansen_tutorialPF2011.pdf\" target=\"_blank\">[1]<\/a>. In most of the situations, the more or less &#8220;extreme&#8221; case shown in the figure above, is not as pronounced.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"has-inline-color has-black-color\"><strong>Filtering<\/strong><\/span><\/h3>\n\n\n\n<p><span class=\"has-inline-color has-black-color\">We have already described the idea behind filtering at the beginning the last post, i.e. to try to guess the distribution of the state of the hidden process at the current time, given the data up to now. This can also be thought of a &#8220;tracking&#8221; problem, where we keep track of the location of the system noisy observations. One simple way of restoring the hidden path is by doing a weighted average with respected to the weights at each time interval. In particular, imagine that we have just received our <span class=\"wp-katex-eq\" data-display=\"false\">j-1<\/span> noisy observation and we have resampled our particles. Then each of the particles will have a weight of <span class=\"wp-katex-eq\" data-display=\"false\">1\/N<\/span> and when we receive the <span class=\"wp-katex-eq\" data-display=\"false\">j<\/span> observation, the weights will correspondingly be <span class=\"wp-katex-eq\" data-display=\"false\">\\{w_{j}^{i}\\}_{i=1}^{N}<\/span>, for the particles <span class=\"wp-katex-eq\" data-display=\"false\">\\{\\mathbf{x}_{j}^{i}\\}_{i=1}^{N}<\/span>. We can introduce the weight vector at time <span class=\"wp-katex-eq\" data-display=\"false\">j<\/span> as <span class=\"wp-katex-eq\" data-display=\"false\">\\mathbf{w}_{j} = (w_{j}^{1}, w_{j}^{2}, \\ldots, w_{j}^{N})<\/span> and the corresponding particle trajectories in a matrix form as <span class=\"wp-katex-eq\" data-display=\"false\">\\mathbf{x}_{j} = ((\\mathbf{x}_{j}^{1})^{T}, (\\mathbf{x}_{j}^{2})^{T}, \\ldots, (\\mathbf{x}_{j}^{N})^{T})<\/span>. Then we can perform a weighted average over every single time segment and connect the predicted paths over the segments. Hence, if we denote the approximated path as <span class=\"wp-katex-eq\" data-display=\"false\">\\mathbf{x}_{best}<\/span>, it will take the form:<\/span><\/p>\n\n\n\n<p class=\"has-text-align-center\"><span class=\"has-inline-color has-black-color\"><span class=\"wp-katex-eq\" data-display=\"false\">\\mathbf{x}^{best} = (\\mathbf{x}^{best}_{1}, \\mathbf{x}^{best}_{2}, \\ldots, \\mathbf{x}^{best}_{j})<\/span><\/span>,<\/p>\n\n\n\n<p><span class=\"has-inline-color has-black-color\">where <span class=\"wp-katex-eq\" data-display=\"false\">\\mathbf{x}^{best}_{s} = \\mathbf{x}_{s}\\mathbf{w}_{s}^{T}<\/span>, for all <span class=\"wp-katex-eq\" data-display=\"false\">s \\in \\{1, \\ldots, N\\}<\/span>.<\/span> <span class=\"has-inline-color has-black-color\">After performing the simulation, we achieve the following plot:<\/span><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"653\" height=\"428\" src=\"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-content\/uploads\/sites\/31\/2021\/05\/particle_filter.png\" alt=\"\" class=\"wp-image-446\" srcset=\"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-content\/uploads\/sites\/31\/2021\/05\/particle_filter.png 653w, https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-content\/uploads\/sites\/31\/2021\/05\/particle_filter-300x197.png 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><figcaption><span class=\"has-inline-color has-black-color\"><strong>Particle filtering follow SIR algorithm<\/strong><\/span><\/figcaption><\/figure><\/div>\n\n\n\n<p><span class=\"has-inline-color has-black-color\">It is interesting to point out that the plot below was produced using <span class=\"wp-katex-eq\" data-display=\"false\">100<\/span> particles. Running the particle filter for <span class=\"wp-katex-eq\" data-display=\"false\">1000<\/span> particles instead introduces only a slight improvement, while considerably increasing the running time. In fact, on my computer the simulation took about <span class=\"wp-katex-eq\" data-display=\"false\">3<\/span> seconds for <span class=\"wp-katex-eq\" data-display=\"false\">100<\/span> particles and approximately <span class=\"wp-katex-eq\" data-display=\"false\">30<\/span> seconds for <span class=\"wp-katex-eq\" data-display=\"false\">1000<\/span> particles, suggesting an <span class=\"wp-katex-eq\" data-display=\"false\">\\mathcal{O}(n)<\/span> complexity when it comes to the number of particles, which is further confirmed by <a href=\"https:\/\/www.researchgate.net\/publication\/26532303_Resampling_Algorithms_for_Particle_Filters_A_Computational_Complexity_Perspective\" data-type=\"URL\" data-id=\"https:\/\/www.researchgate.net\/publication\/26532303_Resampling_Algorithms_for_Particle_Filters_A_Computational_Complexity_Perspective\" target=\"_blank\" rel=\"noreferrer noopener\">[2]<\/a>.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As we saw from the previous blog, the SIS algorithm is degenerate, which simply means that after some observations, relatively small in number, one of the particles achieves a weight close to . A solution has been proposed to sample the particles at each time observation. SIR algorithm The SIR (sequential importance resampling) algorithm can&hellip; <br \/> <a class=\"read-more\" href=\"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/2021\/05\/14\/particle-filters-part-ii\/\">Read more<\/a><\/p>\n","protected":false},"author":32,"featured_media":432,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-431","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/posts\/431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/comments?post=431"}],"version-history":[{"count":10,"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/posts\/431\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/posts\/431\/revisions\/450"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/media\/432"}],"wp:attachment":[{"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/media?parent=431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/categories?post=431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancaster.ac.uk\/stor-i-student-sites\/martin-dimitrov\/wp-json\/wp\/v2\/tags?post=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}