Commit 9df38579 authored by Frédéric Karamé's avatar Frédéric Karamé
Browse files

Huge modification of the file: uses now the PCA to orthogonalize the state variables to resample

in order to use independent smooth resampling; modification of the input of the procedure since
now no partition is required
parent d440767b
function new_particles = multivariate_smooth_resampling(weights,particles,number_of_new_particles,number_of_partitions)
function new_particles = multivariate_smooth_resampling(particles,weights)
% Smooth Resampling of the particles.
%@info:
......@@ -59,63 +59,15 @@ function new_particles = multivariate_smooth_resampling(weights,particles,number
% stephane DOT adjemian AT univ DASH lemans DOT fr
number_of_particles = length(weights);
weights = weights' ;
number_of_states = size(particles,2);
number = number_of_particles/number_of_partitions ;
tout = sortrows([particles weights],1) ;
particles = tout(:,1:number_of_states) ;
weights = tout(:,1+number_of_states) ;
if number_of_partitions>1
cum_weights = cumsum(weights) ;
indx = 1:number_of_particles ;
for i=1:number_of_partitions
if i==number_of_partitions
tmp = bsxfun(@gt,cum_weights,(i-1)/number_of_partitions) ;
kp = indx( tmp ) ;
else
tmp = bsxfun(@and,bsxfun(@gt,cum_weights,(i-1)/number_of_partitions),bsxfun(@lt,cum_weights,i/number_of_partitions)) ;
kp = indx( tmp ) ;
end
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)) ) ;
( number_of_partitions*(i/number_of_partitions - cum_weights(kp(Np)-1) ) ) ] ;
elseif numel(kp)==2
Np = length(kp) ;
wtilde = [ ( number_of_partitions*( cum_weights(kp(1)) - (i-1)/number_of_partitions) ) ;
( number_of_partitions*(i/number_of_partitions - cum_weights(kp(Np)-1) ) ) ] ;
elseif numel(kp)==1
new_particles = ones(number,1).*particles(kp,:) ;
return ;
else
% probleme
end
test = sum(wtilde) ;
disp(test)
new_particles = zeros(number_of_particles,number_of_states) ;
new_particles_j = zeros(number,number_of_states) ;
for j=1:number_of_states
particles_j = particles(kp,j) ;
if j>1
tout = sortrows( [ particles_j wtilde],1) ;
particles_j = tout(:,1) ;
wtilde = tout(:,2) ;
end
new_particles_j(:,j) = univariate_smooth_resampling(wtilde,particles_j,number) ;
end
new_particles((i-1)*number+1:i*number,:) = new_particles_j;
end
else
new_particles = zeros(number,number_of_states) ;
for j=1:number_of_states
if j>1
tout = sortrows( [ particles(:,j) weights],1) ;
particles_j = tout(:,1) ;
weights_j = tout(:,2) ;
else
particles_j = particles(:,j) ;
weights_j = weights ;
end
new_particles(:,j) = univariate_smooth_resampling(weights_j,particles_j,number) ;
end
end
\ No newline at end of file
[P,D] = eig(particles'*(bsxfun(@times,1/number_of_particles,particles))) ;
D = diag(D) ;
vectors = bsxfun(@times,P,sqrt(D)') ;
orthogonalized_particles = bsxfun(@rdivide,particles*vectors,D') ;
new_particles = zeros(number_of_particles,number_of_states) ;
for j=1:number_of_states
tout = sortrows( [orthogonalized_particles(:,j) weights],1) ;
new_particles(:,j) = univariate_smooth_resampling(tout(:,2),tout(:,1),number_of_particles) ;
end
new_particles = new_particles*(vectors') ;
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