Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dóra Kocsis
dynare
Commits
dfa744fc
Commit
dfa744fc
authored
Mar 22, 2013
by
Ferhat Mihoubi
Browse files
- adds new files: Evaluate.cc and Evaluate.hh to bytecode
parent
5c2a6b80
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
mex/sources/bytecode/Evaluate.cc
0 → 100644
View file @
dfa744fc
This diff is collapsed.
Click to expand it.
mex/sources/bytecode/Evaluate.hh
0 → 100644
View file @
dfa744fc
/*
* Copyright (C) 2007-2012 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/>.
*/
#ifndef EVALUATE_HH_INCLUDED
#define EVALUATE_HH_INCLUDED
#include <stack>
#include <vector>
#include <string>
#include <cmath>
#define BYTE_CODE
#include "CodeInterpreter.hh"
#ifdef LINBCG
# include "linbcg.hh"
#endif
#ifndef DEBUG_EX
# include <dynmex.h>
#else
# include "mex_interface.hh"
#endif
#include "ErrorHandling.hh"
#define pow_ pow
class
Evaluate
:
public
ErrorMsg
{
private:
unsigned
int
EQN_dvar1
,
EQN_dvar2
,
EQN_dvar3
;
int
EQN_lag1
,
EQN_lag2
,
EQN_lag3
;
protected:
mxArray
*
GlobalTemporaryTerms
;
it_code_type
start_code
,
end_code
;
double
pow1
(
double
a
,
double
b
);
double
divide
(
double
a
,
double
b
);
double
log1
(
double
a
);
double
log10_1
(
double
a
);
void
evaluate_over_periods
(
const
bool
forward
);
void
solve_simple_one_periods
();
void
solve_simple_over_periods
(
const
bool
forward
);
void
compute_block_time
(
const
int
Per_u_
,
const
bool
evaluate
,
const
bool
no_derivatives
);
code_liste_type
code_liste
;
it_code_type
it_code
;
int
Block_Count
,
Per_u_
,
Per_y_
;
int
it_
;
int
maxit_
,
size_of_direction
;
double
*
direction
;
double
solve_tolf
;
bool
GaussSeidel
;
map
<
pair
<
pair
<
int
,
int
>
,
int
>
,
int
>
IM_i
;
int
equation
,
derivative_equation
,
derivative_variable
;
string
filename
;
int
stack_solve_algo
,
solve_algo
;
bool
global_temporary_terms
;
bool
print
,
print_error
;
double
res1
,
res2
,
max_res
;
int
max_res_idx
;
vector
<
Block_contain_type
>
Block_Contain
;
int
size
;
int
*
index_vara
;
bool
print_it
,
forward
;
int
minimal_solving_periods
;
int
type
,
block_num
,
symbol_table_endo_nbr
,
Block_List_Max_Lag
,
Block_List_Max_Lead
,
u_count_int
,
block
;
string
file_name
,
bin_base_name
;
bool
Gaussian_Elimination
,
is_linear
;
public:
bool
steady_state
;
Evaluate
();
Evaluate
(
const
int
y_size_arg
,
const
int
y_kmin_arg
,
const
int
y_kmax_arg
,
const
bool
print_it_arg
,
const
bool
steady_state_arg
,
const
int
periods_arg
,
const
int
minimal_solving_periods_arg
);
//typedef void (Interpreter::*InterfpreterMemFn)(const int block_num, const int size, const bool steady_state, int it);
void
set_block
(
const
int
size_arg
,
const
int
type_arg
,
string
file_name_arg
,
string
bin_base_name_arg
,
const
int
block_num_arg
,
const
bool
is_linear_arg
,
const
int
symbol_table_endo_nbr_arg
,
const
int
Block_List_Max_Lag_arg
,
const
int
Block_List_Max_Lead_arg
,
const
int
u_count_int_arg
,
const
int
block_arg
);
void
evaluate_complete
(
const
bool
no_derivatives
);
bool
compute_complete
(
const
bool
no_derivatives
,
double
&
res1
,
double
&
res2
,
double
&
max_res
,
int
&
max_res_idx
);
void
compute_complete_2b
(
const
bool
no_derivatives
,
double
*
_res1
,
double
*
_res2
,
double
*
_max_res
,
int
*
_max_res_idx
);
bool
compute_complete
(
double
lambda
,
double
*
crit
);
};
#endif
preprocessor/DynamicModel.cc
View file @
dfa744fc
...
...
@@ -3715,6 +3715,19 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context
}
}
void
DynamicModel
::
print_trend_vars
()
{
for
(
trend_symbols_map_t
::
const_iterator
it
=
nonstationary_symbols_map
.
begin
();
it
!=
nonstationary_symbols_map
.
end
();
it
++
)
{
cout
<<
"it->first:"
<<
symbol_table
.
getName
(
it
->
first
)
<<
" "
;
it
->
second
->
print_deflator
();
cout
<<
endl
;
}
}
void
DynamicModel
::
writeParamsDerivativesFile
(
const
string
&
basename
)
const
{
...
...
preprocessor/DynamicModel.hh
View file @
dfa744fc
...
...
@@ -230,6 +230,7 @@ public:
virtual
int
getDerivID
(
int
symb_id
,
int
lag
)
const
throw
(
UnknownDerivIDException
);
virtual
int
getDynJacobianCol
(
int
deriv_id
)
const
throw
(
UnknownDerivIDException
);
virtual
void
addAllParamDerivId
(
set
<
int
>
&
deriv_id_set
);
void
print_trend_vars
();
//! Returns true indicating that this is a dynamic model
virtual
bool
...
...
preprocessor/ExprNode.cc
View file @
dfa744fc
...
...
@@ -175,6 +175,64 @@ ExprNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output
// Nothing to do
}
void
ExprNode
::
print_deflator
()
{
}
void
VariableNode
::
print_deflator
()
{
cout
<<
datatree
.
symbol_table
.
getName
(
symb_id
);
}
void
UnaryOpNode
::
print_deflator
()
{
arg
->
print_deflator
();
}
void
BinaryOpNode
::
print_deflator
()
{
arg1
->
print_deflator
();
arg2
->
print_deflator
();
}
void
TrinaryOpNode
::
print_deflator
()
{
arg1
->
print_deflator
();
arg2
->
print_deflator
();
arg3
->
print_deflator
();
}
void
ExternalFunctionNode
::
print_deflator
()
{
}
void
FirstDerivExternalFunctionNode
::
print_deflator
()
{
}
void
SecondDerivExternalFunctionNode
::
print_deflator
()
{
}
void
ExprNode
::
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
...
...
@@ -297,6 +355,12 @@ NumConstNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, t
temporary_terms_inuse
.
insert
(
idx
);
}
void
NumConstNode
::
print_deflator
()
{
}
void
NumConstNode
::
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
...
...
preprocessor/ExprNode.hh
View file @
dfa744fc
...
...
@@ -284,6 +284,7 @@ public:
//! Returns the relative period of the most forward term in this expression
/*! A negative value means that the expression contains only lagged variables */
virtual
int
maxLead
()
const
=
0
;
virtual
void
print_deflator
();
//! Returns a new expression where all the leads/lags have been shifted backwards by the same amount
/*!
...
...
@@ -455,6 +456,7 @@ public:
virtual
expr_t
detrend
(
int
symb_id
,
expr_t
trend
)
const
;
virtual
expr_t
cloneDynamic
(
DataTree
&
dynamic_datatree
)
const
;
virtual
expr_t
removeTrendLeadLag
(
map
<
int
,
expr_t
>
trend_symbols_map
)
const
;
virtual
void
print_deflator
();
};
//! Symbol or variable node
...
...
@@ -483,6 +485,7 @@ public:
virtual
double
eval
(
const
eval_context_t
&
eval_context
)
const
throw
(
EvalException
,
EvalExternalFunctionException
);
virtual
void
compile
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
expr_t
toStatic
(
DataTree
&
static_datatree
)
const
;
virtual
void
print_deflator
();
SymbolType
get_type
()
const
{
...
...
@@ -554,6 +557,7 @@ public:
virtual
void
collectTemporary_terms
(
const
temporary_terms_t
&
temporary_terms
,
temporary_terms_inuse_t
&
temporary_terms_inuse
,
int
Curr_Block
)
const
;
static
double
eval_opcode
(
UnaryOpcode
op_code
,
double
v
)
throw
(
EvalException
,
EvalExternalFunctionException
);
virtual
double
eval
(
const
eval_context_t
&
eval_context
)
const
throw
(
EvalException
,
EvalExternalFunctionException
);
virtual
void
print_deflator
();
virtual
void
compile
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
//! Returns operand
expr_t
...
...
@@ -633,6 +637,7 @@ public:
virtual
double
eval
(
const
eval_context_t
&
eval_context
)
const
throw
(
EvalException
,
EvalExternalFunctionException
);
virtual
void
compile
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
expr_t
Compute_RHS
(
expr_t
arg1
,
expr_t
arg2
,
int
op
,
int
op_type
)
const
;
virtual
void
print_deflator
();
//! Returns first operand
expr_t
get_arg1
()
const
...
...
@@ -733,6 +738,7 @@ public:
virtual
int
maxEndoLag
()
const
;
virtual
int
maxExoLag
()
const
;
virtual
int
maxLead
()
const
;
virtual
void
print_deflator
();
virtual
expr_t
decreaseLeadsLags
(
int
n
)
const
;
virtual
expr_t
substituteEndoLeadGreaterThanTwo
(
subst_table_t
&
subst_table
,
vector
<
BinaryOpNode
*>
&
neweqs
,
bool
deterministic_model
)
const
;
//! Creates another TrinaryOpNode with the same opcode, but with a possibly different datatree and arguments
...
...
@@ -797,6 +803,7 @@ public:
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
print_deflator
();
virtual
void
compile
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
expr_t
toStatic
(
DataTree
&
static_datatree
)
const
;
...
...
@@ -855,6 +862,7 @@ public:
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
print_deflator
();
};
class
SecondDerivExternalFunctionNode
:
public
ExternalFunctionNode
...
...
@@ -880,6 +888,7 @@ public:
virtual
void
writeExternalFunctionOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
print_deflator
();
};
#endif
preprocessor/ModFile.cc
View file @
dfa744fc
...
...
@@ -107,6 +107,7 @@ ModFile::addStatementAtFront(Statement *st)
void
ModFile
::
checkPass
()
{
dynamic_model
.
print_trend_vars
();
for
(
vector
<
Statement
*>::
iterator
it
=
statements
.
begin
();
it
!=
statements
.
end
();
it
++
)
(
*
it
)
->
checkPass
(
mod_file_struct
,
warnings
);
...
...
@@ -374,8 +375,8 @@ ModFile::computingPass(bool no_tmp_terms)
// Mod file may have no equation (for example in a standalone BVAR estimation)
if
(
dynamic_model
.
equation_number
()
>
0
)
{
if
(
nonstationary_variables
)
trend_dynamic_model
.
runTrendTest
(
global_eval_context
);
/*
if (nonstationary_variables)
trend_dynamic_model.runTrendTest(global_eval_context);
*/
// Compute static model and its derivatives
dynamic_model
.
toStatic
(
static_model
);
...
...
preprocessor/ModelTree.cc
View file @
dfa744fc
...
...
@@ -1002,14 +1002,21 @@ ModelTree::computeJacobian(const set<int> &vars)
{
for
(
set
<
int
>::
const_iterator
it
=
vars
.
begin
();
it
!=
vars
.
end
();
it
++
)
for
(
int
eq
=
0
;
eq
<
(
int
)
equations
.
size
();
eq
++
)
{
expr_t
d1
=
equations
[
eq
]
->
getDerivative
(
*
it
);
if
(
d1
==
Zero
)
continue
;
first_derivatives
[
make_pair
(
eq
,
*
it
)]
=
d1
;
++
NNZDerivatives
[
0
];
}
{
int
prev_deriv
=
NNZDerivatives
[
0
];
for
(
int
eq
=
0
;
eq
<
(
int
)
equations
.
size
();
eq
++
)
{
expr_t
d1
=
equations
[
eq
]
->
getDerivative
(
*
it
);
if
(
d1
==
Zero
)
continue
;
first_derivatives
[
make_pair
(
eq
,
*
it
)]
=
d1
;
++
NNZDerivatives
[
0
];
}
if
(
NNZDerivatives
[
0
]
==
prev_deriv
)
{
cout
<<
"the derivatives w.r. to "
<<
symbol_table
.
getName
(
*
it
)
<<
" is always equal to 0
\n
"
;
}
}
}
void
...
...
tests/conditional_forecasts/fs2000_cal.mod
View file @
dfa744fc
...
...
@@ -13,6 +13,7 @@ rho = 0.7;
psi = 0.787;
del = 0.02;
//model(block, bytecode);
model;
dA = exp(gam+e_a);
log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
...
...
@@ -56,19 +57,39 @@ steady;
check;
stoch_simul(irf=0);
//
stoch_simul(irf=0);
conditional_forecast_paths;
var gp_obs;
periods 1 2:5;
//values 0.05;
//values 0.98 1.00797;
values 0.98 0.99;
//expectation perfect_foresight;
var gy_obs;
periods 1 2 3:5;
values 0.01 -0.02 0;
var gp_obs
;
periods 1:5
;
values 0.05
;
//
values 0.01 -0.02 0;
//values 0.85 0.85 0.95
;
values 0.95 0.95 0.99
;
//expectation perfect_foresight
;
end;
conditional_forecast(parameter_set=calibration, controlled_varexo=(e_a,e_m));
options_.stack_solve_algo = 0;
options_.maxit_ = 50;
if ~(exist('OCTAVE_VERSION') && octave_ver_less_than('3.4.0'))
plot_conditional_forecast(periods=10) gy_obs gp_obs;
end
conditional_forecast(parameter_set=calibration, controlled_varexo=(e_m,e_a), simulation_type = deterministic);
/*shocks;
var e_a;
periods 1 2 3 4 5;
values -0.0109 -0.0122 -0.0137 -0.0154 -0.0173;
var e_m;
periods 1 2 3 4 5;
values -0.1242 -0.0386 -0.0392 -0.0398 -0.0405;
end;
simul(periods=40);*/
rplot gy_obs;
rplot gp_obs;
//if ~(exist('OCTAVE_VERSION') && octave_ver_less_than('3.4.0'))
//plot_conditional_forecast(periods=10) gy_obs gp_obs;
//end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment