NumericalInitialization.cc 4.42 KB
Newer Older
1
2
#include "NumericalInitialization.hh"
#include "Interface.hh"
3

sebastien's avatar
sebastien committed
4
5
6
7
8
9
InitParamStatement::InitParamStatement(const string &param_name_arg,
                                       const string &param_value_arg,
                                       const SymbolTable &symbol_table_arg) :
  param_name(param_name_arg),
  param_value(param_value_arg),
  symbol_table(symbol_table_arg)
10
11
12
{
}

sebastien's avatar
sebastien committed
13
14
void
InitParamStatement::writeOutput(ostream &output) const
15
{
sebastien's avatar
sebastien committed
16
17
18
  int id = symbol_table.getID(param_name) + 1;
  output << "M_.params( " << id << " ) = " << param_value << ";\n";
  output << param_name << " = M_.params( " << id << " );\n";
19
20
}

sebastien's avatar
sebastien committed
21
22
23
24
InitOrEndValStatement::InitOrEndValStatement(const init_values_type &init_values_arg,
                                             const SymbolTable &symbol_table_arg) :
  init_values(init_values_arg),
  symbol_table(symbol_table_arg)
25
26
27
{
}

sebastien's avatar
sebastien committed
28
29
void
InitOrEndValStatement::writeInitValues(ostream &output) const
30
{
sebastien's avatar
sebastien committed
31
32
  for(init_values_type::const_iterator it = init_values.begin();
      it != init_values.end(); it++)
33
    {
sebastien's avatar
sebastien committed
34
35
36
37
38
39
40
41
42
43
44
45
      const string &name = it->first;
      const string &expression = it->second;

      Type type = symbol_table.getType(name);
      int id = symbol_table.getID(name) + 1;

      if (type == eEndogenous)
        output << "oo_.steady_state( " << id << " ) = " << expression << ";\n";
      else if (type == eExogenous)
        output << "oo_.exo_steady_state( " << id << " ) = " << expression << ";\n";
      else if (type == eExogenousDet)
        output << "oo_.exo_det_steady_state( " << id << " ) = " << expression << ";\n";
46
47
48
    }
}

sebastien's avatar
sebastien committed
49
50
51
52
53
InitValStatement::InitValStatement(const init_values_type &init_values_arg,
                                   const SymbolTable &symbol_table_arg,
                                   const ModelParameters &mod_param_arg) :
  InitOrEndValStatement(init_values_arg, symbol_table_arg),
  mod_param(mod_param_arg)
54
{
sebastien's avatar
sebastien committed
55
}
56

sebastien's avatar
sebastien committed
57
58
59
60
61
void
InitValStatement::writeOutput(ostream &output) const
{
  output << interfaces::comment() << "\n" << interfaces::comment() << "INITVAL instructions \n"
         << interfaces::comment() << "\n";
62
  // Writing initval block to set initial values for variables
sebastien's avatar
sebastien committed
63
  output << "options_.initval_file = 0;\nendval_=0;\n";
64
65

  if (mod_param.recur_nbr > 0)
sebastien's avatar
sebastien committed
66
    output << "recurs_ = zeros(" << mod_param.recur_nbr << ", 1);\n";
67

sebastien's avatar
sebastien committed
68
  writeInitValues(output);
69

sebastien's avatar
sebastien committed
70
71
72
73
74
75
76
  output << "oo_.y_simul=[oo_.steady_state*ones(1,M_.maximum_lag)];\n";
  output << "if M_.exo_nbr > 0;\n";
  output << "\too_.exo_simul = [ones(M_.maximum_lag,1)*oo_.exo_steady_state'];\n";
  output <<"end;\n";
  output << "if M_.exo_det_nbr > 0;\n";
  output << "\too_.exo_det_simul = [ones(M_.maximum_lag,1)*oo_.exo_det_steady_state'];\n";
  output <<"end;\n";
77
78
}

sebastien's avatar
sebastien committed
79
80
81
82

EndValStatement::EndValStatement(const init_values_type &init_values_arg,
                                 const SymbolTable &symbol_table_arg) :
  InitOrEndValStatement(init_values_arg, symbol_table_arg)
83
84
85
{
}

sebastien's avatar
sebastien committed
86
87
88

void
EndValStatement::writeOutput(ostream &output) const
89
{
sebastien's avatar
sebastien committed
90
91
  output << interfaces::comment() << "\n" << interfaces::comment() << "ENDVAL instructions\n"
         << interfaces::comment() << "\n";
92
  // Writing endval block to set terminal values for variables
sebastien's avatar
sebastien committed
93
  output << "ys0_= oo_.steady_state;\nex0_ = oo_.exo_steady_state;\nrecurs0_ = recurs_;\nendval_ = 1;\n";
94

sebastien's avatar
sebastien committed
95
  writeInitValues(output);
96
97
}

sebastien's avatar
sebastien committed
98
99
100
101
HistValStatement::HistValStatement(const hist_values_type &hist_values_arg,
                                   const SymbolTable &symbol_table_arg) :
  hist_values(hist_values_arg),
  symbol_table(symbol_table_arg)
102
103
104
{
}

sebastien's avatar
sebastien committed
105
106
void
HistValStatement::writeOutput(ostream &output) const
107
{
sebastien's avatar
sebastien committed
108
109
  output << interfaces::comment() << "\n" << interfaces::comment() << "HISTVAL instructions\n"
         << interfaces::comment() << "\n";
110

sebastien's avatar
sebastien committed
111
112
  for(hist_values_type::const_iterator it = hist_values.begin();
      it != hist_values.end(); it++)
113
    {
sebastien's avatar
sebastien committed
114
115
116
117
118
119
120
121
122
123
124
125
126
      const string &name = it->first.first;
      const int &lag = it->first.second;
      const string &expression = it->second;

      Type type = symbol_table.getType(name);
      int id = symbol_table.getID(name) + 1;

      if (type == eEndogenous)
        output << "oo_.endo_simul( " << id << ", M_.maximum_lag + " << lag + 1 << ") = " << expression << ";\n";
      else if (type == eExogenous)
        output << "oo_.exo_simul( M_.maximum_lag + " << lag + 1 << ", " << id << " ) = " << expression << ";\n";
      else if (type != eExogenousDet)
        output << "oo_.exo_det_simul( M_.maximum_lag + " << lag + 1 << ", " << id << " ) = " << expression << ";\n";
127
128
    }
}