adding comment explaining initialization of persistent variable
penalty in dsge_likelihood.m and dsge_likelihood_hh.m Removed misleading initialization code. Added call to dsge_likelihood_hh in initial_estimation_checks to initialize persistent variable in that function as well.time-shift
parent
de8962b239
commit
111347469f
|
@ -127,17 +127,21 @@ function [fval,exit_flag,ys,trend_coeff,info,Model,DynareOptions,BayesInfo,Dynar
|
||||||
% AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT FR
|
% AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT FR
|
||||||
|
|
||||||
% Declaration of the penalty as a persistent variable.
|
% Declaration of the penalty as a persistent variable.
|
||||||
persistent penalty
|
|
||||||
|
|
||||||
% Initialization of the persistent variable.
|
% Persistent variable 'penalty' is used to compute an endogenous penalty to
|
||||||
if ~nargin || isempty(penalty)
|
% the value 'fval' when various conditions are encountered. These conditions
|
||||||
penalty = 1e8;
|
% set also 'exit_flag' equal to 0 instead of 1. It is only when
|
||||||
if ~nargin, return, end
|
% dsge_likelihood() is called by an optimizer called by
|
||||||
end
|
% dynare_estimation_1() that 'exit_flag' is ignored and penalized 'fval' is
|
||||||
if nargin==1
|
% actually used.
|
||||||
penalty = xparam1;
|
% In that case, 'penalty' is properly initialized, at the very end of the
|
||||||
return
|
% present function, by a call to dsge_likelihood() made in
|
||||||
end
|
% initial_estimation_checks(). If a condition triggers exit_flag ==
|
||||||
|
% 0, initial_estimation_checks() triggers an error.
|
||||||
|
% In summary, an initial call to the present function, without triggering
|
||||||
|
% any condition, guarantees that 'penalty' is properly initialized when needed.
|
||||||
|
|
||||||
|
persistent penalty
|
||||||
|
|
||||||
% Initialization of the returned variables and others...
|
% Initialization of the returned variables and others...
|
||||||
fval = [];
|
fval = [];
|
||||||
|
|
|
@ -41,17 +41,20 @@ function [fval,llik,cost_flag,ys,trend_coeff,info] = dsge_likelihood_hh(xparam1,
|
||||||
|
|
||||||
|
|
||||||
% Declaration of the penalty as a persistent variable.
|
% Declaration of the penalty as a persistent variable.
|
||||||
persistent penalty
|
|
||||||
|
|
||||||
% Initialization of the persistent variable.
|
% Persistent variable 'penalty' is used to compute an endogenous penalty to
|
||||||
if ~nargin || isempty(penalty)
|
% the value 'fval' when various conditions are encountered. These conditions
|
||||||
penalty = 1e8;
|
% set also 'exit_flag' equal to 0 instead of 1. It is only when
|
||||||
if ~nargin, return, end
|
% dsge_likelihood_hh() is called by an newrat() called by
|
||||||
end
|
% dynare_estimation_1() that 'exit_flag' is ignored and penalized 'fval' is
|
||||||
if nargin==1
|
% actually used.
|
||||||
penalty = xparam1;
|
% In that case, 'penalty' is properly initialized, at the very end of the
|
||||||
return
|
% present function, by a call to dsge_likelihood_hh() made in
|
||||||
end
|
% initial_estimation_checks(). If a condition triggers exit_flag ==
|
||||||
|
% 0, initial_estimation_checks() triggers an error.
|
||||||
|
% In summary, an initial call to the present function, without triggering
|
||||||
|
% any condition, guarantees that 'penalty' is properly initialized when needed.
|
||||||
|
persistent penalty
|
||||||
|
|
||||||
% Initialization of the returned variables and others...
|
% Initialization of the returned variables and others...
|
||||||
fval = [];
|
fval = [];
|
||||||
|
|
|
@ -42,6 +42,12 @@ if DynareOptions.dsge_var
|
||||||
[fval,cost_flag,info] = DsgeVarLikelihood(xparam1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
|
[fval,cost_flag,info] = DsgeVarLikelihood(xparam1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
|
||||||
else
|
else
|
||||||
[fval,cost_flag,ys,trend_coeff,info] = dsge_likelihood(xparam1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
|
[fval,cost_flag,ys,trend_coeff,info] = dsge_likelihood(xparam1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
|
||||||
|
if DynareOptions.mode_compute == 5
|
||||||
|
% this call is necessary to initialized persistent variable
|
||||||
|
% 'penalty' in dsge_likelihood_hh
|
||||||
|
[fval,llik,cost_flag,ys,trend_coeff,info] = ...
|
||||||
|
dsge_likelihood_hh(xparam1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if info(1) > 0
|
if info(1) > 0
|
||||||
|
|
Loading…
Reference in New Issue