Newer
Older
abgabensammlungSS15 / mr / ub9 / loc_jp / pf_resample.m
@Jan-Peter Hohloch Jan-Peter Hohloch on 27 Jun 2015 480 bytes MR: begin 1st exercise - not fully working yet
function [ nextx ] = pf_resample( currx, w )
%PF_RESAMPLE Basic resampling

% number of samples:
M = size(currx, 3);

% Redraw particles:
nextx = zeros(3, 1, M);

% Cumulative sum of weights:
cum = cumsum(w);

for p = 1:M
    r = rand();
    % Find first index for which the cumulative sum is >= r. If this ever
    % fails due to unmerical inaccuracies, we should take the last element.
    ind = min(find (cum >= r, 1, 'first'), M);
    nextx(:,:,p) = currx(:,:,ind);
end

end