change variable/parameter collections, finish printing SymbolTable info

time-shift
Houtan Bastani 2015-07-23 17:32:09 +02:00
parent 1ed5a79716
commit 4a5dcfca4d
5 changed files with 228 additions and 190 deletions

140
julia/DynareModel.jl Normal file
View File

@ -0,0 +1,140 @@
module DynareModel
##
# 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/>.
##
export Endo, Exo, ExoDet, Param, Model
abstract Atom
immutable Endo <: Atom
name::UTF8String
tex_name::UTF8String
long_name::UTF8String
end
immutable Exo <: Atom
name::UTF8String
tex_name::UTF8String
long_name::UTF8String
end
immutable ExoDet <: Atom
name::UTF8String
tex_name::UTF8String
long_name::UTF8String
end
immutable Param <: Atom
name::UTF8String
tex_name::UTF8String
long_name::UTF8String
end
immutable AuxVars
endo_index::Int
var_type::Int
orig_index::Int
orig_lead_lag::Int
eq_nbr::Int
orig_expr::UTF8String
end
type Model
fname::ASCIIString
dname::ASCIIString
endo::Array{Endo,1}
exo::Array{Exo,1}
exo_det::Array{ExoDet,1}
param::Array{Param,1}
aux_vars::Array{AuxVars,1}
pred_vars::Array{Int,1}
obs_vars::Array{Int,1}
orig_endo_nbr::Int
orig_eq_nbr::Int
eq_nbr::Int
ramsey_eq_nbr::Int
nstatic::Int
nfwrd::Int
npred::Int
nboth::Int
nsfwrd::Int
nspred::Int
ndynamic::Int
maximum_lag::Int
maximum_lead::Int
maximum_endo_lag::Int
maximum_endo_lead::Int
maximum_exo_lag::Int
maximum_exo_lead::Int
lead_lag_incidence::Matrix{Int}
NNZDerivatives::Vector{Int}
static_and_dynamic_models_differ::Bool
equations_tags::Array{ASCIIString,1}
exo_names_orig_ord::Array{Int, 1}
Sigma_e::Matrix{Float64}
Correlation_matrix::Matrix{Float64}
H::Matrix{Float64}
Correlation_matrix_ME::Matrix{Float64}
sigma_e_is_diagonal::Bool
params::Vector{Float64}
end
function Model()
return Model("", # fname
"", # dname
Array(Endo,0), # endo
Array(Exo,0), # exo
Array(ExoDet,0), # exo_det
Array(Param,0), # param
Array(AuxVars,0), # aux_vars
Array(Int,0), # pred_vars
Array(Int,0), # obs_vars
0, # orig_endo_nbr
0, # orig_eq_nbr
0, # eq_nbr
0, # ramsey_eq_nbr
0, # nstatic
0, # nfwrd
0, # npred
0, # nboth
0, # nsfwrd
0, # nspred
0, # ndynamic
0, # maximum_lag
0, # maximum_lead
0, # maximum_endo_lag
0, # maximum_endo_lead
0, # maximum_exo_lag
0, # maximum_exo_lead
Array(Int, 3, 0), # lead_lag_incidence
zeros(Int, 3), # NNZDerivatives
false, # static_and_dynamic_models_differ
Array(ASCIIString,0), # equations_tags
Array(Int64,1), # exo_names_orig_ord
Array(Float64, 0, 0), # Sigma_e (Covariance matrix of the structural innovations)
Array(Float64, 0, 0), # Correlation_matrix (Correlation matrix of the structural innovations)
Array(Float64, 0, 0), # H (Covariance matrix of the measurement errors)
Array(Float64, 0, 0), # Correlation_matrix_ME (Covariance matrixof the measurement errors)
true, # sigma_e_is_diagonal
Array(Float64, 0) # params
)
end
end

View File

@ -1,4 +1,4 @@
module utils
module Utils
##
# Copyright (C) 2015 Dynare Team
#

View File

@ -1,122 +0,0 @@
module model
##
# 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/>.
##
export modeldescription
type modeldescription
fname::ASCIIString
dname::ASCIIString
exonames::Array{ASCIIString,1}
tex_exonames::Array{ASCIIString,1}
long_exonames::Array{ASCIIString,1}
exodetnames::Array{ASCIIString,1}
tex_exodetnames::Array{ASCIIString,1}
long_exodetnames::Array{ASCIIString,1}
endonames::Array{ASCIIString,1}
tex_endonames::Array{ASCIIString,1}
long_endonames::Array{ASCIIString,1}
paramnames::Array{ASCIIString,1}
tex_paramnames::Array{ASCIIString,1}
long_paramnames::Array{ASCIIString,1}
aux_vars::Array{ASCIIString,1}
exo_nbr::Int
endo_nbr::Int
param_nbr::Int
orig_endo_nbr::Int
orig_eq_nbr::Int
eq_nbr::Int
ramsey_eq_nbr::Int
nstatic::Int
nfwrd::Int
npred::Int
nboth::Int
nsfwrd::Int
nspred::Int
ndynamic::Int
maximum_lag::Int
maximum_lead::Int
maximum_endo_lag::Int
maximum_endo_lead::Int
maximum_exo_lag::Int
maximum_exo_lead::Int
lead_lag_incidence::Matrix{Int}
NNZDerivatives::Vector{Int}
static_and_dynamic_models_differ::Bool
equations_tags::Array{ASCIIString,1}
exo_names_orig_ord::Array{Int, 1}
Sigma_e::Matrix{Float64}
Correlation_matrix::Matrix{Float64}
H::Matrix{Float64}
Correlation_matrix_ME::Matrix{Float64}
sigma_e_is_diagonal::Bool
params::Vector{Float64}
end
function modeldescription()
return modeldescription("", # fname
"", # dname
Array(ASCIIString,0), # exonames
Array(ASCIIString,0), # t_exonames
Array(ASCIIString,0), # l_exonames
Array(ASCIIString,0), # exodetnames
Array(ASCIIString,0), # t_exodetnames
Array(ASCIIString,0), # l_exodetnames
Array(ASCIIString,0), # endonames
Array(ASCIIString,0), # t_endonames
Array(ASCIIString,0), # l_endonames
Array(ASCIIString,0), # paramnames
Array(ASCIIString,0), # t_paramnames
Array(ASCIIString,0), # l_paramnames
Array(ASCIIString,0), # aux_vars
0, # exo_nbr
0, # endo_nbr
0, # param_nbr
0, # orig_endo_nbr
0, # orig_eq_nbr
0, # eq_nbr
0, # ramsey_eq_nbr
0, # nstatic
0, # nfwrd
0, # npred
0, # nboth
0, # nsfwrd
0, # nspred
0, # ndynamic
0, # maximum_lag
0, # maximum_lead
0, # maximum_endo_lag
0, # maximum_endo_lead
0, # maximum_exo_lag
0, # maximum_exo_lead
Array(Int, 3, 0), # lead_lag_incidence
zeros(Int, 3), # NNZDerivatives
false, # static_and_dynamic_models_differ
Array(ASCIIString,0), # equations_tags
Array(Int64,1), # exo_names_orig_ord
Array(Float64, 0, 0), # Sigma_e (Covariance matrix of the structural innovations)
Array(Float64, 0, 0), # Correlation_matrix (Correlation matrix of the structural innovations)
Array(Float64, 0, 0), # H (Covariance matrix of the measurement errors)
Array(Float64, 0, 0), # Correlation_matrix_ME (Covariance matrixof the measurement errors)
true, # sigma_e_is_diagonal
Array(Float64, 0) # params
)
end
end

View File

@ -1077,15 +1077,15 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
}
jlOutputFile << "module " << basename << endl
<< "#" << endl
<< "# Note : this file was automatically generated by Dynare" << endl
<< "# from " << basename << ".mod" << endl
<< "#" << endl
<< "using model" << endl
<< "using utils" << endl
<< "##" << endl
<< " # Note : this file was automatically generated by Dynare" << endl
<< " # from " << basename << ".mod" << endl
<< "##" << endl
<< "using DynareModel" << endl
<< "using Utils" << endl
<< "export dynamicmodel!, staticmodel!, steadystate!" << endl
<< "export model__" << endl
<< "model__ = modeldescription()" << endl
<< "model__ = Model()" << endl
<< "model__.fname = \"" << basename << "\"" << endl;
symbol_table.writeJuliaOutput(jlOutputFile);

View File

@ -725,68 +725,88 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
if (!frozen)
throw NotYetFrozenException();
if (exo_nbr() > 0)
{
output << "model__.exonames = [\"" << getName(exo_ids[0]) << "\"";
for (int id = 1; id < exo_nbr(); id++)
output << ", \"" << getName(exo_ids[id]) << "\"";
output << "]" << endl
<< "model__.tex_exonames = [\"" << getTeXName(exo_ids[0]) << "\"";
for (int id = 1; id < exo_nbr(); id++)
output << ", \"" << getTeXName(exo_ids[id]) << "\"";
output << "]" << endl
<< "model__.long_exonames = [\"" << getLongName(exo_ids[0]) << "\"";
for (int id = 1; id < exo_nbr(); id++)
output << ", \"" << getLongName(exo_ids[id]) << "\"";
output << "]" << endl;
}
if (exo_det_nbr() > 0)
{
output << "model__.exodetnames = [\"" << getName(exo_det_ids[0]) << "\"";
for (int id = 1; id < exo_det_nbr(); id++)
output << ", \"" << getName(exo_det_ids[id]) << "\"";
output << "]" << endl
<< "model__.tex_exodetnames = [\"" << getTeXName(exo_det_ids[0]) << "\"";
for (int id = 1; id < exo_det_nbr(); id++)
output << ", \"" << getTeXName(exo_det_ids[id]) << "\"";
output << "]" << endl
<< "model__.long_exodetnames = [\"" << getLongName(exo_det_ids[0]) << "\"";
for (int id = 1; id < exo_det_nbr(); id++)
output << ", \"" << getLongName(exo_det_ids[id]) << "\"";
output << "]" << endl;
}
output << "# Endogenous Variables" << endl;
if (endo_nbr() > 0)
{
output << "model__.endonames = [\"" << getName(endo_ids[0]) << "\"";
for (int id = 1; id < endo_nbr(); id++)
output << ", \"" << getName(endo_ids[id]) << "\"";
output << "]" << endl
<< "model__.tex_endonames = [\"" << getTeXName(endo_ids[0]) << "\"";
for (int id = 1; id < endo_nbr(); id++)
output << ", \"" << getTeXName(endo_ids[id]) << "\"";
output << "]" << endl
<< "model__.long_endonames = [\"" << getLongName(endo_ids[0]) << "\"";
for (int id = 1; id < endo_nbr(); id++)
output << ", \"" << getLongName(endo_ids[id]) << "\"";
output << "]" << endl;
}
for (int id = 0; id < endo_nbr(); id++)
output << "push!(model__.endo, DynareModel.Endo(\""
<< getName(endo_ids[id]) << "\", \""
<< getTeXName(endo_ids[id]) << "\", \""
<< getLongName(endo_ids[id]) << "\"))" << endl;
output << "# Exogenous Variables" << endl;
if (exo_nbr() > 0)
for (int id = 0; id < exo_nbr(); id++)
output << "push!(model__.exo, DynareModel.Exo(\""
<< getName(exo_ids[id]) << "\", \""
<< getTeXName(exo_ids[id]) << "\", \""
<< getLongName(exo_ids[id]) << "\"))" << endl;
output << "# Exogenous Deterministic Variables" << endl;
if (exo_det_nbr() > 0)
for (int id = 0; id < exo_det_nbr(); id++)
output << "push!(model__.exo_det, DynareModel.ExoDet(\""
<< getName(exo_det_ids[id]) << "\", \""
<< getTeXName(exo_det_ids[id]) << "\", \""
<< getLongName(exo_det_ids[id]) << "\"))" << endl;
output << "# Parameters" << endl;
if (param_nbr() > 0)
{
output << "model__.paramnames = [\"" << getName(param_ids[0]) << "\"";
for (int id = 1; id < param_nbr(); id++)
output << ", \"" << getName(param_ids[id]) << "\"";
output << "]" << endl
<< "model__.tex_paramnames = [\"" << getTeXName(param_ids[0]) << "\"";
for (int id = 1; id < param_nbr(); id++)
output << ", \"" << getTeXName(param_ids[id]) << "\"";
output << "]" << endl
<< "model__.long_paramnames = [\"" << getLongName(param_ids[0]) << "\"";
for (int id = 1; id < param_nbr(); id++)
output << ", \"" << getLongName(param_ids[id]) << "\"";
output << "]" << endl;
}
for (int id = 0; id < param_nbr(); id++)
output << "push!(model__.param, DynareModel.Param(\""
<< getName(param_ids[id]) << "\", \""
<< getTeXName(param_ids[id]) << "\", \""
<< getLongName(param_ids[id]) << "\"))" << endl;
output << "model__.orig_endo_nbr = " << orig_endo_nbr() << endl;
if (aux_vars.size() > 0)
for (int i = 0; i < (int) aux_vars.size(); i++)
{
output << "push!(model__.aux_vars, "
<< getTypeSpecificID(aux_vars[i].get_symb_id()) + 1 << ", "
<< aux_vars[i].get_type() << ", ";
switch (aux_vars[i].get_type())
{
case avEndoLead:
case avExoLead:
break;
case avEndoLag:
case avExoLag:
output << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) + 1 << ", "
<< aux_vars[i].get_orig_lead_lag() << ", ";
break;
case avMultiplier:
output << "NaN, NaN, " << aux_vars[i].get_equation_number_for_multiplier() + 1 << ", " << endl;
break;
case avDiffForward:
output << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ", NaN, ";
break;
case avExpectation:
output << "NaN, NaN, NaN, \"\\mathbb{E}_{t"
<< (aux_vars[i].get_information_set() < 0 ? "" : "+")
<< aux_vars[i].get_information_set() << "}(";
aux_vars[i].get_expectation_expr_node()->writeOutput(output, oLatexDynamicModel);
output << ")\"" << endl;
break;
}
}
if (predeterminedNbr() > 0)
{
output << "model__.pred_vars = [ ";
for (set<int>::const_iterator it = predetermined_variables.begin();
it != predetermined_variables.end(); it++)
output << getTypeSpecificID(*it)+1 << "; ";
output << "];" << endl;
}
if (observedVariablesNbr() > 0)
{
output << "options_.obs_vars = [ ";
for (vector<int>::const_iterator it = varobs.begin();
it != varobs.end(); it++)
output << getTypeSpecificID(*it)+1 << "; ";
output << " ];" << endl;
}
}