Commit e6af5f5b authored by Jonathan Hadida's avatar Jonathan Hadida
Browse files

Add border control

parent 5d2eaefd
......@@ -31,6 +31,10 @@ function [best_particles,best_scores] = particle_filter( objective_fun, range, v
% Number of best particles to return in output.
% DEFAULT: 5
%
% BorderControl
% Actively control that particles never go outside the specified range.
% DEFAULT: false
%
% ----------
% OUTPUTS:
%
......@@ -43,7 +47,7 @@ function [best_particles,best_scores] = particle_filter( objective_fun, range, v
% parse options
opt = struct();
arg = { 'Nnew', ceil(Nparticles/20), 'BestK', 5 }; % defaults
arg = { 'Nnew', ceil(Nparticles/20), 'BestK', 5, 'BorderControl', false }; % defaults
arg = [ arg, varargin ];
narg = numel(arg)/2;
......@@ -79,6 +83,11 @@ function [best_particles,best_scores] = particle_filter( objective_fun, range, v
importance_sampling( particles, scores, variance, Nparticles-opt.Nnew ), ...
uniform_sampling( range, opt.Nnew ) );
if opt.BorderControl
particles = max( particles, (range(:,1)+eps)*ones(1,Nparticles) );
particles = min( particles, (range(:,2)-eps)*ones(1,Nparticles) );
end
% evaluate
scores = evaluate( objective_fun, particles );
......
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