diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..4d5d84092 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.mat filter=lfs diff=lfs merge=lfs -text diff --git a/matlab/missing/mex/local_state_space_iterations/local_state_space_iteration_2.m b/matlab/missing/mex/local_state_space_iterations/local_state_space_iteration_2.m index 28c30f3f3..db2255f43 100644 --- a/matlab/missing/mex/local_state_space_iterations/local_state_space_iteration_2.m +++ b/matlab/missing/mex/local_state_space_iterations/local_state_space_iteration_2.m @@ -1,4 +1,4 @@ -function [y, y_] = local_state_space_iteration_2(yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, a, b, c) +function [y, y_] = local_state_space_iteration_2(yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, a, b, c) % --*-- Unitary tests --*-- % Given the demeaned states (yhat) and structural innovations (epsilon), this routine computes the level of selected endogenous variables when the % model is approximated by an order two taylor expansion around the deterministic steady state. Depending on the number of input/output @@ -109,116 +109,103 @@ T = all(t); %@test:2 old_path = pwd; -cd([fileparts(which('dynare')) '/../tests/']); -dynare('dsge_base2'); -load dsge_base2; +cd([fileparts(which('dynare')) '/../tests/particle']); +load dsgebase2data; cd(old_path); -dr = oo_.dr; -clear('oo_','options_','M_'); -delete([fileparts(which('dynare')) '/../tests/dsge_base2.mat']); -istates = dr.nstatic+(1:dr.npred); -n = dr.npred; -q = size(dr.ghu,2); -yhat = zeros(n,1); -epsilon = zeros(q,1); -ghx = dr.ghx(istates,:); -ghu = dr.ghu(istates,:); -constant = dr.ys(istates,:)+dr.ghs2(istates,:); -ghxx = dr.ghxx(istates,:); -ghuu = dr.ghuu(istates,:); -ghxu = dr.ghxu(istates,:); -yhat_ = zeros(n,1); -ss = dr.ys(istates,:); - -t = ones(2,1); - -% Call the tested routine. +n = length(state_variables_idx); +q = size(ReducedForm.ghu,2); +yhatinit = randn(n,1); +epsilon = randn(q,2); +ghx = ReducedForm.ghx(state_variables_idx,:); +ghu = ReducedForm.ghu(state_variables_idx,:); +constant = ReducedForm.constant(state_variables_idx,:); +ghxx = ReducedForm.ghxx(state_variables_idx,:); +ghuu = ReducedForm.ghuu(state_variables_idx,:); +ghxu = ReducedForm.ghxu(state_variables_idx,:); +yhatinit_ = randn(n,1); +ss = ReducedForm.state_variables_steady_state; +t = true(6,1); +% Call the tested routine (matlab). +addpath(sprintf('%s/missing/mex/local_state_space_iterations', fileparts(which('dynare')))) try - y1 = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1); + yhat1 = local_state_space_iteration_2(yhatinit, epsilon(:,1), ghx, ghu, constant, ghxx, ghuu, ghxu, 1); + yhat1 = local_state_space_iteration_2(yhat1, epsilon(:,2), ghx, ghu, constant, ghxx, ghuu, ghxu, 1); catch - t(1) = 0; + t(1) = false; end try - [y2,y2_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,ss,1); + [yhat2, yhat2_] = local_state_space_iteration_2(yhatinit, epsilon(:,1), ghx, ghu, constant, ghxx, ghuu, ghxu, yhatinit_, ss, 1); + [yhat2, yhat2_] = local_state_space_iteration_2(yhat2, epsilon(:,2), ghx, ghu, constant, ghxx, ghuu, ghxu, yhat2_, ss, 1); catch - t(2) = 0; + t(2) = false; end - -% Check the results. +rmpath(sprintf('%s/missing/mex/local_state_space_iterations', fileparts(which('dynare')))) +% Call the tested routine (mex). +try + yhat3 = local_state_space_iteration_2(yhatinit, epsilon(:,1), ghx, ghu, constant, ghxx, ghuu, ghxu, 1); + yhat3 = local_state_space_iteration_2(yhat3, epsilon(:,2), ghx, ghu, constant, ghxx, ghuu, ghxu, 1); +catch + t(3) = false; +end +try + [yhat4, yhat4_] = local_state_space_iteration_2(yhatinit, epsilon(:,1), ghx, ghu, constant, ghxx, ghuu, ghxu, yhatinit_, ss, 1); + [yhat4, yhat4_] = local_state_space_iteration_2(yhat4, epsilon(:,2), ghx, ghu, constant, ghxx, ghuu, ghxu, yhat4_, ss, 1); +catch + t(4) = false; +end +t(5) = max(abs(yhat1-yhat3))<1e-10; % Compare matlab and mex routines without pruning. +t(6) = max(abs(yhat2-yhat4))<1e-10; % Compare matlab and mex routines with pruning. + % Check the results. T = all(t); %@eof:2 %@test:3 -Bohrbug = 1; % A bug that manifests reliably under a possibly unknown but well-defined set of conditions. -if ~Bohrbug - n = 2; - q = 3; - - yhat = .01*randn(n,1); - epsilon = .001*randn(q,1); - ghx = rand(n,n); - ghu = rand(n,q); - constant = ones(n,1); - ghxx = rand(n,n*n); - ghuu = rand(n,q*q); - ghxu = rand(n,n*q); - yhat_ = zeros(n,1); - ss = ones(n,1); - - % Call the tested routine (mex version). - y1a = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1); - [y2a,y2a_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,ss,1); - - % Call the tested routine (matlab version) - path_to_mex = fileparts(which(['qmc_sequence.' mexext])); - where_am_i_coming_from = pwd; - cd(path_to_mex); - tar('local_state_space_iteration_2.tar',['local_state_space_iteration_2.' mexext]); - cd(where_am_i_coming_from); - dynare_config(); - y1b = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1); - [y2b,y2b_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,ss,1); - cd(path_to_mex); - untar('local_state_space_iteration_2.tar'); - delete('local_state_space_iteration_2.tar'); - cd(where_am_i_coming_from); - dynare_config(); - % Check the results. - t(1) = dassert(y1a,y1b); - t(2) = dassert(y2a,y2b); - t(3) = dassert(y2a_,y2b_); - T = all(t); -else - t(1) = 1; - T = all(t); -end +n = 2; +q = 3; +yhat = .01*randn(n,1); +epsilon = .001*randn(q,1); +ghx = rand(n,n); +ghu = rand(n,q); +constant = ones(n,1); +ghxx = rand(n,n*n); +ghuu = rand(n,q*q); +ghxu = rand(n,n*q); +yhat_ = zeros(n,1); +ss = ones(n,1); +% Call the tested routine (mex version). +y1a = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1); +[y2a,y2a_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,ss,1); +% Call the tested routine (matlab version) +addpath(sprintf('%s/missing/mex/local_state_space_iterations', fileparts(which('dynare')))) +y1b = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1); +[y2b,y2b_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,ss,1); +rmpath(sprintf('%s/missing/mex/local_state_space_iterations', fileparts(which('dynare')))) +% Check the results. +t(1) = max(abs(y1a-y1b))<1e-6; +t(2) = max(abs(y2a-y2b))<1e-6; +t(3) = max(abs(y2a_-y2b_))<1e-6; +T = all(t); %@eof:3 - %@test:4 % TIMING TEST (parallelization with openmp) old_path = pwd; -cd([fileparts(which('dynare')) '/../tests/']); -dynare('dsge_base2'); -load dsge_base2; +cd([fileparts(which('dynare')) '/../tests/particle']); +load dsgebase2data; cd(old_path); -dr = oo_.dr; -clear('oo_','options_','M_'); -delete([fileparts(which('dynare')) '/../tests/dsge_base2.mat']); -istates = dr.nstatic+(1:dr.npred); -n = dr.npred; -q = size(dr.ghu,2); -yhat = zeros(n,10000000); -epsilon = zeros(q,10000000); -ghx = dr.ghx(istates,:); -ghu = dr.ghu(istates,:); -constant = dr.ys(istates,:)+dr.ghs2(istates,:); -ghxx = dr.ghxx(istates,:); -ghuu = dr.ghuu(istates,:); -ghxu = dr.ghxu(istates,:); -yhat_ = zeros(n,10000000); -ss = dr.ys(istates,:); - +n = length(state_variables_idx); +q = size(ReducedForm.ghu,2); +yhat = randn(n,10000000); +epsilon = .01*randn(q,10000000); +ghx = ReducedForm.ghx(state_variables_idx,:); +ghu = ReducedForm.ghu(state_variables_idx,:); +constant = ReducedForm.constant(state_variables_idx,:); +ghxx = ReducedForm.ghxx(state_variables_idx,:); +ghuu = ReducedForm.ghuu(state_variables_idx,:); +ghxu = ReducedForm.ghxu(state_variables_idx,:); +yhatinit_ = randn(n,1); +ss = ReducedForm.state_variables_steady_state; +yhat_ = randn(n,10000000); t = NaN(4,1); tic, for i=1:10, y1 = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1); end t1 = toc; @@ -238,4 +225,4 @@ if ~t(4) end % Check the results. T = all(t); -%@eof:4 +%@eof:4 \ No newline at end of file diff --git a/tests/Makefile.am b/tests/Makefile.am index 864b0f9fd..e532bc68b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1307,6 +1307,7 @@ EXTRA_DIST = \ smoother2histval/fsdat_simul.m \ particle/first_spec_common.inc \ particle/risky.m \ + particle/dsgebase2data.mat \ optimal_policy/Ramsey/find_c.m \ observation_trends_and_prefiltering/generate_trend_stationary_AR1.m \ observation_trends_and_prefiltering/Trend_diagnostics_MCMC_common.inc \ diff --git a/tests/analytic_derivatives/nBrockMirmanSYM.mat b/tests/analytic_derivatives/nBrockMirmanSYM.mat index 7bdc38ac0..113a48a91 100644 Binary files a/tests/analytic_derivatives/nBrockMirmanSYM.mat and b/tests/analytic_derivatives/nBrockMirmanSYM.mat differ diff --git a/tests/block_bytecode/lola_data.mat b/tests/block_bytecode/lola_data.mat index 67c0c926c..e74ec24ea 100644 Binary files a/tests/block_bytecode/lola_data.mat and b/tests/block_bytecode/lola_data.mat differ diff --git a/tests/decision_rules/example1_results_dyn_432.mat b/tests/decision_rules/example1_results_dyn_432.mat index 9674ccf0d..13f800b12 100644 Binary files a/tests/decision_rules/example1_results_dyn_432.mat and b/tests/decision_rules/example1_results_dyn_432.mat differ diff --git a/tests/decision_rules/third_order/FV_2011_policyfunctions.mat b/tests/decision_rules/third_order/FV_2011_policyfunctions.mat index 40d30f764..2135366e2 100644 Binary files a/tests/decision_rules/third_order/FV_2011_policyfunctions.mat and b/tests/decision_rules/third_order/FV_2011_policyfunctions.mat differ diff --git a/tests/estimation/method_of_moments/AFVRR/AFVRR_data.mat b/tests/estimation/method_of_moments/AFVRR/AFVRR_data.mat index f606b2109..d14be4caa 100644 Binary files a/tests/estimation/method_of_moments/AFVRR/AFVRR_data.mat and b/tests/estimation/method_of_moments/AFVRR/AFVRR_data.mat differ diff --git a/tests/estimation/method_of_moments/AnScho/AnScho_MoM_data_2.mat b/tests/estimation/method_of_moments/AnScho/AnScho_MoM_data_2.mat index bce9e7d36..e27910992 100644 Binary files a/tests/estimation/method_of_moments/AnScho/AnScho_MoM_data_2.mat and b/tests/estimation/method_of_moments/AnScho/AnScho_MoM_data_2.mat differ diff --git a/tests/estimation/method_of_moments/RBC/RBC_Andreasen_Data_2.mat b/tests/estimation/method_of_moments/RBC/RBC_Andreasen_Data_2.mat index 0b2ba62de..a2faf16f9 100644 Binary files a/tests/estimation/method_of_moments/RBC/RBC_Andreasen_Data_2.mat and b/tests/estimation/method_of_moments/RBC/RBC_Andreasen_Data_2.mat differ diff --git a/tests/gsa/data_ca1.mat b/tests/gsa/data_ca1.mat index de3fc44b2..0531f7222 100644 Binary files a/tests/gsa/data_ca1.mat and b/tests/gsa/data_ca1.mat differ diff --git a/tests/identification/as2007/G_QT.mat b/tests/identification/as2007/G_QT.mat index 74b7e7399..170b7c0cf 100644 Binary files a/tests/identification/as2007/G_QT.mat and b/tests/identification/as2007/G_QT.mat differ diff --git a/tests/kalman_filter_smoother/test.mat b/tests/kalman_filter_smoother/test.mat index 95db1c32c..2a325d434 100644 Binary files a/tests/kalman_filter_smoother/test.mat and b/tests/kalman_filter_smoother/test.mat differ diff --git a/tests/kronecker/nash_matrices.mat b/tests/kronecker/nash_matrices.mat index 530c7e4eb..0e122960e 100644 Binary files a/tests/kronecker/nash_matrices.mat and b/tests/kronecker/nash_matrices.mat differ diff --git a/tests/objectives/sgu_ex1.mat b/tests/objectives/sgu_ex1.mat index 694139850..5f7a3b3dd 100644 Binary files a/tests/objectives/sgu_ex1.mat and b/tests/objectives/sgu_ex1.mat differ diff --git a/tests/occbin/filter/NKM_mh_mode_saved.mat b/tests/occbin/filter/NKM_mh_mode_saved.mat index 80764521c..fa8e685b5 100644 Binary files a/tests/occbin/filter/NKM_mh_mode_saved.mat and b/tests/occbin/filter/NKM_mh_mode_saved.mat differ diff --git a/tests/occbin/filter/dataobsfile.mat b/tests/occbin/filter/dataobsfile.mat index 93b6334ad..c7932d9a4 100644 Binary files a/tests/occbin/filter/dataobsfile.mat and b/tests/occbin/filter/dataobsfile.mat differ diff --git a/tests/particle/dsgebase2data.mat b/tests/particle/dsgebase2data.mat new file mode 100644 index 000000000..a018a6933 --- /dev/null +++ b/tests/particle/dsgebase2data.mat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1fe5c7ae3cdcabc3b1c9d2c3030d7b055b29e0edc2d4e7d8d9c9926cf4e5734 +size 904 diff --git a/tests/pruning/Andreasen_et_al_2018_Dynare44Pruning_v2.mat b/tests/pruning/Andreasen_et_al_2018_Dynare44Pruning_v2.mat index 7bfbab582..2bf2e03ba 100644 Binary files a/tests/pruning/Andreasen_et_al_2018_Dynare44Pruning_v2.mat and b/tests/pruning/Andreasen_et_al_2018_Dynare44Pruning_v2.mat differ diff --git a/tests/shock_decomposition/example1_calib_shock_decomp_data.mat b/tests/shock_decomposition/example1_calib_shock_decomp_data.mat index a5ecea5bb..7fb4509f9 100644 Binary files a/tests/shock_decomposition/example1_calib_shock_decomp_data.mat and b/tests/shock_decomposition/example1_calib_shock_decomp_data.mat differ