Daniel@0: % See how well partial Kalman filter updates work Daniel@0: Daniel@0: seed = 0; Daniel@0: rand('state', seed); Daniel@0: randn('state', seed); Daniel@0: nlandmarks = 6; Daniel@0: T = 12; Daniel@0: Daniel@0: [A,B,C,Q,R,Qbig,Rbig,init_x,init_V,robot_block,landmark_block,... Daniel@0: true_landmark_pos, true_robot_pos, true_data_assoc, ... Daniel@0: obs_rel_pos, ctrl_signal] = mk_linear_slam(... Daniel@0: 'nlandmarks', nlandmarks, 'T', T, 'ctrl', 'leftright', 'data-assoc', 'cycle'); Daniel@0: Daniel@0: % exact Daniel@0: [xe, Ve] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ... Daniel@0: 'model', true_data_assoc, 'u', ctrl_signal, 'B', B); Daniel@0: Daniel@0: Daniel@0: % approx Daniel@0: %k = nlandmarks-1; % exact Daniel@0: k = 3; Daniel@0: ndx = {}; Daniel@0: for t=1:T Daniel@0: landmarks = unique(true_data_assoc(t:-1:max(t-k,1))); Daniel@0: tmp = [landmark_block(:, landmarks) robot_block']; Daniel@0: ndx{t} = tmp(:); Daniel@0: end Daniel@0: Daniel@0: [xa, Va] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ... Daniel@0: 'model', true_data_assoc, 'u', ctrl_signal, 'B', B, ... Daniel@0: 'ndx', ndx); Daniel@0: Daniel@0: Daniel@0: Daniel@0: nrows = 10; Daniel@0: stepsize = T/(2*nrows); Daniel@0: ts = 1:stepsize:T; Daniel@0: Daniel@0: if 1 % plot Daniel@0: Daniel@0: clim = [0 max(max(Va(:,:,end)))]; Daniel@0: Daniel@0: figure(2) Daniel@0: if 0 Daniel@0: imagesc(Ve(1:2:end,1:2:end, T)) Daniel@0: clim = get(gca,'clim'); Daniel@0: else Daniel@0: i = 1; Daniel@0: for t=ts(:)' Daniel@0: subplot(nrows,2,i) Daniel@0: i = i + 1; Daniel@0: imagesc(Ve(1:2:end,1:2:end, t)) Daniel@0: set(gca, 'clim', clim) Daniel@0: colorbar Daniel@0: end Daniel@0: end Daniel@0: suptitle('exact') Daniel@0: Daniel@0: Daniel@0: figure(3) Daniel@0: if 0 Daniel@0: imagesc(Va(1:2:end,1:2:end, T)) Daniel@0: set(gca,'clim', clim) Daniel@0: else Daniel@0: i = 1; Daniel@0: for t=ts(:)' Daniel@0: subplot(nrows,2,i) Daniel@0: i = i+1; Daniel@0: imagesc(Va(1:2:end,1:2:end, t)) Daniel@0: set(gca, 'clim', clim) Daniel@0: colorbar Daniel@0: end Daniel@0: end Daniel@0: suptitle('approx') Daniel@0: Daniel@0: Daniel@0: figure(4) Daniel@0: i = 1; Daniel@0: for t=ts(:)' Daniel@0: subplot(nrows,2,i) Daniel@0: i = i+1; Daniel@0: Vd = Va(1:2:end,1:2:end, t) - Ve(1:2:end,1:2:end,t); Daniel@0: imagesc(Vd) Daniel@0: set(gca, 'clim', clim) Daniel@0: colorbar Daniel@0: end Daniel@0: suptitle('diff') Daniel@0: Daniel@0: end % all plot Daniel@0: Daniel@0: Daniel@0: for t=1:T Daniel@0: %err(t)=rms(xa(:,t), xe(:,t)); Daniel@0: err(t)=rms(xa(1:end-2,t), xe(1:end-2,t)); % exclude robot Daniel@0: end Daniel@0: figure(5);plot(err) Daniel@0: title('rms mean pos') Daniel@0: Daniel@0: Daniel@0: for t=1:T Daniel@0: i = 1:2*nlandmarks; Daniel@0: denom = Ve(i,i,t) + (Ve(i,i,t)==0); Daniel@0: Vd =(Va(i,i,t)-Ve(i,i,t)) ./ denom; Daniel@0: Verr(t) = max(Vd(:)); Daniel@0: end Daniel@0: figure(6); plot(Verr) Daniel@0: title('max relative Verr')