trend_component_model: simplify AR
parent
a3c08f932e
commit
f1d1c1e1c1
|
@ -4043,7 +4043,7 @@ DynamicModel::fillVarModelTable() const
|
|||
var_model_table.setLhsExprT(lhs_expr_tr);
|
||||
|
||||
// Fill AR Matrix
|
||||
var_model_table.setAR(fillAutoregressiveMatrixForVAR());
|
||||
var_model_table.setAR(fillAutoregressiveMatrix(true));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -4114,37 +4114,27 @@ DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
|
|||
}
|
||||
|
||||
map<string, map<tuple<int, int, int>, expr_t>>
|
||||
DynamicModel::fillAutoregressiveMatrixForVAR() const
|
||||
DynamicModel::fillAutoregressiveMatrix(bool is_var) const
|
||||
{
|
||||
map<string, map<tuple<int, int, int>, expr_t>> ARr;
|
||||
for (const auto & it : var_model_table.getEqNums())
|
||||
auto eqnums = is_var ?
|
||||
var_model_table.getEqNums() : trend_component_model_table.getNonTargetEqNums();
|
||||
for (const auto & it : eqnums)
|
||||
{
|
||||
int i = 0;
|
||||
map<tuple<int, int, int>, expr_t> AR;
|
||||
vector<int> lhs = is_var ?
|
||||
var_model_table.getLhsOrigIds(it.first) : trend_component_model_table.getNonTargetLhs(it.first);
|
||||
for (auto eqn : it.second)
|
||||
{
|
||||
auto *bopn = dynamic_cast<BinaryOpNode *>(equations[eqn]->arg2);
|
||||
bopn->fillAutoregressiveRowForVAR(i++, var_model_table.getLhsOrigIds(it.first), AR);
|
||||
bopn->fillAutoregressiveRow(i++, lhs, AR);
|
||||
}
|
||||
ARr[it.first] = AR;
|
||||
}
|
||||
return ARr;
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::fillAutoregressiveMatrix(map<string, map<tuple<int, int, int>, expr_t>> &ARr) const
|
||||
{
|
||||
for (const auto & it : trend_component_model_table.getNonTargetEqNums())
|
||||
{
|
||||
int i = 0;
|
||||
map<tuple<int, int, int>, expr_t> AR;
|
||||
vector<int> lhs = trend_component_model_table.getNonTargetLhs(it.first);
|
||||
for (auto eqn : it.second)
|
||||
equations[eqn]->arg2->fillAutoregressiveRow(i++, lhs, AR);
|
||||
ARr[it.first] = AR;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::fillTrendComponentModelTable() const
|
||||
{
|
||||
|
@ -4348,7 +4338,7 @@ void
|
|||
DynamicModel::fillTrendComponentmodelTableAREC(ExprNode::subst_table_t &diff_subst_table) const
|
||||
{
|
||||
map<string, map<tuple<int, int, int>, expr_t>> ARr, A0r, A0starr;
|
||||
fillAutoregressiveMatrix(ARr);
|
||||
ARr = fillAutoregressiveMatrix(false);
|
||||
trend_component_model_table.setAR(ARr);
|
||||
fillErrorComponentMatrix(A0r, A0starr, diff_subst_table);
|
||||
trend_component_model_table.setA0(A0r, A0starr);
|
||||
|
|
|
@ -316,11 +316,8 @@ public:
|
|||
//! Set the equations that have non-zero second derivatives
|
||||
void setNonZeroHessianEquations(map<int, string> &eqs);
|
||||
|
||||
//! Fill Autoregressive Matrix for trend_component_model
|
||||
void fillAutoregressiveMatrix(map<string, map<tuple<int, int, int>, expr_t>> &ARr) const;
|
||||
|
||||
//! Fill Autoregressive Matrix for var_model
|
||||
map<string, map<tuple<int, int, int>, expr_t>> fillAutoregressiveMatrixForVAR() const;
|
||||
map<string, map<tuple<int, int, int>, expr_t>> fillAutoregressiveMatrix(bool is_var) const;
|
||||
|
||||
//! Fill Error Component Matrix for trend_component_model
|
||||
void fillErrorComponentMatrix(map<string, map<tuple<int, int, int>, expr_t>> &A0r, map<string, map<tuple<int, int, int>, expr_t>> &A0starr, ExprNode::subst_table_t &diff_subst_table) const;
|
||||
|
|
110
src/ExprNode.cc
110
src/ExprNode.cc
|
@ -686,11 +686,6 @@ NumConstNode::substituteStaticAuxiliaryVariable() const
|
|||
return const_cast<NumConstNode *>(this);
|
||||
}
|
||||
|
||||
void
|
||||
NumConstNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
NumConstNode::fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const
|
||||
{
|
||||
|
@ -1979,11 +1974,6 @@ VariableNode::getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const
|
|||
model_endos_and_lags[varname] = lag;
|
||||
}
|
||||
|
||||
void
|
||||
VariableNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
VariableNode::fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const
|
||||
{
|
||||
|
@ -3794,12 +3784,6 @@ UnaryOpNode::substituteStaticAuxiliaryVariable() const
|
|||
return buildSimilarUnaryOpNode(argsubst, datatree);
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
arg->fillAutoregressiveRow(eqn, lhs, AR);
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const
|
||||
{
|
||||
|
@ -5853,73 +5837,8 @@ BinaryOpNode::getPacOptimizingShareAndExprNodes(int lhs_symb_id, int lhs_orig_sy
|
|||
return {optim_share, optim_part, non_optim_part, additive_part};
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::fillAutoregressiveRowHelper(expr_t arg1, expr_t arg2,
|
||||
int eqn,
|
||||
const vector<int> &lhs,
|
||||
map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
if (op_code != BinaryOpcode::times)
|
||||
return;
|
||||
|
||||
set<pair<int, int>> endogs, tmp;
|
||||
arg1->collectDynamicVariables(SymbolType::endogenous, tmp);
|
||||
arg1->collectDynamicVariables(SymbolType::exogenous, tmp);
|
||||
if (tmp.size() != 0)
|
||||
return;
|
||||
|
||||
arg1->collectDynamicVariables(SymbolType::parameter, tmp);
|
||||
if (tmp.size() != 1)
|
||||
return;
|
||||
|
||||
auto *vn = dynamic_cast<VariableNode *>(arg2);
|
||||
if (vn == nullptr)
|
||||
return;
|
||||
|
||||
arg2->collectDynamicVariables(SymbolType::exogenous, endogs);
|
||||
if (endogs.size() != 0)
|
||||
{
|
||||
cerr << "BinaryOpNode::fillAutoregressiveRowHelper: do not currently support param*exog;" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
arg2->collectDynamicVariables(SymbolType::endogenous, endogs);
|
||||
if (endogs.size() != 1)
|
||||
return;
|
||||
|
||||
int lhs_symb_id = endogs.begin()->first;
|
||||
int lag = endogs.begin()->second;
|
||||
if (datatree.symbol_table.isAuxiliaryVariable(lhs_symb_id))
|
||||
{
|
||||
int orig_lhs_symb_id = datatree.symbol_table.getOrigSymbIdForDiffAuxVar(lhs_symb_id);
|
||||
if (find(lhs.begin(), lhs.end(), orig_lhs_symb_id) == lhs.end())
|
||||
return;
|
||||
lag = -1 * datatree.symbol_table.getOrigLeadLagForDiffAuxVar(lhs_symb_id);
|
||||
lhs_symb_id = orig_lhs_symb_id;
|
||||
}
|
||||
else
|
||||
if (find(lhs.begin(), lhs.end(), lhs_symb_id) == lhs.end())
|
||||
return;
|
||||
|
||||
if (AR.find({eqn, -lag, lhs_symb_id}) != AR.end())
|
||||
{
|
||||
cerr << "BinaryOpNode::fillAutoregressiveRowHelper: Error filling AR matrix: lag/symb_id encountered more than once in equtaion" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
AR[{eqn, -lag, lhs_symb_id}] = arg1;
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
fillAutoregressiveRowHelper(arg1, arg2, eqn, lhs, AR);
|
||||
fillAutoregressiveRowHelper(arg2, arg1, eqn, lhs, AR);
|
||||
arg1->fillAutoregressiveRow(eqn, lhs, AR);
|
||||
arg2->fillAutoregressiveRow(eqn, lhs, AR);
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::fillAutoregressiveRowForVAR(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
vector<pair<expr_t, int>> terms;
|
||||
decomposeAdditiveTerms(terms, 1);
|
||||
|
@ -7100,14 +7019,6 @@ TrinaryOpNode::substituteStaticAuxiliaryVariable() const
|
|||
return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree);
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
arg1->fillAutoregressiveRow(eqn, lhs, AR);
|
||||
arg2->fillAutoregressiveRow(eqn, lhs, AR);
|
||||
arg3->fillAutoregressiveRow(eqn, lhs, AR);
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const
|
||||
{
|
||||
|
@ -7736,13 +7647,6 @@ AbstractExternalFunctionNode::substituteStaticAuxiliaryVariable() const
|
|||
return buildSimilarExternalFunctionNode(arguments_subst, datatree);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractExternalFunctionNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
cerr << "External functions not supported in VARs or Trend Component Models" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractExternalFunctionNode::fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const
|
||||
{
|
||||
|
@ -9254,13 +9158,6 @@ VarExpectationNode::substituteStaticAuxiliaryVariable() const
|
|||
return const_cast<VarExpectationNode *>(this);
|
||||
}
|
||||
|
||||
void
|
||||
VarExpectationNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
cerr << "Var Expectation not supported in VARs or Trend Component Models" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void
|
||||
VarExpectationNode::fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const
|
||||
{
|
||||
|
@ -9670,13 +9567,6 @@ PacExpectationNode::substituteStaticAuxiliaryVariable() const
|
|||
return const_cast<PacExpectationNode *>(this);
|
||||
}
|
||||
|
||||
void
|
||||
PacExpectationNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const
|
||||
{
|
||||
cerr << "Pac Expectation not supported in VARs" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void
|
||||
PacExpectationNode::fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const
|
||||
{
|
||||
|
|
|
@ -593,9 +593,6 @@ class ExprNode
|
|||
//! param * (endog op endog op ...) + param * (endog op endog op ...) + ...
|
||||
virtual bool isParamTimesEndogExpr() const = 0;
|
||||
|
||||
//! Fills the AR matrix structure
|
||||
virtual void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const = 0;
|
||||
|
||||
//! Fills the EC matrix structure
|
||||
virtual void fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs,
|
||||
map<tuple<int, int, int>, expr_t> &A0,
|
||||
|
@ -718,7 +715,6 @@ public:
|
|||
expr_t clone(DataTree &datatree) const override;
|
||||
expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const override;
|
||||
bool isInStaticForm() const override;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const override;
|
||||
void fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const override;
|
||||
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
|
@ -803,7 +799,6 @@ public:
|
|||
expr_t clone(DataTree &datatree) const override;
|
||||
expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const override;
|
||||
bool isInStaticForm() const override;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const override;
|
||||
void fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const override;
|
||||
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
|
@ -916,7 +911,6 @@ public:
|
|||
expr_t clone(DataTree &datatree) const override;
|
||||
expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const override;
|
||||
bool isInStaticForm() const override;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const override;
|
||||
void fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const override;
|
||||
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
|
@ -1038,10 +1032,7 @@ public:
|
|||
//! Returns the non-zero hand-side of an equation (that must have a hand side equal to zero)
|
||||
expr_t getNonZeroPartofEquation() const;
|
||||
bool isInStaticForm() const override;
|
||||
void fillAutoregressiveRowHelper(expr_t arg1, expr_t arg2,
|
||||
int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const override;
|
||||
void fillAutoregressiveRowForVAR(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const;
|
||||
void fillErrorCorrectionRowHelper(expr_t arg1, expr_t arg2,
|
||||
int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs,
|
||||
map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const;
|
||||
|
@ -1167,7 +1158,6 @@ public:
|
|||
expr_t clone(DataTree &datatree) const override;
|
||||
expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const override;
|
||||
bool isInStaticForm() const override;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const override;
|
||||
void fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const override;
|
||||
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
|
@ -1289,7 +1279,6 @@ public:
|
|||
expr_t clone(DataTree &datatree) const override = 0;
|
||||
expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const override;
|
||||
bool isInStaticForm() const override;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const override;
|
||||
void fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const override;
|
||||
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
|
@ -1499,7 +1488,6 @@ public:
|
|||
expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override;
|
||||
expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const override;
|
||||
bool isInStaticForm() const override;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const override;
|
||||
void fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const override;
|
||||
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
|
@ -1582,7 +1570,6 @@ public:
|
|||
expr_t detrend(int symb_id, bool log_trend, expr_t trend) const override;
|
||||
expr_t removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const override;
|
||||
bool isInStaticForm() const override;
|
||||
void fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<int, int, int>, expr_t> &AR) const override;
|
||||
void fillErrorCorrectionRow(int eqn, const vector<int> &nontrend_lhs, const vector<int> &trend_lhs, map<tuple<int, int, int>, expr_t> &A0, map<tuple<int, int, int>, expr_t> &A0star) const override;
|
||||
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
|
||||
|
|
Loading…
Reference in New Issue