diff --git a/matlab/method_of_moments/method_of_moments.m b/matlab/method_of_moments/method_of_moments.m index a059536e38619db58a188de85b7690f7fdf703ee..30d47f7fe533c0f661fb8c65ae5aad6ee97b6204 100644 --- a/matlab/method_of_moments/method_of_moments.m +++ b/matlab/method_of_moments/method_of_moments.m @@ -416,7 +416,7 @@ for jm=1:size(M_.matched_moments,1) % sort such that t=0 variable comes first [M_.matched_moments{jm,2},idx_sort] = sort(M_.matched_moments{jm,2},'descend'); M_.matched_moments{jm,1} = M_.matched_moments{jm,1}(idx_sort); - M_.matched_moments{jm,3} = M_.matched_moments{jm,3}(idx_sort); + M_.matched_moments{jm,3} = M_.matched_moments{jm,3}(idx_sort); end % find duplicate rows in cell array by making groups according to powers as we can then use cell2mat for the unique function @@ -430,14 +430,14 @@ end % remove duplicate elements DuplicateMoms = setdiff(1:size(M_.matched_moments_orig,1),UniqueMomIdx); -if ~isempty(DuplicateMoms) +if ~isempty(DuplicateMoms) fprintf('Found and removed duplicate declared moments in ''matched_moments'' block in rows:\n %s.\n',num2str(DuplicateMoms)) fprintf('Dynare will continue with remaining moment conditions\n'); end if strcmp(options_mom_.mom.mom_method, 'SMM') % for SMM we can keep the original structure but get rid of duplicate moments - M_.matched_moments = M_.matched_moments_orig(sort(UniqueMomIdx),:); + M_.matched_moments = M_.matched_moments_orig(sort(UniqueMomIdx),:); elseif strcmp(options_mom_.mom.mom_method, 'GMM') % for GMM we use the transformed matched_moments structure M_.matched_moments = M_.matched_moments(sort(UniqueMomIdx),:); @@ -447,7 +447,7 @@ end first_moment_indicator = find(cellfun(@(x) sum(abs(x))==1,M_.matched_moments(:,3)))'; if options_mom_.prefilter && ~isempty(first_moment_indicator) fprintf('Centered moments requested (prefilter option is set); therefore, ignore declared first moments in ''matched_moments'' block.\n'); - M_.matched_moments(first_moment_indicator,:)=[]; %remove first moments entries + M_.matched_moments(first_moment_indicator,:)=[]; %remove first moments entries end options_mom_.mom.mom_nbr = size(M_.matched_moments,1); @@ -987,7 +987,7 @@ for jm = 1:size(M_.matched_moments,1) end data_mat=[oo_.mom.data_moments oo_.mom.model_moments ]; dyntable(options_mom_, title, headers, labels, data_mat, cellofchararraymaxlength(labels)+2, 10, 7); -if options_mom_.TeX +if options_mom_.TeX dyn_latex_table(M_, options_mom_, title, ['comparison_moments_', options_mom_.mom.mom_method], headers, labels_TeX, data_mat, cellofchararraymaxlength(labels)+2, 10, 7); end diff --git a/matlab/method_of_moments/method_of_moments_objective_function.m b/matlab/method_of_moments/method_of_moments_objective_function.m index c3b1362cbf2acd867d2a4df3a5c0fcaeff5e21bb..27af647a5c3a459de7817f8a8111660c525d7cb8 100644 --- a/matlab/method_of_moments/method_of_moments_objective_function.m +++ b/matlab/method_of_moments/method_of_moments_objective_function.m @@ -184,7 +184,7 @@ if strcmp(options_mom_.mom.mom_method,'GMM') oo_.mom.model_moments_params_derivs(jm,jp) = pruned_state_space.dVar_y(idx1,idx2,jp) + pruned_state_space.dE_y(idx1,jp)*pruned_state_space.E_y(idx2)' + pruned_state_space.E_y(idx1)*pruned_state_space.dE_y(idx2,jp)'; end end - end + end else % Autocovariance lag = -M_.matched_moments{jm,2}(2); %note that leads/lags in matched_moments are transformed such that first entry is always 0 and the second is a lag @@ -200,12 +200,12 @@ if strcmp(options_mom_.mom.mom_method,'GMM') oo_.mom.model_moments_params_derivs(jm,jp) = vec( pruned_state_space.dVar_yi(idx1,idx2,lag,jp) + pruned_state_space.dE_y(idx1,jp)*pruned_state_space.E_y(idx2)' + pruned_state_space.E_y(idx1)*pruned_state_space.dE_y(idx2,jp)'); end end - end + end end - end + end end - - + + elseif strcmp(options_mom_.mom.mom_method,'SMM') %------------------------------------------------------------------------------ % 3. Compute Moments of the model solution for normal innovations diff --git a/tests/estimation/method_of_moments/AnScho/AnScho_MoM_common.inc b/tests/estimation/method_of_moments/AnScho/AnScho_MoM_common.inc index 866f2ac517bfc3b3348b68c745c0f4927cb40ba6..b858efd3fe57f192f3a1a4518dfce07523d0a94f 100644 --- a/tests/estimation/method_of_moments/AnScho/AnScho_MoM_common.inc +++ b/tests/estimation/method_of_moments/AnScho/AnScho_MoM_common.inc @@ -253,7 +253,7 @@ method_of_moments( ,'MaxFunEvals' , 1D6 % maximum number of function evaluations allowed, a positive integer % ,'UseParallel' , 1 % when true (and supported by optimizer) solver estimates gradients in parallel (using Matlab/Octave's parallel toolbox) % ,'Jacobian' , 'off' % when 'off' gradient-based solvers approximate Jacobian using finite differences; for GMM we can also pass the analytical Jacobian to gradient-based solvers by setting this 'on' - ) + ) %, silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between % Numerical algorithms options diff --git a/tests/estimation/method_of_moments/AnScho/AnScho_matched_moments.mod b/tests/estimation/method_of_moments/AnScho/AnScho_matched_moments.mod index 76c48ad75117323f71fbfbc8b50c05bb46ad073b..99e465adc7ca5b4789b5050c5392018c7d243bb7 100644 --- a/tests/estimation/method_of_moments/AnScho/AnScho_matched_moments.mod +++ b/tests/estimation/method_of_moments/AnScho/AnScho_matched_moments.mod @@ -17,7 +17,7 @@ iINT = strmatch('INT', M_.endo_names,'exact'); % - third entry: power matched_moments_orig = { - + %first-order product moments [iYGR ] [0 ], [1]; [iYGR ] [-1], [1]; @@ -27,7 +27,7 @@ matched_moments_orig = { [iINFL ] [2 ], [1]; [iINT ] [-2], [1]; [iINT ] [2 ], [1]; - + %second-order contemporenous product moments [iYGR ] [0 ], [2 ]; [iYGR ] [-1 ], [2 ]; @@ -54,7 +54,7 @@ matched_moments_orig = { [iYGR iINFL] [5 -3], [1 1]; [iYGR iINFL] [5 -3], [1 1]; [iINT iINFL] [2 3], [1 1]; - + [iYGR ] [0 ], [3 ]; [iYGR iYGR ] [-3 -3 ], [1 2 ]; [iYGR iYGR ] [-3 -3 ], [1 2 ]; @@ -64,12 +64,12 @@ matched_moments_orig = { [iINFL iINT ] [1 0 ], [4 2 ]; [iYGR iINFL iINT] [0 -3 5], [2 4 6]; [iINFL iYGR iINT] [-3 0 5], [4 2 6]; - [iINFL iYGR iINT] [-3 0 5], [4 2 6]; + [iINFL iYGR iINT] [-3 0 5], [4 2 6]; }; % Removed duplicate moment conditions matched_moments_no_duplicate= { - + %first-order product moments [iYGR ] [0 ], [1]; % [iYGR ] [-1], [1]; @@ -79,7 +79,7 @@ matched_moments_no_duplicate= { [iINFL ] [2 ], [1]; [iINT ] [-2], [1]; % [iINT ] [2 ], [1]; - + %second-order contemporenous product moments [iYGR ] [0 ], [2 ]; % [iYGR ] [-1 ], [2 ]; @@ -106,7 +106,7 @@ matched_moments_no_duplicate= { [iYGR iINFL] [5 -3], [1 1]; % [iYGR iINFL] [5 -3], [1 1]; [iINT iINFL] [2 3], [1 1]; - + [iYGR ] [0 ], [3 ]; % [iYGR iYGR ] [-3 -3 ], [1 2 ]; % [iYGR iYGR ] [-3 -3 ], [1 2 ]; @@ -116,7 +116,7 @@ matched_moments_no_duplicate= { % [iINFL iINT ] [1 0 ], [4 2 ]; [iYGR iINFL iINT] [0 -3 5], [2 4 6]; % [iINFL iYGR iINT] [-3 0 5], [4 2 6]; -% [iINFL iYGR iINT] [-3 0 5], [4 2 6]; +% [iINFL iYGR iINT] [-3 0 5], [4 2 6]; }; @@ -131,4 +131,4 @@ if ~isequal(M_.matched_moments,matched_moments_no_duplicate) error('Removal of duplicate moment conditions failed!') else fprintf('Removal of duplicate moment conditions was successful!\n\n') -end \ No newline at end of file +end