root/applications/dual/SIDP/smc29/resample_multinomial.m @ 1288

Revision 1256, 1.1 kB (checked in by smidl, 14 years ago)

resampling procedures

Line 
1function outIndex = resample_multinomial(inIndex,q);
2% PURPOSE : Performs the resampling stage of the SIR
3%           in order(number of samples) steps.
4% INPUTS  : - inIndex = Input particle indices.
5%           - q = Normalised importance ratios.
6% OUTPUTS : - outIndex = Resampled indices.
7% AUTHORS  : Arnaud Doucet and Nando de Freitas - Thanks for the acknowledgement.
8% DATE     : 08-09-98
9
10if nargin < 2, error('Not enough input arguments.'); end
11
12[S,arb] = size(q);  % S = Number of particles.
13
14% MULTINOMIAL SAMPLING:
15% =====================
16N_babies= zeros(1,S);
17cumDist= cumsum(q');   
18% generate S ordered random variables uniformly distributed in [0,1]
19% high speed Niclas Bergman Procedure
20u = fliplr(cumprod(rand(1,S).^(1./(S:-1:1))));
21j=1;
22for i=1:S
23  while (u(1,i)>cumDist(1,j))
24    j=j+1;
25  end
26  N_babies(1,j)=N_babies(1,j)+1;
27end;
28
29% COPY RESAMPLED TRAJECTORIES: 
30% ============================
31index=1;
32for i=1:S
33  if (N_babies(1,i)>0)
34    for j=index:index+N_babies(1,i)-1
35      outIndex(j) = inIndex(i);
36    end;
37  end;   
38  index= index+N_babies(1,i);   
39end
Note: See TracBrowser for help on using the browser.