diff --git a/matlab/DSMH_sampler.m b/matlab/DSMH_sampler.m index b5231d28a..fdba5160c 100644 --- a/matlab/DSMH_sampler.m +++ b/matlab/DSMH_sampler.m @@ -1,5 +1,5 @@ function DSMH_sampler(TargetFun,xparam1,mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_) -% function DSMH_sampler(TargetFun,xparam1,mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_) + % Dynamic Striated Metropolis-Hastings algorithm. % % INPUTS @@ -33,7 +33,7 @@ function DSMH_sampler(TargetFun,xparam1,mh_bounds,dataset_,dataset_info,options_ % Then the comments write here can be used for all the other pairs of % parallel functions and also for management functions. -% Copyright (C) 2006-2021 Dynare Team +% Copyright © 2006-2022 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/Herbst_Schorfheide_sampler.m b/matlab/Herbst_Schorfheide_sampler.m index 2c29de4a5..b73b8f87b 100644 --- a/matlab/Herbst_Schorfheide_sampler.m +++ b/matlab/Herbst_Schorfheide_sampler.m @@ -33,7 +33,7 @@ function Herbst_Schorfheide_sampler(TargetFun,xparam1,mh_bounds,dataset_,dataset % Then the comments write here can be used for all the other pairs of % parallel functions and also for management functions. -% Copyright (C) 2006-2021 Dynare Team +% Copyright © 2006-2022 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/SMC_resampling.m b/matlab/SMC_resampling.m index bac7eeac0..750eec105 100644 --- a/matlab/SMC_resampling.m +++ b/matlab/SMC_resampling.m @@ -1,11 +1,30 @@ -function indx = smc_resampling(weights,noise,number) - indx = zeros(number,1); - cumweights = cumsum(weights); - randvec = (transpose(1:number)-1+noise(:))/number; - j = 1; - for i=1:number - while (randvec(i)>cumweights(j)) - j = j+1; - end - indx(i) = j; +function indx = SMC_resampling(weights,noise,number) + +% Copyright © 2022 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + + +indx = zeros(number,1); +cumweights = cumsum(weights); +randvec = (transpose(1:number)-1+noise(:))/number; +j = 1; +for i=1:number + while (randvec(i)>cumweights(j)) + j = j+1; end + indx(i) = j; +end diff --git a/matlab/SMC_samplers_initialization.m b/matlab/SMC_samplers_initialization.m index 4f998926b..a4a90acbf 100644 --- a/matlab/SMC_samplers_initialization.m +++ b/matlab/SMC_samplers_initialization.m @@ -28,7 +28,7 @@ function [ ix2, temperedlogpost, loglik, bayestopt_] = ... % SPECIAL REQUIREMENTS % None. -% Copyright (C) 2006-2017 Dynare Team +% Copyright © 2006-2022 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/particles b/matlab/particles index 494248828..d71f8be6e 160000 --- a/matlab/particles +++ b/matlab/particles @@ -1 +1 @@ -Subproject commit 494248828735d762052877abc264d305146c366f +Subproject commit d71f8be6e777fd3e08f1ab2cb74bbf9621ad2d8e diff --git a/matlab/tempered_likelihood.m b/matlab/tempered_likelihood.m index 4af11080a..af9e8626d 100644 --- a/matlab/tempered_likelihood.m +++ b/matlab/tempered_likelihood.m @@ -1,5 +1,23 @@ - function [tlogpostkern,loglik] = tempered_likelihood(TargetFun,xparam1,lambda,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_) - logpostkern = -feval(TargetFun,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); - logprior = priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7,bayestopt_.p3,bayestopt_.p4); - loglik = logpostkern-logprior ; - tlogpostkern = lambda*loglik + logprior; +function [tlogpostkern,loglik] = tempered_likelihood(TargetFun,xparam1,lambda,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_) + +% Copyright © 2022 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + +logpostkern = -feval(TargetFun,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); +logprior = priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7,bayestopt_.p3,bayestopt_.p4); +loglik = logpostkern-logprior ; +tlogpostkern = lambda*loglik + logprior;