Commit 55ea2100 authored by MichelJuillard's avatar MichelJuillard
Browse files

Merge branch 'master' into new_ep

parents f8af7724 bbee8830
......@@ -95,7 +95,7 @@
@c %**end of header
@copying
Copyright @copyright{} 1996-2014, Dynare Team.
Copyright @copyright{} 1996-2015, Dynare Team.
@quotation
Permission is granted to copy, distribute and/or modify this document
......@@ -1875,10 +1875,33 @@ end;
@end deffn
Dynare has the ability to output the list of model equations to a
@LaTeX{} file, using the @code{write_latex_dynamic_model} command. The
static model can also be written with the
@code{write_latex_static_model} command.
Dynare has the ability to output the original list of model equations
to a @LaTeX{} file, using the @code{write_latex_original_model}
command, the list of transformed model equations using the
@code{write_latex_dynamic_model} command, and the list of static model
equations using the @code{write_latex_static_model} command.
@anchor{write_latex_original_model}
@deffn Command write_latex_original_model ;
@descriptionhead
This command creates a @LaTeX{} file containing the model, as defined
in the model block.
If your @file{.mod} file is @file{@var{FILENAME}.mod}, then Dynare
will create a file called @file{@var{FILENAME}_dynamic.tex},
containing the list of all the dynamic model equations.
If @LaTeX{} names were given for variables and parameters
(@pxref{Variable declarations}), then those will be used; otherwise,
the plain text names will be used.
Time subscripts (@code{t}, @code{t+1}, @code{t-1}, @dots{}) will be
appended to the variable names, as @LaTeX{} subscripts.
@end deffn
@anchor{write_latex_dynamic_model}
......
......@@ -33,7 +33,7 @@ function [dr,info,M_,options_,oo_] = dr_block(dr,task,M_,options_,oo_,varargin)
% none.
%
% Copyright (C) 2010-2013 Dynare Team
% Copyright (C) 2010-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -72,7 +72,7 @@ end;
if (options_.bytecode)
[chck, zz, data]= bytecode('dynamic','evaluate', z, zx, M_.params, dr.ys, 1, data);
else
[r, data] = feval([M_.fname '_dynamic'], z', zx, M_.params, dr.ys, M_.maximum_lag+1, data);
[r, data] = feval([M_.fname '_dynamic'], options_, M_, oo_, z', zx, M_.params, dr.ys, M_.maximum_lag+1, data);
chck = 0;
end;
mexErrCheck('bytecode', chck);
......
......@@ -16,7 +16,7 @@ function info = dyn_forecast(var_list,task)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2003-2013 Dynare Team
% Copyright (C) 2003-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -37,6 +37,8 @@ global options_ oo_ M_
info = 0;
make_ex_;
maximum_lag = M_.maximum_lag;
endo_names = M_.endo_names;
......@@ -122,15 +124,15 @@ if ~isscalar(trend)
end
for i=1:n_var
eval(['oo_.forecast.Mean.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+1:end)'';']);
eval(['oo_.forecast.HPDinf.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+1:end)''-' ...
' int_width(:,' int2str(i) ');']);
eval(['oo_.forecast.HPDsup.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+1:end)''+' ...
' int_width(:,' int2str(i) ');']);
eval(['oo_.forecast.Mean.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+(1:horizon))'';']);
eval(['oo_.forecast.HPDinf.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+(1:horizon))''-' ...
' int_width(1:horizon,' int2str(i) ');']);
eval(['oo_.forecast.HPDsup.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+(1:horizon))''+' ...
' int_width(1:horizon,' int2str(i) ');']);
end
for i=1:M_.exo_det_nbr
eval(['oo_.forecast.Exogenous.' M_.exo_det_names(i,:) '= oo_.exo_det_simul(:,' int2str(i) ');']);
eval(['oo_.forecast.Exogenous.' M_.exo_det_names(i,:) '= oo_.exo_det_simul(maximum_lag+(1:horizon),' int2str(i) ');']);
end
if options_.nograph == 0
......
......@@ -14,7 +14,7 @@ function [steady_state,params,check] = dyn_ramsey_static(ys_init,M,options_,oo)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2003-2014 Dynare Team
% Copyright (C) 2003-2015 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -15,7 +15,7 @@ function dynareroot = dynare_config(path_to_dynare,verbose)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2014 Dynare Team
% Copyright (C) 2001-2015 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -14,7 +14,7 @@ function [ts,results] = extended_path(initial_conditions,sample_size)
%
% SPECIAL REQUIREMENTS
% Copyright (C) 2009-2013 Dynare Team
% Copyright (C) 2009-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -325,4 +325,4 @@ if info_convergence
y = endo_simul(:,2);
else
y = NaN(size(endo_nbr,1));
end
\ No newline at end of file
end
function [flag,endo_simul,err] = solve_stochastic_perfect_foresight_model(endo_simul,exo_simul,pfm,nnodes,order)
% Copyright (C) 2012-2013 Dynare Team
% Copyright (C) 2012-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -232,4 +232,4 @@ function [flag,endo_simul,err] = solve_stochastic_perfect_foresight_model(endo_s
end
if verbose
disp (['-----------------------------------------------------']) ;
end
\ No newline at end of file
end
......@@ -19,7 +19,7 @@ function DynareResults = initial_estimation_checks(objective_function,xparam1,Dy
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2003-2014 Dynare Team
% Copyright (C) 2003-2015 Dynare Team
%
% This file is part of Dynare.
%
......
function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
params, steady_state, periods, y_kmin, y_size)
params, steady_state, periods, y_kmin, y_size,Periods)
% wrapper for solve_one_boundary m-file when it is used with a dynamic
% model
%
......@@ -26,7 +26,7 @@ function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
% none.
%
% Copyright (C) 2009-2011 Dynare Team
% Copyright (C) 2009-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -45,5 +45,5 @@ function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
%reshape the input arguments of the dynamic function
y(y_kmin+1:y_kmin+periods, y_index) = reshape(ya',length(y_index),periods)';
[r, y, g1, g2, g3, b]=feval(fname, y, x, params, steady_state, periods, 0, y_kmin, y_size);
[r, y, g1, g2, g3, b]=feval(fname, y, x, params, steady_state, periods, 0, y_kmin, y_size, Periods);
ra = reshape(r(:, y_kmin+1:periods+y_kmin),periods*y_size, 1);
......@@ -12,7 +12,7 @@ function perfect_foresight_solver()
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 1996-2014 Dynare Team
% Copyright (C) 1996-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -164,4 +164,4 @@ else
end
ts = dseries(transpose(oo_.endo_simul),initial_period,cellstr(M_.endo_names));
assignin('base', 'Simulated_time_series', ts);
\ No newline at end of file
assignin('base', 'Simulated_time_series', ts);
function check_input_arguments(DynareOptions, DynareModel, DynareResults)
%function check_input_arguments(DynareOptions, DynareModel, DynareResults)
% Copyright (C) 2014 Dynare Team
% Copyright (C) 2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -43,6 +44,7 @@ if isempty(DynareResults.endo_simul) || any(size(DynareResults.endo_simul) ~= [
error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?')
end
if isempty(DynareResults.exo_simul) || any(size(DynareResults.exo_simul) ~= [ DynareModel.maximum_lag+DynareOptions.periods+DynareModel.maximum_lead, DynareModel.exo_nbr ])
if (DynareModel.exo_nbr > 0) && (isempty(DynareResults.exo_simul) || ...
any(size(DynareResults.exo_simul) ~= [ DynareModel.maximum_lag+DynareOptions.periods+DynareModel.maximum_lead, DynareModel.exo_nbr ]))
error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?')
end
function [oo_, maxerror] = simulation_core(options_, M_, oo_)
%function [oo_, maxerror] = simulation_core(options_, M_, oo_)
% Copyright (C) 2015 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/>.
if options_.block
if options_.bytecode
......@@ -15,7 +33,7 @@ if options_.block
end
mexErrCheck('bytecode', info);
else
eval([M_.fname '_dynamic']);
oo_ = feval([M_.fname '_dynamic'], options_, M_, oo_);
end
else
if options_.bytecode
......
......@@ -13,7 +13,7 @@ function oo = sim1(M, options, oo)
% SPECIAL REQUIREMENTS
% None.
% Copyright (C) 1996-2013 Dynare Team
% Copyright (C) 1996-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -216,4 +216,4 @@ end
if verbose
disp (['-----------------------------------------------------']) ;
skipline();
end
\ No newline at end of file
end
......@@ -16,7 +16,7 @@ function oo_ = sim1_lbj(options_, M_, oo_)
% SPECIAL REQUIREMENTS
% None.
% Copyright (C) 1996-2012 Dynare Team
% Copyright (C) 1996-2015 Dynare Team
%
% This file is part of Dynare.
%
......
function oo_ = sim1_purely_backward(options_, M_, oo_)
% Performs deterministic simulation of a purely backward model
% Copyright (C) 2012-2014 Dynare Team
% Copyright (C) 2012-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -52,4 +52,4 @@ function oo_ = sim1_purely_backward(options_, M_, oo_)
end
oo_.endo_simul(:,it) = tmp(nyb+1:nyb+M_.endo_nbr);
end
\ No newline at end of file
end
function oo_ = sim1_purely_forward(options_, M_, oo_)
% Performs deterministic simulation of a purely forward model
% Copyright (C) 2012-2014 Dynare Team
% Copyright (C) 2012-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -44,4 +44,4 @@ function oo_ = sim1_purely_forward(options_, M_, oo_)
end
oo_.endo_simul(:,it) = tmp(1:M_.endo_nbr);
end
\ No newline at end of file
end
function [y, oo]= solve_two_boundaries(fname, y, x, params, steady_state, y_index, nze, periods, y_kmin_l, y_kmax_l, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, M, oo)
function [y, oo]= solve_two_boundaries(fname, y, x, params, steady_state, y_index, nze, periods, y_kmin_l, y_kmax_l, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo,options,M, oo)
% Computes the deterministic simulation of a block of equation containing
% both lead and lag variables using relaxation methods
%
......@@ -46,7 +46,7 @@ function [y, oo]= solve_two_boundaries(fname, y, x, params, steady_state, y_inde
% none.
%
% Copyright (C) 1996-2013 Dynare Team
% Copyright (C) 1996-2015 Dynare Team
%
% This file is part of Dynare.
%
......@@ -81,7 +81,7 @@ Jacobian_Size=Blck_size*(y_kmin+y_kmax_l +periods);
g1=spalloc( Blck_size*periods, Jacobian_Size, nze*periods);
reduced = 0;
while ~(cvg==1 || iter>maxit_),
[r, y, g1, g2, g3, b]=feval(fname, y, x, params, steady_state, periods, 0, y_kmin, Blck_size);
[r, y, g1, g2, g3, b]=feval(fname, y, x, params, steady_state, periods, 0, y_kmin, Blck_size,options.periods);
preconditioner = 2;
g1a=g1(:, y_kmin*Blck_size+1:(periods+y_kmin)*Blck_size);
term1 = g1(:, 1:y_kmin_l*Blck_size)*reshape(y(1+y_kmin-y_kmin_l:y_kmin,y_index)',1,y_kmin_l*Blck_size)';
......@@ -298,8 +298,7 @@ while ~(cvg==1 || iter>maxit_),
g = (ra'*g1a)';
f = 0.5*ra'*ra;
p = -g1a\ra;
[yn,f,ra,check]=lnsrch1(ya,f,g,p,stpmax, ...
'lnsrch1_wrapper_two_boundaries',nn,nn, fname, y, y_index, x, params, steady_state, periods, y_kmin, Blck_size);
[yn,f,ra,check]=lnsrch1(ya,f,g,p,stpmax,'lnsrch1_wrapper_two_boundaries',nn,nn, fname, y, y_index,x, params, steady_state, periods, y_kmin, Blck_size,options.periods);
dx = ya - yn;
y(1+y_kmin:periods+y_kmin,y_index)=reshape(yn',length(y_index),periods)';
end
......
......@@ -1431,6 +1431,17 @@ WriteLatexStaticModelStatement::writeOutput(ostream &output, const string &basen
static_model.writeLatexFile(basename);
}
WriteLatexOriginalModelStatement::WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg) :
original_model(original_model_arg)
{
}
void
WriteLatexOriginalModelStatement::writeOutput(ostream &output, const string &basename) const
{
original_model.writeLatexOriginalFile(basename);
}
ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
symbol_list(symbol_list_arg),
......
/*
* Copyright (C) 2003-2014 Dynare Team
* Copyright (C) 2003-2015 Dynare Team
*
* This file is part of Dynare.
*
......@@ -509,6 +509,15 @@ public:
virtual void writeOutput(ostream &output, const string &basename) const;
};
class WriteLatexOriginalModelStatement : public Statement
{
private:
const DynamicModel &original_model;
public:
WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};
class ShockDecompositionStatement : public Statement
{
private:
......
......@@ -342,7 +342,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
else if (simulation_type == SOLVE_BACKWARD_SIMPLE || simulation_type == SOLVE_FORWARD_SIMPLE)
output << "function [residual, y, g1, g2, g3, varargout] = " << dynamic_basename << "_" << block+1 << "(y, x, params, steady_state, it_, jacobian_eval)\n";
else
output << "function [residual, y, g1, g2, g3, b, varargout] = " << dynamic_basename << "_" << block+1 << "(y, x, params, steady_state, periods, jacobian_eval, y_kmin, y_size)\n";
output << "function [residual, y, g1, g2, g3, b, varargout] = " << dynamic_basename << "_" << block+1 << "(y, x, params, steady_state, periods, jacobian_eval, y_kmin, y_size, Periods)\n";
BlockType block_type;
if (simulation_type == SOLVE_TWO_BOUNDARIES_COMPLETE || simulation_type == SOLVE_TWO_BOUNDARIES_SIMPLE)
block_type = SIMULTAN;
......@@ -364,7 +364,6 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
<< " % // Simulation type "
<< BlockSim(simulation_type) << " //" << endl
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
output << " global options_ oo_;" << endl;
//The Temporary terms
if (simulation_type == EVALUATE_BACKWARD || simulation_type == EVALUATE_FORWARD)
{
......@@ -385,9 +384,9 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
output << " else\n";
if (simulation_type == SOLVE_TWO_BOUNDARIES_COMPLETE || simulation_type == SOLVE_TWO_BOUNDARIES_SIMPLE)
{
output << " g1 = spalloc(" << block_mfs << "*options_.periods, "
<< block_mfs << "*(options_.periods+" << max_leadlag_block[block].first+max_leadlag_block[block].second+1 << ")"
<< ", " << nze << "*options_.periods);\n";
output << " g1 = spalloc(" << block_mfs << "*Periods, "
<< block_mfs << "*(Periods+" << max_leadlag_block[block].first+max_leadlag_block[block].second+1 << ")"
<< ", " << nze << "*Periods);\n";
}
else
{
......@@ -1789,8 +1788,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
int Nb_SGE = 0;
bool open_par = false;
mDynamicModelFile << "function [varargout] = " << dynamic_basename << "(varargin)\n";
mDynamicModelFile << " global oo_ options_ M_ ;\n";
mDynamicModelFile << "function [varargout] = " << dynamic_basename << "(options_, M_, oo_, varargin)\n";
mDynamicModelFile << " g2=[];g3=[];\n";
//Temporary variables declaration
OK = true;
......@@ -1805,7 +1803,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
(*it)->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms);
}
if (tmp_output.str().length() > 0)
mDynamicModelFile << " global " << tmp_output.str() << " M_ ;\n";
mDynamicModelFile << " global " << tmp_output.str() << ";\n";
mDynamicModelFile << " T_init=zeros(1,options_.periods+M_.maximum_lag+M_.maximum_lead);\n";
tmp_output.str("");
......@@ -1882,7 +1880,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
break;
case SOLVE_TWO_BOUNDARIES_COMPLETE:
case SOLVE_TWO_BOUNDARIES_SIMPLE:
mDynamicModelFile << " [r, y, dr(" << count_call << ").g1, dr(" << count_call << ").g2, dr(" << count_call << ").g3, b, dr(" << count_call << ").g1_x, dr(" << count_call << ").g1_xd, dr(" << count_call << ").g1_o]=" << dynamic_basename << "_" << block + 1 << "(y, x, params, steady_state, it_-" << max_lag << ", 1, " << max_lag << ", " << block_recursive << ");\n";
mDynamicModelFile << " [r, y, dr(" << count_call << ").g1, dr(" << count_call << ").g2, dr(" << count_call << ").g3, b, dr(" << count_call << ").g1_x, dr(" << count_call << ").g1_xd, dr(" << count_call << ").g1_o]=" << dynamic_basename << "_" << block + 1 << "(y, x, params, steady_state, it_-" << max_lag << ", 1, " << max_lag << ", " << block_recursive << "," << "options_.periods" << ");\n";
mDynamicModelFile << " residual(y_index_eq)=r(:,M_.maximum_lag+1);\n";
break;
default:
......@@ -2065,7 +2063,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
<<", options_.periods, " << max_leadlag_block[block].first
<<", " << max_leadlag_block[block].second
<<", " << blocks_linear[block]
<<", blck_num, y_kmin, options_.simul.maxit, options_.solve_tolf, options_.slowc, " << cutoff << ", options_.stack_solve_algo, M_, oo_);\n";
<<", blck_num, y_kmin, options_.simul.maxit, options_.solve_tolf, options_.slowc, " << cutoff << ", options_.stack_solve_algo, options_, M_, oo_);\n";
mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n";
mDynamicModelFile << " if any(isnan(tmp) | isinf(tmp))\n";
mDynamicModelFile << " disp(['Inf or Nan value during the resolution of block " << block <<"']);\n";
......@@ -2077,6 +2075,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
mDynamicModelFile << " end;\n";
open_par = false;
mDynamicModelFile << " oo_.endo_simul = y';\n";
mDynamicModelFile << " varargout{1} = oo_;\n";
mDynamicModelFile << "return;\n";
mDynamicModelFile << "end" << endl;
......@@ -3997,6 +3996,12 @@ DynamicModel::writeLatexFile(const string &basename) const
writeLatexModelFile(basename + "_dynamic.tex", oLatexDynamicModel);
}
void
DynamicModel::writeLatexOriginalFile(const string &basename) const
{
writeLatexModelFile(basename + "_original.tex", oLatexDynamicModel);
}
void
DynamicModel::substituteEndoLeadGreaterThanTwo(bool deterministic_model)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment