


Resamples particles.


0001 function indx = resample(weights,method1,method2) 0002 % Resamples particles. 0003 0004 %@info: 0005 %! @deftypefn {Function File} {@var{indx} =} resample (@var{weights}, @var{method}) 0006 %! @anchor{particle/resample} 0007 %! @sp 1 0008 %! Resamples particles. 0009 %! @sp 2 0010 %! @strong{Inputs} 0011 %! @sp 1 0012 %! @table @ @var 0013 %! @item weights 0014 %! n*1 vector of doubles, particles' weights. 0015 %! @item method 0016 %! string equal to 'residual' or 'traditional'. 0017 %! @end table 0018 %! @sp 2 0019 %! @strong{Outputs} 0020 %! @sp 1 0021 %! @table @ @var 0022 %! @item indx 0023 %! n*1 vector of intergers, indices. 0024 %! @end table 0025 %! @sp 2 0026 %! @strong{This function is called by:} 0027 %! @sp 1 0028 %! @ref{particle/sequantial_importance_particle_filter} 0029 %! @sp 2 0030 %! @strong{This function calls:} 0031 %! @sp 1 0032 %! @ref{residual_resampling}, @ref{traditional_resampling} 0033 %! @sp 2 0034 %! @end deftypefn 0035 %@eod: 0036 0037 % Copyright (C) 2011, 2012 Dynare Team 0038 % 0039 % This file is part of Dynare. 0040 % 0041 % Dynare is free software: you can redistribute it and/or modify 0042 % it under the terms of the GNU General Public License as published by 0043 % the Free Software Foundation, either version 3 of the License, or 0044 % (at your option) any later version. 0045 % 0046 % Dynare is distributed in the hope that it will be useful, 0047 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0048 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0049 % GNU General Public License for more details. 0050 % 0051 % You should have received a copy of the GNU General Public License 0052 % along with Dynare. If not, see <http://www.gnu.org/licenses/>. 0053 0054 % AUTHOR(S) frederic DOT karame AT univ DASH evry DOT fr 0055 % stephane DOT adjemian AT univ DASH lemans DOT fr 0056 0057 switch method1 0058 case 'residual' 0059 indx = residual_resampling(weights); 0060 case 'traditional' 0061 if strcmpi(method2,'kitagawa') 0062 indx = traditional_resampling(weights,rand); 0063 elseif strcmpi(method2,'stratified') 0064 indx = traditional_resampling(weights,rand(size(weights))); 0065 else 0066 error('particle::resample: Unknown method!') 0067 end 0068 otherwise 0069 error('particle::resample: Unknown method!') 0070 end