Merge branch 'master' into new_ep

time-shift
Michel Juillard 2015-05-25 17:20:23 +02:00
commit 3ef5bc2989
13 changed files with 85 additions and 69 deletions

View File

@ -50,9 +50,11 @@ elseif options_.steadystate_flag
M.endo_names,'exact')];
end
if inst_nbr == 1
inst_val = csolve(nl_func,ys_init(k_inst),'',options_.solve_tolf,100); %solve for instrument, using univariate solver, starting at initial value for instrument
%solve for instrument, using univariate solver, starting at initial value for instrument
inst_val = csolve(nl_func,ys_init(k_inst),'',options_.solve_tolf,100);
else
[inst_val,info1] = dynare_solve(nl_func,ys_init(k_inst),0); %solve for instrument, using multivariate solver, starting at initial value for instrument
%solve for instrument, using multivariate solver, starting at initial value for instrument
[inst_val,info1] = dynare_solve(nl_func,ys_init(k_inst),options_);
end
ys_init(k_inst) = inst_val;
exo_ss = [oo.exo_steady_state oo.exo_det_steady_state];
@ -61,7 +63,7 @@ elseif options_.steadystate_flag
else
n_var = M.orig_endo_nbr;
xx = oo.steady_state(1:n_var);
[xx,check] = dynare_solve(nl_func,xx,0);
[xx,check] = dynare_solve(nl_func,xx,options_);
[junk,junk,steady_state] = nl_func(xx);
end

View File

@ -1,12 +1,11 @@
function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
% function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
function [x,info] = dynare_solve(func,x,options,varargin)
% function [x,info] = dynare_solve(func,x,options,varargin)
% proposes different solvers
%
% INPUTS
% func: name of the function to be solved
% x: guess values
% jacobian_flag=1: jacobian given by the 'func' function
% jacobian_flag=0: jacobian obtained numerically
% options: struct of Dynare options
% varargin: list of arguments following jacobian_flag
%
% OUTPUTS
@ -16,7 +15,7 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2014 Dynare Team
% Copyright (C) 2001-2015 Dynare Team
%
% This file is part of Dynare.
%
@ -33,14 +32,16 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global options_
% jacobian_flag=1: jacobian given by the 'func' function
% jacobian_flag=0: jacobian obtained numerically
jacobian_flag = options.jacobian_flag;
% Set tolerance parameter depending the the caller function.
stack = dbstack;
if strcmp(stack(2).file,'simulation_core.m')
tolf = options_.dynatol.f;
tolf = options.dynatol.f;
else
tolf = options_.solve_tolf;
tolf = options.solve_tolf;
end
info = 0;
@ -81,7 +82,7 @@ if (options_.solve_algo ~= 10) && (max(abs(fvec)) < tolf)
return ;
end
if options_.solve_algo == 0
if options.solve_algo == 0
if ~isoctave
if ~user_has_matlab_license('optimization_toolbox')
error('You can''t use solve_algo=0 since you don''t have MATLAB''s Optimization Toolbox')
@ -89,7 +90,7 @@ if options_.solve_algo == 0
end
options=optimset('fsolve');
options.MaxFunEvals = 50000;
options.MaxIter = options_.steady.maxit;
options.MaxIter = options.steady.maxit;
options.TolFun = tolf;
options.Display = 'iter';
if jacobian_flag
@ -117,17 +118,17 @@ if options_.solve_algo == 0
else
info = 1;
end
elseif options_.solve_algo == 1
[x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,options_.gstep, ...
tolf,options_.solve_tolx, ...
options_.steady.maxit,options_.debug,varargin{:});
elseif options_.solve_algo == 9
[x,info]=trust_region(func,x,1:nn,1:nn,jacobian_flag,options_.gstep, ...
tolf,options_.solve_tolx, ...
options_.steady.maxit,options_.debug,varargin{:});
elseif options_.solve_algo == 2 || options_.solve_algo == 4
elseif options.solve_algo == 1
[x,info]=solve1(func,x,1:nn,1:nn,jacobian_flag,options.gstep, ...
tolf,options.solve_tolx, ...
options.steady.maxit,options.debug,varargin{:});
elseif options.solve_algo == 9
[x,info]=trust_region(func,x,1:nn,1:nn,jacobian_flag,options.gstep, ...
tolf,options.solve_tolx, ...
options.steady.maxit,options.debug,varargin{:});
elseif options.solve_algo == 2 || options.solve_algo == 4
if options_.solve_algo == 2
if options.solve_algo == 2
solver = @solve1;
else
solver = @trust_region;
@ -135,7 +136,7 @@ elseif options_.solve_algo == 2 || options_.solve_algo == 4
if ~jacobian_flag
fjac = zeros(nn,nn) ;
dh = max(abs(x),options_.gstep(1)*ones(nn,1))*eps^(1/3);
dh = max(abs(x),options.gstep(1)*ones(nn,1))*eps^(1/3);
for j = 1:nn
xdh = x ;
xdh(j) = xdh(j)+dh(j) ;
@ -145,18 +146,18 @@ elseif options_.solve_algo == 2 || options_.solve_algo == 4
[j1,j2,r,s] = dmperm(fjac);
if options_.debug
if options.debug
disp(['DYNARE_SOLVE (solve_algo=2|4): number of blocks = ' num2str(length(r))]);
end
for i=length(r)-1:-1:1
if options_.debug
if options.debug
disp(['DYNARE_SOLVE (solve_algo=2|4): solving block ' num2str(i) ', of size ' num2str(r(i+1)-r(i)) ]);
end
[x,info]=solver(func,x,j1(r(i):r(i+1)-1),j2(r(i):r(i+1)-1),jacobian_flag, ...
options_.gstep, ...
tolf,options_.solve_tolx, ...
options_.steady.maxit,options_.debug,varargin{:});
options.gstep, ...
tolf,options.solve_tolx, ...
options.steady.maxit,options.debug,varargin{:});
if info
return
end
@ -164,17 +165,17 @@ elseif options_.solve_algo == 2 || options_.solve_algo == 4
fvec = feval(func,x,varargin{:});
if max(abs(fvec)) > tolf
[x,info]=solver(func,x,1:nn,1:nn,jacobian_flag, ...
options_.gstep, tolf,options_.solve_tolx, ...
options_.steady.maxit,options_.debug,varargin{:});
options.gstep, tolf,options.solve_tolx, ...
options.steady.maxit,options.debug,varargin{:});
end
elseif options_.solve_algo == 3
elseif options.solve_algo == 3
if jacobian_flag
[x,info] = csolve(func,x,func,1e-6,500,varargin{:});
else
[x,info] = csolve(func,x,[],1e-6,500,varargin{:});
end
elseif options_.solve_algo == 10
olmmcp = options_.lmmcp;
elseif options.solve_algo == 10
olmmcp = options.lmmcp;
[x,fval,exitflag] = lmmcp(func,x,olmmcp.lb,olmmcp.ub,olmmcp,varargin{:});
if exitflag == 1
info = 0;

View File

@ -1,5 +1,5 @@
function [x,info] = dynare_solve_block_or_bytecode(y, exo, params, options, M)
% Copyright (C) 2010-2012 Dynare Team
% Copyright (C) 2010-2015 Dynare Team
%
% This file is part of Dynare.
%
@ -26,7 +26,7 @@ if options.block && ~options.bytecode
if options.solve_algo <= 4
[y, check] = dynare_solve('block_mfs_steadystate', ...
ss(M.block_structure_stat.block(b).variable), ...
options.jacobian_flag, b, ss, exo, params, M);
options, b, ss, exo, params, M);
if check ~= 0
% error(['STEADY: convergence
% problems in block ' int2str(b)])
@ -62,18 +62,21 @@ elseif options.bytecode
if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ...
M.block_structure_stat.block(b).Simulation_Type ~= 2
[y, check] = dynare_solve('block_bytecode_mfs_steadystate', ...
x(M.block_structure_stat.block(b).variable), ...
options.jacobian_flag, b, x, exo, params, M);
x(M.block_structure_stat ...
.block(b).variable), ...
options, b, x, exo, params, M);
if check
% error(['STEADY: convergence
% problems in block ' int2str(b)])
% error(['STEADY: convergence problems in block '
% int2str(b)])
info = 1;
return
end
x(M.block_structure_stat.block(b).variable) = y;
else
[chk, nulldev, nulldev1, x] = bytecode( x, exo, params, ...
x, 1, x, 'evaluate', 'static', ['block = ' int2str(b)]);
x, 1, x, 'evaluate', ...
'static', ['block ' ...
'= '] int2str(b)]);
if chk
info = 1;
return
@ -81,9 +84,8 @@ elseif options.bytecode
end;
end
else
[x, check] = dynare_solve('bytecode_steadystate', ...
y, ...
options.jacobian_flag, exo, params);
[x, check] = dynare_solve('bytecode_steadystate', y, ...
options, exo, params);
if check
% error('STEADY: convergence problems')
info = 1;

View File

@ -146,7 +146,7 @@ y = repmat(steady_state,block_nbr,1);
old_options = options_;
options_.solve_algo = options_.ep.solve_algo;
options_.steady.maxit = options_.ep.maxit;
[y,info] = dynare_solve(@ep_problem_2,y,1,exo_simul,pfm);
[y,info] = dynare_solve(@ep_problem_2,y,options_,exo_simul,pfm);
options_ = old_options;
if info
flag = 1;

View File

@ -193,8 +193,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
% non linear model
[ys,check] = dynare_solve([M.fname '_static'],...
ys_init,...
options.jacobian_flag, ...
exo_ss, params);
options, exo_ss, params);
else
% linear model
fh_static = str2func([M.fname '_static']);

View File

@ -63,7 +63,7 @@ function [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M,options)
updated_params_flag = max(abs(params1-params)) > 1e-12 ...
|| ~isequal(isnan(params1),isnan(params)); %checks whether numbers or NaN changed
else
updated_params_flag = 0
updated_params_flag = 0;
end
h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']);
@ -117,8 +117,7 @@ function [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M,options)
end
[ys,check] = dynare_solve('restricted_steadystate',...
ys(indv),...
options.jacobian_flag, ...
exo_ss,indv);
options, exo_ss,indv);
end

View File

@ -44,6 +44,16 @@ if DynareDataset.vobs>length(find(diag(Model.Sigma_e)))+EstimatedParameters.nvn
error(['initial_estimation_checks:: Estimation can''t take place because too many shocks have been calibrated with a zero variance!'])
end
if ~(strcmpi(DynareOptions.proposal_distribution, 'rand_multivariate_student') || ...
strcmpi(DynareOptions.proposal_distribution, 'rand_multivariate_normal'))
error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ...
'rand_multivariate_student or rand_multivariate_normal as options']);
end
if DynareOptions.student_degrees_of_freedom <= 0
error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument');
end
old_steady_params=Model.params; %save initial parameters for check if steady state changes param values
% % check if steady state solves static model (except if diffuse_filter == 1)

View File

@ -89,7 +89,7 @@ else
% nonlinear models
if max(abs(feval(fh,dr.ys,[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params))) > options_.dynatol.f
[dr.ys,check1] = dynare_solve(fh,dr.ys,options_.jacobian_flag,...
[dr.ys,check1] = dynare_solve(fh,dr.ys,options_,...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params);
end

View File

@ -87,7 +87,7 @@ if options_.ramsey_policy && options_.ACES_solver == 0
end
old_solve_algo = options_.solve_algo;
% options_.solve_algo = 1;
oo_.steady_state = dynare_solve('ramsey_static',oo_.steady_state,0,M_,options_,oo_,it_);
oo_.steady_state = dynare_solve('ramsey_static',oo_.steady_state,options_,M_,options_,oo_,it_);
options_.solve_algo = old_solve_algo;
[junk,junk,multbar] = ramsey_static(oo_.steady_state,M_,options_,oo_,it_);
[jacobia_,M_] = ramsey_dynamic(oo_.steady_state,multbar,M_,options_,oo_,it_);

View File

@ -87,9 +87,9 @@ class ParsingDriver;
%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA TARB_OPTIM
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
%token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED
%token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED PROPOSAL_DISTRIBUTION
%token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION
%token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED
%token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED STUDENT_DEGREES_OF_FREEDOM
%token DATAFILE FILE SERIES DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR
%token FILENAME DIRNAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME
@ -1719,6 +1719,8 @@ estimation_options : o_datafile
| o_tarb_mode_compute
| o_tarb_new_block_probability
| o_tarb_optim
| o_proposal_distribution
| o_student_degrees_of_freedom
;
list_optim_option : QUOTED_STRING COMMA QUOTED_STRING
@ -2633,6 +2635,8 @@ o_mh_drop : MH_DROP EQUAL non_negative_number { driver.option_num("mh_drop", $3)
o_mh_jscale : MH_JSCALE EQUAL non_negative_number { driver.option_num("mh_jscale", $3); };
o_optim : OPTIM EQUAL '(' optim_options ')';
o_tarb_optim : TARB_OPTIM EQUAL '(' tarb_optim_options ')';
o_proposal_distribution : PROPOSAL_DISTRIBUTION EQUAL symbol { driver.option_str("proposal_distribution", $3); };
o_student_degrees_of_freedom : STUDENT_DEGREES_OF_FREEDOM EQUAL INT_NUMBER { driver.option_num("student_degrees_of_freedom", $3); };
o_mh_init_scale : MH_INIT_SCALE EQUAL non_negative_number { driver.option_num("mh_init_scale", $3); };
o_mode_file : MODE_FILE EQUAL filename { driver.option_str("mode_file", $3); };
o_mode_compute : MODE_COMPUTE EQUAL INT_NUMBER { driver.option_num("mode_compute", $3); };

View File

@ -371,6 +371,8 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<DYNARE_STATEMENT>unscented {return token::UNSCENTED;}
<DYNARE_STATEMENT>montecarlo {return token::MONTECARLO;}
<DYNARE_STATEMENT>distribution_approximation {return token::DISTRIBUTION_APPROXIMATION;}
<DYNARE_STATEMENT>proposal_distribution {return token::PROPOSAL_DISTRIBUTION;}
<DYNARE_STATEMENT>student_degrees_of_freedom {return token::STUDENT_DEGREES_OF_FREEDOM;}
<DYNARE_STATEMENT>alpha {
yylval->string_val = new string(yytext);

View File

@ -437,7 +437,7 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES)
@echo 'Octave Tests Done'
%.m.trs %.m.log: %.mod
@echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$*... `tput sgr0`"
@echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$*... `tput sgr0`"
@DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \
$(MATLAB)/bin/matlab -nosplash -nodisplay -r run_test_matlab > $*.m.log 2> /dev/null
@if grep -q ":test-result: PASS" $*.m.trs; then \
@ -450,13 +450,13 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES)
@cat $*.m.log
%.m.trs %.m.log : %.m
@echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$*... `tput sgr0`"
@echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$*... `tput sgr0`"
@DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \
$(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null
@echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$* Done!`tput sgr0`"
@echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$* Done!`tput sgr0`"
%.o.trs %.o.log: %.mod
@echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$*... `tput sgr0`"
@echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$*... `tput sgr0`"
@DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \
$(OCTAVE) --no-init-file --silent --no-history run_test_octave.m > $*.o.log 2>&1
@if grep -q ":test-result: PASS" $*.o.trs; then \
@ -469,24 +469,24 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES)
@cat $*.o.log
%.o.trs %.o.log : %.m
@echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$*... `tput sgr0`"
@echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$*... `tput sgr0`"
@DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \
$(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1
@echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$* Done!`tput sgr0`"
@echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$* Done!`tput sgr0`"
%.m.tls : %.m
@echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$*... `tput sgr0`"
@echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$*... `tput sgr0`"
@TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \
$(MATLAB)/bin/matlab -nosplash -nodisplay -r run_m_script 2> /dev/null
@touch $*.m.tls
@echo "`tput bold`MATLAB`tput setaf 3`: $(PWD)/$* Done!`tput sgr0`"
@echo "`tput bold`MATLAB`tput setaf 8`: $(PWD)/$* Done!`tput sgr0`"
%.o.tls : %.m
@echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$*... `tput sgr0`"
@echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$*... `tput sgr0`"
@TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \
$(OCTAVE) --no-init-file --silent --no-history run_o_script.m 2>&1
@touch $*.o.tls
@echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$* Done!`tput sgr0`"
@echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$* Done!`tput sgr0`"
clean-local:
rm -f $(M_TRS_FILES) \

View File

@ -17,7 +17,7 @@
*/
/*
* Copyright (C) 2004-2010 Dynare Team
* Copyright (C) 2004-2015 Dynare Team
*
* This file is part of Dynare.
*
@ -114,7 +114,4 @@ end;
varobs gp_obs gy_obs;
options_.proposal_distribution='rand_multivariate_student';
options_.student_degrees_of_freedom=5;
estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=2002, mh_nblocks=2, mh_jscale=0.8,mode_compute=4);
estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=2002, mh_nblocks=2, mh_jscale=0.8,mode_compute=4, proposal_distribution=rand_multivariate_studuuent, student_degrees_of_freedom=5);