⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stratified_resample.m

📁 This a collection of MATLAB functions for extended Kalman filtering, unscented Kalman filtering, par
💻 M
字号:
function [keep, Neff] = stratified_resample(w)
%function [keep, Neff] = stratified_resample(w)
%
% INPUT:
%   w - set of N weights [w1, w2, ..]
%
% OUTPUTS:
%   keep - N indices of particles to keep 
%   Neff - number of effective particles (measure of weight variance)
%
% USAGE:
%   Given a set of N particles p and their associated weights w,
%       [keep, Neff] = stratified_resample(w);
%       if Neff < N/2
%           p = p(:, keep);
%           w = ones(1, N)/N;
%       end
%
% Tim Bailey 2004.


w = w / sum(w); % normalise
Neff = 1 / sum(w .^ 2); 

len = length(w);
keep = zeros(1,len);
select = stratified_random(len); 
w = cumsum(w); 

ctr=1; 
for i=1:len
   while ctr<=len & select(ctr)<w(i)
       keep(ctr)= i;
       ctr=ctr+1; 
   end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -