Skip to content

Commit cff30b9

Browse files
author
compops
committed
fixed bug when sampling trajectory in the particle filter
Former-commit-id: d8b2b16 [formerly d8b2b16 [formerly ccb4307]] Former-commit-id: ca79fc6e8b1fcc2af36a9fa2faa72a5b0512fa87 Former-commit-id: b1e548c
1 parent d1b646e commit cff30b9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

matlab/sm.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
% Resample ( multinomial )
6363
%=========================================================
6464
idx = randsample( nPart, nPart, true, w(:,tt-1) );
65-
idx = idx( randperm( nPart ) );
6665

6766
%=========================================================
6867
% Propagate

matlab/sm_sv.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
% Resample ( multinomial )
6161
%=========================================================
6262
idx = randsample( N, N, true, w(:,tt-1) );
63-
idx = idx( randperm( N ) );
6463

6564
% Resample the ancestory linage
6665
a(:,1:tt-1) = a(idx,1:tt-1);
@@ -91,9 +90,11 @@
9190
end
9291

9392
% Sample the state estimate using the weights at tt=T
93+
xhatf = zeros( 1, T+1);
9494
nIdx = randsample( N, 1, true, w(:,T) );
95-
indices = sub2ind(size(p), a(nIdx,:), 1:(T+1));
96-
xhatf = p( indices );
95+
for tt = 1:(T+1)
96+
xhatf(tt) = p( a(nIdx,tt), tt );
97+
end
9798
end
9899

99100
% Helper for computing the logarithm of the Gaussian density
@@ -105,4 +106,4 @@
105106

106107
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107108
% End of file
108-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0 commit comments

Comments
 (0)