Move various functions from main matlab folder to subfolders

covariance-quadratic-approximation
Johannes Pfeifer 2023-12-08 10:06:00 +01:00 committed by Sébastien Villemot
parent 2e73856f5a
commit c3268c0279
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
128 changed files with 195 additions and 472 deletions

View File

@ -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 <minka@microsoft.com>
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 <brunoluong@yahoo.com>
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 <kan@chass.utoronto.ca>
2019-2020 Dynare Team
License: GPL-3+

View File

@ -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=[];

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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)'...

View File

@ -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;

View File

@ -1,49 +1,49 @@
function p = uperm(a)
% Return all unique permutations of possibly-repeating array elements
% =========================================================================
% Copyright © 2014 Bruno Luong <brunoluong@yahoo.com>
% 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 <https://www.gnu.org/licenses/>.
% =========================================================================
% Original author: Bruno Luong <brunoluong@yahoo.com>, 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 <brunoluong@yahoo.com>
% 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 <https://www.gnu.org/licenses/>.
% =========================================================================
% Original author: Bruno Luong <brunoluong@yahoo.com>, 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

View File

@ -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 <https://www.gnu.org/licenses/>.
[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);

View File

@ -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.
%

View File

@ -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);

View File

@ -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 <https://www.gnu.org/licenses/>.
[ivar,vartan,options_] = get_variables_list(options_,M_);
moments = th_autocovariances(dr,ivar,M_,options_,options_.nodecomposition);

View File

@ -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

View File

@ -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 <https://www.gnu.org/licenses/>.
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

View File

@ -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 <https://www.gnu.org/licenses/>.
m = length(Vector);
n = (sqrt(1+8*m)-1)/2;
k = cumsum(1:n);
d = Vector(k);

View File

@ -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/' ; ...

View File

@ -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 <https://www.gnu.org/licenses/>.
% 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

View File

@ -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;

View File

@ -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);

View File

@ -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 <https://www.gnu.org/licenses/>.
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

View File

@ -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;

View File

@ -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 <https://www.gnu.org/licenses/>.
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);

View File

@ -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 <https://www.gnu.org/licenses/>.
global oo_
for i=1:size(x,2)
eval([s_name deblank(names(i,:)) '= x(:,i);']);
end

Some files were not shown because too many files have changed in this diff Show More