Commit 9255d1c7 authored by Jonathan Hadida's avatar Jonathan Hadida
Browse files

Add output messages

parent e6af5f5b
......@@ -48,6 +48,7 @@ function [best_particles,best_scores] = particle_filter( objective_fun, range, v
% parse options
opt = struct();
arg = { 'Nnew', ceil(Nparticles/20), 'BestK', 5, 'BorderControl', false }; % defaults
nopt = numel(arg)/2;
arg = [ arg, varargin ];
narg = numel(arg)/2;
......@@ -61,11 +62,15 @@ function [best_particles,best_scores] = particle_filter( objective_fun, range, v
assert( all(variance >= 0), 'Variances should be positive.' );
assert( all(range(:,2) > range(:,1)), 'Second column should be larger than first column in range.' );
assert( numel(fieldnames(opt)) == nopt, 'Wrong number of options; check that your input keys match option names.' );
assert( opt.Nnew < Nparticles, 'Nnew cant be larger than Nparticles.' );
assert( opt.BestK < Nparticles, 'BestK cant be larger than Nparticles.' );
assert( opt.BestK > 0, 'BestK should be non-zero.' );
% initialise the particles
fprintf('Particle filter starting with %d particles and %d cycles\n',Nparticles,Ncycles);
fprintf('\t- Initialisation\n');
particles = uniform_sampling( range, Nparticles );
scores = evaluate( objective_fun, particles );
......@@ -78,6 +83,8 @@ function [best_particles,best_scores] = particle_filter( objective_fun, range, v
for c = 1:Ncycles
fprintf('\t- Starting cycle #%d\n',c);
% resample
particles = horzcat( ...
importance_sampling( particles, scores, variance, Nparticles-opt.Nnew ), ...
......@@ -101,6 +108,8 @@ function [best_particles,best_scores] = particle_filter( objective_fun, range, v
best_particles = [ best_particles(:,id_keep), particles(:,id_new) ];
end
fprintf('Done!\n');
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment