From b773a242c8ab33b0faf0f024da546551e68aeebe Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 12 Jun 2017 20:59:18 +0200 Subject: [PATCH 01/17] discretionary_policy_1.m: output which derivative is nonzero --- matlab/discretionary_policy_1.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/matlab/discretionary_policy_1.m b/matlab/discretionary_policy_1.m index 0837067b2..b4f9cc35c 100644 --- a/matlab/discretionary_policy_1.m +++ b/matlab/discretionary_policy_1.m @@ -68,6 +68,15 @@ if options_.steadystate_flag end [U,Uy,W] = feval([M_.fname,'_objective_static'],zeros(endo_nbr,1),[], M_.params); if any(any(Uy~=0)) + non_zero_derivs=find(any(Uy~=0)); + for ii=1:length(non_zero_derivs) + non_zero_deriv_names{ii,1}=deblank(M_.endo_names(non_zero_derivs(ii),:)); + end + disp_string=[non_zero_deriv_names{1,:}]; + for ii=2:size(non_zero_deriv_names,1) + disp_string=[disp_string,', ',non_zero_deriv_names{ii,:}]; + end + fprintf('\nThe derivative of the objective function w.r.t. to variable(s) %s is not 0\n',disp_string) error(['discretionary_policy: the objective function must have zero ' ... 'first order derivatives']) end From 89326090b929ee631e0bf472e00e6218fc34bd3d Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 23 Jun 2017 10:50:06 +0200 Subject: [PATCH 02/17] simpsa: Only store output strcuture if requested Otherwise a huge three-dimensional array is created by default that is not used, but can run computer out of memory --- matlab/optimization/simpsa.m | 71 +++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/matlab/optimization/simpsa.m b/matlab/optimization/simpsa.m index 87b881a2c..760298a13 100644 --- a/matlab/optimization/simpsa.m +++ b/matlab/optimization/simpsa.m @@ -142,8 +142,9 @@ DEFAULT_OPTIONS = simpsaset('TEMP_START',[],... % starting temperature (if none OPTIONS = simpsaset(DEFAULT_OPTIONS,OPTIONS); % store options in OUTPUT - -OUTPUT.OPTIONS = OPTIONS; +if nargout>3 + OUTPUT.OPTIONS = OPTIONS; +end % initialize simplex % ------------------ @@ -175,13 +176,13 @@ end % initialize OUTPUT structure % --------------------------- - -OUTPUT.TEMPERATURE = zeros(OPTIONS.MAX_ITER_TOTAL,1); -OUTPUT.SIMPLEX = zeros(NDIM+1,NDIM,OPTIONS.MAX_ITER_TOTAL); -OUTPUT.SIMPLEX_BEST = zeros(OPTIONS.MAX_ITER_TOTAL,NDIM); -OUTPUT.COSTS = zeros(OPTIONS.MAX_ITER_TOTAL,NDIM+1); -OUTPUT.COST_BEST = zeros(OPTIONS.MAX_ITER_TOTAL,1); - +if nargout>3 + OUTPUT.TEMPERATURE = zeros(OPTIONS.MAX_ITER_TOTAL,1); + OUTPUT.SIMPLEX = zeros(NDIM+1,NDIM,OPTIONS.MAX_ITER_TOTAL); + OUTPUT.SIMPLEX_BEST = zeros(OPTIONS.MAX_ITER_TOTAL,NDIM); + OUTPUT.COSTS = zeros(OPTIONS.MAX_ITER_TOTAL,NDIM+1); + OUTPUT.COST_BEST = zeros(OPTIONS.MAX_ITER_TOTAL,1); +end % initialize iteration data % ------------------------- @@ -304,17 +305,19 @@ while 1 Y = help(:,2); P = help(:,3:end); - % store temperature at current iteration - OUTPUT.TEMPERATURE(nITERATIONS) = TEMP; + if nargout>3 + % store temperature at current iteration + OUTPUT.TEMPERATURE(nITERATIONS) = TEMP; - % store information about simplex at the current iteration - OUTPUT.SIMPLEX(:,:,nITERATIONS) = P; - OUTPUT.SIMPLEX_BEST(nITERATIONS,:) = PBEST; - - % store cost function value of best vertex in current iteration - OUTPUT.COSTS(nITERATIONS,:) = Y; - OUTPUT.COST_BEST(nITERATIONS) = YBEST; + % store information about simplex at the current iteration + OUTPUT.SIMPLEX(:,:,nITERATIONS) = P; + OUTPUT.SIMPLEX_BEST(nITERATIONS,:) = PBEST; + % store cost function value of best vertex in current iteration + OUTPUT.COSTS(nITERATIONS,:) = Y; + OUTPUT.COST_BEST(nITERATIONS) = YBEST; + end + if strcmp(OPTIONS.DISPLAY,'iter') disp(sprintf('%5.0f %5.0f %12.6g %15.6g %12.6g %s',nITERATIONS,nFUN_EVALS,Y(1),YBEST,TEMP,ALGOSTEP)); end @@ -452,21 +455,23 @@ end X = transpose(PBEST); FVAL = YBEST; -% store number of function evaluations -OUTPUT.nFUN_EVALS = nFUN_EVALS; - -% store number of iterations -OUTPUT.nITERATIONS = nITERATIONS; - -% trim OUTPUT data structure -OUTPUT.TEMPERATURE(nITERATIONS+1:end) = []; -OUTPUT.SIMPLEX(:,:,nITERATIONS+1:end) = []; -OUTPUT.SIMPLEX_BEST(nITERATIONS+1:end,:) = []; -OUTPUT.COSTS(nITERATIONS+1:end,:) = []; -OUTPUT.COST_BEST(nITERATIONS+1:end) = []; - -% store the amount of time needed in OUTPUT data structure -OUTPUT.TIME = toc; +if nargout>3 + % store number of function evaluations + OUTPUT.nFUN_EVALS = nFUN_EVALS; + + % store number of iterations + OUTPUT.nITERATIONS = nITERATIONS; + + % trim OUTPUT data structure + OUTPUT.TEMPERATURE(nITERATIONS+1:end) = []; + OUTPUT.SIMPLEX(:,:,nITERATIONS+1:end) = []; + OUTPUT.SIMPLEX_BEST(nITERATIONS+1:end,:) = []; + OUTPUT.COSTS(nITERATIONS+1:end,:) = []; + OUTPUT.COST_BEST(nITERATIONS+1:end) = []; + + % store the amount of time needed in OUTPUT data structure + OUTPUT.TIME = toc; +end return From aa2a1e4d6046ce841a724af587d9c6f1b3dfa706 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 26 Jun 2017 16:43:13 +0200 Subject: [PATCH 03/17] generate_trace_plots: Add measurement errors --- matlab/generate_trace_plots.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/matlab/generate_trace_plots.m b/matlab/generate_trace_plots.m index b7a38e016..83b9003fc 100644 --- a/matlab/generate_trace_plots.m +++ b/matlab/generate_trace_plots.m @@ -50,6 +50,11 @@ for ii=1:size(estim_params_.var_exo,1) trace_plot(options_,M_,estim_params_,'StructuralShock',chain_number,parameter_name) end +for ii=1:size(estim_params_.var_endo,1) + parameter_name=deblank(M_.endo_names(estim_params_.var_endo(ii,1),:)); + trace_plot(options_,M_,estim_params_,'MeasurementError',chain_number,parameter_name) +end + for ii=1:size(estim_params_.corrn,1) parameter_name_1=deblank(M_.endo_names(estim_params_.corrn(ii,1),:)); parameter_name_2=deblank(M_.endo_names(estim_params_.corrn(ii,2),:)); From 3bac10a97de11cced895ee5385058861fb49bd4f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 16 Jun 2017 13:51:03 +0200 Subject: [PATCH 04/17] Fix bug in use_shock_groups and colormap Option was not written to correct subfield of options_-structure. Related to 7cd56e96877de4ed2dd22bb579884ab292034d71 --- matlab/plot_shock_decomposition.m | 1 - preprocessor/DynareBison.yy | 12 ++++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/matlab/plot_shock_decomposition.m b/matlab/plot_shock_decomposition.m index 182a0f906..377ab68d3 100644 --- a/matlab/plot_shock_decomposition.m +++ b/matlab/plot_shock_decomposition.m @@ -30,7 +30,6 @@ function [z, steady_state] = plot_shock_decomposition(M_,oo_,options_,varlist) options_.nodisplay = options_.plot_shock_decomp.nodisplay; options_.graph_format = options_.plot_shock_decomp.graph_format; -options_.use_shock_groups = options_.plot_shock_decomp.use_shock_groups; % indices of endogenous variables if size(varlist,1) == 0 diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index c82b7025b..d9e3169ea 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -2553,8 +2553,8 @@ plot_shock_decomposition_options_list : plot_shock_decomposition_option COMMA pl | plot_shock_decomposition_option ; -plot_shock_decomposition_option : o_psd_use_shock_groups - | o_psd_colormap +plot_shock_decomposition_option : o_use_shock_groups + | o_colormap | o_psd_nodisplay | o_psd_graph_format | o_psd_detail_plot @@ -3375,14 +3375,10 @@ o_lmmcp : LMMCP {driver.option_num("lmmcp.status", "1"); }; o_occbin : OCCBIN {driver.option_num("occbin", "1"); }; o_function : FUNCTION EQUAL filename { driver.option_str("function", $3); }; o_sampling_draws : SAMPLING_DRAWS EQUAL INT_NUMBER { driver.option_num("sampling_draws",$3); }; -o_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("use_shock_groups","default"); } - | USE_SHOCK_GROUPS EQUAL symbol { driver.option_str("use_shock_groups", $3); } +o_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("plot_shock_decomp.use_shock_groups","default"); } + | USE_SHOCK_GROUPS EQUAL symbol { driver.option_str("plot_shock_decomp.use_shock_groups", $3); } ; -o_psd_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("plot_shock_decomp.use_shock_groups","default"); } - | USE_SHOCK_GROUPS EQUAL symbol { driver.option_str("plot_shock_decomp.use_shock_groups", $3); } - ; o_colormap : COLORMAP EQUAL symbol { driver.option_num("plot_shock_decomp.colormap",$3); }; -o_psd_colormap : COLORMAP EQUAL symbol { driver.option_num("plot_shock_decomp.colormap",$3); }; range : symbol ':' symbol { From 9f00081310b617de0dde24b44ea3ef7d0db54265 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 17 Jul 2017 08:30:30 +0200 Subject: [PATCH 05/17] Fix typos in manual Thanks to Jean-Paul K. Tsasa --- doc/dynare.texi | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 7350af741..50b4a98fa 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -1213,9 +1213,10 @@ or @var{Sigma_e} to name your variable. Not conforming to this rule might yield error messages or crashes. Second, to minimize interference with MATLAB or Octave functions that may be called by Dynare or user-defined steady state files, it is recommended to avoid using the name of MATLAB functions. In particular when working with steady state files, do not use correctly-spelled greek -names like @var{alpha}, because there are Matlab functions of the same name. Rather go for @var{alppha} or so. +names like @var{alpha}, because there are Matlab functions of the same name. Rather go for @var{alppha} or @var{alph}. Lastly, please do not name a variable or parameter @var{i}. This may interfere with the imaginary -number @var{i} and the index in many loops. Rather, name investment @var{invest}. +number @var{i} and the index in many loops. Rather, name investment @var{invest}. Using @var{inv} is also not recommended +as it alread denotes the inverse operator. Declarations of variables and parameters are made with the following commands: @@ -1932,7 +1933,7 @@ different purposes by allowing the user to attach arbitrary informations to each equation and to recover them at runtime. For instance, it is possible to name the equations with a @code{name}-tag, using a syntax like: @example -mode; +model; ... [name = 'Budget constraint'] c + k = k^theta*A; @@ -1944,7 +1945,7 @@ of the model is tagged with a name, the @code{resid} command will display the name of the equations (which may be more informative than the equation numbers) in addition to the equation number. Several tags for one equation can be separated using a comma. @example -mode; +model; ... [name='Taylor rule',mcp = 'r > -1.94478'] r = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e; @@ -2310,7 +2311,7 @@ static equilibria, but not necessarily. One typical application is to consider an economy at the equilibrium at time 0, trigger a shock in first period, and study the trajectory of return to the initial equilibrium. To do that, one needs @code{initval} and -@code{shocks} (@pxref{Shocks on exogenous variables}. +@code{shocks} (@pxref{Shocks on exogenous variables}). Another one is to study, how an economy, starting from arbitrary initial conditions at time 0 converges toward equilibrium. @@ -3181,7 +3182,7 @@ option, @pxref{Model declaration}) Trust-region algorithm on the entire model. @item 10 -Levenberg-Marquardt mixed compleproblem (LMMCP) solver +Levenberg-Marquardt mixed complementarity problem (LMMCP) solver (@cite{Kanzow and Petra 2004}) @item 11 @@ -3628,7 +3629,7 @@ to the equation appears currently on the left hand side and where no backward looking endogenous variables appear. The block has the form: @math{y_{j,t} = f_j(y_t, y_{t+1}, \ldots, y_{t+k})}. -@item SOLVE FORWARD @var{x} +@item SOLVE BACKWARD @var{x} The block contains only equations where endogenous variable attributed to the equation does not appear currently on the left hand side and where no forward looking endogenous variables appear. The block has @@ -4334,7 +4335,7 @@ If option @code{periods} is present, sets @code{oo_.skewness}, MATLAB/Octave vectors of the global workspace with the same name as the endogenous variables. -If options @code{irf} is different from zero, sets @code{oo_.irfs} +If option @code{irf} is different from zero, sets @code{oo_.irfs} (see below) and also saves the IRFs in MATLAB/Octave vectors of the global workspace (this latter way of accessing the IRFs is deprecated and will disappear in a future version). @@ -4760,7 +4761,7 @@ non-decreasing tuples are stored, @i{i.e.} those for which @math{i_1 \leq i_2 \leq i_3}. The columns are arranged in the lexicographical order of non-decreasing tuples. Also note that for tuples that have three distinct indices (@i{i.e.} @math{i_1 \neq i_2} and @math{i_1 -\neq i_3} and @math{i_2 \neq i_3}, since these elements are stored +\neq i_3} and @math{i_2 \neq i_3}), since these elements are stored only once but appears six times in the unfolded @math{G_3} matrix, they must be multiplied by 6 when computing the decision rules. Similarly, for those tuples that have two equal indices @@ -4922,7 +4923,7 @@ likelihood estimation. In a Bayesian estimation context, sets a lower bound only effective while maximizing the posterior kernel. This lower bound does not modify the shape of the prior density, and is only aimed at helping the optimizer in identifying the posterior mode (no consequences for the MCMC). For -some prior densities (namely inverse gamma, gamma, uniform, beta or weibull) it is +some prior densities (namely inverse gamma, gamma, uniform, beta or Weibull) it is possible to shift the support of the prior distributions to the left or the right using @ref{prior_3rd_parameter}. In this case the prior density is effectively modified (note that the truncated Gaussian density is not implemented in @@ -4950,7 +4951,7 @@ that @code{inv_gamma_pdf} is equivalent to @item @var{PRIOR_3RD_PARAMETER} @anchor{prior_3rd_parameter} A third parameter of the prior used for generalized beta distribution, -generalized gamma, generalized weibull and for the uniform distribution. Default: @code{0} +generalized gamma, generalized Weibull and for the uniform distribution. Default: @code{0} @item @var{PRIOR_4TH_PARAMETER} @anchor{prior_4th_parameter} @@ -5851,7 +5852,7 @@ distribution of IRFs. The length of the IRFs are controlled by the weight of the DSGE prior of the VAR model is calibrated to the value passed (see @cite{Del Negro and Schorfheide (2004)}). It represents ratio of dummy over actual observations. To assure that the prior is proper, the value must be bigger than @math{(k+n)/T}, -where @math{k} is the number of estimated parameters, @math{n} is the number of observables, # +where @math{k} is the number of estimated parameters, @math{n} is the number of observables, and @math{T} is the number of observations. NB: The previous method of declaring @code{dsge_prior_weight} as a parameter and then calibrating it is now deprecated and will be removed in a future release @@ -6763,8 +6764,8 @@ observation for which the forecast has been made. @defvr {MATLAB/Octave variable} oo_.Smoother.State_uncertainty @anchor{oo_.Smoother.State_uncertainty} Three-dimensional array set by the @code{estimation} command (if used with the -@code{smoother}) without Metropolis, -or by the @code{calib_smoother} command, if the @code{o_smoothed_state_uncertainty} option +@code{smoother} option) without Metropolis, +or by the @code{calib_smoother} command, if the @code{smoothed_state_uncertainty} option has been requested. Contains the series of covariance matrices for the state estimate given the full data from the Kalman smoother. The @code{M_.endo_nbr} times @code{M_.endo_nbr} times @@ -7705,7 +7706,7 @@ uncertainty, but ignoring the effect of measurement error on observed variables @item HPDsup -Lower bound of a 90% HPD interval due to parameter uncertainty, but +Upper bound of a 90% HPD forecast interval due to parameter uncertainty, but ignoring the effect of measurement error on observed variables @@ -7715,7 +7716,7 @@ to change the size of the HPD interval} of forecast for observed variables due to parameter uncertainty and measurement error @item HPDsup_ME -Lower bound of a 90% HPD interval of forecast for observed variables +Upper bound of a 90% HPD interval of forecast for observed variables due to parameter uncertainty and measurement error @item Mean @@ -9205,7 +9206,7 @@ named as: @code{_vs_}: for entries of the matrix of the shocks. @end itemize -The following files are stored in each directory (we stick with prior sample but similar convetins are used for MC samples): +The following files are stored in each directory (we stick with prior sample but similar conventions are used for MC samples): @itemize @item @code{_prior__vs_.fig}: histogram and CDF plot of the MC sample of the individual entry @@ -9481,7 +9482,7 @@ In case of estimating a MS-DSGE model,@footnote{An example can be found at @uref @table @code @item parameters = @var{[LIST OF PARAMETERS]} -This option specifies which parameters are controlled by this Markov Chai +This option specifies which parameters are controlled by this Markov Chain. @item number_of_lags = @var{DOUBLE} Provides the number of lags that each parameter can take within each regime in this chain. @@ -10728,8 +10729,8 @@ This file computes the steady state. It begins with: @@#include "modeqs.mod" @end example Then it initializes parameters (including @code{lab_rat}, excluding -@math{\alpha}, computes the steady state (using guess values for -endogenous, including @math{\alpha}, then saves values of parameters +@math{\alpha}), computes the steady state (using guess values for +endogenous, including @math{\alpha}), then saves values of parameters and endogenous at steady state in a file, using the @code{save_params_and_steady_state} command. @@ -10786,7 +10787,7 @@ array (@code{rhos}). The advantage of this method is that it uses a shorter syntax, since list of values directly given in the loop construct. Note that values are given as character strings (the macro-processor does not know -floating point values. The inconvenient is that you can not reuse an +floating point values). The inconvenience is that you can not reuse an array stored in a MATLAB/Octave variable. @end table @@ -11731,7 +11732,7 @@ ans = @deftypefn{dates} {@var{C} =} gt (@var{A}, @var{B}) -Overloads the Matlab/Octave @code{gt} (greater than, @code{>=}) operator. @dates objects @var{A} and @var{B} must have the same number of elements (say, @code{n}). The returned argument is a @code{n} by @code{1} vector of zeros and ones. The i-th element of @var{C} is equal to @code{1} if and only if the date @code{A(i)} is posterior to the date @code{B(i)}. +Overloads the Matlab/Octave @code{gt} (greater than, @code{>}) operator. @dates objects @var{A} and @var{B} must have the same number of elements (say, @code{n}). The returned argument is a @code{n} by @code{1} vector of zeros and ones. The i-th element of @var{C} is equal to @code{1} if and only if the date @code{A(i)} is posterior to the date @code{B(i)}. @examplehead @example @@ -11880,7 +11881,7 @@ ans = @deftypefn{dates} {@var{C} =} lt (@var{A}, @var{B}) -Overloads the Matlab/Octave @code{lt} (less than, @code{<=}) operator. @dates objects @var{A} and @var{B} must have the same number of elements (say, @code{n}). The returned argument is a @code{n} by @code{1} vector of zeros and ones. The i-th element of @var{C} is equal to @code{1} if and only if the date @code{A(i)} preceeds the date @code{B(i)}. +Overloads the Matlab/Octave @code{lt} (less than, @code{<}) operator. @dates objects @var{A} and @var{B} must have the same number of elements (say, @code{n}). The returned argument is a @code{n} by @code{1} vector of zeros and ones. The i-th element of @var{C} is equal to @code{1} if and only if the date @code{A(i)} preceeds the date @code{B(i)}. @examplehead @example @@ -13754,7 +13755,7 @@ command. Default: @code{`!'} @end defmethod @anchor{addGraph} -@defmethod Report addGraph axisShape, data, graphDirName, graphName, graphSize, height, showGrid, showLegend, legendAt, showLegendBox, legendLocation, legendOrientation, legendFontSize, miscTikzAxisOptions, miscTikzPictureOptions, seriesToUse, shade, shadeColor, shadeOpacity, tickFontSize, title, titleFontSize, titleFormat, width, writeCSV, xlabel, ylabel, xAxisTight, xrange, xTicks, xTickLabels, xTickLabelAnchor, xTickLabelRotation, yAxisTight, yTickLabelFixed, yTickLabelPrecision, yTickLabelScaled, yTickLabelZeroFill, yrange, showZeroline, zeroLineColor +@defmethod Report addGraph axisShape, data, graphDirName, graphName, graphSize, height, showGrid, showLegend, legendAt, showLegendBox, legendLocation, legendOrientation, legendFontSize, miscTikzAxisOptions, miscTikzPictureOptions, seriesToUse, shade, shadeColor, shadeOpacity, tickFontSize, title, titleFontSize, titleFormat, width, writeCSV, xlabel, ylabel, xAxisTight, xrange, xTicks, xTickLabels, xTickLabelAnchor, xTickLabelRotation, yAxisTight, yTickLabelFixed, yTickLabelPrecision, yTickLabelScaled, yTickLabelZeroFill, yrange, showZeroLine, zeroLineColor Adds a @code{Graph} to a @code{Section}. @optionshead @table @code From 7486760461a841c6c244cf59599d3dceac040b55 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 17 Jul 2017 08:42:50 +0200 Subject: [PATCH 06/17] Make osr error message more informative --- matlab/osr1.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/osr1.m b/matlab/osr1.m index b73db2b24..2f9c65ec9 100644 --- a/matlab/osr1.m +++ b/matlab/osr1.m @@ -126,7 +126,7 @@ elseif isequal(options_.osr.opt_algo,11) else if ~isempty(M_.osr.param_bounds) && ~(ismember(options_.osr.opt_algo,[1,2,5,9]) || ischar(options_.osr.opt_algo)) - error('OSR: OSR with bounds on parameters requires a constrained optimizer, i.e. 1,2,5, or 9.') + error('OSR: OSR with bounds on parameters requires a constrained optimizer, i.e. opt_algo= 1,2,5, or 9.') end %%do actual optimization [p, f, exitflag] = dynare_minimize_objective(str2func('osr_obj'),t0,options_.osr.opt_algo,options_,M_.osr.param_bounds,cellstr(M_.param_names(i_params,:)),[],[], i_params,... From 8e899aa6bca62b3b315262f574f7372aaf219134 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 17 Jul 2017 19:33:51 +0200 Subject: [PATCH 07/17] Fix another typo in manual --- doc/dynare.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 50b4a98fa..42788d1d9 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -8316,7 +8316,7 @@ Note that the use of this block requires the use of a constrained optimizer, @i{ @example -osr_param_bounds; +osr_params_bounds; gamma_inf_, 0, 2.5; end; From 0b9244dc01ef3052f23f3225194789ad0fdb574d Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 5 Jul 2017 18:03:14 +0200 Subject: [PATCH 08/17] Posterior moments: fix bug that prevented updating decision rules for parameter vector, leading to wrong results/crashes when computing second moments When removing globals in 24cd4236710b452f5131b20d844a5bba991c0d3b the call to set_parameters.m, which relies on M_ being global, was not removed. The problem arises 1. When computing second moments for big models with drsize*SampleSize>MaxMegaBytes (in which case decision rules dr were not saved, but recomputed) 2. When computing the conditional variance decomposition for all models regardless of size (dsge_simulated_theoretical_conditional_variance_decomposition.m relied on the wrong M_.Sigma_e in this case) --- ...tical_conditional_variance_decomposition.m | 4 +- .../dsge_simulated_theoretical_correlation.m | 2 +- .../dsge_simulated_theoretical_covariance.m | 2 +- ...lated_theoretical_variance_decomposition.m | 2 +- matlab/set_parameters_locally.m | 85 +++++++++++++++++++ 5 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 matlab/set_parameters_locally.m diff --git a/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m b/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m index 1c0441361..4a2604d5b 100644 --- a/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m +++ b/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m @@ -109,10 +109,10 @@ for file = 1:NumberOfDrawsFiles for linee = 1:NumberOfDraws linea = linea+1; if isdrsaved - set_parameters(pdraws{linee,1});% Needed to update the covariance matrix of the state innovations. + M_=set_parameters_locally(M_,pdraws{linee,1});% Needed to update the covariance matrix of the state innovations. dr = pdraws{linee,2}; else - set_parameters(pdraws{linee,1}); + M_=set_parameters_locally(M_,pdraws{linee,1}); [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); end if first_call diff --git a/matlab/dsge_simulated_theoretical_correlation.m b/matlab/dsge_simulated_theoretical_correlation.m index ae141905b..dca103166 100644 --- a/matlab/dsge_simulated_theoretical_correlation.m +++ b/matlab/dsge_simulated_theoretical_correlation.m @@ -106,7 +106,7 @@ for file = 1:NumberOfDrawsFiles if isdrsaved dr = pdraws{linee,2}; else - set_parameters(pdraws{linee,1}); + M_=set_parameters_locally(M_,pdraws{linee,1}); [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); end tmp = th_autocovariances(dr,ivar,M_,options_,nodecomposition); diff --git a/matlab/dsge_simulated_theoretical_covariance.m b/matlab/dsge_simulated_theoretical_covariance.m index 304028ba5..19f56297f 100644 --- a/matlab/dsge_simulated_theoretical_covariance.m +++ b/matlab/dsge_simulated_theoretical_covariance.m @@ -105,7 +105,7 @@ for file = 1:NumberOfDrawsFiles if isdrsaved dr = pdraws{linee,2}; else - set_parameters(pdraws{linee,1}); + M_=set_parameters_locally(M_,pdraws{linee,1}); [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); end tmp = th_autocovariances(dr,ivar,M_,options_,nodecomposition); diff --git a/matlab/dsge_simulated_theoretical_variance_decomposition.m b/matlab/dsge_simulated_theoretical_variance_decomposition.m index 9eb985174..3441b152e 100644 --- a/matlab/dsge_simulated_theoretical_variance_decomposition.m +++ b/matlab/dsge_simulated_theoretical_variance_decomposition.m @@ -113,7 +113,7 @@ for file = 1:NumberOfDrawsFiles if isdrsaved dr = pdraws{linee,2}; else - set_parameters(pdraws{linee,1}); + M_=set_parameters_locally(M_,pdraws{linee,1}); [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); end if file==1 && linee==1 diff --git a/matlab/set_parameters_locally.m b/matlab/set_parameters_locally.m new file mode 100644 index 000000000..173e50257 --- /dev/null +++ b/matlab/set_parameters_locally.m @@ -0,0 +1,85 @@ +function M_=set_parameters_locally(M_,xparam1) + +% function M_out=set_parameters(M_,xparam1) +% Sets parameters value (except measurement errors) +% This is called for computations such as IRF and forecast +% when measurement errors aren't taken into account; in contrast to +% set_parameters.m, the global M_-structure is not altered +% +% INPUTS +% xparam1: vector of parameters to be estimated (initial values) +% M_: Dynare model-structure +% +% OUTPUTS +% M_: Dynare model-structure +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 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 . + +global estim_params_ + +nvx = estim_params_.nvx; +ncx = estim_params_.ncx; +nvn = estim_params_.nvn; +ncn = estim_params_.ncn; +np = estim_params_.np; +Sigma_e = M_.Sigma_e; +Correlation_matrix = M_.Correlation_matrix; +offset = 0; + +% setting shocks variance on the diagonal of Covariance matrix; used later +% for updating covariances +if nvx + var_exo = estim_params_.var_exo; + for i=1:nvx + k = var_exo(i,1); + Sigma_e(k,k) = xparam1(i)^2; + end +end +% and update offset +offset = offset + nvx + nvn; + +% correlations amonx shocks (ncx) +if ncx + corrx = estim_params_.corrx; + for i=1:ncx + k1 = corrx(i,1); + k2 = corrx(i,2); + Correlation_matrix(k1,k2) = xparam1(i+offset); + Correlation_matrix(k2,k1) = Correlation_matrix(k1,k2); + end +end +%build covariance matrix from correlation matrix and variances already on +%diagonal +Sigma_e = diag(sqrt(diag(Sigma_e)))*Correlation_matrix*diag(sqrt(diag(Sigma_e))); +if isfield(estim_params_,'calibrated_covariances') + Sigma_e(estim_params_.calibrated_covariances.position)=estim_params_.calibrated_covariances.cov_value; +end + +% and update offset +offset = offset + ncx + ncn; + +% structural parameters +if np + M_.params(estim_params_.param_vals(:,1)) = xparam1(offset+1:end); +end + +M_.Sigma_e = Sigma_e; +M_.Correlation_matrix=Correlation_matrix; \ No newline at end of file From cc9e0ed09af1422ca60178a69d6395bf09894f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 21 Jul 2017 12:13:44 +0200 Subject: [PATCH 09/17] Code factorization. --- matlab/set_parameters.m | 51 ++--------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/matlab/set_parameters.m b/matlab/set_parameters.m index 15f4175ed..99be93213 100644 --- a/matlab/set_parameters.m +++ b/matlab/set_parameters.m @@ -31,53 +31,6 @@ function set_parameters(xparam1) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -global estim_params_ M_ +global M_ -nvx = estim_params_.nvx; -ncx = estim_params_.ncx; -nvn = estim_params_.nvn; -ncn = estim_params_.ncn; -np = estim_params_.np; -Sigma_e = M_.Sigma_e; -Correlation_matrix = M_.Correlation_matrix; -offset = 0; - -% setting shocks variance on the diagonal of Covariance matrix; used later -% for updating covariances -if nvx - var_exo = estim_params_.var_exo; - for i=1:nvx - k = var_exo(i,1); - Sigma_e(k,k) = xparam1(i)^2; - end -end -% and update offset -offset = offset + nvx + nvn; - -% correlations amonx shocks (ncx) -if ncx - corrx = estim_params_.corrx; - for i=1:ncx - k1 = corrx(i,1); - k2 = corrx(i,2); - Correlation_matrix(k1,k2) = xparam1(i+offset); - Correlation_matrix(k2,k1) = Correlation_matrix(k1,k2); - end -end -%build covariance matrix from correlation matrix and variances already on -%diagonal -Sigma_e = diag(sqrt(diag(Sigma_e)))*Correlation_matrix*diag(sqrt(diag(Sigma_e))); -if isfield(estim_params_,'calibrated_covariances') - Sigma_e(estim_params_.calibrated_covariances.position)=estim_params_.calibrated_covariances.cov_value; -end - -% and update offset -offset = offset + ncx + ncn; - -% structural parameters -if np - M_.params(estim_params_.param_vals(:,1)) = xparam1(offset+1:end); -end - -M_.Sigma_e = Sigma_e; -M_.Correlation_matrix=Correlation_matrix; +M_ = set_parameters_locally(M_, xparam1); \ No newline at end of file From 1f20ceb46168074e7400b206774282dd27a2f1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Sun, 23 Jul 2017 23:21:36 +0200 Subject: [PATCH 10/17] Fixed bug in filtered variables with trend. Was crashing in models with only one observed variable. The squeeze function cannot be used in this case, only the first dimension of stock_filter_step_ahead should be squeezed. --- matlab/prior_posterior_statistics_core.m | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/matlab/prior_posterior_statistics_core.m b/matlab/prior_posterior_statistics_core.m index 03cc43a3e..8e39e5ae2 100644 --- a/matlab/prior_posterior_statistics_core.m +++ b/matlab/prior_posterior_statistics_core.m @@ -260,23 +260,23 @@ for b=fpar:B else constant_part=repmat(SteadyState(dr.order_var)',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]); end - - stock_filter_step_ahead(:,dr.order_var,:,irun(4)) = aK(options_.filter_step_ahead,1:endo_nbr,:) + ... - constant_part; - + stock_filter_step_ahead(:,dr.order_var,:,irun(4)) = aK(options_.filter_step_ahead,1:endo_nbr,:) + constant_part; %now add trend to observables for ii=1:length(options_.filter_step_ahead) if options_.prefilter - stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeeze(stock_filter_step_ahead(ii,IdObs,:,irun(4)))... - +repmat(mean_correction(:,1),1,gend+max(options_.filter_step_ahead))... %constant correction + zdim = size(stock_filter_step_ahead(ii,IdObs,:,irun(4))); + squeezed = reshape(stock_filter_step_ahead(ii,IdObs,:,irun(4)), [zdim(2:end) 1]); + stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeezed ... + +repmat(mean_correction(:,1),1,gend+max(options_.filter_step_ahead)) ... %constant correction +[trend_addition repmat(trend_addition(:,end),1,max(options_.filter_step_ahead))+trend_coeff*[1:max(options_.filter_step_ahead)]]; %trend else - stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeeze(stock_filter_step_ahead(ii,IdObs,:,irun(4)))... + zdim = size(stock_filter_step_ahead(ii,IdObs,:,irun(4))); + squeezed = reshape(stock_filter_step_ahead(ii,IdObs,:,irun(4)), [zdim(2:end) 1]); + stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeezed ... +[trend_addition repmat(trend_addition(:,end),1,max(options_.filter_step_ahead))+trend_coeff*[1:max(options_.filter_step_ahead)]]; %trend end end end - if horizon yyyy = alphahat(iendo,i_last_obs); yf = forcst2a(yyyy,dr,zeros(horizon,exo_nbr)); From 45864f414f98269dff288ddb2cbc49f52dab282f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Sun, 23 Jul 2017 23:34:49 +0200 Subject: [PATCH 11/17] Added integration test. Trend + posterior filtered variables in a model with only one observed variable. --- tests/Makefile.am | 2 + .../trend_cycle_decomposition.mod | 38 ++++ .../trend_cycle_decomposition_data.m | 164 ++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 tests/filter_step_ahead/trend_cycle_decomposition.mod create mode 100644 tests/filter_step_ahead/trend_cycle_decomposition_data.m diff --git a/tests/Makefile.am b/tests/Makefile.am index 8fd228521..89f031db8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -301,6 +301,7 @@ MODFILES = \ gradient/fs2000_numgrad_5.mod \ filter_step_ahead/fs2000_filter_step_ahead_bayesian.mod \ filter_step_ahead/fs2000_filter_step_ahead_ML.mod \ + filter_step_ahead/trend_cycle_decomposition.mod \ loglinear/example4_exp.mod \ loglinear/example4_loglinear.mod \ loglinear/example4_loglinear_lagged_exogenous.mod \ @@ -760,6 +761,7 @@ EXTRA_DIST = \ external_function/extFunNoDerivs.m \ external_function/extFunWithFirstAndSecondDerivs.m \ expectations/expectation_ss_old_steadystate.m \ + filter_step_ahead/trend_cycle_decomposition_data.m \ steady_state/walsh1_old_ss_steadystate.m \ data/test.xlsx \ gsa/morris/nk_est_data.m \ diff --git a/tests/filter_step_ahead/trend_cycle_decomposition.mod b/tests/filter_step_ahead/trend_cycle_decomposition.mod new file mode 100644 index 000000000..4bdde9a94 --- /dev/null +++ b/tests/filter_step_ahead/trend_cycle_decomposition.mod @@ -0,0 +1,38 @@ +var y yp z mu; + +varexo ez eyp emu; + +parameters alpha; + +alpha = .889; + +model(linear); + y = yp + z; + yp = mu + yp(-1) + eyp; + mu = mu(-1) + emu; + z = alpha*z(-1) + ez; +end; + +initval; +y=8.655680; +z=0; +yp=8.655680; +mu=0; +end; + +steady(nocheck); +//resid(1); + +//options_.steadystate.nocheck; + +estimated_params; +stderr emu , inv_gamma_pdf, 0.002 , inf; +stderr eyp , inv_gamma_pdf, 0.002 , inf; +stderr ez , inv_gamma_pdf, 0.06 , inf; +alpha, normal_pdf, 0.9, 0.1; +end; + +varobs y; + + +estimation(datafile=data_i,nobs=82, mh_replic=2000, mode_compute=4, mh_nblocks=2, mh_jscale=0.3, filtered_vars, smoother, diffuse_filter) yp z; diff --git a/tests/filter_step_ahead/trend_cycle_decomposition_data.m b/tests/filter_step_ahead/trend_cycle_decomposition_data.m new file mode 100644 index 000000000..8f6d42235 --- /dev/null +++ b/tests/filter_step_ahead/trend_cycle_decomposition_data.m @@ -0,0 +1,164 @@ +y=[8.655680 +8.656123 +8.654401 +8.641229 +8.630567 +8.620637 +8.605288 +8.608660 +8.620357 +8.619683 +8.630202 +8.636380 +8.614226 +8.605106 +8.537263 +8.555079 +8.591242 +8.626651 +8.645062 +8.671851 +8.704031 +8.723127 +8.737705 +8.750433 +8.758621 +8.772876 +8.790050 +8.794088 +8.798091 +8.816624 +8.836301 +8.852974 +8.872307 +8.887314 +8.902466 +8.924601 +8.944691 +8.960662 +8.973784 +8.984161 +9.000123 +9.019129 +9.035000 +9.054575 +9.075913 +9.094302 +9.114171 +9.135554 +9.157538 +9.176307 +9.193220 +9.220434 +9.246620 +9.257001 +9.243476 +9.202275 +9.160007 +9.147657 +9.157229 +9.171294 +9.189745 +9.198273 +9.201042 +9.214450 +9.225220 +9.233702 +9.247974 +9.262110 +9.272097 +9.275883 +9.277719 +9.278357 +9.282812 +9.289376 +9.290788 +9.292530 +9.295274 +9.297219 +9.297555 +9.290289 +9.271941 +9.255655]; +ipc=[23.5993149 +24.9374227 +15.5668177 +12.822998 +8.720567 +5.2893706 +3.4198277 +3.274742 +3.664711 +3.0744047 +2.0693272 +1.704983 +1.3786582 +1.3437517 +2.6167173 +4.7126735 +6.3341827 +7.3020707 +6.5659735 +4.3717219 +3.4512364 +4.7505574 +5.6671666 +5.6241466 +5.5933745 +4.7565382 +3.7032831 +3.6624086 +3.8250059 +3.2723449 +3.3568247 +3.7965188 +3.5401286 +2.7513284 +2.5482882 +2.2870368 +2.0836978 +2.6555146 +3.3263235 +3.3905589 +3.2762151 +2.8684465 +2.1706005 +2.3531933 +2.5136208 +2.3339758 +2.0782414 +1.8397957 +1.7220838 +2.3651145 +3.4129652 +3.8212567 +3.9356373 +3.6723844 +3.11287 +2.9099557 +3.1280929 +2.5837809 +1.5138311 +1.191679 +1.286452 +1.8904928 +2.4851907 +2.7408867 +2.2572768 +1.3839678 +0.813925 +0.88364 +1.2723562 +2.0426676 +2.4161978 +1.5967846 +0.9763814 +1.6120089 +2.0962214 +1.6427865 +1.5391928 +2.0537506 +3.1496297 +4.34142 +4.3532191 +2.2026746]; From 356c73039b83e48340d25f9c68064453530e2345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Mon, 24 Jul 2017 09:44:02 +0200 Subject: [PATCH 12/17] Fixed date release of 4.5.0 in NEWS file. --- NEWS | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 71e9b45d4..9dc3638b1 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -Announcement for Dynare 4.5.0 (on 2013-12-16) +Announcement for Dynare 4.5.0 (on 2017-06-11) ============================================= We are pleased to announce the release of Dynare 4.5.0. @@ -19,11 +19,6 @@ This release is compatible with MATLAB versions ranging from 7.3 (R2006b) to Here is the list of major user-visible changes: - -Dynare 4.5 -========== - - - Ramsey policy + Added command `ramsey_model` that builds the expanded model with From d78be7fdf0b34d03f326897e6198b96cccb3564b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Mon, 24 Jul 2017 09:56:58 +0200 Subject: [PATCH 13/17] Updated NEWS file for 4.5.1 bug fix release. --- NEWS | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/NEWS b/NEWS index 9dc3638b1..e38acc20b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,47 @@ +Announcement for Dynare 4.5.1 (on 2017-08-24) +============================================= + +We are pleased to announce the release of Dynare 4.5.1. + +This is a bugfix release. + +The Windows packages are already available for download at: + + http://www.dynare.org/download/dynare-stable + +The Mac and GNU/Linux packages (for Debian and Ubuntu LTS) should follow soon. + +This release is compatible with MATLAB versions 7.3 (R2006b) to 9.2 (R2017a) +and with GNU Octave versions 4.2. + +Here is a list of the problems identified in version 4.5.0 and that have been +fixed in version 4.5.1: + + + - Fixed out of memory issue with simpsa optimization algorithm. + + - Added missing plots for measurement errors with `generate_trace_plot` + command. + + - Posterior moments after MCMC for very big models were not correctly computed + and their plotting might crash Dynare. + + - Results of the posterior conditional variance decomposition after MCMC were + not correctly computed. + + - Options `use_shock_groups` and `colormap` of the `shock_decomposition` + command were not working. + + - Added a clean error message if sensitivity toolbox is used with recursive + estimation. + + - Computation of posterior filtered variables was crashing in models with only + one variable. + + - Fixed various typos and errors in the reference manual. + + + Announcement for Dynare 4.5.0 (on 2017-06-11) ============================================= From 9203f9e52f02aaa6d49c5c6faf1ce34c31cd1f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Mon, 24 Jul 2017 10:53:14 +0200 Subject: [PATCH 14/17] Fixed encondig in the integration test added in 45864f414f98269dff2. --- .../trend_cycle_decomposition.mod | 73 ++-- .../trend_cycle_decomposition_data.m | 328 +++++++++--------- 2 files changed, 199 insertions(+), 202 deletions(-) diff --git a/tests/filter_step_ahead/trend_cycle_decomposition.mod b/tests/filter_step_ahead/trend_cycle_decomposition.mod index 4bdde9a94..4308590f5 100644 --- a/tests/filter_step_ahead/trend_cycle_decomposition.mod +++ b/tests/filter_step_ahead/trend_cycle_decomposition.mod @@ -1,38 +1,35 @@ -var y yp z mu; - -varexo ez eyp emu; - -parameters alpha; - -alpha = .889; - -model(linear); - y = yp + z; - yp = mu + yp(-1) + eyp; - mu = mu(-1) + emu; - z = alpha*z(-1) + ez; -end; - -initval; -y=8.655680; -z=0; -yp=8.655680; -mu=0; -end; - -steady(nocheck); -//resid(1); - -//options_.steadystate.nocheck; - -estimated_params; -stderr emu , inv_gamma_pdf, 0.002 , inf; -stderr eyp , inv_gamma_pdf, 0.002 , inf; -stderr ez , inv_gamma_pdf, 0.06 , inf; -alpha, normal_pdf, 0.9, 0.1; -end; - -varobs y; - - -estimation(datafile=data_i,nobs=82, mh_replic=2000, mode_compute=4, mh_nblocks=2, mh_jscale=0.3, filtered_vars, smoother, diffuse_filter) yp z; +var y yp z mu; + +varexo ez eyp emu; + +parameters alpha; + +alpha = .889; + +model(linear); + y = yp + z; + yp = mu + yp(-1) + eyp; + mu = mu(-1) + emu; + z = alpha*z(-1) + ez; +end; + +initval; +y=8.655680; +z=0; +yp=8.655680; +mu=0; +end; + +steady(nocheck); + +estimated_params; +stderr emu , inv_gamma_pdf, 0.002 , inf; +stderr eyp , inv_gamma_pdf, 0.002 , inf; +stderr ez , inv_gamma_pdf, 0.06 , inf; +alpha, normal_pdf, 0.9, 0.1; +end; + +varobs y; + + +estimation(datafile=data_i,nobs=82, mh_replic=2000, mode_compute=4, mh_nblocks=2, mh_jscale=0.3, filtered_vars, smoother, diffuse_filter) yp z; diff --git a/tests/filter_step_ahead/trend_cycle_decomposition_data.m b/tests/filter_step_ahead/trend_cycle_decomposition_data.m index 8f6d42235..206d2ae95 100644 --- a/tests/filter_step_ahead/trend_cycle_decomposition_data.m +++ b/tests/filter_step_ahead/trend_cycle_decomposition_data.m @@ -1,164 +1,164 @@ -y=[8.655680 -8.656123 -8.654401 -8.641229 -8.630567 -8.620637 -8.605288 -8.608660 -8.620357 -8.619683 -8.630202 -8.636380 -8.614226 -8.605106 -8.537263 -8.555079 -8.591242 -8.626651 -8.645062 -8.671851 -8.704031 -8.723127 -8.737705 -8.750433 -8.758621 -8.772876 -8.790050 -8.794088 -8.798091 -8.816624 -8.836301 -8.852974 -8.872307 -8.887314 -8.902466 -8.924601 -8.944691 -8.960662 -8.973784 -8.984161 -9.000123 -9.019129 -9.035000 -9.054575 -9.075913 -9.094302 -9.114171 -9.135554 -9.157538 -9.176307 -9.193220 -9.220434 -9.246620 -9.257001 -9.243476 -9.202275 -9.160007 -9.147657 -9.157229 -9.171294 -9.189745 -9.198273 -9.201042 -9.214450 -9.225220 -9.233702 -9.247974 -9.262110 -9.272097 -9.275883 -9.277719 -9.278357 -9.282812 -9.289376 -9.290788 -9.292530 -9.295274 -9.297219 -9.297555 -9.290289 -9.271941 -9.255655]; -ipc=[23.5993149 -24.9374227 -15.5668177 -12.822998 -8.720567 -5.2893706 -3.4198277 -3.274742 -3.664711 -3.0744047 -2.0693272 -1.704983 -1.3786582 -1.3437517 -2.6167173 -4.7126735 -6.3341827 -7.3020707 -6.5659735 -4.3717219 -3.4512364 -4.7505574 -5.6671666 -5.6241466 -5.5933745 -4.7565382 -3.7032831 -3.6624086 -3.8250059 -3.2723449 -3.3568247 -3.7965188 -3.5401286 -2.7513284 -2.5482882 -2.2870368 -2.0836978 -2.6555146 -3.3263235 -3.3905589 -3.2762151 -2.8684465 -2.1706005 -2.3531933 -2.5136208 -2.3339758 -2.0782414 -1.8397957 -1.7220838 -2.3651145 -3.4129652 -3.8212567 -3.9356373 -3.6723844 -3.11287 -2.9099557 -3.1280929 -2.5837809 -1.5138311 -1.191679 -1.286452 -1.8904928 -2.4851907 -2.7408867 -2.2572768 -1.3839678 -0.813925 -0.88364 -1.2723562 -2.0426676 -2.4161978 -1.5967846 -0.9763814 -1.6120089 -2.0962214 -1.6427865 -1.5391928 -2.0537506 -3.1496297 -4.34142 -4.3532191 -2.2026746]; +y=[8.655680 +8.656123 +8.654401 +8.641229 +8.630567 +8.620637 +8.605288 +8.608660 +8.620357 +8.619683 +8.630202 +8.636380 +8.614226 +8.605106 +8.537263 +8.555079 +8.591242 +8.626651 +8.645062 +8.671851 +8.704031 +8.723127 +8.737705 +8.750433 +8.758621 +8.772876 +8.790050 +8.794088 +8.798091 +8.816624 +8.836301 +8.852974 +8.872307 +8.887314 +8.902466 +8.924601 +8.944691 +8.960662 +8.973784 +8.984161 +9.000123 +9.019129 +9.035000 +9.054575 +9.075913 +9.094302 +9.114171 +9.135554 +9.157538 +9.176307 +9.193220 +9.220434 +9.246620 +9.257001 +9.243476 +9.202275 +9.160007 +9.147657 +9.157229 +9.171294 +9.189745 +9.198273 +9.201042 +9.214450 +9.225220 +9.233702 +9.247974 +9.262110 +9.272097 +9.275883 +9.277719 +9.278357 +9.282812 +9.289376 +9.290788 +9.292530 +9.295274 +9.297219 +9.297555 +9.290289 +9.271941 +9.255655]; +ipc=[23.5993149 +24.9374227 +15.5668177 +12.822998 +8.720567 +5.2893706 +3.4198277 +3.274742 +3.664711 +3.0744047 +2.0693272 +1.704983 +1.3786582 +1.3437517 +2.6167173 +4.7126735 +6.3341827 +7.3020707 +6.5659735 +4.3717219 +3.4512364 +4.7505574 +5.6671666 +5.6241466 +5.5933745 +4.7565382 +3.7032831 +3.6624086 +3.8250059 +3.2723449 +3.3568247 +3.7965188 +3.5401286 +2.7513284 +2.5482882 +2.2870368 +2.0836978 +2.6555146 +3.3263235 +3.3905589 +3.2762151 +2.8684465 +2.1706005 +2.3531933 +2.5136208 +2.3339758 +2.0782414 +1.8397957 +1.7220838 +2.3651145 +3.4129652 +3.8212567 +3.9356373 +3.6723844 +3.11287 +2.9099557 +3.1280929 +2.5837809 +1.5138311 +1.191679 +1.286452 +1.8904928 +2.4851907 +2.7408867 +2.2572768 +1.3839678 +0.813925 +0.88364 +1.2723562 +2.0426676 +2.4161978 +1.5967846 +0.9763814 +1.6120089 +2.0962214 +1.6427865 +1.5391928 +2.0537506 +3.1496297 +4.34142 +4.3532191 +2.2026746]; From 209e16888d2f2c6648bb15717a3086c9a554dce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Mon, 24 Jul 2017 10:55:49 +0200 Subject: [PATCH 15/17] Fixed bug in the integration test added in 45864f414f98269dff2 Wrong name for the data file. Also reduced the number of chains. --- tests/filter_step_ahead/trend_cycle_decomposition.mod | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/filter_step_ahead/trend_cycle_decomposition.mod b/tests/filter_step_ahead/trend_cycle_decomposition.mod index 4308590f5..178dd0ed5 100644 --- a/tests/filter_step_ahead/trend_cycle_decomposition.mod +++ b/tests/filter_step_ahead/trend_cycle_decomposition.mod @@ -31,5 +31,4 @@ end; varobs y; - -estimation(datafile=data_i,nobs=82, mh_replic=2000, mode_compute=4, mh_nblocks=2, mh_jscale=0.3, filtered_vars, smoother, diffuse_filter) yp z; +estimation(datafile=trend_cycle_decomposition_data,nobs=82, mh_replic=2000, mode_compute=4, mh_nblocks=1, mh_jscale=0.3, filtered_vars, smoother, diffuse_filter) yp z; From 47c2fa361039035244bf7c9e0d55e322b6bfcf05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 25 Jul 2017 16:26:21 +0200 Subject: [PATCH 16/17] Use magic comments for autoloads in Emacs mode file Also automatically trigger the mode for files with the .mod extension. --- scripts/dynare.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/dynare.el b/scripts/dynare.el index 839b89eb2..82d9713a3 100644 --- a/scripts/dynare.el +++ b/scripts/dynare.el @@ -28,8 +28,6 @@ ;; add this to your .emacs or site-init.el file: ;; ;; (require 'dynare) -;; (autoload 'dynare-mode "dynare" "Enter dynare mode." t) -;; (setq auto-mode-alist (cons '("\\.mod\\'" . dynare-mode) auto-mode-alist)) ;;; Commentary: ;; @@ -107,7 +105,8 @@ For detail, see `comment-dwim'." ("(\\(+\\|-\\)[1-9])" . font-lock-constant-face) )) -;; define the major mode +;;; define the major mode +;;;###autoload (define-derived-mode dynare-mode fundamental-mode "dynare mode" "dynare is a mode for editing mod files used by dynare." @@ -149,5 +148,9 @@ For detail, see `comment-dwim'." (setq dynare-functions-regexp nil) ) +;;; mode trigger +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.mod$" . dynare-mode)) + (provide 'dynare) ;;; dynare.el ends here From 91096d8d02e3fc46324b5eaaee5397b03c4df9d9 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 27 Jul 2017 12:33:19 -0400 Subject: [PATCH 17/17] preprocessor: store max lead/lag info, write to output --- preprocessor/DynamicModel.cc | 65 +++++++++++++++++++++++++++++++++++- preprocessor/DynamicModel.hh | 11 ++++++ preprocessor/ModFile.cc | 1 + 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index e827d58ce..c927a8736 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -44,6 +44,10 @@ DynamicModel::DynamicModel(SymbolTable &symbol_table_arg, max_endo_lag(0), max_endo_lead(0), max_exo_lag(0), max_exo_lead(0), max_exo_det_lag(0), max_exo_det_lead(0), + max_lag_orig(0), max_lead_orig(0), + max_endo_lag_orig(0), max_endo_lead_orig(0), + max_exo_lag_orig(0), max_exo_lead_orig(0), + max_exo_det_lag_orig(0), max_exo_det_lead_orig(0), dynJacobianColsNbr(0), global_temporary_terms(true) { @@ -2563,7 +2567,15 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de outstruct = "oo_."; } - output << modstruct << "lead_lag_incidence = ["; + output << modstruct << "max_endo_lag_orig = " << max_endo_lag_orig << ";" << endl + << modstruct << "max_endo_lead_orig = " << max_endo_lead_orig << ";" << endl + << modstruct << "max_exo_lag_orig = " << max_exo_lag_orig << ";" << endl + << modstruct << "max_exo_lead_orig = " << max_exo_lead_orig << ";" << endl + << modstruct << "max_exo_det_lag_orig = " << max_exo_det_lag_orig << ";" << endl + << modstruct << "max_exo_det_lead_orig = " << max_exo_det_lead_orig << ";" << endl + << modstruct << "max_lag_orig = " << max_lag_orig << ";" << endl + << modstruct << "max_lead_orig = " << max_lead_orig << ";" << endl + << modstruct << "lead_lag_incidence = ["; // Loop on endogenous variables int nstatic = 0, nfwrd = 0, @@ -3740,6 +3752,8 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const for (size_t i = 0; i < static_only_equations.size(); i++) dynamic_model.addStaticOnlyEquation(static_only_equations[i]->cloneDynamic(dynamic_model), static_only_equations_lineno[i]); + + dynamic_model.setLeadsLagsOrig(); } void @@ -3912,6 +3926,55 @@ DynamicModel::findUnusedExogenous() return unusedExo; } +void +DynamicModel::setLeadsLagsOrig() +{ + set > dynvars; + + for (int i = 0; i < (int) equations.size(); i++) + { + equations[i]->collectDynamicVariables(eEndogenous, dynvars); + equations[i]->collectDynamicVariables(eExogenous, dynvars); + equations[i]->collectDynamicVariables(eExogenousDet, dynvars); + } + + for (set >::const_iterator it = dynvars.begin(); + it != dynvars.end(); it++) + { + int lag = it->second; + SymbolType type = symbol_table.getType(it->first); + + if (max_lead_orig < lag) + max_lead_orig= lag; + else if (-max_lag_orig > lag) + max_lag_orig = -lag; + + switch (type) + { + case eEndogenous: + if (max_endo_lead_orig < lag) + max_endo_lead_orig = lag; + else if (-max_endo_lag_orig > lag) + max_endo_lag_orig = -lag; + break; + case eExogenous: + if (max_exo_lead_orig < lag) + max_exo_lead_orig = lag; + else if (-max_exo_lag_orig > lag) + max_exo_lag_orig = -lag; + break; + case eExogenousDet: + if (max_exo_det_lead_orig < lag) + max_exo_det_lead_orig = lag; + else if (-max_exo_det_lag_orig > lag) + max_exo_det_lag_orig = -lag; + break; + default: + break; + } + } +} + void DynamicModel::computeDerivIDs() { diff --git a/preprocessor/DynamicModel.hh b/preprocessor/DynamicModel.hh index 1fb14bc20..8b68744d8 100644 --- a/preprocessor/DynamicModel.hh +++ b/preprocessor/DynamicModel.hh @@ -61,6 +61,14 @@ private: //! Maximum lag and lead over deterministic exogenous variables (positive values) /*! Set by computeDerivIDs() */ int max_exo_det_lag, max_exo_det_lead; + //! Maximum lag and lead over all types of variables (positive values) of original model + int max_lag_orig, max_lead_orig; + //! Maximum lag and lead over endogenous variables (positive values) of original model + int max_endo_lag_orig, max_endo_lead_orig; + //! Maximum lag and lead over exogenous variables (positive values) of original model + int max_exo_lag_orig, max_exo_lead_orig; + //! Maximum lag and lead over deterministic exogenous variables (positive values) of original model + int max_exo_det_lag_orig, max_exo_det_lead_orig; //! Cross reference information map xrefs; @@ -277,6 +285,9 @@ public: //! Find exogenous variables not used in model set findUnusedExogenous(); + //! Set the max leads/lags of the original model + void setLeadsLagsOrig(); + //! Copies a dynamic model (only the equations) /*! It assumes that the dynamic model given in argument has just been allocated */ void cloneDynamic(DynamicModel &dynamic_model) const; diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 29fcd93f4..71f5f33a0 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -335,6 +335,7 @@ void ModFile::transformPass(bool nostrict, bool compute_xrefs) { // Save the original model (must be done before any model transformations by preprocessor) + dynamic_model.setLeadsLagsOrig(); dynamic_model.cloneDynamic(original_model); if (nostrict)