root/applications/dual/SIDP/smc29/resample_deterministic.m @ 1296

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

resampling procedures

Line 
1function outIndex = resample_deterministic(inIndex,q);
2% PURPOSE : Performs the resampling stage of the SIR
3%           in order(number of samples) steps. It uses Kitagawa's
4%           deterministic resampling algorithm.
5% INPUTS  : - inIndex = Input particle indices.
6%           - q = Normalised importance ratios.
7% OUTPUTS : - outIndex = Resampled indices.
8% AUTHORS  : Arnaud Doucet and Nando de Freitas - Thanks for the acknowledgement.
9% DATE     : 08-09-98
10
11if nargin < 2, error('Not enough input arguments.'); end
12
13[S,arb] = size(q);  % S = Number of particles.
14
15% RESIDUAL RESAMPLING:
16% ====================
17
18N_babies= zeros(1,S);
19u=zeros(1,S);
20
21% generate the cumulative distribution
22cumDist = cumsum(q');
23aux=rand(1);
24u=aux:1:(S-1+aux);
25u=u./S;
26j=1;
27for i=1:S
28   while (u(1,i)>cumDist(1,j))
29      j=j+1;
30   end
31   N_babies(1,j)=N_babies(1,j)+1;
32end
33
34% COPY RESAMPLED TRAJECTORIES: 
35% ============================
36index=1;
37for i=1:S
38  if (N_babies(1,i)>0)
39    for j=index:index+N_babies(1,i)-1
40      outIndex(j) = inIndex(i);
41    end;
42  end;   
43  index= index+N_babies(1,i);   
44end
Note: See TracBrowser for help on using the browser.