Commit 1aceb504 authored by Ferhat Mihoubi's avatar Ferhat Mihoubi
Browse files

Check command is now compatible with block and bytecode options

parent 36941dd7
function [r, g1] = block_bytecode_mfs_steadystate(y, b)
function [r, g1] = block_bytecode_mfs_steadystate(y, b, y_all)
% Wrapper around the *_static.m file, for use with dynare_solve,
% when block_mfs option is given to steady.
......@@ -20,8 +20,7 @@ function [r, g1] = block_bytecode_mfs_steadystate(y, b)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global M_ oo_
ss = oo_.steady_state;
indx = M_.blocksMFS{b};
ss(indx) = y;
y_all(indx) = y;
x = [oo_.exo_steady_state; oo_.exo_det_steady_state];
eval(['[chk, r, g1] = bytecode( ss, x, M_.params, 1, ss, ''evaluate'', ''static'', ''block = ' int2str(b) ''');']);
\ No newline at end of file
eval(['[chk, r, g1] = bytecode( y_all, x, M_.params, 1, y_all, ''evaluate'', ''static'', ''block = ' int2str(b) ''');']);
\ No newline at end of file
function [r, g1] = block_mfs_steadystate(y, b)
function [r, g1] = block_mfs_steadystate(y, b, y_all)
% Wrapper around the *_static.m file, for use with dynare_solve,
% when block_mfs option is given to steady.
......@@ -21,10 +21,9 @@ function [r, g1] = block_mfs_steadystate(y, b)
global M_ oo_
ss = oo_.steady_state;
indx = M_.blocksMFS{b};
ss(indx) = y;
y_all(indx) = y;
x = [oo_.exo_steady_state; oo_.exo_det_steady_state];
eval(['[r,g1] = ' M_.fname '_static(b, ss, x, M_.params);']);
eval(['[r,g1] = ' M_.fname '_static(b, y_all, x, M_.params);']);
......@@ -30,9 +30,6 @@ function [result,info] = check
global M_ options_ oo_
if options_.block || options_.bytecode
error('CHECK: incompatibility with "block" or "bytecode" option')
end
temp_options = options_;
tempex = oo_.exo_simul;
......@@ -53,7 +50,11 @@ end
oo_.exo_simul = tempex;
eigenvalues_ = dr.eigval;
nyf = nnz(dr.kstate(:,2)>M_.maximum_endo_lag+1);
if (options_.block)
nyf = dr.nfwrd;
else
nyf = nnz(dr.kstate(:,2)>M_.maximum_endo_lag+1);
end;
[m_lambda,i]=sort(abs(eigenvalues_));
n_explod = nnz(abs(eigenvalues_) > options_.qz_criterium);
......
......@@ -161,10 +161,18 @@ else
it_ = M_.maximum_lag + 1;
z = repmat(dr.ys,1,klen);
z = z(iyr0) ;
if ~options_.bytecode
z = z(iyr0) ;
end;
if options_.order == 1
[junk,jacobia_] = feval([M_.fname '_dynamic'],z,[oo_.exo_simul ...
oo_.exo_det_simul], M_.params, it_);
if (options_.bytecode)
jacobia_ = [];
[chck, junk, jacobia_] = bytecode('dynamic','evaluate', z,[oo_.exo_simul ...
oo_.exo_det_simul], M_.params, 1, jacobia_);
else
[junk,jacobia_] = feval([M_.fname '_dynamic'],z,[oo_.exo_simul ...
oo_.exo_det_simul], M_.params, it_);
end;
elseif options_.order == 2
[junk,jacobia_,hessian1] = feval([M_.fname '_dynamic'],z,...
[oo_.exo_simul ...
......
function [x,info] = dynare_solve_block_or_bytecode(y, exo, params)
% Copyright (C) 1996-2010 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/>.
global options_ M_
info = 0;
x = y;
if options_.block && ~options_.bytecode
for b = 1:size(M_.blocksMFS,1)
n = size(M_.blocksMFS{b}, 1);
ss = x;
if n ~= 0
if options_.solve_algo <= 4
[y, check] = dynare_solve('block_mfs_steadystate', ...
ss(M_.blocksMFS{b}), ...
options_.jacobian_flag, b, ss);
if check ~= 0
error(['STEADY: convergence problems in block ' int2str(b)])
end
ss(M_.blocksMFS{b}) = y;
else
[ss, check] = solve_one_boundary([M_.fname '_static_' int2str(b)], ss, exo, ...
params, M_.blocksMFS{b}, n, 1, 0, b, 0, options_.maxit_, ...
options_.solve_tolf, options_.slowc, 0, options_.solve_algo, 1, 0, 0);
end
end
[r, g1, x] = feval([M_.fname '_static'], b, ss, ...
exo, params);
end
elseif options_.bytecode
if options_.solve_algo > 4
[check, x] = bytecode('static', y, exo, params);
mexErrCheck('bytecode', check);
info = check;
elseif options_.block
for b = 1:size(M_.blocksMFS,1)
n = size(M_.blocksMFS{b}, 1);
if n ~= 0
[y, check] = dynare_solve('block_bytecode_mfs_steadystate', ...
x(M_.blocksMFS{b}), ...
options_.jacobian_flag, b, x);
if check ~= 0
error(['STEADY: convergence problems in block ' int2str(b)])
end
x(M_.blocksMFS{b}) = y;
else
[check, x] = feval('bytecode', x, exo, params, 'static', ['block = ' int2str(b)]);
end;
end
else
[x, check] = dynare_solve('bytecode_steadystate', ...
y, ...
options_.jacobian_flag);
if check ~= 0
error('STEADY: convergence problems')
end
end
end
\ No newline at end of file
......@@ -66,7 +66,10 @@ end
dr.ys = ys;
check1 = 0;
% testing for steadystate file
fh = str2func([M_.fname '_static']);
if (~options_.bytecode)
fh = str2func([M_.fname '_static']);
end;
if options_.steadystate_flag
[dr.ys,check1] = feval([M_.fname '_steadystate'],dr.ys,...
[oo_.exo_steady_state; ...
......@@ -88,12 +91,18 @@ else
if options_.ramsey_policy == 0
if options_.linear == 0
% nonlinear models
if max(abs(feval(fh,dr.ys,[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params))) > options_.dynatol
[dr.ys,check1] = dynare_solve(fh,dr.ys,options_.jacobian_flag,...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params);
end
if (options_.block == 0 && options_.bytecode == 0)
if max(abs(feval(fh,dr.ys,[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params))) > options_.dynatol
[dr.ys,check1] = dynare_solve(fh,dr.ys,options_.jacobian_flag,...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params);
end
else
[dr.ys,check1] = dynare_solve_block_or_bytecode(dr.ys,...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params);
end;
else
% linear models
[fvec,jacob] = feval(fh,dr.ys,[oo_.exo_steady_state;...
......@@ -125,7 +134,11 @@ if ~isreal(dr.ys)
end
dr.fbias = zeros(M_.endo_nbr,1);
[dr,info,M_,options_,oo_] = dr1(dr,check_flag,M_,options_,oo_);
if options_.block
[dr,info,M_,options_,oo_] = dr_block(dr,check_flag,M_,options_,oo_);
else
[dr,info,M_,options_,oo_] = dr1(dr,check_flag,M_,options_,oo_);
end
if info(1)
return
end
......
......@@ -114,67 +114,16 @@ if options_.steadystate_flag
options_.jacobian_flag, ...
[oo_.exo_steady_state;oo_.exo_det_steady_state],indv);
end
elseif options_.block && ~options_.bytecode
for b = 1:size(M_.blocksMFS,1)
n = size(M_.blocksMFS{b}, 1);
ss = oo_.steady_state;
if n ~= 0
if options_.solve_algo <= 4
[y, check] = dynare_solve('block_mfs_steadystate', ...
ss(M_.blocksMFS{b}), ...
options_.jacobian_flag, b);
if check ~= 0
error(['STEADY: convergence problems in block ' int2str(b)])
end
ss(M_.blocksMFS{b}) = y;
else
[ss, check] = solve_one_boundary([M_.fname '_static_' int2str(b)], ss, [oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params, M_.blocksMFS{b}, n, 1, 0, b, 0, options_.maxit_, ...
options_.solve_tolf, options_.slowc, 0, options_.solve_algo, 1, 0, 0);
end
end
[r, g1, oo_.steady_state] = feval([M_.fname '_static'], b, ss, ...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params);
end
elseif options_.bytecode
if options_.solve_algo > 4
[check, oo_.steady_state] = bytecode('static');
mexErrCheck('bytecode', check);
elseif options_.block
for b = 1:size(M_.blocksMFS,1)
n = size(M_.blocksMFS{b}, 1);
ss = oo_.steady_state;
if n ~= 0
[y, check] = dynare_solve('block_bytecode_mfs_steadystate', ...
ss(M_.blocksMFS{b}), ...
options_.jacobian_flag, b);
if check ~= 0
error(['STEADY: convergence problems in block ' int2str(b)])
end
oo_.steady_state(M_.blocksMFS{b}) = y;
else
[check, r, g1, oo_.steady_state] = feval('bytecode', oo_.steady_state, ...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params, 1, options_.solve_algo, 'static', 'evaluate', ['block = ' int2str(b)]);
end;
end
else
[y, check] = dynare_solve('bytecode_steadystate', ...
oo_.steady_state, ...
options_.jacobian_flag);
if check ~= 0
error('STEADY: convergence problems')
end
oo_.steady_state = y;
end
else
elseif (options_.bytecode == 0 && options_.block == 0)
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...
oo_.steady_state,...
options_.jacobian_flag, ...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params);
else
[oo_.steady_state,check] = dynare_solve_block_or_bytecode(oo_.steady_state,...
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params);
end
if check ~= 0
......
......@@ -1733,7 +1733,6 @@ Interpreter::compute_block_time(int Per_u_, bool evaluate, int block_num, int si
var = ((FSTPG3_ *) it_code->second)->get_col();
lag = ((FSTPG3_ *) it_code->second)->get_lag();
pos_col = ((FSTPG3_ *) it_code->second)->get_col_pos();
mexPrintf("jacob_other_endo[%d(size=%d*pos_col=%d + eq=%d)]=%f\n",size*pos_col + eq, size, pos_col, eq, rr);
jacob_other_endo[eq + size*pos_col] = rr;
break;
case FirstExoDerivative:
......@@ -1742,7 +1741,6 @@ Interpreter::compute_block_time(int Per_u_, bool evaluate, int block_num, int si
var = ((FSTPG3_ *) it_code->second)->get_col();
lag = ((FSTPG3_ *) it_code->second)->get_lag();
pos_col = ((FSTPG3_ *) it_code->second)->get_col_pos();
mexPrintf("jacob_exo[%d(size=%d*pos_col=%dr + eq=%d)]=%f\n",size*pos_col+eq, size, pos_col, eq, rr);
jacob_exo[eq + size*pos_col] = rr;
break;
case FirstExodetDerivative:
......@@ -1751,7 +1749,6 @@ Interpreter::compute_block_time(int Per_u_, bool evaluate, int block_num, int si
var = ((FSTPG3_ *) it_code->second)->get_col();
lag = ((FSTPG3_ *) it_code->second)->get_lag();
pos_col = ((FSTPG3_ *) it_code->second)->get_col_pos();
mexPrintf("jacob_exo_det[%d(size=%d*pos_col=%dr + eq=%d)]=%f\n",size*pos_col+eq, size, pos_col, eq, rr);
jacob_exo_det[eq + size*pos_col] = rr;
break;
default:
......
......@@ -372,36 +372,34 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int jacob_field_number = 0, jacob_exo_field_number = 0, jacob_exo_det_field_number = 0, jacob_other_endo_field_number = 0;
if (!block_structur)
{
const char *field_names[] = {"jacob","jacob_exo","jacob_exo_det","jacob_other_endo"};
const char *field_names[] = {"g1","g1_x","g1_xd","g1_o"};
jacob_field_number=0;
jacob_exo_field_number=1;
jacob_exo_det_field_number=2;
jacob_other_endo_field_number=2;
mwSize dims[1] = {nb_blocks };
block_structur = plhs[2] = mxCreateStructArray(1, dims, 4, field_names);
//block_structur =
plhs[2] = mxCreateStructArray(1, dims, 4, field_names);
}
else if (!mxIsStruct(block_structur))
if (block >=0 )
{
block_structur = plhs[2] = mxDuplicateArray(interprete.get_jacob(0));
//mexCallMATLAB(0,NULL, 1, &block_structur, "disp");
dont_store_a_structure = true;
}
else
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, the third output argument must be a structure\n");
{
//plhs[2] = mxDuplicateArray(interprete.get_jacob(0));
plhs[2] = interprete.get_jacob(0);
//mexCallMATLAB(0,NULL, 1, &plhs[2], "disp");
dont_store_a_structure = true;
}
else
{
jacob_field_number = mxAddField(block_structur, "jacob");
jacob_field_number = mxAddField(block_structur, "g1");
if (jacob_field_number == -1)
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, cannot add extra field jacob to the structArray\n");
jacob_exo_field_number = mxAddField(block_structur, "jacob_exo");
jacob_exo_field_number = mxAddField(block_structur, "g1_x");
if (jacob_exo_field_number == -1)
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, cannot add extra field jacob_exo to the structArray\n");
jacob_exo_det_field_number = mxAddField(block_structur, "jacob_exo_det");
jacob_exo_det_field_number = mxAddField(block_structur, "g1_xd");
if (jacob_exo_det_field_number == -1)
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, cannot add extra field jacob_exo_det to the structArray\n");
jacob_other_endo_field_number = mxAddField(block_structur, "jacob_other_endo");
jacob_other_endo_field_number = mxAddField(block_structur, "g1_o");
if (jacob_other_endo_field_number == -1)
DYN_MEX_FUNC_ERR_MSG_TXT("Fatal error in bytecode: in main, cannot add extra field jacob_other_endo to the structArray\n");
}
......
This diff is collapsed.
......@@ -700,13 +700,13 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob
for (int i = 0; i < epilogue; i++)
{
if (variable_lag_lead[tmp_variable_reordered[prologue+num+i]].first != 0 && variable_lag_lead[tmp_variable_reordered[prologue+num+i]].second != 0)
if (variable_lag_lead[tmp_variable_reordered[prologue+n+i]].first != 0 && variable_lag_lead[tmp_variable_reordered[prologue+n+i]].second != 0)
n_mixed[prologue+num+i]++;
else if (variable_lag_lead[tmp_variable_reordered[prologue+num+i]].first == 0 && variable_lag_lead[tmp_variable_reordered[prologue+num+i]].second != 0)
else if (variable_lag_lead[tmp_variable_reordered[prologue+n+i]].first == 0 && variable_lag_lead[tmp_variable_reordered[prologue+n+i]].second != 0)
n_forward[prologue+num+i]++;
else if (variable_lag_lead[tmp_variable_reordered[prologue+num+i]].first != 0 && variable_lag_lead[tmp_variable_reordered[prologue+num+i]].second == 0)
else if (variable_lag_lead[tmp_variable_reordered[prologue+n+i]].first != 0 && variable_lag_lead[tmp_variable_reordered[prologue+n+i]].second == 0)
n_backward[prologue+num+i]++;
else if (variable_lag_lead[tmp_variable_reordered[prologue+num+i]].first == 0 && variable_lag_lead[tmp_variable_reordered[prologue+num+i]].second == 0)
else if (variable_lag_lead[tmp_variable_reordered[prologue+n+i]].first == 0 && variable_lag_lead[tmp_variable_reordered[prologue+n+i]].second == 0)
n_static[prologue+num+i]++;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment