replaceWithObservations
PURPOSE 
REPLACEWITHOBSERVATIONS - replace some of the particles with observations
SYNOPSIS 
function [new_particles, new_weights] = replaceWithObservations( particles, weights, target, observations, ratio )
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
This function is called by:
SOURCE CODE 
0001 function [new_particles, new_weights] = replaceWithObservations( particles, weights, target, observations, ratio )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 disp('Entering replaceWithObservations');
0019
0020
0021 new_particles = [];
0022
0023 [M N] = size(particles);
0024
0025 if (M ~= length(weights))
0026 disp('replaceWithObservartions: number of particles and weights do not agree!');
0027 return;
0028 end
0029
0030 no_of_particles_to_replace = ceil( M*ratio )
0031
0032 no_of_observations = length( observations );
0033
0034
0035
0036 observations = observations( randperm( no_of_observations ) );
0037 particles_per_observation = ceil(no_of_particles_to_replace/no_of_observations);
0038
0039 replaced = 0;
0040
0041
0042 [weights indices] = sort(weights);
0043
0044 new_particles = particles( indices(no_of_particles_to_replace+1:end), : )
0045 new_weights = weights(indices(no_of_particles_to_replace+1:end));
0046
0047 obs = 1;
0048 while (replaced < no_of_particles_to_replace)
0049 replace = min( particles_per_observation, no_of_particles_to_replace - replaced );
0050 for i=1:replace
0051 pos = observations( obs ).data;
0052 if length(pos) < 2
0053 disp('replaceWithObservations: pos malformed');
0054 pos
0055 end
0056 speed = target.max_speed*rand;
0057 angle = 2*pi*rand;
0058 pos
0059 speed
0060 angle
0061 new_particles
0062 new_particles = [[pos speed angle]; new_particles]
0063 new_weights = [1.1; new_weights]
0064 end
0065 replaced = replaced + replace;
0066 obs = obs+1;
0067 end
0068
0069 [M2 N2] = size(new_particles);
0070
0071 if (M2 ~= M)
0072 disp('replaceWithObservations: the new set of particles does not have the right size.')
0073 end
0074
0075 disp('Leaving replaceWithObservations');
Generated on Wed 16-Mar-2005 09:17:47 by m2html © 2003