diff --git a/license.txt b/license.txt index c1bee92b0..73fb4bc4d 100644 --- a/license.txt +++ b/license.txt @@ -113,7 +113,7 @@ Copyright: 1995 E.G.Tsionas 2015-2017 Dynare Team License: GPL-3+ -Files: matlab/endogenous_prior.m +Files: matlab/estimation/endogenous_prior.m Copyright: 2011 Lawrence J. Christiano, Mathias Trabandt and Karl Walentin 2013-2017 Dynare Team License: GPL-3+ @@ -128,7 +128,7 @@ Copyright: 2016 Benjamin Born and Johannes Pfeifer 2016-2017 Dynare Team License: GPL-3+ -Files: matlab/commutation.m matlab/duplication.m +Files: matlab/+pruned_SS/commutation.m matlab/+pruned_SS/duplication.m Copyright: 1997 Tom Minka 2019-2020 Dynare Team License: GPL-3+ @@ -141,7 +141,7 @@ Comment: The original author gave authorization to change the license from BSD-2-clause to GPL-3+ and redistribute it under GPL-3+ with Dynare. -Files: matlab/uperm.m +Files: matlab/+pruned_SS/uperm.m Copyright: 2014 Bruno Luong 2020 Dynare Team License: GPL-3+ @@ -149,7 +149,7 @@ Comment: The original author gave authorization to change the license from BSD-2-clause to GPL-3+ and redistribute it under GPL-3+ with Dynare. -Files: matlab/prodmom.m matlab/bivmom.m +Files: matlab/+pruned_SS/prodmom.m matlab/+pruned_SS/bivmom.m Copyright: 2008-2015 Raymond Kan 2019-2020 Dynare Team License: GPL-3+ diff --git a/matlab/+identification/analysis.m b/matlab/+identification/analysis.m index e2dba28ac..c1a387e2a 100644 --- a/matlab/+identification/analysis.m +++ b/matlab/+identification/analysis.m @@ -375,7 +375,7 @@ if info(1) == 0 %no errors in solution if size(quant,1)==1 si_dMOMENTSnorm = abs(quant).*normaliz_prior_std; else - si_dMOMENTSnorm = vnorm(quant).*normaliz_prior_std; + si_dMOMENTSnorm = identification.vnorm(quant).*normaliz_prior_std; end iy = find(diag_chh); ind_dREDUCEDFORM = ind_dREDUCEDFORM(iy); @@ -385,7 +385,7 @@ if info(1) == 0 %no errors in solution if size(quant,1)==1 si_dREDUCEDFORMnorm = abs(quant).*normaliz_prior_std; else - si_dREDUCEDFORMnorm = vnorm(quant).*normaliz_prior_std; + si_dREDUCEDFORMnorm = identification.vnorm(quant).*normaliz_prior_std; end else si_dREDUCEDFORMnorm = []; @@ -399,7 +399,7 @@ if info(1) == 0 %no errors in solution if size(quant,1)==1 si_dDYNAMICnorm = abs(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end); else - si_dDYNAMICnorm = vnorm(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end); + si_dDYNAMICnorm = identification.vnorm(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end); end else si_dDYNAMICnorm=[]; diff --git a/matlab/+identification/checks.m b/matlab/+identification/checks.m index 71c62c012..03895b6ad 100644 --- a/matlab/+identification/checks.m +++ b/matlab/+identification/checks.m @@ -75,7 +75,7 @@ end % find non-zero columns at machine precision if size(Xpar,1) > 1 - ind1 = find(vnorm(Xpar) >= eps); + ind1 = find(identification.vnorm(Xpar) >= eps); else ind1 = find(abs(Xpar) >= eps); % if only one parameter end diff --git a/matlab/fjaco.m b/matlab/+identification/fjaco.m similarity index 83% rename from matlab/fjaco.m rename to matlab/+identification/fjaco.m index b020ed269..b1818932c 100644 --- a/matlab/fjaco.m +++ b/matlab/+identification/fjaco.m @@ -30,7 +30,7 @@ function fjac = fjaco(f,x,varargin) ff=feval(f,x,varargin{:}); tol = eps.^(1/3); %some default value -if strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') +if strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') tol= varargin{4}.dynatol.x; end h = tol.*max(abs(x),1); @@ -40,12 +40,12 @@ fjac = NaN(length(ff),length(x)); for j=1:length(x) xx = x; xx(j) = xh1(j); f1=feval(f,xx,varargin{:}); - if isempty(f1) && (strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') ) + if isempty(f1) && (strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') ) [~,info]=feval(f,xx,varargin{:}); disp_info_error_identification_perturbation(info,j); end xx(j) = xh0(j); f0=feval(f,xx,varargin{:}); - if isempty(f0) && (strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') ) + if isempty(f0) && (strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') ) [~,info]=feval(f,xx,varargin{:}); disp_info_error_identification_perturbation(info,j) end diff --git a/matlab/+identification/get_jacobians.m b/matlab/+identification/get_jacobians.m index fc1ba1436..f1bdac9ef 100644 --- a/matlab/+identification/get_jacobians.m +++ b/matlab/+identification/get_jacobians.m @@ -153,7 +153,7 @@ obs_nbr = length(indvobs); d2flag = 0; % do not compute second parameter derivatives % Get Jacobians (wrt selected params) of steady state, dynamic model derivatives and perturbation solution matrices for all endogenous variables -dr.derivs = get_perturbation_params_derivs(M_, options_, estim_params, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag); +dr.derivs = identification.get_perturbation_params_derivs(M_, options_, estim_params, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag); [I,~] = find(lead_lag_incidence'); %I is used to select nonzero columns of the Jacobian of endogenous variables in dynamic model files yy0 = dr.ys(I); %steady state of dynamic (endogenous and auxiliary variables) in lead_lag_incidence order @@ -230,7 +230,7 @@ elseif order == 3 end % Get (pruned) state space representation: -pruned = pruned_state_space_system(M_, options_, dr, indvobs, nlags, useautocorr, 1); +pruned = pruned_SS.pruned_state_space_system(M_, options_, dr, indvobs, nlags, useautocorr, 1); MEAN = pruned.E_y; dMEAN = pruned.dE_y; %storage for Jacobians used in dsge_likelihood.m for analytical Gradient and Hession of likelihood (only at order=1) @@ -258,7 +258,7 @@ if ~no_identification_moments if kronflag == -1 %numerical derivative of autocovariogram - dMOMENTS = fjaco(str2func('identification.numerical_objective'), xparam1, 1, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=1] + dMOMENTS = identification.fjaco(str2func('identification.numerical_objective'), xparam1, 1, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=1] dMOMENTS = [dMEAN; dMOMENTS]; %add Jacobian of steady state of VAROBS variables else dMOMENTS = zeros(obs_nbr + obs_nbr*(obs_nbr+1)/2 + nlags*obs_nbr^2 , totparam_nbr); @@ -315,7 +315,7 @@ if ~no_identification_spectrum IA = eye(size(pruned.A,1)); if kronflag == -1 %numerical derivative of spectral density - dOmega_tmp = fjaco(str2func('identification.numerical_objective'), xparam1, 2, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=2] + dOmega_tmp = identification.fjaco(str2func('identification.numerical_objective'), xparam1, 2, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=2] kk = 0; for ig = 1:length(freqs) kk = kk+1; @@ -333,7 +333,7 @@ if ~no_identification_spectrum dC = reshape(pruned.dC,size(pruned.dC,1)*size(pruned.dC,2),size(pruned.dC,3)); dD = reshape(pruned.dD,size(pruned.dD,1)*size(pruned.dD,2),size(pruned.dD,3)); dVarinov = reshape(pruned.dVarinov,size(pruned.dVarinov,1)*size(pruned.dVarinov,2),size(pruned.dVarinov,3)); - K_obs_exo = commutation(obs_nbr,size(pruned.Varinov,1)); + K_obs_exo = pruned_SS.commutation(obs_nbr,size(pruned.Varinov,1)); for ig=1:length(freqs) z = tneg(ig); zIminusA = (z*IA - pruned.A); @@ -400,7 +400,7 @@ if ~no_identification_minimal SYS.dC = dr.derivs.dghx(pruned.indy,:,:); SYS.D = dr.ghu(pruned.indy,:); SYS.dD = dr.derivs.dghu(pruned.indy,:,:); - [CheckCO,minnx,SYS] = get_minimal_state_representation(SYS,1); + [CheckCO,minnx,SYS] = identification.get_minimal_state_representation(SYS,1); if CheckCO == 0 warning_KomunjerNg = 'WARNING: Komunjer and Ng (2011) failed:\n'; @@ -423,7 +423,7 @@ if ~no_identification_minimal dvechSig = dvechSig(indvechSig,:); Inx = eye(minnx); Inu = eye(exo_nbr); - [~,Enu] = duplication(exo_nbr); + [~,Enu] = pruned_SS.duplication(exo_nbr); KomunjerNg_DL = [dminA; dminB; dminC; dminD; dvechSig]; KomunjerNg_DT = [kron(transpose(minA),Inx) - kron(Inx,minA); kron(transpose(minB),Inx); diff --git a/matlab/get_minimal_state_representation.m b/matlab/+identification/get_minimal_state_representation.m similarity index 100% rename from matlab/get_minimal_state_representation.m rename to matlab/+identification/get_minimal_state_representation.m diff --git a/matlab/get_perturbation_params_derivs.m b/matlab/+identification/get_perturbation_params_derivs.m similarity index 97% rename from matlab/get_perturbation_params_derivs.m rename to matlab/+identification/get_perturbation_params_derivs.m index 6721b3a42..9f6543998 100644 --- a/matlab/get_perturbation_params_derivs.m +++ b/matlab/+identification/get_perturbation_params_derivs.m @@ -191,7 +191,7 @@ if order > 1 && analytic_derivation_mode == 1 analytic_derivation_mode = 0; fprintf('As order > 1, reset ''analytic_derivation_mode'' to 0\n'); end -numerical_objective_fname = str2func('get_perturbation_params_derivs_numerical_objective'); +numerical_objective_fname = str2func('identification.get_perturbation_params_derivs_numerical_objective'); idx_states = nstatic+(1:nspred); %index for state variables, in DR order modparam_nbr = length(indpmodel); %number of selected model parameters stderrparam_nbr = length(indpstderr); %number of selected stderr parameters @@ -295,7 +295,7 @@ if analytic_derivation_mode == -1 % - perturbation solution matrices: dghx, dghu, dghxx, dghxu, dghuu, dghs2, dghxxx, dghxxu, dghxuu, dghuuu, dghxss, dghuss %Parameter Jacobian of covariance matrix and solution matrices (wrt selected stderr, corr and model paramters) - dSig_gh = fjaco(numerical_objective_fname, xparam1, 'perturbation_solution', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); + dSig_gh = identification.fjaco(numerical_objective_fname, xparam1, 'perturbation_solution', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); ind_Sigma_e = (1:exo_nbr^2); ind_ghx = ind_Sigma_e(end) + (1:endo_nbr*nspred); ind_ghu = ind_ghx(end) + (1:endo_nbr*exo_nbr); @@ -348,7 +348,7 @@ if analytic_derivation_mode == -1 end %Parameter Jacobian of dynamic model derivatives (wrt selected model parameters only) - dYss_g = fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); + dYss_g = identification.fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); ind_Yss = 1:endo_nbr; if options_.discretionary_policy || options_.ramsey_policy ind_g1 = ind_Yss(end) + (1:M_.eq_nbr*yy0ex0_nbr); @@ -374,7 +374,7 @@ if analytic_derivation_mode == -1 % Hessian (wrt paramters) of steady state and first-order solution matrices ghx and Om % note that hessian_sparse.m (contrary to hessian.m) does not take symmetry into account, but focuses already on unique values options_.order = 1; %make sure only first order - d2Yss_KalmanA_Om = hessian_sparse(numerical_objective_fname, xparam1, gstep, 'Kalman_Transition', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); + d2Yss_KalmanA_Om = identification.hessian_sparse(numerical_objective_fname, xparam1, gstep, 'Kalman_Transition', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); options_.order = order; %make sure to set back ind_KalmanA = ind_Yss(end) + (1:endo_nbr^2); DERIVS.d2KalmanA = d2Yss_KalmanA_Om(ind_KalmanA, indp2tottot2); %only unique elements @@ -394,7 +394,7 @@ if analytic_derivation_mode == -2 % The parameter derivatives of perturbation solution matrices are computed analytically below (analytic_derivation_mode=0) if order == 3 [~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1); - g3 = unfold_g3(g3, yy0ex0_nbr); + g3 = identification.unfold_g3(g3, yy0ex0_nbr); elseif order == 2 [~, g1, g2] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1); elseif order == 1 @@ -405,7 +405,7 @@ if analytic_derivation_mode == -2 % computation of d2Yss and d2g1 % note that hessian_sparse does not take symmetry into account, i.e. compare hessian_sparse.m to hessian.m, but focuses already on unique values, which are duplicated below options_.order = 1; %d2flag requires only first order - d2Yss_g1 = hessian_sparse(numerical_objective_fname, modparam1, gstep, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); % d2flag requires only first-order + d2Yss_g1 = identification.hessian_sparse(numerical_objective_fname, modparam1, gstep, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); % d2flag requires only first-order options_.order = order; %make sure to set back the order d2Yss = reshape(full(d2Yss_g1(1:endo_nbr,:)), [endo_nbr modparam_nbr modparam_nbr]); %put into tensor notation for j=1:endo_nbr @@ -431,7 +431,7 @@ if analytic_derivation_mode == -2 end %Parameter Jacobian of dynamic model derivatives (wrt selected model parameters only) - dYss_g = fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); + dYss_g = identification.fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); ind_Yss = 1:endo_nbr; ind_g1 = ind_Yss(end) + (1:endo_nbr*yy0ex0_nbr); dYss = dYss_g(ind_Yss,:); %in tensor notation, wrt selected model parameters only @@ -460,7 +460,7 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1) [~, ~, g2_static] = feval([fname,'.static'], ys, exo_steady_state', params); %g2_static is [endo_nbr by endo_nbr^2] second derivative (wrt all endogenous variables) of static model equations f, i.e. d(df/dys)/dys, in declaration order if order < 3 [~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1); %note that g3 does not contain symmetric elements - g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3 + g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3 else T = NaN(sum(dynamic_tmp_nbr(1:5))); T = feval([fname, '.dynamic_g4_tt'], T, ys(I), exo_steady_state', params, ys, 1); @@ -468,8 +468,8 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1) g2 = feval([fname, '.dynamic_g2'], T, ys(I), exo_steady_state', params, ys, 1, false); %g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order g3 = feval([fname, '.dynamic_g3'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g3 does not contain symmetric elements g4 = feval([fname, '.dynamic_g4'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g4 does not contain symmetric elements - g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order - g4 = unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order + g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order + g4 = identification.unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order end %g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order %g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order @@ -556,7 +556,7 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1) error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order) end [~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1); %note that g3 does not contain symmetric elements - g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3 + g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3 %g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order %g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order @@ -575,8 +575,8 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1) g2 = feval([fname, '.dynamic_g2'], T, ys(I), exo_steady_state', params, ys, 1, false); %g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order g3 = feval([fname, '.dynamic_g3'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g3 does not contain symmetric elements g4 = feval([fname, '.dynamic_g4'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g4 does not contain symmetric elements - g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order - g4 = unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order + g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order + g4 = identification.unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order end end % Parameter Jacobian of steady state in different orderings, note dys is in declaration order @@ -801,7 +801,7 @@ if analytic_derivation_mode == 1 dghu = [zeros(endo_nbr*exo_nbr, stderrparam_nbr+corrparam_nbr) dghu]; % Compute dOm = dvec(ghu*Sigma_e*ghu') from expressions 34 in Iskrev (2010) Appendix A - dOm = kron(I_endo,ghu*Sigma_e)*(commutation(endo_nbr, exo_nbr)*dghu)... + dOm = kron(I_endo,ghu*Sigma_e)*(pruned_SS.commutation(endo_nbr, exo_nbr)*dghu)... + kron(ghu,ghu)*reshape(dSigma_e, exo_nbr^2, totparam_nbr) + kron(ghu*Sigma_e,I_endo)*dghu; % Put into tensor notation diff --git a/matlab/get_perturbation_params_derivs_numerical_objective.m b/matlab/+identification/get_perturbation_params_derivs_numerical_objective.m similarity index 98% rename from matlab/get_perturbation_params_derivs_numerical_objective.m rename to matlab/+identification/get_perturbation_params_derivs_numerical_objective.m index efb997309..4fc7f47f5 100644 --- a/matlab/get_perturbation_params_derivs_numerical_objective.m +++ b/matlab/+identification/get_perturbation_params_derivs_numerical_objective.m @@ -95,7 +95,7 @@ if strcmp(outputflag,'dynamic_model') out = [Yss; g1(:); g2(:)]; elseif options_.order == 3 [~, g1, g2, g3] = feval([M_.fname,'.dynamic'], ys(I), exo_steady_state', M_.params, ys, 1); - g3 = unfold_g3(g3, length(ys(I))+M_.exo_nbr); + g3 = identification.unfold_g3(g3, length(ys(I))+M_.exo_nbr); out = [Yss; g1(:); g2(:); g3(:)]; end end diff --git a/matlab/hessian_sparse.m b/matlab/+identification/hessian_sparse.m similarity index 100% rename from matlab/hessian_sparse.m rename to matlab/+identification/hessian_sparse.m diff --git a/matlab/+identification/numerical_objective.m b/matlab/+identification/numerical_objective.m index ec0ffc793..84c1695b7 100644 --- a/matlab/+identification/numerical_objective.m +++ b/matlab/+identification/numerical_objective.m @@ -1,5 +1,5 @@ -function out = identification_numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state) -% out = identification_numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state) +function out = numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state) +% out = numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state) % ------------------------------------------------------------------------- % Objective function to compute numerically the Jacobians used for identification analysis % Previously this function was called thet2tau.m @@ -80,7 +80,7 @@ end %% compute Kalman transition matrices and steady state with updated parameters [dr,info,M_.params] = compute_decision_rules(M_,options_,dr, steady_state, exo_steady_state, exo_det_steady_state); options_ = rmfield(options_,'options_ident'); -pruned = pruned_state_space_system(M_, options_, dr, indvar, nlags, useautocorr, 0); +pruned = pruned_SS.pruned_state_space_system(M_, options_, dr, indvar, nlags, useautocorr, 0); %% out = [vech(cov(Y_t,Y_t)); vec(cov(Y_t,Y_{t-1}); ...; vec(cov(Y_t,Y_{t-nlags})] of indvar variables, in DR order. This is Iskrev (2010)'s J matrix. if outputflag == 1 diff --git a/matlab/+identification/run.m b/matlab/+identification/run.m index e716fa1ea..fac0c5d22 100644 --- a/matlab/+identification/run.m +++ b/matlab/+identification/run.m @@ -803,24 +803,24 @@ if iload <=0 iter=iter+1; % note that this is not the same si_dDYNAMICnorm as computed in identification.analysis % given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure - si_dDYNAMICnorm(iter,:) = vnorm(STO_si_dDYNAMIC(:,:,irun)./repmat(normalize_STO_DYNAMIC,1,totparam_nbr-(stderrparam_nbr+corrparam_nbr))).*normaliz1((stderrparam_nbr+corrparam_nbr)+1:end); + si_dDYNAMICnorm(iter,:) = identification.vnorm(STO_si_dDYNAMIC(:,:,irun)./repmat(normalize_STO_DYNAMIC,1,totparam_nbr-(stderrparam_nbr+corrparam_nbr))).*normaliz1((stderrparam_nbr+corrparam_nbr)+1:end); if ~options_MC.no_identification_reducedform && ~isempty(STO_si_dREDUCEDFORM) % note that this is not the same si_dREDUCEDFORMnorm as computed in identification.analysis % given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure - si_dREDUCEDFORMnorm(iter,:) = vnorm(STO_si_dREDUCEDFORM(:,:,irun)./repmat(normalize_STO_REDUCEDFORM,1,totparam_nbr)).*normaliz1; + si_dREDUCEDFORMnorm(iter,:) = identification.vnorm(STO_si_dREDUCEDFORM(:,:,irun)./repmat(normalize_STO_REDUCEDFORM,1,totparam_nbr)).*normaliz1; end if ~options_MC.no_identification_moments && ~isempty(STO_si_dMOMENTS) % note that this is not the same si_dMOMENTSnorm as computed in identification.analysis % given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure - si_dMOMENTSnorm(iter,:) = vnorm(STO_si_dMOMENTS(:,:,irun)./repmat(normalize_STO_MOMENTS,1,totparam_nbr)).*normaliz1; + si_dMOMENTSnorm(iter,:) = identification.vnorm(STO_si_dMOMENTS(:,:,irun)./repmat(normalize_STO_MOMENTS,1,totparam_nbr)).*normaliz1; end if ~options_MC.no_identification_spectrum && ~isempty(STO_dSPECTRUM) % note that this is not the same dSPECTRUMnorm as computed in identification.analysis - dSPECTRUMnorm(iter,:) = vnorm(STO_dSPECTRUM(:,:,irun)); %not yet used + dSPECTRUMnorm(iter,:) = identification.vnorm(STO_dSPECTRUM(:,:,irun)); %not yet used end if ~options_MC.no_identification_minimal && ~isempty(STO_dMINIMAL) % note that this is not the same dMINIMALnorm as computed in identification.analysis - dMINIMALnorm(iter,:) = vnorm(STO_dMINIMAL(:,:,irun)); %not yet used + dMINIMALnorm(iter,:) = identification.vnorm(STO_dMINIMAL(:,:,irun)); %not yet used end end end diff --git a/matlab/unfold_g3.m b/matlab/+identification/unfold_g3.m similarity index 100% rename from matlab/unfold_g3.m rename to matlab/+identification/unfold_g3.m diff --git a/matlab/unfold_g4.m b/matlab/+identification/unfold_g4.m similarity index 100% rename from matlab/unfold_g4.m rename to matlab/+identification/unfold_g4.m diff --git a/matlab/vnorm.m b/matlab/+identification/vnorm.m similarity index 100% rename from matlab/vnorm.m rename to matlab/+identification/vnorm.m diff --git a/matlab/+mom/objective_function.m b/matlab/+mom/objective_function.m index 42c459856..2e7ed196b 100644 --- a/matlab/+mom/objective_function.m +++ b/matlab/+mom/objective_function.m @@ -150,11 +150,11 @@ if strcmp(options_mom_.mom.mom_method,'GMM') stderrparam_nbr = estim_params_.nvx; % number of stderr parameters corrparam_nbr = estim_params_.ncx; % number of corr parameters totparam_nbr = stderrparam_nbr+corrparam_nbr+modparam_nbr; - oo_.dr.derivs = get_perturbation_params_derivs(M_, options_mom_, estim_params_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, indpmodel, indpstderr, indpcorr, 0); %analytic derivatives of perturbation matrices + oo_.dr.derivs = identification.get_perturbation_params_derivs(M_, options_mom_, estim_params_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, indpmodel, indpstderr, indpcorr, 0); %analytic derivatives of perturbation matrices oo_.mom.model_moments_params_derivs = NaN(options_mom_.mom.mom_nbr,totparam_nbr); - pruned_state_space = pruned_state_space_system(M_, options_mom_, oo_.dr, oo_.mom.obs_var, options_mom_.ar, 0, 1); + pruned_state_space = pruned_SS.pruned_state_space_system(M_, options_mom_, oo_.dr, oo_.mom.obs_var, options_mom_.ar, 0, 1); else - pruned_state_space = pruned_state_space_system(M_, options_mom_, oo_.dr, oo_.mom.obs_var, options_mom_.ar, 0, 0); + pruned_state_space = pruned_SS.pruned_state_space_system(M_, options_mom_, oo_.dr, oo_.mom.obs_var, options_mom_.ar, 0, 0); end oo_.mom.model_moments = NaN(options_mom_.mom.mom_nbr,1); for jm = 1:size(M_.matched_moments,1) diff --git a/matlab/+osr/objective.m b/matlab/+osr/objective.m index 1bb3148ad..5c3b38059 100644 --- a/matlab/+osr/objective.m +++ b/matlab/+osr/objective.m @@ -64,9 +64,9 @@ if ~options_.analytic_derivation loss = full(weights(:)'*vx(:)); else totparam_nbr=length(i_params); - oo_.dr.derivs = get_perturbation_params_derivs(M_, options_, [], oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, i_params, [], [], 0); %analytic derivatives of perturbation matrices + oo_.dr.derivs = identification.get_perturbation_params_derivs(M_, options_, [], oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, i_params, [], [], 0); %analytic derivatives of perturbation matrices - pruned_state_space = pruned_state_space_system(M_, options_, oo_.dr, i_var, 0, 0, 1); + pruned_state_space = pruned_SS.pruned_state_space_system(M_, options_, oo_.dr, i_var, 0, 0, 1); vx = pruned_state_space.Var_y + pruned_state_space.E_y*pruned_state_space.E_y'; dE_yy = pruned_state_space.dVar_y; for jp=1:length(i_params) diff --git a/matlab/+pruned_SS/Q6_plication.m b/matlab/+pruned_SS/Q6_plication.m index 68a2bf816..ef432d1c2 100644 --- a/matlab/+pruned_SS/Q6_plication.m +++ b/matlab/+pruned_SS/Q6_plication.m @@ -49,7 +49,7 @@ for i1=1:p for i4=i3:p for i5=i4:p for i6=i5:p - idx = uperm([i6 i5 i4 i3 i2 i1]); + idx = pruned_SS.uperm([i6 i5 i4 i3 i2 i1]); for r = 1:size(idx,1) ii1 = idx(r,1); ii2= idx(r,2); ii3=idx(r,3); ii4=idx(r,4); ii5=idx(r,5); ii6=idx(r,6); n = ii1 + (ii2-1)*p + (ii3-1)*p^2 + (ii4-1)*p^3 + (ii5-1)*p^4 + (ii6-1)*p^5; diff --git a/matlab/commutation.m b/matlab/+pruned_SS/commutation.m similarity index 100% rename from matlab/commutation.m rename to matlab/+pruned_SS/commutation.m diff --git a/matlab/duplication.m b/matlab/+pruned_SS/duplication.m similarity index 100% rename from matlab/duplication.m rename to matlab/+pruned_SS/duplication.m diff --git a/matlab/pruned_state_space_system.m b/matlab/+pruned_SS/pruned_state_space_system.m similarity index 99% rename from matlab/pruned_state_space_system.m rename to matlab/+pruned_SS/pruned_state_space_system.m index 40d974ca9..26d5eeb3d 100644 --- a/matlab/pruned_state_space_system.m +++ b/matlab/+pruned_SS/pruned_state_space_system.m @@ -418,7 +418,7 @@ if order > 1 hx_hu = kron(hx,hu); hu_hu = kron(hu,hu); I_xx = eye(x_nbr^2); - K_x_x = commutation(x_nbr,x_nbr,1); + K_x_x = pruned_SS.commutation(x_nbr,x_nbr,1); invIx_hx = (eye(x_nbr)-hx)\eye(x_nbr); %Compute unique fourth order product moments of u, i.e. unique(E[kron(kron(kron(u,u),u),u)],'stable') @@ -596,9 +596,9 @@ if order > 1 if order > 2 % Some common and useful objects for order > 2 if isempty(K_u_xx) - K_u_xx = commutation(u_nbr,x_nbr^2,1); - K_u_ux = commutation(u_nbr,u_nbr*x_nbr,1); - K_xx_x = commutation(x_nbr^2,x_nbr); + K_u_xx = pruned_SS.commutation(u_nbr,x_nbr^2,1); + K_u_ux = pruned_SS.commutation(u_nbr,u_nbr*x_nbr,1); + K_xx_x = pruned_SS.commutation(x_nbr^2,x_nbr); end hx_hss2 = kron(hx,1/2*hss); hu_hss2 = kron(hu,1/2*hss); @@ -627,7 +627,7 @@ if order > 1 E_xf_xfxs = Var_z(id_z3_xf_xf, id_z2_xs ) + E_xfxf(:)*E_xs'; %this is E[kron(xf,xf)*xs'] E_xf_xfxf_xf = Var_z(id_z3_xf_xf, id_z3_xf_xf) + E_xfxf(:)*E_xfxf(:)'; %this is E[kron(xf,xf)*kron(xf,xf)'] E_xrdxf = reshape(invIxx_hx_hx*vec(... - hxx*reshape( commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*hx'... + hxx*reshape( pruned_SS.commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*hx'... + hxu*kron(E_xs,E_uu)*hu'... + 1/6*hxxx*reshape(E_xf_xfxf_xf,x_nbr^3,x_nbr)*hx'... + 1/6*huuu*reshape(QPu*E_u_u_u_u,u_nbr^3,u_nbr)*hu'... @@ -655,7 +655,7 @@ if order > 1 dE_xf_xfxf_xf(:,:,jp2) = dVar_z(id_z3_xf_xf , id_z3_xf_xf , jp2) + vec(dE_xfxf(:,:,jp2))*E_xfxf(:)' + E_xfxf(:)*vec(dE_xfxf(:,:,jp2))'; dE_xrdxf(:,:,jp2) = reshape(invIxx_hx_hx*vec(... dhx(:,:,jp2)*E_xrdxf*hx' + hx*E_xrdxf*dhx(:,:,jp2)'... - + dhxx(:,:,jp2)*reshape( commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*hx' + hxx*reshape( commutation(x_nbr^2,x_nbr,1)*vec(dE_xf_xfxs(:,:,jp2)), x_nbr^2,x_nbr)*hx' + hxx*reshape( commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*dhx(:,:,jp2)'... + + dhxx(:,:,jp2)*reshape( pruned_SS.commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*hx' + hxx*reshape( pruned_SS.commutation(x_nbr^2,x_nbr,1)*vec(dE_xf_xfxs(:,:,jp2)), x_nbr^2,x_nbr)*hx' + hxx*reshape( pruned_SS.commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*dhx(:,:,jp2)'... + dhxu(:,:,jp2)*kron(E_xs,E_uu)*hu' + hxu*kron(dE_xs(:,jp2),E_uu)*hu' + hxu*kron(E_xs,dE_uu(:,:,jp2))*hu' + hxu*kron(E_xs,E_uu)*dhu(:,:,jp2)'... + 1/6*dhxxx(:,:,jp2)*reshape(E_xf_xfxf_xf,x_nbr^3,x_nbr)*hx' + 1/6*hxxx*reshape(dE_xf_xfxf_xf(:,:,jp2),x_nbr^3,x_nbr)*hx' + 1/6*hxxx*reshape(E_xf_xfxf_xf,x_nbr^3,x_nbr)*dhx(:,:,jp2)'... + 1/6*dhuuu(:,:,jp2)*reshape(QPu*E_u_u_u_u,u_nbr^3,u_nbr)*hu' + 1/6*huuu*reshape(dE_u_u_u_u_jp2,u_nbr^3,u_nbr)*hu' + 1/6*huuu*reshape(QPu*E_u_u_u_u,u_nbr^3,u_nbr)*dhu(:,:,jp2)'... diff --git a/matlab/+pruned_SS/quadruplication.m b/matlab/+pruned_SS/quadruplication.m index f6a31a29c..6350d9735 100644 --- a/matlab/+pruned_SS/quadruplication.m +++ b/matlab/+pruned_SS/quadruplication.m @@ -49,7 +49,7 @@ for l=1:p for k=l:p for j=k:p for i=j:p - idx = uperm([i j k l]); + idx = pruned_SS.uperm([i j k l]); for r = 1:size(idx,1) ii = idx(r,1); jj= idx(r,2); kk=idx(r,3); ll=idx(r,4); n = ii + (jj-1)*p + (kk-1)*p^2 + (ll-1)*p^3; diff --git a/matlab/uperm.m b/matlab/+pruned_SS/uperm.m similarity index 96% rename from matlab/uperm.m rename to matlab/+pruned_SS/uperm.m index 5b7e8df20..28a22d625 100644 --- a/matlab/uperm.m +++ b/matlab/+pruned_SS/uperm.m @@ -1,49 +1,49 @@ -function p = uperm(a) -% Return all unique permutations of possibly-repeating array elements -% ========================================================================= -% Copyright © 2014 Bruno Luong -% Copyright © 2020 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . -% ========================================================================= -% Original author: Bruno Luong , April 20, 2014 -% https://groups.google.com/d/msg/comp.soft-sys.matlab/yQKVPTYrv6Q/gw1MzNd9sYkJ -% https://stackoverflow.com/a/42810388 - -[u, ~, J] = unique(a); -p = u(up(J, length(a))); - -function p = up(J, n) -ktab = histc(J,1:max(J)); -l = n; -p = zeros(1, n); -s = 1; -for i=1:length(ktab) - k = ktab(i); - c = nchoosek(1:l, k); - m = size(c,1); - [t, ~] = find(~p.'); - t = reshape(t, [], s); - c = t(c,:)'; - s = s*m; - r = repmat((1:s)',[1 k]); - q = accumarray([r(:) c(:)], i, [s n]); - p = repmat(p, [m 1]) + q; - l = l - k; -end -end - +function p = uperm(a) +% Return all unique permutations of possibly-repeating array elements +% ========================================================================= +% Copyright © 2014 Bruno Luong +% Copyright © 2020 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . +% ========================================================================= +% Original author: Bruno Luong , April 20, 2014 +% https://groups.google.com/d/msg/comp.soft-sys.matlab/yQKVPTYrv6Q/gw1MzNd9sYkJ +% https://stackoverflow.com/a/42810388 + +[u, ~, J] = unique(a); +p = u(up(J, length(a))); + +function p = up(J, n) +ktab = histc(J,1:max(J)); +l = n; +p = zeros(1, n); +s = 1; +for i=1:length(ktab) + k = ktab(i); + c = nchoosek(1:l, k); + m = size(c,1); + [t, ~] = find(~p.'); + t = reshape(t, [], s); + c = t(c,:)'; + s = s*m; + r = repmat((1:s)',[1 k]); + q = accumarray([r(:) c(:)], i, [s n]); + p = repmat(p, [m 1]) + q; + l = l - k; +end +end + end % uperm \ No newline at end of file diff --git a/matlab/simul_static_model.m b/matlab/backward/simul_static_model.m similarity index 100% rename from matlab/simul_static_model.m rename to matlab/backward/simul_static_model.m diff --git a/matlab/cellofchar2mfile.m b/matlab/cellofchar2mfile.m deleted file mode 100644 index 0862058c1..000000000 --- a/matlab/cellofchar2mfile.m +++ /dev/null @@ -1,63 +0,0 @@ -function cellofchar2mfile(fname, c, cname) - -% Write a cell of char in a matlab script. -% -% INPUTS -% - fname [string] name of the file where c is to be saved. -% - c [cell] a two dimensional cell of char. -% -% OUTPUTS -% None. - -% Copyright © 2015-2017 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -[pathstr,name,ext] = fileparts(fname); - -if isempty(ext) - fname = [pathstr, name, '.m'] -else - if ~isequal(ext, '.m') - error(['The first argument needs to be the name of a matlab script (with an .m extension)!']) - end -end - -if ~iscell(c) - error('The second input argument must be a cell!') -end - -if ndims(c)>2 - error(['The cell passed has a second argument cannot have more than two dimensions!']) -end - -variablename = inputname(2); - -if isempty(variablename) && nargin<3 - error(['You must pass the name of the cell (second input argument) as a string in the third input argument!']) -end - -if nargin>2 - if isvarname(cname) - variablename = cname; - else - error('The third input argument must be a valid variable name!') - end -end - -fid = fopen(fname,'w'); -fprintf(fid, '%s = %s;', variablename, writecellofchar(c)); -fclose(fid); \ No newline at end of file diff --git a/matlab/check_model.m b/matlab/check_model.m index 71dc6a2b5..7dc297109 100644 --- a/matlab/check_model.m +++ b/matlab/check_model.m @@ -2,7 +2,7 @@ function check_model(M_) % check_model(M_) % Performs various consistency checks on the model -% Copyright (C) 2005-2033 Dynare Team +% Copyright (C) 2005-2023 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/clear_persistent_variables.m b/matlab/clear_persistent_variables.m index 989d4a361..32223192b 100644 --- a/matlab/clear_persistent_variables.m +++ b/matlab/clear_persistent_variables.m @@ -1,5 +1,5 @@ function clear_persistent_variables(folder, writelistofroutinestobecleared) - +% clear_persistent_variables(folder, writelistofroutinestobecleared) % Clear all the functions with persistent variables in directory folder (and subdirectories). % Copyright © 2015-2019 Dynare Team @@ -60,3 +60,51 @@ end list_of_functions_to_be_cleared; clear(list_of_functions{:}); + +function cellofchar2mfile(fname, c, cname) +% Write a cell of char in a matlab script. +% +% INPUTS +% - fname [string] name of the file where c is to be saved. +% - c [cell] a two dimensional cell of char. +% +% OUTPUTS +% None. + + + +[pathstr,name,ext] = fileparts(fname); + +if isempty(ext) + fname = [pathstr, name, '.m']; +else + if ~isequal(ext, '.m') + error(['The first argument needs to be the name of a matlab script (with an .m extension)!']) + end +end + +if ~iscell(c) + error('The second input argument must be a cell!') +end + +if ndims(c)>2 + error(['The cell passed has a second argument cannot have more than two dimensions!']) +end + +variablename = inputname(2); + +if isempty(variablename) && nargin<3 + error(['You must pass the name of the cell (second input argument) as a string in the third input argument!']) +end + +if nargin>2 + if isvarname(cname) + variablename = cname; + else + error('The third input argument must be a valid variable name!') + end +end + +fid = fopen(fname,'w'); +fprintf(fid, '%s = %s;', variablename, writecellofchar(c)); +fclose(fid); diff --git a/matlab/print_moments_implied_prior.m b/matlab/cli/print_moments_implied_prior.m similarity index 100% rename from matlab/print_moments_implied_prior.m rename to matlab/cli/print_moments_implied_prior.m diff --git a/matlab/compute_model_moments.m b/matlab/compute_model_moments.m deleted file mode 100644 index aa92954ff..000000000 --- a/matlab/compute_model_moments.m +++ /dev/null @@ -1,32 +0,0 @@ -function moments=compute_model_moments(dr,M_,options_) -% -% INPUTS -% dr: structure describing model solution -% M_: structure of Dynare options -% options_ -% -% OUTPUTS -% moments: a cell array containing requested moments -% -% SPECIAL REQUIREMENTS -% none - -% Copyright © 2008-2017 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -[ivar,vartan,options_] = get_variables_list(options_,M_); -moments = th_autocovariances(dr,ivar,M_,options_,options_.nodecomposition); diff --git a/matlab/convergence_diagnostics/mcmc_ifac.m b/matlab/convergence_diagnostics/mcmc_ifac.m index 29d881dad..1c63bb7c2 100644 --- a/matlab/convergence_diagnostics/mcmc_ifac.m +++ b/matlab/convergence_diagnostics/mcmc_ifac.m @@ -69,3 +69,27 @@ for i=(Nc/2)+1: Nc+1 end Parzen=Parzen'; Ifac= 1+2*sum(Parzen(:).* AcorrXSIM); + + +function acf = dyn_autocorr(y, ar) +% function acf = dyn_autocorr(y, ar) +% autocorrelation function of y +% +% INPUTS +% y: time series +% ar: # of lags +% +% OUTPUTS +% acf: autocorrelation for lags 1 to ar +% +% SPECIAL REQUIREMENTS +% none + +y=y(:); +acf = NaN(ar+1,1); +acf(1)=1; +m = mean(y); +sd = std(y,1); +for i=1:ar + acf(i+1) = (y(i+1:end)-m)'*(y(1:end-i)-m)./((size(y,1))*sd^2); +end diff --git a/matlab/dyn_autocorr.m b/matlab/dyn_autocorr.m deleted file mode 100644 index dcf19ca31..000000000 --- a/matlab/dyn_autocorr.m +++ /dev/null @@ -1,40 +0,0 @@ -function acf = dyn_autocorr(y, ar) -% function acf = dyn_autocorr(y, ar) -% autocorrelation function of y -% -% INPUTS -% y: time series -% ar: # of lags -% -% OUTPUTS -% acf: autocorrelation for lags 1 to ar -% -% SPECIAL REQUIREMENTS -% none - -% Copyright © 2015-16 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - - -y=y(:); -acf = NaN(ar+1,1); -acf(1)=1; -m = mean(y); -sd = std(y,1); -for i=1:ar - acf(i+1) = (y(i+1:end)-m)'*(y(1:end-i)-m)./((size(y,1))*sd^2); -end diff --git a/matlab/dyn_diag_vech.m b/matlab/dyn_diag_vech.m deleted file mode 100644 index e07825cbb..000000000 --- a/matlab/dyn_diag_vech.m +++ /dev/null @@ -1,31 +0,0 @@ -function d = dyn_diag_vech(Vector) -% This function returns the diagonal elements of a symmetric matrix -% stored in vech form -% -% INPUTS -% Vector [double] a m*1 vector. -% -% OUTPUTS -% d [double] a n*1 vector, where n solves n*(n+1)/2=m. - -% Copyright © 2010-2017 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -m = length(Vector); -n = (sqrt(1+8*m)-1)/2; -k = cumsum(1:n); -d = Vector(k); diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 13f0d5c84..7702fd7eb 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -47,6 +47,7 @@ p = {'/../contrib/ms-sbvar/TZcode/MatlabFiles/' ; ... '/AIM/' ; ... '/backward/' ; ... '/cli/' ; ... + '/conditional_forecasts/'; ... '/convergence_diagnostics/' ; ... '/discretionary_policy/' ; ... '/distributions/' ; ... @@ -57,19 +58,24 @@ p = {'/../contrib/ms-sbvar/TZcode/MatlabFiles/' ; ... '/gsa/' ; ... '/kalman/' ; ... '/kalman/likelihood' ; ... + '/latex/' ; ... '/lmmcp/' ; ... '/modules/dseries/src/' ; ... '/reporting/' ; ... + '/matrix_solver/'; ... '/moments/'; ... '/ms-sbvar/' ; ... '/ms-sbvar/identification/' ; ... '/nonlinear-filters/' ; ... '/ols/' ; ... + '/optimal_policy/' ; ... '/optimization/' ; ... '/pac-tools/' ; ... '/parallel/' ; ... '/partial_information/' ; ... '/perfect-foresight-models/' ; ... + '/shock_decomposition/' ; ... + '/stochastic_solver/' ; ... '/utilities/dataset/' ; ... '/utilities/doc/' ; ... '/utilities/estimation/' ; ... diff --git a/matlab/dynare_gradient.m b/matlab/dynare_gradient.m deleted file mode 100644 index 641ad81d9..000000000 --- a/matlab/dynare_gradient.m +++ /dev/null @@ -1,66 +0,0 @@ -function [F,G] = dynare_gradient(fcn,x,epsilon,varargin) -% Computes the gradient of a function from R^m in R^n. -% -% INPUTS: -% fcn [string] name of the matlab's function. -% x [double] m*1 vector (where the gradient is evaluated). -% epsilon [double] scalar or m*1 vector of steps. -% -% OUTPUTS: -% F [double] n*1 vector, evaluation of the function at x. -% G [double] n*m matrix, evaluation of the gradient at x. -% -% OUTPUTS -% -% Copyright © 2010-2017 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -% Evaluate the function at x. -F = feval(fcn, x, varargin{:}); - -% (G)Set dimensions. -m = length(x); -n = length(F); - -% Initialization of the gradient. -G = NaN(length(F),length(x)); - -if length(epsilon==1) - H = epsilon*eye(m); -else - H = diag(epsilon); -end - -% Compute the gradient. -for i=1:m - if size(x,1)>size(x,2) - h = H(i,:); - else - h = H(:,i); - end - [Fh,~,~,flag] = feval(fcn, x+transpose(h), varargin{:}); - if flag - G(:,i) = (Fh-F)/epsilon; - else - [Fh,~,~,flag] = feval(fcn, x-transpose(h), varargin{:}); - if flag - G(:,i) = (F-Fh)/epsilon; - else - error('-- Bad gradient --') - end - end -end \ No newline at end of file diff --git a/matlab/cartesian_product_of_sets.m b/matlab/ep/cartesian_product_of_sets.m similarity index 100% rename from matlab/cartesian_product_of_sets.m rename to matlab/ep/cartesian_product_of_sets.m diff --git a/matlab/cubature_with_gaussian_weight.m b/matlab/ep/cubature_with_gaussian_weight.m similarity index 100% rename from matlab/cubature_with_gaussian_weight.m rename to matlab/ep/cubature_with_gaussian_weight.m diff --git a/matlab/gauss_hermite_weights_and_nodes.m b/matlab/ep/gauss_hermite_weights_and_nodes.m similarity index 100% rename from matlab/gauss_hermite_weights_and_nodes.m rename to matlab/ep/gauss_hermite_weights_and_nodes.m diff --git a/matlab/gauss_legendre_weights_and_nodes.m b/matlab/ep/gauss_legendre_weights_and_nodes.m similarity index 100% rename from matlab/gauss_legendre_weights_and_nodes.m rename to matlab/ep/gauss_legendre_weights_and_nodes.m diff --git a/matlab/estimation/dsge_likelihood.m b/matlab/estimation/dsge_likelihood.m index 5ea603593..87689b61e 100644 --- a/matlab/estimation/dsge_likelihood.m +++ b/matlab/estimation/dsge_likelihood.m @@ -482,14 +482,14 @@ if analytic_derivation old_analytic_derivation_mode = options_.analytic_derivation_mode; options_.analytic_derivation_mode = kron_flag; if full_Hess - DERIVS = get_perturbation_params_derivs(M_, options_, estim_params_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indparam, indexo, [], true); + DERIVS = identification.get_perturbation_params_derivs(M_, options_, estim_params_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indparam, indexo, [], true); indD2T = reshape(1:M_.endo_nbr^2, M_.endo_nbr, M_.endo_nbr); indD2Om = dyn_unvech(1:M_.endo_nbr*(M_.endo_nbr+1)/2); D2T = DERIVS.d2KalmanA(indD2T(iv,iv),:); D2Om = DERIVS.d2Om(dyn_vech(indD2Om(iv,iv)),:); D2Yss = DERIVS.d2Yss(iv,:,:); else - DERIVS = get_perturbation_params_derivs(M_, options_, estim_params_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indparam, indexo, [], false); + DERIVS = identification.get_perturbation_params_derivs(M_, options_, estim_params_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indparam, indexo, [], false); end DT = zeros(M_.endo_nbr, M_.endo_nbr, size(DERIVS.dghx,3)); DT(:,M_.nstatic+(1:M_.nspred),:) = DERIVS.dghx; diff --git a/matlab/estimation/dsge_simulated_theoretical_covariance.m b/matlab/estimation/dsge_simulated_theoretical_covariance.m index 3fb978ada..93d9e1fef 100644 --- a/matlab/estimation/dsge_simulated_theoretical_covariance.m +++ b/matlab/estimation/dsge_simulated_theoretical_covariance.m @@ -132,7 +132,7 @@ for file = 1:NumberOfDrawsFiles if ~options_.pruning tmp = th_autocovariances(dr,ivar,M_,options_,nodecomposition); else - pruned_state_space = pruned_state_space_system(M_, options_, dr, obs_var, options_.ar, 1, 0); + pruned_state_space = pruned_SS.pruned_state_space_system(M_, options_, dr, obs_var, options_.ar, 1, 0); tmp{1} = pruned_state_space.Var_y; for i=1:nar tmp{i+1} = pruned_state_space.Corr_yi(:,:,i); diff --git a/matlab/evaluate_dynamic_model.m b/matlab/evaluate_dynamic_model.m deleted file mode 100644 index 6c57d6c1b..000000000 --- a/matlab/evaluate_dynamic_model.m +++ /dev/null @@ -1,29 +0,0 @@ -function residuals = evaluate_dynamic_model(dynamicmodel, endogenousvariables, exogenousvariables, params, steadystate, leadlagincidence, samplesize) - -% Copyright © 2016 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -ny = length(steadystate); -periods = rows(exogenousvariables); - -residuals = zeros(ny,samplesize); -icols = find(leadlagincidence'); - -for t = 2:samplesize+1 - residuals(:,t-1) = dynamicmodel(endogenousvariables(icols), exogenousvariables, params, steadystate, t); - icols = icols + ny; -end \ No newline at end of file diff --git a/matlab/DsgeSmoother.m b/matlab/kalman/DsgeSmoother.m similarity index 100% rename from matlab/DsgeSmoother.m rename to matlab/kalman/DsgeSmoother.m diff --git a/matlab/evaluate_smoother.m b/matlab/kalman/evaluate_smoother.m similarity index 100% rename from matlab/evaluate_smoother.m rename to matlab/kalman/evaluate_smoother.m diff --git a/matlab/missing_DiffuseKalmanSmootherH1_Z.m b/matlab/kalman/missing_DiffuseKalmanSmootherH1_Z.m similarity index 100% rename from matlab/missing_DiffuseKalmanSmootherH1_Z.m rename to matlab/kalman/missing_DiffuseKalmanSmootherH1_Z.m diff --git a/matlab/missing_DiffuseKalmanSmootherH3_Z.m b/matlab/kalman/missing_DiffuseKalmanSmootherH3_Z.m similarity index 100% rename from matlab/missing_DiffuseKalmanSmootherH3_Z.m rename to matlab/kalman/missing_DiffuseKalmanSmootherH3_Z.m diff --git a/matlab/save_display_classical_smoother_results.m b/matlab/kalman/save_display_classical_smoother_results.m similarity index 100% rename from matlab/save_display_classical_smoother_results.m rename to matlab/kalman/save_display_classical_smoother_results.m diff --git a/matlab/store_smoother_results.m b/matlab/kalman/store_smoother_results.m similarity index 100% rename from matlab/store_smoother_results.m rename to matlab/kalman/store_smoother_results.m diff --git a/matlab/collect_latex_files.m b/matlab/latex/collect_latex_files.m similarity index 100% rename from matlab/collect_latex_files.m rename to matlab/latex/collect_latex_files.m diff --git a/matlab/dyn_latex_table.m b/matlab/latex/dyn_latex_table.m similarity index 100% rename from matlab/dyn_latex_table.m rename to matlab/latex/dyn_latex_table.m diff --git a/matlab/isbayes.m b/matlab/latex/isbayes.m similarity index 100% rename from matlab/isbayes.m rename to matlab/latex/isbayes.m diff --git a/matlab/write_latex_definitions.m b/matlab/latex/write_latex_definitions.m similarity index 100% rename from matlab/write_latex_definitions.m rename to matlab/latex/write_latex_definitions.m diff --git a/matlab/write_latex_parameter_table.m b/matlab/latex/write_latex_parameter_table.m similarity index 100% rename from matlab/write_latex_parameter_table.m rename to matlab/latex/write_latex_parameter_table.m diff --git a/matlab/write_latex_prior_table.m b/matlab/latex/write_latex_prior_table.m similarity index 100% rename from matlab/write_latex_prior_table.m rename to matlab/latex/write_latex_prior_table.m diff --git a/matlab/mcp_func.m b/matlab/lmmcp/mcp_func.m similarity index 100% rename from matlab/mcp_func.m rename to matlab/lmmcp/mcp_func.m diff --git a/matlab/fastgensylv.m b/matlab/matrix_solver/fastgensylv.m similarity index 100% rename from matlab/fastgensylv.m rename to matlab/matrix_solver/fastgensylv.m diff --git a/matlab/gensylv_fp.m b/matlab/matrix_solver/gensylv_fp.m similarity index 100% rename from matlab/gensylv_fp.m rename to matlab/matrix_solver/gensylv_fp.m diff --git a/matlab/lyapunov_solver.m b/matlab/matrix_solver/lyapunov_solver.m similarity index 100% rename from matlab/lyapunov_solver.m rename to matlab/matrix_solver/lyapunov_solver.m diff --git a/matlab/lyapunov_symm.m b/matlab/matrix_solver/lyapunov_symm.m similarity index 100% rename from matlab/lyapunov_symm.m rename to matlab/matrix_solver/lyapunov_symm.m diff --git a/matlab/quadratic_matrix_equation_solver.m b/matlab/matrix_solver/quadratic_matrix_equation_solver.m similarity index 100% rename from matlab/quadratic_matrix_equation_solver.m rename to matlab/matrix_solver/quadratic_matrix_equation_solver.m diff --git a/matlab/sylvester3.m b/matlab/matrix_solver/sylvester3.m similarity index 100% rename from matlab/sylvester3.m rename to matlab/matrix_solver/sylvester3.m diff --git a/matlab/sylvester3a.m b/matlab/matrix_solver/sylvester3a.m similarity index 100% rename from matlab/sylvester3a.m rename to matlab/matrix_solver/sylvester3a.m diff --git a/matlab/UnivariateSpectralDensity.m b/matlab/moments/UnivariateSpectralDensity.m similarity index 100% rename from matlab/UnivariateSpectralDensity.m rename to matlab/moments/UnivariateSpectralDensity.m diff --git a/matlab/add_filter_subtitle.m b/matlab/moments/add_filter_subtitle.m similarity index 100% rename from matlab/add_filter_subtitle.m rename to matlab/moments/add_filter_subtitle.m diff --git a/matlab/compute_moments_varendo.m b/matlab/moments/compute_moments_varendo.m similarity index 100% rename from matlab/compute_moments_varendo.m rename to matlab/moments/compute_moments_varendo.m diff --git a/matlab/conditional_variance_decomposition.m b/matlab/moments/conditional_variance_decomposition.m similarity index 100% rename from matlab/conditional_variance_decomposition.m rename to matlab/moments/conditional_variance_decomposition.m diff --git a/matlab/conditional_variance_decomposition_ME_mc_analysis.m b/matlab/moments/conditional_variance_decomposition_ME_mc_analysis.m similarity index 100% rename from matlab/conditional_variance_decomposition_ME_mc_analysis.m rename to matlab/moments/conditional_variance_decomposition_ME_mc_analysis.m diff --git a/matlab/conditional_variance_decomposition_mc_analysis.m b/matlab/moments/conditional_variance_decomposition_mc_analysis.m similarity index 100% rename from matlab/conditional_variance_decomposition_mc_analysis.m rename to matlab/moments/conditional_variance_decomposition_mc_analysis.m diff --git a/matlab/correlation_mc_analysis.m b/matlab/moments/correlation_mc_analysis.m similarity index 100% rename from matlab/correlation_mc_analysis.m rename to matlab/moments/correlation_mc_analysis.m diff --git a/matlab/covariance_mc_analysis.m b/matlab/moments/covariance_mc_analysis.m similarity index 100% rename from matlab/covariance_mc_analysis.m rename to matlab/moments/covariance_mc_analysis.m diff --git a/matlab/disp_moments.m b/matlab/moments/disp_moments.m similarity index 100% rename from matlab/disp_moments.m rename to matlab/moments/disp_moments.m diff --git a/matlab/moments/disp_th_moments_pruned_state_space.m b/matlab/moments/disp_th_moments_pruned_state_space.m index 8db2dad71..55d504458 100644 --- a/matlab/moments/disp_th_moments_pruned_state_space.m +++ b/matlab/moments/disp_th_moments_pruned_state_space.m @@ -52,7 +52,7 @@ for i=1:nvars obs_var(i,1) = find(strcmp(M_.endo_names(i_var(i),:), M_.endo_names(dr.order_var))); end -pruned_state_space = pruned_state_space_system(M_, options_, dr, obs_var, options_.ar, 1, 0); +pruned_state_space = pruned_SS.pruned_state_space_system(M_, options_, dr, obs_var, options_.ar, 1, 0); m = pruned_state_space.E_y; diff --git a/matlab/my_subplot.m b/matlab/my_subplot.m deleted file mode 100644 index ad03060a2..000000000 --- a/matlab/my_subplot.m +++ /dev/null @@ -1,56 +0,0 @@ -function my_subplot(i,imax,irow,icol,fig_title) - -% function my_subplot(i,imax,irow,icol,fig_title) -% spreads subplots on several figures according to a maximum number of -% subplots per figure -% -% INPUTS -% i: subplot number -% imax: total number of subplots -% irow: maximum number of rows in a figure -% icol: maximum number of columns in a figure -% fig_title: title to be repeated on each figure -% -% OUTPUT -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright © 2003-2009 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -nfig_max = irow*icol; -if imax < nfig_max - icol = ceil(sqrt(imax)); - irow=icol; - if (icol-1)*(icol-2) >= imax - irow = icol-2; - icol = icol-1; - elseif (icol)*(icol-2) >= imax - irow = icol-2; - elseif icol*(icol-1) >= imax - irow = icol-1; - end -end - -i1 = mod(i-1,nfig_max); -if i1 == 0 - figure('Name',fig_title); -end - -subplot(irow,icol,i1+1); \ No newline at end of file diff --git a/matlab/reduced_rank_cholesky.m b/matlab/nonlinear-filters/reduced_rank_cholesky.m similarity index 100% rename from matlab/reduced_rank_cholesky.m rename to matlab/nonlinear-filters/reduced_rank_cholesky.m diff --git a/matlab/dyn_ramsey_static.m b/matlab/optimal_policy/dyn_ramsey_static.m similarity index 100% rename from matlab/dyn_ramsey_static.m rename to matlab/optimal_policy/dyn_ramsey_static.m diff --git a/matlab/evaluate_planner_objective.m b/matlab/optimal_policy/evaluate_planner_objective.m similarity index 100% rename from matlab/evaluate_planner_objective.m rename to matlab/optimal_policy/evaluate_planner_objective.m diff --git a/matlab/get_optimal_policy_discount_factor.m b/matlab/optimal_policy/get_optimal_policy_discount_factor.m similarity index 100% rename from matlab/get_optimal_policy_discount_factor.m rename to matlab/optimal_policy/get_optimal_policy_discount_factor.m diff --git a/matlab/mult_elimination.m b/matlab/optimal_policy/mult_elimination.m similarity index 100% rename from matlab/mult_elimination.m rename to matlab/optimal_policy/mult_elimination.m diff --git a/matlab/csolve.m b/matlab/optimization/csolve.m similarity index 100% rename from matlab/csolve.m rename to matlab/optimization/csolve.m diff --git a/matlab/dynare_solve.m b/matlab/optimization/dynare_solve.m similarity index 100% rename from matlab/dynare_solve.m rename to matlab/optimization/dynare_solve.m diff --git a/matlab/lnsrch1.m b/matlab/optimization/lnsrch1.m similarity index 100% rename from matlab/lnsrch1.m rename to matlab/optimization/lnsrch1.m diff --git a/matlab/options2cell.m b/matlab/optimization/options2cell.m similarity index 100% rename from matlab/options2cell.m rename to matlab/optimization/options2cell.m diff --git a/matlab/solve1.m b/matlab/optimization/solve1.m similarity index 100% rename from matlab/solve1.m rename to matlab/optimization/solve1.m diff --git a/matlab/solve_one_boundary.m b/matlab/optimization/solve_one_boundary.m similarity index 100% rename from matlab/solve_one_boundary.m rename to matlab/optimization/solve_one_boundary.m diff --git a/matlab/step_length_correction.m b/matlab/optimization/step_length_correction.m similarity index 100% rename from matlab/step_length_correction.m rename to matlab/optimization/step_length_correction.m diff --git a/matlab/trust_region.m b/matlab/optimization/trust_region.m similarity index 100% rename from matlab/trust_region.m rename to matlab/optimization/trust_region.m diff --git a/matlab/basic_plan.m b/matlab/perfect-foresight-models/basic_plan.m similarity index 100% rename from matlab/basic_plan.m rename to matlab/perfect-foresight-models/basic_plan.m diff --git a/matlab/evaluate_max_dynamic_residual.m b/matlab/perfect-foresight-models/evaluate_max_dynamic_residual.m similarity index 100% rename from matlab/evaluate_max_dynamic_residual.m rename to matlab/perfect-foresight-models/evaluate_max_dynamic_residual.m diff --git a/matlab/flip_plan.m b/matlab/perfect-foresight-models/flip_plan.m similarity index 100% rename from matlab/flip_plan.m rename to matlab/perfect-foresight-models/flip_plan.m diff --git a/matlab/init_plan.m b/matlab/perfect-foresight-models/init_plan.m similarity index 100% rename from matlab/init_plan.m rename to matlab/perfect-foresight-models/init_plan.m diff --git a/matlab/save_results.m b/matlab/save_results.m deleted file mode 100644 index 7ee4801de..000000000 --- a/matlab/save_results.m +++ /dev/null @@ -1,38 +0,0 @@ -function save_results(x,s_name,names) - -% function save_results(x,s_name,names) -% save results in appropriate structure -% -% INPUT -% x: matrix to be saved column by column -% s_name: name of the structure where to save the results -% names: names of the individual series -% -% OUTPUT -% none -% -% SPECIAL REQUIREMENT -% none - -% Copyright © 2006-2009 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -global oo_ - -for i=1:size(x,2) - eval([s_name deblank(names(i,:)) '= x(:,i);']); -end \ No newline at end of file diff --git a/matlab/WriteShockDecomp2Excel.m b/matlab/shock_decomposition/WriteShockDecomp2Excel.m similarity index 100% rename from matlab/WriteShockDecomp2Excel.m rename to matlab/shock_decomposition/WriteShockDecomp2Excel.m diff --git a/matlab/annualized_shock_decomposition.m b/matlab/shock_decomposition/annualized_shock_decomposition.m similarity index 100% rename from matlab/annualized_shock_decomposition.m rename to matlab/shock_decomposition/annualized_shock_decomposition.m diff --git a/matlab/epilogue_shock_decomposition.m b/matlab/shock_decomposition/epilogue_shock_decomposition.m similarity index 100% rename from matlab/epilogue_shock_decomposition.m rename to matlab/shock_decomposition/epilogue_shock_decomposition.m diff --git a/matlab/expand_group.m b/matlab/shock_decomposition/expand_group.m similarity index 100% rename from matlab/expand_group.m rename to matlab/shock_decomposition/expand_group.m diff --git a/matlab/graph_decomp.m b/matlab/shock_decomposition/graph_decomp.m similarity index 100% rename from matlab/graph_decomp.m rename to matlab/shock_decomposition/graph_decomp.m diff --git a/matlab/graph_decomp_detail.m b/matlab/shock_decomposition/graph_decomp_detail.m similarity index 100% rename from matlab/graph_decomp_detail.m rename to matlab/shock_decomposition/graph_decomp_detail.m diff --git a/matlab/initial_condition_decomposition.m b/matlab/shock_decomposition/initial_condition_decomposition.m similarity index 100% rename from matlab/initial_condition_decomposition.m rename to matlab/shock_decomposition/initial_condition_decomposition.m diff --git a/matlab/plot_shock_decomposition.m b/matlab/shock_decomposition/plot_shock_decomposition.m similarity index 100% rename from matlab/plot_shock_decomposition.m rename to matlab/shock_decomposition/plot_shock_decomposition.m diff --git a/matlab/realtime_shock_decomposition.m b/matlab/shock_decomposition/realtime_shock_decomposition.m similarity index 100% rename from matlab/realtime_shock_decomposition.m rename to matlab/shock_decomposition/realtime_shock_decomposition.m diff --git a/matlab/set_default_initial_condition_decomposition_options.m b/matlab/shock_decomposition/set_default_initial_condition_decomposition_options.m similarity index 100% rename from matlab/set_default_initial_condition_decomposition_options.m rename to matlab/shock_decomposition/set_default_initial_condition_decomposition_options.m diff --git a/matlab/set_default_plot_shock_decomposition_options.m b/matlab/shock_decomposition/set_default_plot_shock_decomposition_options.m similarity index 100% rename from matlab/set_default_plot_shock_decomposition_options.m rename to matlab/shock_decomposition/set_default_plot_shock_decomposition_options.m diff --git a/matlab/shock_decomposition.m b/matlab/shock_decomposition/shock_decomposition.m similarity index 100% rename from matlab/shock_decomposition.m rename to matlab/shock_decomposition/shock_decomposition.m diff --git a/matlab/squeeze_shock_decomposition.m b/matlab/shock_decomposition/squeeze_shock_decomposition.m similarity index 100% rename from matlab/squeeze_shock_decomposition.m rename to matlab/shock_decomposition/squeeze_shock_decomposition.m diff --git a/matlab/AIM_first_order_solver.m b/matlab/stochastic_solver/AIM_first_order_solver.m similarity index 100% rename from matlab/AIM_first_order_solver.m rename to matlab/stochastic_solver/AIM_first_order_solver.m diff --git a/matlab/compute_decision_rules.m b/matlab/stochastic_solver/compute_decision_rules.m similarity index 100% rename from matlab/compute_decision_rules.m rename to matlab/stochastic_solver/compute_decision_rules.m diff --git a/matlab/convertAimCodeToInfo.m b/matlab/stochastic_solver/convertAimCodeToInfo.m similarity index 100% rename from matlab/convertAimCodeToInfo.m rename to matlab/stochastic_solver/convertAimCodeToInfo.m diff --git a/matlab/disp_dr.m b/matlab/stochastic_solver/disp_dr.m similarity index 100% rename from matlab/disp_dr.m rename to matlab/stochastic_solver/disp_dr.m diff --git a/matlab/dyn_first_order_solver.m b/matlab/stochastic_solver/dyn_first_order_solver.m similarity index 100% rename from matlab/dyn_first_order_solver.m rename to matlab/stochastic_solver/dyn_first_order_solver.m diff --git a/matlab/dyn_second_order_solver.m b/matlab/stochastic_solver/dyn_second_order_solver.m similarity index 100% rename from matlab/dyn_second_order_solver.m rename to matlab/stochastic_solver/dyn_second_order_solver.m diff --git a/matlab/dynare_resolve.m b/matlab/stochastic_solver/dynare_resolve.m similarity index 100% rename from matlab/dynare_resolve.m rename to matlab/stochastic_solver/dynare_resolve.m diff --git a/matlab/getIrfShocksIndx.m b/matlab/stochastic_solver/getIrfShocksIndx.m similarity index 100% rename from matlab/getIrfShocksIndx.m rename to matlab/stochastic_solver/getIrfShocksIndx.m diff --git a/matlab/irf.m b/matlab/stochastic_solver/irf.m similarity index 100% rename from matlab/irf.m rename to matlab/stochastic_solver/irf.m diff --git a/matlab/k_order_pert.m b/matlab/stochastic_solver/k_order_pert.m similarity index 100% rename from matlab/k_order_pert.m rename to matlab/stochastic_solver/k_order_pert.m diff --git a/matlab/kalman_transition_matrix.m b/matlab/stochastic_solver/kalman_transition_matrix.m similarity index 100% rename from matlab/kalman_transition_matrix.m rename to matlab/stochastic_solver/kalman_transition_matrix.m diff --git a/matlab/resol.m b/matlab/stochastic_solver/resol.m similarity index 100% rename from matlab/resol.m rename to matlab/stochastic_solver/resol.m diff --git a/matlab/select_qz_criterium_value.m b/matlab/stochastic_solver/select_qz_criterium_value.m similarity index 100% rename from matlab/select_qz_criterium_value.m rename to matlab/stochastic_solver/select_qz_criterium_value.m diff --git a/matlab/set_state_space.m b/matlab/stochastic_solver/set_state_space.m similarity index 100% rename from matlab/set_state_space.m rename to matlab/stochastic_solver/set_state_space.m diff --git a/matlab/simult.m b/matlab/stochastic_solver/simult.m similarity index 100% rename from matlab/simult.m rename to matlab/stochastic_solver/simult.m diff --git a/matlab/simult_.m b/matlab/stochastic_solver/simult_.m similarity index 100% rename from matlab/simult_.m rename to matlab/stochastic_solver/simult_.m diff --git a/matlab/simultxdet.m b/matlab/stochastic_solver/simultxdet.m similarity index 100% rename from matlab/simultxdet.m rename to matlab/stochastic_solver/simultxdet.m diff --git a/matlab/stoch_simul.m b/matlab/stochastic_solver/stoch_simul.m similarity index 100% rename from matlab/stoch_simul.m rename to matlab/stochastic_solver/stoch_simul.m diff --git a/matlab/stochastic_solvers.m b/matlab/stochastic_solver/stochastic_solvers.m similarity index 100% rename from matlab/stochastic_solvers.m rename to matlab/stochastic_solver/stochastic_solvers.m diff --git a/tests/analytic_derivatives/BrockMirman_PertParamsDerivs.mod b/tests/analytic_derivatives/BrockMirman_PertParamsDerivs.mod index 0c5ac994d..9c181990a 100644 --- a/tests/analytic_derivatives/BrockMirman_PertParamsDerivs.mod +++ b/tests/analytic_derivatives/BrockMirman_PertParamsDerivs.mod @@ -440,7 +440,7 @@ for jj = 1:2 oo_.dr.Correlation_matrix = M_.Correlation_matrix; ex0 = oo_.exo_steady_state'; [~, oo_.dr.g1, oo_.dr.g2, oo_.dr.g3] = feval([M_.fname,'.dynamic'], oo_.dr.ys(I), oo_.exo_steady_state', M_.params, oo_.dr.ys, 1); - oo_.dr.g3 = unfold_g3(oo_.dr.g3, length(oo_.dr.ys(I))+length(oo_.exo_steady_state')); %add symmetric elements to g3 + oo_.dr.g3 = identification.unfold_g3(oo_.dr.g3, length(oo_.dr.ys(I))+length(oo_.exo_steady_state')); %add symmetric elements to g3 fprintf('***** %s: SOME COMMON OBJECTS *****\n', strparamset) for id_var = 1:size(lst_vars,2) @@ -460,7 +460,7 @@ for jj = 1:2 for id_kronflag = 1:length(KRONFLAG) fprintf('***** %s: d2flag=%d and kronflag=%d *****\n',strparamset, d2flag,KRONFLAG(id_kronflag)) options_.analytic_derivation_mode = KRONFLAG(id_kronflag); - DERIVS = get_perturbation_params_derivs(M_, options_, estim_params_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag); + DERIVS = identification.get_perturbation_params_derivs(M_, options_, estim_params_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag); for id_var = 1:size(lst_dvars,2) dx = norm( vec(nSYM.(sprintf('%s',lst_dvars{id_var}))) - vec(DERIVS.(sprintf('%s',lst_dvars{id_var}))), Inf); fprintf('Max absolute deviation for %s: %e\n', lst_dvars{id_var}, dx); diff --git a/tests/analytic_derivatives/burnside_3_order_PertParamsDerivs.mod b/tests/analytic_derivatives/burnside_3_order_PertParamsDerivs.mod index ba7f17762..b1f3351ed 100644 --- a/tests/analytic_derivatives/burnside_3_order_PertParamsDerivs.mod +++ b/tests/analytic_derivatives/burnside_3_order_PertParamsDerivs.mod @@ -170,7 +170,7 @@ KRONFLAGS = [-1 -2 0 1]; for k = 1:length(KRONFLAGS) fprintf('KRONFLAG=%d\n',KRONFLAGS(k)); options_.analytic_derivation_mode = KRONFLAGS(k); - DERIVS = get_perturbation_params_derivs(M_, options_, estim_params_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag); + DERIVS = identification.get_perturbation_params_derivs(M_, options_, estim_params_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag); oo_.dr.dg_0 = permute(1/2*DERIVS.dghs2,[1 3 2]); oo_.dr.dg_1 = cat(2,DERIVS.dghx,DERIVS.dghu) + 3/6*cat(2,DERIVS.dghxss,DERIVS.dghuss); oo_.dr.dg_2 = 1/2*cat(2,DERIVS.dghxx,DERIVS.dghxu,DERIVS.dghuu); diff --git a/tests/minimal_state_space_system/as2007_minimal.mod b/tests/minimal_state_space_system/as2007_minimal.mod index 81bb6c049..09b924615 100644 --- a/tests/minimal_state_space_system/as2007_minimal.mod +++ b/tests/minimal_state_space_system/as2007_minimal.mod @@ -81,7 +81,7 @@ SS.B = oo_.dr.ghu(indx,:); SS.C = oo_.dr.ghx(indy,:); SS.D = oo_.dr.ghu(indy,:); -[CheckCO,minnx,minSS] = get_minimal_state_representation(SS,0); +[CheckCO,minnx,minSS] = identification.get_minimal_state_representation(SS,0); Sigmax_full = lyapunov_symm(SS.A, SS.B*M_.Sigma_e*SS.B', options_.lyapunov_fixed_point_tol, options_.qz_criterium, options_.lyapunov_complex_threshold, 1, options_.debug); Sigmay_full = SS.C*Sigmax_full*SS.C' + SS.D*M_.Sigma_e*SS.D'; diff --git a/tests/minimal_state_space_system/sw_minimal.mod b/tests/minimal_state_space_system/sw_minimal.mod index 585e851f3..b7dc1150b 100644 --- a/tests/minimal_state_space_system/sw_minimal.mod +++ b/tests/minimal_state_space_system/sw_minimal.mod @@ -414,7 +414,7 @@ SS.B = oo_.dr.ghu(indx,:); SS.C = oo_.dr.ghx(indy,:); SS.D = oo_.dr.ghu(indy,:); -[CheckCO,minnx,minSS] = get_minimal_state_representation(SS,0); +[CheckCO,minnx,minSS] = identification.get_minimal_state_representation(SS,0); Sigmax_full = lyapunov_symm(SS.A, SS.B*M_.Sigma_e*SS.B', options_.lyapunov_fixed_point_tol, options_.qz_criterium, options_.lyapunov_complex_threshold, 1, options_.debug); Sigmay_full = SS.C*Sigmax_full*SS.C' + SS.D*M_.Sigma_e*SS.D'; diff --git a/tests/stochastic_simulations/pruning/AS_pruned_state_space_red_shock.mod b/tests/stochastic_simulations/pruning/AS_pruned_state_space_red_shock.mod index 08c96ecdb..e2dc1af98 100644 --- a/tests/stochastic_simulations/pruning/AS_pruned_state_space_red_shock.mod +++ b/tests/stochastic_simulations/pruning/AS_pruned_state_space_red_shock.mod @@ -97,7 +97,7 @@ steady; check; model_diagnostics; @#for orderApp in [1, 2, 3] stoch_simul(order=@{orderApp},pruning,irf=0,periods=0); - pruned_state_space.order_@{orderApp} = pruned_state_space_system(M_, options_, oo_.dr, [], options_.ar, 1, 0); + pruned_state_space.order_@{orderApp} = pruned_SS.pruned_state_space_system(M_, options_, oo_.dr, [], options_.ar, 1, 0); @#if Andreasen_et_al_toolbox addpath('Dynare44Pruning_v2/simAndMoments3order'); %provide path to toolbox optPruning.orderApp = @{orderApp}; diff --git a/tests/stochastic_simulations/pruning/AnSchorfheide_pruned_state_space.mod b/tests/stochastic_simulations/pruning/AnSchorfheide_pruned_state_space.mod index 623b966cf..39d644ac7 100644 --- a/tests/stochastic_simulations/pruning/AnSchorfheide_pruned_state_space.mod +++ b/tests/stochastic_simulations/pruning/AnSchorfheide_pruned_state_space.mod @@ -96,7 +96,7 @@ steady; check; model_diagnostics; @#for orderApp in [1, 2, 3] stoch_simul(order=@{orderApp},pruning,irf=0,periods=0); - pruned_state_space.order_@{orderApp} = pruned_state_space_system(M_, options_, oo_.dr, [], options_.ar, 1, 0); + pruned_state_space.order_@{orderApp} = pruned_SS.pruned_state_space_system(M_, options_, oo_.dr, [], options_.ar, 1, 0); @#if Andreasen_et_al_toolbox addpath('Dynare44Pruning_v2/simAndMoments3order'); %provide path to toolbox optPruning.orderApp = @{orderApp}; diff --git a/tests/stochastic_simulations/pruning/fs2000_pruning.mod b/tests/stochastic_simulations/pruning/fs2000_pruning.mod index f325bf71f..732e4be18 100644 --- a/tests/stochastic_simulations/pruning/fs2000_pruning.mod +++ b/tests/stochastic_simulations/pruning/fs2000_pruning.mod @@ -97,7 +97,7 @@ if (max(abs(Y2_local(:) - Y2_simult(:)))>1e-12) end % pruned_state_space_system.m: implements Andreasen et al. -pss = pruned_state_space_system(M_, options_, oo_.dr, [], 0, false, false); +pss = pruned_SS.pruned_state_space_system(M_, options_, oo_.dr, [], 0, false, false); Y2_an = zeros(M_.endo_nbr,T+1); Y2_an(:,1) = oo_.dr.ys; % z = [xf;xs;kron(xf,xf)] @@ -127,7 +127,7 @@ stoch_simul(order=3, nograph, irf=0); % simult_.m Y3_simult = simult_(M_,options_,oo_.dr.ys,oo_.dr,ex,options_.order); % pruned_state_space_system.m -pss = pruned_state_space_system(M_, options_, oo_.dr, [], 0, false, false); +pss = pruned_SS.pruned_state_space_system(M_, options_, oo_.dr, [], 0, false, false); Y3_an = zeros(M_.endo_nbr,T+1); Y3_an(:,1) = oo_.dr.ys; % z = [xf; xs; kron(xf,xf); xrd; kron(xf,xs); kron(kron(xf,xf),xf)]