Revision 1256, 1.1 kB
(checked in by smidl, 14 years ago)
|
resampling procedures
|
Line | |
---|
1 | function 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 | |
---|
11 | if nargin < 2, error('Not enough input arguments.'); end |
---|
12 | |
---|
13 | [S,arb] = size(q); % S = Number of particles. |
---|
14 | |
---|
15 | % RESIDUAL RESAMPLING: |
---|
16 | % ==================== |
---|
17 | |
---|
18 | N_babies= zeros(1,S); |
---|
19 | u=zeros(1,S); |
---|
20 | |
---|
21 | % generate the cumulative distribution |
---|
22 | cumDist = cumsum(q'); |
---|
23 | aux=rand(1); |
---|
24 | u=aux:1:(S-1+aux); |
---|
25 | u=u./S; |
---|
26 | j=1; |
---|
27 | for 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; |
---|
32 | end |
---|
33 | |
---|
34 | % COPY RESAMPLED TRAJECTORIES: |
---|
35 | % ============================ |
---|
36 | index=1; |
---|
37 | for 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); |
---|
44 | end |
---|