Revision 1256, 1.1 kB
(checked in by smidl, 14 years ago)
|
resampling procedures
|
Rev | Line | |
---|
[1256] | 1 | function 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 | |
---|
| 10 | if nargin < 2, error('Not enough input arguments.'); end |
---|
| 11 | |
---|
| 12 | [S,arb] = size(q); % S = Number of particles. |
---|
| 13 | |
---|
| 14 | % MULTINOMIAL SAMPLING: |
---|
| 15 | % ===================== |
---|
| 16 | N_babies= zeros(1,S); |
---|
| 17 | cumDist= cumsum(q'); |
---|
| 18 | % generate S ordered random variables uniformly distributed in [0,1] |
---|
| 19 | % high speed Niclas Bergman Procedure |
---|
| 20 | u = fliplr(cumprod(rand(1,S).^(1./(S:-1:1)))); |
---|
| 21 | j=1; |
---|
| 22 | for 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; |
---|
| 27 | end; |
---|
| 28 | |
---|
| 29 | % COPY RESAMPLED TRAJECTORIES: |
---|
| 30 | % ============================ |
---|
| 31 | index=1; |
---|
| 32 | for 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); |
---|
| 39 | end |
---|