diff --git a/matlab/particle/multivariate_smooth_resampling.m b/matlab/particle/multivariate_smooth_resampling.m index ab8d584c8..08ed24471 100644 --- a/matlab/particle/multivariate_smooth_resampling.m +++ b/matlab/particle/multivariate_smooth_resampling.m @@ -1,26 +1,30 @@ -function new_etat = multivariate_smooth_resmp(weights,particles,number,number_of_partitions) -% Smooth Resamples particles. +function new_particles = multivariate_smooth_resampling(weights,particles,number_of_new_particles,number_of_partitions) +% Smooth Resampling of the particles. %@info: -%! @deftypefn {Function File} {@var{indx} =} resample (@var{weights}, @var{method}) -%! @anchor{particle/resample} +%! @deftypefn {Function File} {@var{new_particles} =} multivariate_smooth_resampling (@var{weights}, @var{particles}, @var{number_of_new_particles}, @var{number_of_partitions}) +%! @anchor{particle/multivariate_smooth_resampling} %! @sp 1 -%! Resamples particles. +%! Smooth Resampling of the particles (multivariate version). %! @sp 2 %! @strong{Inputs} %! @sp 1 %! @table @ @var %! @item weights %! n*1 vector of doubles, particles' weights. -%! @item method -%! string equal to 'residual' or 'traditional'. +%! @item particles +%! n*1 vector of doubles, particles. +%! @item number_of_new_particles +%! Integer scalar. +%! @item number_of_partitions +%! Integer scalar. %! @end table %! @sp 2 %! @strong{Outputs} %! @sp 1 %! @table @ @var %! @item indx -%! n*1 vector of intergers, indices. +%! number_of_new_particles*1 vector of doubles, new particles. %! @end table %! @sp 2 %! @strong{This function is called by:} @@ -29,12 +33,12 @@ function new_etat = multivariate_smooth_resmp(weights,particles,number,number_of %! @sp 2 %! @strong{This function calls:} %! @sp 1 -%! @ref{residual_resampling}, @ref{traditional_resampling} +%! @ref{particle/univariate_smooth_resampling} %! @sp 2 %! @end deftypefn %@eod: -% Copyright (C) 2011, 2012 Dynare Team +% Copyright (C) 2012 Dynare Team % % This file is part of Dynare. % @@ -55,38 +59,38 @@ function new_etat = multivariate_smooth_resmp(weights,particles,number,number_of % stephane DOT adjemian AT univ DASH lemans DOT fr number_of_particles = length(weights); -number_of_states = size(particles,2); -number = number_of_particles/number_of_partitions ; +number_of_states = size(particles,2); +number = number_of_particles/number_of_partitions ; tout = sort([particles weights],1) ; particles = tout(:,1:number_of_states) ; weights = tout(:,1+number_of_states) ; -cum_weights = cumsum(weights) ; -new_etat = zeros(number_of_particles,number_of_states) ; -indx = 1:number_of_particles ; +cum_weights = cumsum(weights) ; +new_particles = zeros(number_of_particles,number_of_states) ; +indx = 1:number_of_particles ; for i=1:number_of_partitions - if i==number_of_partitions + if i==number_of_partitions tmp = bsxfun(@ge,cum_weights,(i-1)/number_of_partitions) ; kp = indx( tmp ) ; - else + else tmp = bsxfun(@and,bsxfun(@ge,cum_weights,(i-1)/number_of_partitions),bsxfun(@lt,cum_weights,i/number_of_partitions)) ; kp = indx( tmp ) ; end - if numel(kp)>2 + if numel(kp)>2 Np = length(kp) ; - wtilde = [ ( number_of_partitions*( cum_weights(kp(1)) - (i-1)/number_of_partitions) ) ; - ( number_of_partitions*weights(kp(2:Np-1)) ) ; + wtilde = [ ( number_of_partitions*( cum_weights(kp(1)) - (i-1)/number_of_partitions) ) ; + ( number_of_partitions*weights(kp(2:Np-1)) ) ; ( number_of_partitions*(i/number_of_partitions - cum_weights(kp(Np)-1) ) ) ] ; test = sum(wtilde) ; - new_etat_j = zeros(number,number_of_states) ; + new_particles_j = zeros(number,number_of_states) ; for j=1:number_of_states - etat_j = particles(kp,j) ; - if j>1 - tout = sort( [ etat_j wtilde],1) ; - etat_j = tout(:,1) ; - wtilde = tout(:,2) ; - end - new_etat_j(:,j) = univariate_smooth_resmp(wtilde,etat_j,number) ; + particles_j = particles(kp,j) ; + if j>1 + tout = sort( [ particles_j wtilde],1) ; + particles_j = tout(:,1) ; + wtilde = tout(:,2) ; + end + new_particles_j(:,j) = univariate_smooth_resmp(wtilde,particles_j,number) ; end - new_etat((i-1)*number+1:i*number,:) = new_etat_j ; - end + new_particles((i-1)*number+1:i*number,:) = new_particles_j; + end end