Fix and update unit tests for local_state_space_iteration_2.

Add mat file with git lfs.
fix-tolerance-parameters
Stéphane Adjemian (Ryûk) 2022-05-13 12:13:46 +02:00
parent f7204e6ec8
commit cd76bdff9e
Signed by: stepan
GPG Key ID: 295C1FE89E17EB3C
20 changed files with 87 additions and 95 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.mat filter=lfs diff=lfs merge=lfs -text

View File

@ -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 % 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 % 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 %@test:2
old_path = pwd; old_path = pwd;
cd([fileparts(which('dynare')) '/../tests/']); cd([fileparts(which('dynare')) '/../tests/particle']);
dynare('dsge_base2'); load dsgebase2data;
load dsge_base2;
cd(old_path); cd(old_path);
dr = oo_.dr; n = length(state_variables_idx);
clear('oo_','options_','M_'); q = size(ReducedForm.ghu,2);
delete([fileparts(which('dynare')) '/../tests/dsge_base2.mat']); yhatinit = randn(n,1);
istates = dr.nstatic+(1:dr.npred); epsilon = randn(q,2);
n = dr.npred; ghx = ReducedForm.ghx(state_variables_idx,:);
q = size(dr.ghu,2); ghu = ReducedForm.ghu(state_variables_idx,:);
yhat = zeros(n,1); constant = ReducedForm.constant(state_variables_idx,:);
epsilon = zeros(q,1); ghxx = ReducedForm.ghxx(state_variables_idx,:);
ghx = dr.ghx(istates,:); ghuu = ReducedForm.ghuu(state_variables_idx,:);
ghu = dr.ghu(istates,:); ghxu = ReducedForm.ghxu(state_variables_idx,:);
constant = dr.ys(istates,:)+dr.ghs2(istates,:); yhatinit_ = randn(n,1);
ghxx = dr.ghxx(istates,:); ss = ReducedForm.state_variables_steady_state;
ghuu = dr.ghuu(istates,:); t = true(6,1);
ghxu = dr.ghxu(istates,:); % Call the tested routine (matlab).
yhat_ = zeros(n,1); addpath(sprintf('%s/missing/mex/local_state_space_iterations', fileparts(which('dynare'))))
ss = dr.ys(istates,:);
t = ones(2,1);
% Call the tested routine.
try 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 catch
t(1) = 0; t(1) = false;
end end
try 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 catch
t(2) = 0; t(2) = false;
end end
rmpath(sprintf('%s/missing/mex/local_state_space_iterations', fileparts(which('dynare'))))
% Check the results. % 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); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
Bohrbug = 1; % A bug that manifests reliably under a possibly unknown but well-defined set of conditions. n = 2;
if ~Bohrbug q = 3;
n = 2; yhat = .01*randn(n,1);
q = 3; epsilon = .001*randn(q,1);
ghx = rand(n,n);
yhat = .01*randn(n,1); ghu = rand(n,q);
epsilon = .001*randn(q,1); constant = ones(n,1);
ghx = rand(n,n); ghxx = rand(n,n*n);
ghu = rand(n,q); ghuu = rand(n,q*q);
constant = ones(n,1); ghxu = rand(n,n*q);
ghxx = rand(n,n*n); yhat_ = zeros(n,1);
ghuu = rand(n,q*q); ss = ones(n,1);
ghxu = rand(n,n*q); % Call the tested routine (mex version).
yhat_ = zeros(n,1); y1a = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1);
ss = ones(n,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)
% Call the tested routine (mex version). addpath(sprintf('%s/missing/mex/local_state_space_iterations', fileparts(which('dynare'))))
y1a = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1); y1b = 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); [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'))))
% Call the tested routine (matlab version) % Check the results.
path_to_mex = fileparts(which(['qmc_sequence.' mexext])); t(1) = max(abs(y1a-y1b))<1e-6;
where_am_i_coming_from = pwd; t(2) = max(abs(y2a-y2b))<1e-6;
cd(path_to_mex); t(3) = max(abs(y2a_-y2b_))<1e-6;
tar('local_state_space_iteration_2.tar',['local_state_space_iteration_2.' mexext]); T = all(t);
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
%@eof:3 %@eof:3
%@test:4 %@test:4
% TIMING TEST (parallelization with openmp) % TIMING TEST (parallelization with openmp)
old_path = pwd; old_path = pwd;
cd([fileparts(which('dynare')) '/../tests/']); cd([fileparts(which('dynare')) '/../tests/particle']);
dynare('dsge_base2'); load dsgebase2data;
load dsge_base2;
cd(old_path); cd(old_path);
dr = oo_.dr; n = length(state_variables_idx);
clear('oo_','options_','M_'); q = size(ReducedForm.ghu,2);
delete([fileparts(which('dynare')) '/../tests/dsge_base2.mat']); yhat = randn(n,10000000);
istates = dr.nstatic+(1:dr.npred); epsilon = .01*randn(q,10000000);
n = dr.npred; ghx = ReducedForm.ghx(state_variables_idx,:);
q = size(dr.ghu,2); ghu = ReducedForm.ghu(state_variables_idx,:);
yhat = zeros(n,10000000); constant = ReducedForm.constant(state_variables_idx,:);
epsilon = zeros(q,10000000); ghxx = ReducedForm.ghxx(state_variables_idx,:);
ghx = dr.ghx(istates,:); ghuu = ReducedForm.ghuu(state_variables_idx,:);
ghu = dr.ghu(istates,:); ghxu = ReducedForm.ghxu(state_variables_idx,:);
constant = dr.ys(istates,:)+dr.ghs2(istates,:); yhatinit_ = randn(n,1);
ghxx = dr.ghxx(istates,:); ss = ReducedForm.state_variables_steady_state;
ghuu = dr.ghuu(istates,:); yhat_ = randn(n,10000000);
ghxu = dr.ghxu(istates,:);
yhat_ = zeros(n,10000000);
ss = dr.ys(istates,:);
t = NaN(4,1); 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 tic, for i=1:10, y1 = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,1); end
t1 = toc; t1 = toc;
@ -238,4 +225,4 @@ if ~t(4)
end end
% Check the results. % Check the results.
T = all(t); T = all(t);
%@eof:4 %@eof:4

View File

@ -1307,6 +1307,7 @@ EXTRA_DIST = \
smoother2histval/fsdat_simul.m \ smoother2histval/fsdat_simul.m \
particle/first_spec_common.inc \ particle/first_spec_common.inc \
particle/risky.m \ particle/risky.m \
particle/dsgebase2data.mat \
optimal_policy/Ramsey/find_c.m \ optimal_policy/Ramsey/find_c.m \
observation_trends_and_prefiltering/generate_trend_stationary_AR1.m \ observation_trends_and_prefiltering/generate_trend_stationary_AR1.m \
observation_trends_and_prefiltering/Trend_diagnostics_MCMC_common.inc \ observation_trends_and_prefiltering/Trend_diagnostics_MCMC_common.inc \

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tests/particle/dsgebase2data.mat (Stored with Git LFS) Normal file

Binary file not shown.