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
Dynare
preprocessor
Commits
7fb59164
Verified
Commit
7fb59164
authored
May 03, 2019
by
Houtan Bastani
Browse files
fix bug in pac equation: match terms of param*linear_expression
parent
82cd95a6
Pipeline
#1195
passed with stage
in 1 minute and 33 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/ExprNode.cc
View file @
7fb59164
...
...
@@ -5681,33 +5681,56 @@ BinaryOpNode::getPacAREC(int lhs_symb_id, int lhs_orig_symb_id,
if (dynamic_cast<PacExpectationNode *>(it.first))
continue;
int pid, vid, lag;
double constant;
pair<int, vector<tuple<int, int, int, double>>> m;
try
{
tie(vid, lag, pid, constant) = it.first->matchVariableTimesConstantTimesParam();
constant *= it.second;
m = {-1, {it.first->matchVariableTimesConstantTimesParam()}};
}
catch (MatchFailureException &e)
{
cerr << "Unsupported expression in PAC equation" << endl;
exit(EXIT_FAILURE);
try
{
m = it.first->matchParamTimesLinearCombinationOfVariables();
}
catch (MatchFailureException &e)
{
cerr << "Unsupported expression in PAC equation" << endl;
exit(EXIT_FAILURE);
}
}
int vidorig = datatree.symbol_table.getUltimateOrigSymbID(vid);
if (vidorig == lhs_symb_id || vidorig == lhs_orig_symb_id)
for (auto &t : m.second)
get<3>(t) *= it.second; // Update sign of constants
int vid, lag, pidtmp, pid = get<0>(m);
double constant;
for (auto &t : m.second)
{
// This is an autoregressive term
if (constant != 1 || pid == -1)
tie(vid, lag, pidtmp, constant) = t;
if (pid == -1)
pid = pidtmp;
else
if (pidtmp >= 0)
{
cerr << "unexpected parameter found in PAC equation" << endl;
exit(EXIT_FAILURE);
}
int vidorig = datatree.symbol_table.getUltimateOrigSymbID(vid);
if (vidorig == lhs_symb_id || vidorig == lhs_orig_symb_id)
{
cerr << "BinaryOpNode::getPacAREC: autoregressive terms must be of the form 'parameter*lagged_variable" << endl;
exit(EXIT_FAILURE);
// This is an autoregressive term
if (constant != 1 || pid == -1)
{
cerr << "BinaryOpNode::getPacAREC: autoregressive terms must be of the form 'parameter*lagged_variable" << endl;
exit(EXIT_FAILURE);
}
ar_params_and_vars.insert({pid, { vid, lag }});
}
ar_params_and_vars.insert({pid, { vid, lag }});
else
// This is a residual additive term
additive_vars_params_and_constants.emplace_back(vid, lag, pid, constant);
}
else
// This is a residual additive term
additive_vars_params_and_constants.emplace_back(vid, lag, pid, constant);
}
}
...
...
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