Global reindentation of MATLAB code (excluding submodules)

Also convert to Unix end-of-lines, and remove trailing whitespaces.
parent b901b7af
......@@ -158,13 +158,13 @@ for i=fpar:npar
end
subplotnum = 0;
end
end% loop over selected endo_var
end % loop over selected endo_var
if whoiam
fprintf('Done! \n');
waitbarString = [ 'Exog. shocks ' int2str(i) '/' int2str(npar) ' done.'];
% fMessageStatus((i-fpar+1)/(npar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
dyn_waitbar((i-fpar+1)/(npar-fpar+1),[],waitbarString);
end
end% loop over exo_var
end % loop over exo_var
myoutput.OutputFileName = OutputFileName;
function y0 = get_irf(exo,varargin)
% function x = get_irf(exoname, vname1, vname2, ...)
% returns IRF to individual exogenous for a list of variables and adds the
% steady state
%
% INPUTS:
% exo: exo variable name
% vname1, vname2, ... : list of variable names
%
% OUTPUTS
% x: irf matrix [time x number of variables]
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global M_ oo_
ys_ = [oo_.steady_state];
y0=zeros(length(oo_.irfs.([varargin{1} '_' exo]))+1,length(varargin));
[i_var,nvar] = varlist_indices(varargin,M_.endo_names);
for j=1:nvar
% mfys = strmatch(varargin{j},lgy_,'exact');
y0(:,j)=[0; oo_.irfs.([ varargin{j} '_' exo ])']+ys_(i_var(j));
end
function y0 = get_irf(exo,varargin)
% function x = get_irf(exoname, vname1, vname2, ...)
% returns IRF to individual exogenous for a list of variables and adds the
% steady state
%
% INPUTS:
% exo: exo variable name
% vname1, vname2, ... : list of variable names
%
% OUTPUTS
% x: irf matrix [time x number of variables]
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global M_ oo_
ys_ = [oo_.steady_state];
y0=zeros(length(oo_.irfs.([varargin{1} '_' exo]))+1,length(varargin));
[i_var,nvar] = varlist_indices(varargin,M_.endo_names);
for j=1:nvar
% mfys = strmatch(varargin{j},lgy_,'exact');
y0(:,j)=[0; oo_.irfs.([ varargin{j} '_' exo ])']+ys_(i_var(j));
end
function y0 = get_mean(varargin)
% function x = get_mean(vname1, vname2, <order>)
% returns the steady-state of a variable identified by its name
%
% INPUTS:
% vname1, vname2, ... : list of variable names
% order: if integer 1 or 2, optionally last input can trigger the order
% at which steady state is computed
%
% OUTPUTS
% x: steady state values
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global M_ oo_ options_
if ~isempty(regexp(varargin{end},'\d','ONCE')) && isempty(regexp(varargin{end},'\D','ONCE'))
order=eval(varargin{end});
else
order=1;
end
if order==1
ys_ = oo_.steady_state;
ys_ = evaluate_steady_state(ys_,M_,options_,oo_,1);
elseif order==2
ys_ = oo_.dr.ys;
ys_(oo_.dr.order_var)=ys_(oo_.dr.order_var)+oo_.dr.ghs2./2;
else
return
end
lgy_ = M_.endo_names;
mfys=nan(length(varargin),1);
for j=1:length(varargin)
mfys(j) = find(strcmp(varargin{j},lgy_));
end
y0 = ys_(mfys);
function y0 = get_mean(varargin)
% function x = get_mean(vname1, vname2, <order>)
% returns the steady-state of a variable identified by its name
%
% INPUTS:
% vname1, vname2, ... : list of variable names
% order: if integer 1 or 2, optionally last input can trigger the order
% at which steady state is computed
%
% OUTPUTS
% x: steady state values
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global M_ oo_ options_
if ~isempty(regexp(varargin{end},'\d','ONCE')) && isempty(regexp(varargin{end},'\D','ONCE'))
order=eval(varargin{end});
else
order=1;
end
if order==1
ys_ = oo_.steady_state;
ys_ = evaluate_steady_state(ys_,M_,options_,oo_,1);
elseif order==2
ys_ = oo_.dr.ys;
ys_(oo_.dr.order_var)=ys_(oo_.dr.order_var)+oo_.dr.ghs2./2;
else
return
end
lgy_ = M_.endo_names;
mfys=nan(length(varargin),1);
for j=1:length(varargin)
mfys(j) = find(strcmp(varargin{j},lgy_));
end
y0 = ys_(mfys);
function x = get_shock_stderr_by_name(exoname)
% function x = get_shock_stderr_by_name(exoname)
% returns the value of a shock identified by its name
%
%
% INPUTS:
% exoname: shock name
%
......
function y0 = get_smooth(varargin)
% function x = get_smooth(vname1, vname2, )
% returns smoothed variables or shocks identified by their name
%
% INPUTS:
% vname1, vname2, ... : list of variable/shock names
%
% OUTPUTS
% x: smoothed variables [T x number of variables]
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global oo_
SmoothedVariables=[struct2cell(oo_.SmoothedVariables); struct2cell(oo_.SmoothedShocks)];
my_field_names = [fieldnames(oo_.SmoothedVariables); fieldnames(oo_.SmoothedShocks)];
isvar=zeros(length(SmoothedVariables),1);
for jf = 1:length(SmoothedVariables)
isvar(jf)=~(isstruct(SmoothedVariables{jf}));
end
SmoothedVariables=cell2struct(SmoothedVariables(logical(isvar)),my_field_names(logical(isvar)));
y0=zeros(length(SmoothedVariables.(varargin{1})),length(varargin));
for j=1:length(varargin)
y0(:,j)=SmoothedVariables.(varargin{j});
end
function y0 = get_smooth(varargin)
% function x = get_smooth(vname1, vname2, )
% returns smoothed variables or shocks identified by their name
%
% INPUTS:
% vname1, vname2, ... : list of variable/shock names
%
% OUTPUTS
% x: smoothed variables [T x number of variables]
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global oo_
SmoothedVariables=[struct2cell(oo_.SmoothedVariables); struct2cell(oo_.SmoothedShocks)];
my_field_names = [fieldnames(oo_.SmoothedVariables); fieldnames(oo_.SmoothedShocks)];
isvar=zeros(length(SmoothedVariables),1);
for jf = 1:length(SmoothedVariables)
isvar(jf)=~(isstruct(SmoothedVariables{jf}));
end
SmoothedVariables=cell2struct(SmoothedVariables(logical(isvar)),my_field_names(logical(isvar)));
y0=zeros(length(SmoothedVariables.(varargin{1})),length(varargin));
for j=1:length(varargin)
y0(:,j)=SmoothedVariables.(varargin{j});
end
function y0 = get_update(varargin)
% function x = get_update(vname1, vname2, )
% returns updated variables identified by their name
%
% INPUTS:
% vname1, vname2, ... : list of variable names
%
% OUTPUTS
% x: smoothed variables [T x number of variables]
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global oo_
y0=zeros(length(oo_.UpdatedVariables.(varargin{1})),length(varargin));
for j=1:length(varargin)
y0(:,j)=oo_.UpdatedVariables.(varargin{j});
end
function y0 = get_update(varargin)
% function x = get_update(vname1, vname2, )
% returns updated variables identified by their name
%
% INPUTS:
% vname1, vname2, ... : list of variable names
%
% OUTPUTS
% x: smoothed variables [T x number of variables]
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global oo_
y0=zeros(length(oo_.UpdatedVariables.(varargin{1})),length(varargin));
for j=1:length(varargin)
y0(:,j)=oo_.UpdatedVariables.(varargin{j});
end
......@@ -2,13 +2,13 @@ function forecasts = backward_model_forecast(initialcondition, listofvariables,
% Returns unconditional forecasts.
%
% INPUTS
% INPUTS
% - initialcondition [dseries] Initial conditions for the endogenous variables.
% - periods [integer] scalar, the number of (forecast) periods.
% - withuncertainty [logical] scalar, returns confidence bands if true.
%
% OUTPUTS
% - forecast [dseries]
% OUTPUTS
% - forecast [dseries]
% Copyright (C) 2017-2018 Dynare Team
%
......@@ -98,7 +98,7 @@ end
forecasts.pointforecast = dseries(transpose(ysim__0(idy,:)), initialcondition.init, listofvariables);
% Set first period of forecast
forecasts.start = start;
forecasts.start = start;
if withuncertainty
% Preallocate an array gathering the simulations.
......@@ -110,7 +110,7 @@ if withuncertainty
else
[ysim__, xsim__] = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, iy1, model_dynamic);
end
ArrayOfForecasts(:,:,i) = ysim__(idy,:);
ArrayOfForecasts(:,:,i) = ysim__(idy,:);
end
% Compute mean (over future uncertainty) forecast.
forecasts.meanforecast = dseries(transpose(mean(ArrayOfForecasts, 3)), initialcondition.init, listofvariables);
......
......@@ -45,7 +45,7 @@ ydata = dbase{info.endonames{:}}.data;
exogenousvariablesindbase = intersect(info.exonames, dbase.name);
residuals = dseries(NaN(dbase.nobs, length(info.residuals)), dbase.init, info.residuals);
allexogenousvariables = [dbase{exogenousvariablesindbase{:}}, residuals];
allexogenousvariables = allexogenousvariables{info.exonames{:}};
allexogenousvariables = allexogenousvariables{info.exonames{:}};
xdata = allexogenousvariables.data;
% Evaluate the dynamic equation
......
function l = get_lags_on_endogenous_variables(DynareModel)
% Returns a vector with the max lag for each endogenous variable.
% Returns a vector with the max lag for each endogenous variable.
% Copyright (C) 2017 Dynare Team
%
......
function l = get_lags_on_exogenous_variables(DynareModel)
% Returns a vector with the max lag for each exogenous variable.
% Returns a vector with the max lag for each exogenous variable.
% Copyright (C) 2017 Dynare Team
%
......
......@@ -44,9 +44,9 @@ end
% Get coefficients
[cst, jacob] = model_dynamic(zeros(DynareModel.endo_nbr+ny1,1), ...
zeros(DynareModel.orig_maximum_lag+1,DynareModel.exo_nbr), ...
DynareModel.params, ...
DynareOutput.steady_state, DynareModel.orig_maximum_lag+1);
zeros(DynareModel.orig_maximum_lag+1,DynareModel.exo_nbr), ...
DynareModel.params, ...
DynareOutput.steady_state, DynareModel.orig_maximum_lag+1);
A0inv = inv(jacob(:,jdx));
A1 = jacob(:,nonzeros(DynareModel.lead_lag_incidence(1,:)));
......
function [initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, nx, ny1, iy1, jdx, model_dynamic, y] = ...
simul_backward_model_init(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations)
% Initialization of the routines simulating backward models.
% Initialization of the routines simulating backward models.
% Copyright (C) 2017-2019 Dynare Team
%
......@@ -67,7 +67,7 @@ endolags_ = endolags(find(endolags));
endowithlagnames = endonames(find(endolags));
if ~isempty(missingendogenousvariables)
missingendogenousvariables = setdiff(endowithlagnames, initialconditions.name);
missingendogenouslaggedvariables = intersect(endowithlagnames, missingendogenousvariables);
missingendogenouslaggedvariables = intersect(endowithlagnames, missingendogenousvariables);
if ~isempty(missingendogenouslaggedvariables)
disp('You have to initialize the following endogenous variables:')
msg = sprintf('%s\n', missingendogenouslaggedvariables{1:end-1});
......@@ -83,7 +83,7 @@ maxlag = abs(min(endolags));
if maxlag>initialconditions.nobs
error('The dseries object provided as first input argument should at least have %s periods!', num2str(maxlag))
end
missinginitialcondition = false;
missinginitialcondition = false;
for i = 1:length(endowithlagnames)
lags = abs(endolags_(i));
variable = initialconditions{endowithlagnames{i}};
......@@ -102,7 +102,7 @@ if missinginitialcondition
error('Please fix the dseries object used for setting the initial conditions!')
end
% If the model has lags on the exogenous variables, test if we have corresponding initial conditions.
% If the model has lags on the exogenous variables, test if we have corresponding initial conditions.
exonames = DynareModel.exo_names;
missingexogenousvariables = setdiff(exonames, initialconditions.name);
exolags = get_lags_on_exogenous_variables(DynareModel);
......@@ -110,7 +110,7 @@ exolags_ = exolags(find(exolags));
exowithlagnames = exonames(find(exolags));
if ~isempty(missingexogenousvariables)
missingexogenousvariables = setdiff(exowithlagnames, initialconditions.name);
missingexogenouslaggedvariables = intersect(exowithlagnames, missingexogenousvariables);
missingexogenouslaggedvariables = intersect(exowithlagnames, missingexogenousvariables);
if ~isempty(missingexogenouslaggedvariables)
disp('You have to initialize the following exogenous variables:')
msg = sprintf('%s\n', missingexogenouslaggedvariables{1:end-1});
......@@ -126,7 +126,7 @@ maxlag = abs(min(exolags));
if maxlag>initialconditions.nobs
error('The dseries object provided as first input argument should at least have %s periods!', num2str(maxlag))
end
missinginitialcondition = false;
missinginitialcondition = false;
for i = 1:length(exowithlagnames)
lags = abs(exolags_(i));
variable = initialconditions{exowithlagnames{i}};
......@@ -190,14 +190,14 @@ end
if nargout>8
nx = size(DynareOutput.exo_simul,2);
ny0 = nnz(DynareModel.lead_lag_incidence(2,:));
ny1 = nnz(DynareModel.lead_lag_incidence(1,:));
iy1 = find(DynareModel.lead_lag_incidence(1,:)>0);
idx = 1:DynareModel.endo_nbr;
jdx = idx+ny1;
% Get the name of the dynamic model routine.
model_dynamic = str2func([DynareModel.fname,'.dynamic']);
% initialization of vector y.
y = NaN(length(idx)+ny1,1);
nx = size(DynareOutput.exo_simul,2);
ny0 = nnz(DynareModel.lead_lag_incidence(2,:));
ny1 = nnz(DynareModel.lead_lag_incidence(1,:));
iy1 = find(DynareModel.lead_lag_incidence(1,:)>0);
idx = 1:DynareModel.endo_nbr;
jdx = idx+ny1;
% Get the name of the dynamic model routine.
model_dynamic = str2func([DynareModel.fname,'.dynamic']);
% initialization of vector y.
y = NaN(length(idx)+ny1,1);
end
\ No newline at end of file
function n = cellofchararraymaxlength(c)
% Copyright (C) 2018 Dynare Team
%
% This file is part of Dynare.
......
function k = commutation(n, m, sparseflag)
% k = commutation(n, m, sparseflag)
% -------------------------------------------------------------------------
% Returns Magnus and Neudecker's commutation matrix of dimensions n by m,
% Returns Magnus and Neudecker's commutation matrix of dimensions n by m,
% that solves k*vec(X)=vec(X')
% =========================================================================
% INPUTS
......@@ -10,9 +10,9 @@ function k = commutation(n, m, sparseflag)
% sparseflag: [integer] whether to use sparse matrices (=1) or not (else)
% -------------------------------------------------------------------------
% OUTPUTS
% k: [n by m] commutation matrix
% k: [n by m] commutation matrix
% -------------------------------------------------------------------------
% This function is called by
% This function is called by
% * get_perturbation_params_derivs.m (previously getH.m)
% * get_identification_jacobians.m (previously getJJ.m)
% -------------------------------------------------------------------------
......@@ -40,25 +40,25 @@ function k = commutation(n, m, sparseflag)
% Original author: Thomas P Minka (tpminka@media.mit.edu), April 22, 2013
if nargin < 2
m = n(2);
n = n(1);
m = n(2);
n = n(1);
end
if nargin < 3
sparseflag = 0;
sparseflag = 0;
end
if 0
% first method
i = 1:(n*m);
a = reshape(i, n, m);
j = vec(transpose(a));
k = zeros(n*m,n*m);
for r = i
k(r, j(r)) = 1;
end
% first method
i = 1:(n*m);
a = reshape(i, n, m);
j = vec(transpose(a));
k = zeros(n*m,n*m);
for r = i
k(r, j(r)) = 1;
end
else
% second method
k = reshape(kron(vec(eye(n)), eye(m)), n*m, n*m);
% second method
k = reshape(kron(vec(eye(n)), eye(m)), n*m, n*m);
end
if sparseflag ~= 0
......@@ -66,7 +66,7 @@ if sparseflag ~= 0
end
function V = vec(A)
V = A(:);
V = A(:);
end
end
......@@ -150,8 +150,8 @@ Pinf = zeros(np,np);
Pinf(1:nk,1:nk) = eye(nk);
if np0
STtriu = STinf-eye(nk);
% A\B is the matrix division of A into B, which is roughly the
% same as INV(A)*B
% A\B is the matrix division of A into B, which is roughly the
% same as INV(A)*B
STinf0 = ST00*(eye(nk)-iSTinf*STtriu);
Pinf = blkdiag(zeros(np0),Pinf);
QT = blkdiag(eye(np0),QT);
......
......@@ -247,7 +247,7 @@ if M_.exo_nbr > 1
title = 'Posterior mean conditional variance decomposition (in percent) with measurement error';
save_name_string = 'dsge_post_mean_var_decomp_ME_cond_h';