Replaced DynareOptions by ParticleOptions and ThreadsOptions.

ParticleOptions is DynareOptions.particles
ThreadsOptions is DynareOptions.threads
rm-particles^2
Stéphane Adjemian (Charybdis) 2014-12-12 17:25:11 +01:00
parent f187c3d414
commit f82afdf8aa
2 changed files with 15 additions and 15 deletions

View File

@ -1,4 +1,4 @@
function resampled_particles = resample(particles,weights,DynareOptions)
function resampled_particles = resample(particles,weights,ParticleOptions)
% Resamples particles.
%@info:
@ -54,19 +54,19 @@ function resampled_particles = resample(particles,weights,DynareOptions)
defaultmethod = 1; % For residual based method set this variable equal to 0.
if defaultmethod
if DynareOptions.particle.resampling.method.kitagawa
if ParticleOptions.resampling.method.kitagawa
resampled_particles = traditional_resampling(particles,weights,rand);
elseif DynareOptions.particle.resampling.method.stratified
elseif ParticleOptions.resampling.method.stratified
resampled_particles = traditional_resampling(particles,weights,rand(size(weights)));
elseif DynareOptions.particle.resampling.method.smooth
elseif ParticleOptions.resampling.method.smooth
resampled_particles = multivariate_smooth_resampling(particles,weights);
else
error('Unknow sampling method!')
end
else
if DynareOptions.particle.resampling.method.kitagawa
if ParticleOptions.resampling.method.kitagawa
resampled_particles = residual_resampling(particles,weights,rand);
elseif DynareOptions.particle.resampling.method.stratified
elseif ParticleOptions.resampling.method.stratified
resampled_particles = residual_resampling(particles,weights,rand(size(weights)));
else
error('Unknown sampling method!')

View File

@ -1,4 +1,4 @@
function [LIK,lik] = sequential_importance_particle_filter(ReducedForm,Y,start,DynareOptions)
function [LIK,lik] = sequential_importance_particle_filter(ReducedForm,Y,start,ParticleOptions,ThreadsOptions)
% Evaluates the likelihood of a nonlinear model with a particle filter (optionally with resampling).
@ -30,7 +30,7 @@ if isempty(start)
end
% Set flag for prunning
pruning = DynareOptions.particle.pruning;
pruning = ParticleOptions.pruning;
% Get steady state and mean.
steadystate = ReducedForm.steadystate;
@ -45,7 +45,7 @@ if isempty(init_flag)
number_of_state_variables = length(mf0);
number_of_observed_variables = length(mf1);
number_of_structural_innovations = length(ReducedForm.Q);
number_of_particles = DynareOptions.particle.number_of_particles;
number_of_particles = ParticleOptions.number_of_particles;
init_flag = 1;
end
@ -99,9 +99,9 @@ for t=1:sample_size
epsilon = Q_lower_triangular_cholesky*randn(number_of_structural_innovations,number_of_particles);
if pruning
yhat_ = bsxfun(@minus,StateVectors_,state_variables_steady_state);
[tmp, tmp_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,steadystate,DynareOptions.threads.local_state_space_iteration_2);
[tmp, tmp_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,steadystate,ThreadsOptions.local_state_space_iteration_2);
else
tmp = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,DynareOptions.threads.local_state_space_iteration_2);
tmp = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,ThreadsOptions.local_state_space_iteration_2);
end
PredictedObservedMean = tmp(mf1,:)*transpose(weights);
PredictionError = bsxfun(@minus,Y(:,t),tmp(mf1,:));
@ -117,16 +117,16 @@ for t=1:sample_size
wtilde = weights.*exp(lnw-dfac);
lik(t) = log(sum(wtilde))+dfac;
weights = wtilde/sum(wtilde);
if (DynareOptions.particle.resampling.status.generic && neff(weights)<DynareOptions.particle.resampling.threshold*sample_size) || DynareOptions.particle.resampling.status.systematic
if (ParticleOptions.resampling.status.generic && neff(weights)<ParticleOptions.resampling.threshold*sample_size) || ParticleOptions.resampling.status.systematic
if pruning
temp = resample([tmp(mf0,:)' tmp_(mf0,:)'],weights',DynareOptions);
temp = resample([tmp(mf0,:)' tmp_(mf0,:)'],weights',ParticleOptions);
StateVectors = temp(:,1:number_of_state_variables)';
StateVectors_ = temp(:,number_of_state_variables+1:2*number_of_state_variables)';
else
StateVectors = resample(tmp(mf0,:)',weights',DynareOptions)';
StateVectors = resample(tmp(mf0,:)',weights',ParticleOptions)';
end
weights = ones(1,number_of_particles)/number_of_particles;
elseif DynareOptions.particle.resampling.status.none
elseif ParticleOptions.resampling.status.none
StateVectors = tmp(mf0,:);
if pruning
StateVectors_ = tmp_(mf0,:);