From f7f44a7b65e39c5b1138799dc26e846dd6b264b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Karam=C3=A9?=
 <frederic.karame@univ-lemans.fr>
Date: Fri, 13 Dec 2024 11:33:27 +0100
Subject: [PATCH] kitagawa.m: allow drawing defined number of particles instead
 of all particles

---
 matlab/estimation/resampler/kitagawa.m | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/matlab/estimation/resampler/kitagawa.m b/matlab/estimation/resampler/kitagawa.m
index f082321528..0dd54f555e 100644
--- a/matlab/estimation/resampler/kitagawa.m
+++ b/matlab/estimation/resampler/kitagawa.m
@@ -1,15 +1,16 @@
-function indices = kitagawa(weights, noise)
-
+function indices = kitagawa(weights, noise, m)
+% function indices = kitagawa(weights, noise, m)
 % Return indices for resampling.
 %
 % INPUTS
-% - weights   [double]    n×1 vector of partcles' weights.
+% - weights   [double]    n×1 vector of particles' weights.
 % - noise     [double]    scalar, uniform random deviates in [0,1]
+% - m         [integer]   scalar, number of particles to resample 
 %
 % OUTPUTS
-% - indices   [integer]   n×1 vector of indices in [1:n]
+% - indices   [integer]   m×1 vector of indices in [1:n]
 
-% Copyright © 2022-2023 Dynare Team
+% Copyright © 2022-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -26,7 +27,11 @@ function indices = kitagawa(weights, noise)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
-n= length(weights);
+if nargin<3
+    n = length(weights);
+else 
+    n = m ;
+end 
 
 if nargin<2, noise = rand; end
 
-- 
GitLab