completing replacement of auxiliary variables in static model
parent
5199638b3a
commit
2313f20a35
|
@ -143,8 +143,8 @@ end
|
||||||
% the auxiliary variables before the Lagrange multipliers are treated
|
% the auxiliary variables before the Lagrange multipliers are treated
|
||||||
% as ordinary endogenous variables
|
% as ordinary endogenous variables
|
||||||
aux_eq = [1:orig_endo_aux_nbr, orig_endo_aux_nbr+orig_eq_nbr+1:size(fJ,1)];
|
aux_eq = [1:orig_endo_aux_nbr, orig_endo_aux_nbr+orig_eq_nbr+1:size(fJ,1)];
|
||||||
A = fJ(aux_eq,orig_endo_aux_nbr+1:end);
|
A = fJ(1:orig_endo_nbr,orig_endo_nbr+find(aux_vars_type==6));
|
||||||
y = res(aux_eq);
|
y = res(1:orig_endo_nbr);
|
||||||
mult = -A\y;
|
mult = -A\y;
|
||||||
|
|
||||||
resids1 = y+A*mult;
|
resids1 = y+A*mult;
|
||||||
|
|
|
@ -125,7 +125,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
|
||||||
%check whether steady state really solves the model
|
%check whether steady state really solves the model
|
||||||
resids = evaluate_static_model(ys,exo_ss,params,M,options);
|
resids = evaluate_static_model(ys,exo_ss,params,M,options);
|
||||||
|
|
||||||
n_multipliers=M.endo_nbr-M.orig_endo_nbr;
|
n_multipliers=M.orig_eq_nbr;
|
||||||
nan_indices_multiplier=find(isnan(resids(1:n_multipliers)));
|
nan_indices_multiplier=find(isnan(resids(1:n_multipliers)));
|
||||||
nan_indices=find(isnan(resids(n_multipliers+1:end)));
|
nan_indices=find(isnan(resids(n_multipliers+1:end)));
|
||||||
|
|
||||||
|
@ -196,9 +196,12 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
|
||||||
elseif (options.bytecode == 0 && options.block == 0)
|
elseif (options.bytecode == 0 && options.block == 0)
|
||||||
if options.linear == 0
|
if options.linear == 0
|
||||||
% non linear model
|
% non linear model
|
||||||
[ys,check] = dynare_solve([M.fname '_static'],...
|
static_model = str2func([M.fname '_static']);
|
||||||
|
[ys,check] = dynare_solve(@static_problem,...
|
||||||
ys_init,...
|
ys_init,...
|
||||||
options, exo_ss, params);
|
options, exo_ss, params,...
|
||||||
|
M.orig_endo_nbr,...
|
||||||
|
static_model);
|
||||||
else
|
else
|
||||||
% linear model
|
% linear model
|
||||||
fh_static = str2func([M.fname '_static']);
|
fh_static = str2func([M.fname '_static']);
|
||||||
|
@ -294,3 +297,8 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
|
||||||
info(2) = NaN;
|
info(2) = NaN;
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function [resids,jac] = static_problem(y,x,params,nvar,fh_static_model)
|
||||||
|
[r,j] = fh_static_model(y,x,params);
|
||||||
|
resids = r(1:nvar);
|
||||||
|
jac = j(1:nvar,1:nvar);
|
||||||
|
|
|
@ -1052,17 +1052,11 @@ StaticModel::computingPass(const eval_context_t &eval_context, bool no_tmp_terms
|
||||||
initializeVariablesAndEquations();
|
initializeVariablesAndEquations();
|
||||||
|
|
||||||
vector<BinaryOpNode *> neweqs;
|
vector<BinaryOpNode *> neweqs;
|
||||||
for (unsigned int eq = 0; eq < equations.size(); eq++)
|
for (unsigned int eq = 0; eq < equations.size() - aux_equations.size(); eq++)
|
||||||
if (eq < equations.size() - aux_equations.size())
|
|
||||||
{
|
{
|
||||||
expr_t eq_tmp = equations[eq]->substituteStaticAuxiliaryVariable();
|
expr_t eq_tmp = equations[eq]->substituteStaticAuxiliaryVariable();
|
||||||
neweqs.push_back(dynamic_cast<BinaryOpNode *>(eq_tmp->toStatic(*this)));
|
neweqs.push_back(dynamic_cast<BinaryOpNode *>(eq_tmp->toStatic(*this)));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
expr_t eq_tmp = equations[eq]->substituteStaticAuxiliaryDefinition();
|
|
||||||
neweqs.push_back(dynamic_cast<BinaryOpNode *>(eq_tmp->toStatic(*this)));
|
|
||||||
}
|
|
||||||
|
|
||||||
equations.clear();
|
equations.clear();
|
||||||
copy(neweqs.begin(),neweqs.end(),back_inserter(equations));
|
copy(neweqs.begin(),neweqs.end(),back_inserter(equations));
|
||||||
|
@ -1070,7 +1064,11 @@ StaticModel::computingPass(const eval_context_t &eval_context, bool no_tmp_terms
|
||||||
set<int> vars;
|
set<int> vars;
|
||||||
|
|
||||||
for (int i = 0; i < symbol_table.endo_nbr(); i++)
|
for (int i = 0; i < symbol_table.endo_nbr(); i++)
|
||||||
vars.insert(getDerivID(symbol_table.getID(eEndogenous, i), 0));
|
{
|
||||||
|
int id = symbol_table.getID(eEndogenous, i);
|
||||||
|
if (!symbol_table.isAuxiliaryVariableButNotMultiplier(id))
|
||||||
|
vars.insert(getDerivID(id, 0));
|
||||||
|
}
|
||||||
|
|
||||||
// Launch computations
|
// Launch computations
|
||||||
cout << "Computing static model derivatives:" << endl
|
cout << "Computing static model derivatives:" << endl
|
||||||
|
@ -2126,7 +2124,7 @@ void StaticModel::writeAuxVarRecursiveDefinitions(const string &basename, const
|
||||||
|
|
||||||
for (int i = 0; i < (int) aux_equations.size(); i++)
|
for (int i = 0; i < (int) aux_equations.size(); i++)
|
||||||
{
|
{
|
||||||
dynamic_cast<ExprNode *>(aux_equations[i])->writeOutput(output, oMatlabStaticModel, temporary_terms, tef_terms);
|
dynamic_cast<ExprNode *>(aux_equations[i]->substituteStaticAuxiliaryDefinition())->writeOutput(output, oMatlabStaticModel, temporary_terms, tef_terms);
|
||||||
output << ";" << endl;
|
output << ";" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -786,6 +786,15 @@ SymbolTable::isAuxiliaryVariable(int symb_id) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
SymbolTable::isAuxiliaryVariableButNotMultiplier(int symb_id) const
|
||||||
|
{
|
||||||
|
for (int i = 0; i < (int) aux_vars.size(); i++)
|
||||||
|
if (aux_vars[i].get_symb_id() == symb_id && aux_vars[i].get_type() != avMultiplier)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
set<int>
|
set<int>
|
||||||
SymbolTable::getOrigEndogenous() const
|
SymbolTable::getOrigEndogenous() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -325,6 +325,8 @@ public:
|
||||||
set <int> getEndogenous() const;
|
set <int> getEndogenous() const;
|
||||||
//! Is a given symbol an auxiliary variable
|
//! Is a given symbol an auxiliary variable
|
||||||
bool isAuxiliaryVariable(int symb_id) const;
|
bool isAuxiliaryVariable(int symb_id) const;
|
||||||
|
//! Is a given symbol an auxiliary variable but not a Lagrange multiplier
|
||||||
|
bool isAuxiliaryVariableButNotMultiplier(int symb_id) const;
|
||||||
//! Get list of endogenous variables without aux vars
|
//! Get list of endogenous variables without aux vars
|
||||||
set <int> getOrigEndogenous() const;
|
set <int> getOrigEndogenous() const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue