Merge branch 'master' into ecb-master

Fixed conflicts:
	matlab/modules/dseries
time-shift
Stéphane Adjemian(Charybdis) 2018-07-23 17:05:30 +02:00
commit 7d7449c775
23 changed files with 729 additions and 416 deletions

View File

@ -242,6 +242,12 @@ Alternatively, if you want to build everything, manually install the following p
- `latex2html`
- `doxygen`
You can load all necessary packages at once with
```
sudo apt install build-essential gfortran liboctave-dev libboost-graph-dev libboost-filesystem-dev libgsl-dev libmatio-dev libslicot-dev libslicot-pic libsuitesparse-dev flex bison autoconf automake texlive texlive-publishers texlive-extra-utils texlive-formats-extra texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texinfo lmodern latex2html doxygen
```
## Fedora
**NB**: Documentation still in progress…

View File

@ -516,7 +516,7 @@ options_.newrat=newrat;
% Simplex optimization routine (variation on Nelder Mead algorithm).
simplex.tolerance.x = 1e-4;
simplex.tolerance.f = 1e-4;
simplex.maxiter = 5000;
simplex.maxiter = 10000;
simplex.maxfcallfactor = 500;
simplex.maxfcall = [];
simplex.verbosity = 2;

View File

@ -206,7 +206,7 @@ end
%$
%$ try
%$ if isoctave
%$ s = quadv(density, .0000000001, 100000,1e-10);
%$ s = quadl(density, .0000000001, 100000, 1e-10);
%$ else
%$ s = integral(density, 0, 100000);
%$ end
@ -229,7 +229,7 @@ end
%$
%$ try
%$ if isoctave
%$ s = quadv(density, .0000000001, 100000,1e-10);
%$ s = quadl(density, .0000000001, 100000, 1e-10);
%$ else
%$ s = integral(density, 0, 100000);
%$ end
@ -252,7 +252,7 @@ end
%$
%$ try
%$ if isoctave
%$ s = quadv(density, .0000000001, 100000,1e-10)
%$ s = quadl(density, .0000000001, 100000, 1e-10);
%$ else
%$ s = integral(density, 0, 100000);
%$ end
@ -279,7 +279,7 @@ end
%$
%$ try
%$ if isoctave
%$ s = quadv(xdens, .0000000001, 20,1e-10)
%$ s = quadgk(xdens, .0000000001, 100000, 1e-10);
%$ else
%$ s = integral(xdens, 0, 100000);
%$ end
@ -302,7 +302,7 @@ end
%$
%$ try
%$ if isoctave
%$ s = quadv(xdens, .0000000001, 100000,1e-10)
%$ s = quadl(xdens, .0000000001, 100000, 1e-10);
%$ else
%$ s = integral(xdens, 0, 100000);
%$ end
@ -325,7 +325,7 @@ end
%$
%$ try
%$ if isoctave
%$ s = quadv(xdens, .0000000001, 100000,1e-10)
%$ s = quadl(xdens, .0000000001, 100000, 1e-10);
%$ else
%$ s = integral(xdens, 0, 100000);
%$ end
@ -351,7 +351,7 @@ end
%$ s = NaN(n, 1);
%$ for i=1:n
%$ if isoctave()
%$ s(i) = quadv(density, .0000000001, .1*i,1e-10)
%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10);
%$ else
%$ s(i) = integral(density, 0, .1*i);
%$ end
@ -382,7 +382,7 @@ end
%$ s = NaN(n, 1);
%$ for i=1:n
%$ if isoctave()
%$ s(i) = quadv(density, .0000000001, .1*i,1e-10)
%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10);
%$ else
%$ s(i) = integral(density, 0, .1*i);
%$ end
@ -413,7 +413,7 @@ end
%$ s = NaN(n, 1);
%$ for i=1:n
%$ if isoctave()
%$ s(i) = quadv(density, .0000000001, .1*i,1e-10)
%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10);
%$ else
%$ s(i) = integral(density, 0, .1*i);
%$ end

View File

@ -46,11 +46,9 @@ steadystate_flag = options.steadystate_flag;
params = M.params;
exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state];
if length(M.aux_vars) > 0 && ~steadystate_flag
if length(M.aux_vars) > 0 && ~steadystate_flag && M.set_auxiliary_variables
h_set_auxiliary_variables = str2func([M.fname '.set_auxiliary_variables']);
if M.set_auxiliary_variables
ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params);
end
ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params);
end
if options.ramsey_policy

129
matlab/islagof.m Normal file
View File

@ -0,0 +1,129 @@
function b = islagof(v1, v2)
% Returns true if and only if variable v1 is a lag of variable v2.
%
% INPUTS
% - v1 [string] Variable name.
% - v2 [string] Variable name.
%
% OUTPUTS
% - b [logical]
% Copyright (C) 2018 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 M_
if ~ischar(v1) && isscalar(v1) && isnumeric(v1) && isint(v1)
id1 = v1;
if id1>M_.endo_nbr
error('First input must be an integer between 1 and %u', M_.endo_nbr)
end
end
if ~ischar(v2) && isscalar(v2) && isnumeric(v2) && isint(v2)
id2 = v2;
if id2>M_.endo_nbr
error('First input must be an integer between 1 and %u', M_.endo_nbr)
end
end
% Set output default value
b = false;
% Get index of v1
if ischar(v1)
id1 = find(strcmp(v1, M_.endo_names));
end
if isempty(id1)
error('First input must be a variable name.')
end
% Get index of v2
if ischar(v2)
id2 = find(strcmp(v2, M_.endo_names));
end
if isempty(id2)
error('Second input must be a variable name.')
end
% A variable cannot be a lag of itself.
if isequal(id1, id2)
return
end
% Are v1 and v2 auxiliary variables?
v1_is_an_auxiliary_variable = id1>M_.orig_endo_nbr;
v2_is_an_auxiliary_variable = id2>M_.orig_endo_nbr;
% At least one of the variables must be an auxiliary variable
if ~v1_is_an_auxiliary_variable && ~v2_is_an_auxiliary_variable
return
end
% If v1 and v2 are auxiliary variables
if v1_is_an_auxiliary_variable && v2_is_an_auxiliary_variable
auxinfo1 = M_.aux_vars(get_aux_variable_id(id1));
auxinfo2 = M_.aux_vars(get_aux_variable_id(id2));
isleadlag1 = ismember(auxinfo1.type, [1,0]);
isleadlag2 = ismember(auxinfo2.type, [1,0]);
% If v1 and v2 are lead/lag auxiliary variables
if isleadlag1 && isleadlag2
% If v1 and v2 are lead/lag of a common endogenous variable.
if auxinfo1.orig_index && auxinfo2.orig_index
if auxinfo1.orig_lead_lag<auxinfo2.orig_lead_lag
b = true;
end
end
return
end
isdiff1 = ismember(auxinfo1.type, [8,9]);
isdiff2 = ismember(auxinfo1.type, [8,9]);
if isdiff1 && isdiff2
if isequal(auxinfo1.type, 9) && isequal(auxinfo2.type, 8)
while isequal(auxinfo1.type, 9)
if isequal(auxinfo1.orig_index, id2)
b = true;
end
auxinfo1 = M_.aux_vars(get_aux_variable_id(auxinfo1.orig_index));
end
end
return
end
end
if v1_is_an_auxiliary_variable && ~v2_is_an_auxiliary_variable
auxinfo1 = M_.aux_vars(get_aux_variable_id(id1));
% If v1 is not an auxiliary of type 1, it cannot be a lag of v2
if isequal(auxinfo1.type, 1)
if isequal(auxinfo1.orig_index, id2)
b = true;
end
end
end
if ~v1_is_an_auxiliary_variable && v2_is_an_auxiliary_variable
auxinfo2 = M_.aux_vars(get_aux_variable_id(id2));
% If v2 is not an auxiliary of type 0, v1 cannot be a lag of v2
if isequal(auxinfo2.type, 0)
if isequal(auxinfo2.orig_index, id1)
b = true;
end
end
end

View File

@ -58,31 +58,31 @@ end
%@test:1
%$ t = false(3,1);
%$ mkdir toto
%$ mkdir toto;
%$ cd toto
%$ mkdir titi
%$ mkdir tata
%$ mkdir titi;
%$ mkdir tata;
%$ cd tata
%$ mkdir tutu
%$ mkdir tutu;
%$ cd tutu
%$ system('touch a.m')
%$ system('touch a.m');
%$ cd ..
%$ system('touch b.m')
%$ system('touch c.m')
%$ system('touch b.m');
%$ system('touch c.m');
%$ cd ../titi
%$ system('touch d.m')
%$ system('touch d.m');
%$ cd ..
%$ pause(1)
%$ system('touch e.m')
%$ system('touch e.m');
%$ t(1) = isequal(isolder('e.m'), false);
%$ pause(1)
%$ system('touch tata/tutu/a.m')
%$ system('touch tata/b.m')
%$ system('touch tata/c.m')
%$ system('touch titi/d.m')
%$ system('touch tata/tutu/a.m');
%$ system('touch tata/b.m');
%$ system('touch tata/c.m');
%$ system('touch titi/d.m');
%$ t(2) = isequal(isolder('e.m'), true);
%$ pause(1)
%$ system('touch e.m')
%$ system('touch e.m');
%$ t(3) = isequal(isolder('e.m'), false);
%$ cd ..
%$ if isoctave()

View File

@ -82,7 +82,7 @@ return
%@test:1
% Write a data file
fid = fopen('example.m','w');
fid = fopen('example1.m','w');
fwriten(fid, 'a = randn(100,1);');
fwriten(fid, 'b = randn(100,1);');
fwriten(fid, 'c = transpose(randn(100,1));');
@ -98,8 +98,8 @@ fclose(fid);
listofvariablestobeloaded = {'b', 'a'};
% Test if we can load the data.
try
data = load_m_file_data_legacy('example.m', listofvariablestobeloaded);
delete example.m
data = load_m_file_data_legacy('example1.m', listofvariablestobeloaded);
delete('example1.m');
t(1) = 1;
catch
t(1) = 0;
@ -109,7 +109,7 @@ T = all(t);
%@test:2
% Write a data file
fid = fopen('example.m','w');
fid = fopen('example2.m','w');
fwriten(fid, 'a = randn(100,1);');
fwriten(fid, 'b = randn(100,1);');
fwriten(fid, 'c = transpose(randn(100,1));');
@ -125,8 +125,8 @@ fclose(fid);
listofvariablestobeloaded = {'e', 'a'};
% Test if we can load the data.
try
data = load_m_file_data_legacy('example.m', listofvariablestobeloaded);
delete example.m
data = load_m_file_data_legacy('example2.m', listofvariablestobeloaded);
delete('example2.m');
t(1) = 0;
catch
t(1) = 1;
@ -136,7 +136,7 @@ T = all(t);
%@test:3
% Write a data file
fid = fopen('example.m','w');
fid = fopen('example3.m','w');
fwriten(fid, 'a = randn(100,1);');
fwriten(fid, 'b = randn(100,1);');
fwriten(fid, 'c = transpose(randn(100,1));');
@ -152,8 +152,8 @@ fclose(fid);
listofvariablestobeloaded = {'c', 'a'};
% Test if we can load the data.
try
data = load_m_file_data_legacy('example.m', listofvariablestobeloaded);
delete example.m
data = load_m_file_data_legacy('example3.m', listofvariablestobeloaded);
delete('example3.m');
t(1) = 1;
catch
t(1) = 0;

View File

@ -135,10 +135,14 @@ end
%@eof:2
%@test:3
%$ t = zeros(3,1);
%$ t(1) = dassert(corr(5), NaN);
%$ t(2) = dassert(corr([1 2 3],5),NaN(3,1));
%$ t(3) = dassert(corr(5,[1 2 3]),NaN(1,3));
%$ if ~isoctave()
%$ t = zeros(3,1);
%$ t(1) = dassert(corr(5), NaN);
%$ t(2) = dassert(corr([1 2 3],5),NaN(3,1));
%$ t(3) = dassert(corr(5,[1 2 3]),NaN(1,3));
%$ else
%$ t = 1;
%$ end
%$ T = all(t);
%@eof:3

View File

@ -236,6 +236,12 @@ y = ipermute(y,order);
%@test:1
%$ if isoctave()
%$ t = true;
%$ T = t;
%$ LOG = NaN;
%$ return
%$ end
%$ X = randn(10000000, 1);
%$
%$ try

View File

@ -29,7 +29,7 @@ function [x,fval,exitflag] = simplex_optimization_routine(objective_function,x,o
% o exitflag [integer] scalar equal to 0 or 1 (0 if the algorithm did not converge to
% a minimum).
% Copyright (C) 2010-2017 Dynare Team
% Copyright (C) 2010-2018 Dynare Team
%
% This file is part of Dynare.
%
@ -49,6 +49,13 @@ function [x,fval,exitflag] = simplex_optimization_routine(objective_function,x,o
% Set verbose mode
verbose = options.verbosity;
% Set header
if verbose
header = sprintf('#Iter. #FnCalls. Best Value Worst Value Norm(f) Norm(x) Move');
iter_ = ' ';
fval_ = ' ';
end
% Set number of control variables.
number_of_variables = length(x);
@ -77,7 +84,7 @@ end
if isfield(options,'maxiter')
max_iterations = options.maxiter;
else
max_iterations = 5000;
max_iterations = 10000;
end
% Set reflection parameter.
@ -179,27 +186,23 @@ trend_vector_2 = 2:(number_of_variables+1);
% Set initial simplex around the initial guess (x).
if verbose
skipline(3)
disp('+----------------------+')
disp(' SIMPLEX INITIALIZATION ')
disp('+----------------------+')
skipline()
disp('Simplex initialization...')
end
initial_point = x;
[initial_score,junk1,junk2,nopenalty] = feval(objective_function,x,varargin{:});
[initial_score,junk1,nopenalty] = feval(objective_function,x,varargin{:});
if ~nopenalty
disp('Cannot initialize the simplex with the provided initial guess.')
skipline()
error('simplex_optimization_routine:: Initial condition is wrong!')
else
[v,fv,delta] = simplex_initialization(objective_function,initial_point,initial_score,delta,zero_delta,1,varargin{:});
disp('Done!')
skipline()
func_count = number_of_variables + 1;
iter_count = 1;
if verbose
disp(['Objective function value: ' num2str(fv(1))])
disp(['Current parameter values: '])
fprintf(1,'%s: \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \n','Names','Best point', 'Worst point', 'Mean values', 'Min values', 'Max values');
for i=1:number_of_variables
fprintf(1,'%s: \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \n',var_names{i},v(i,1), v(i,end), mean(v(i,:),2), min(v(i,:),[],2), max(v(i,:),[],2));
end
skipline()
end
end
@ -220,10 +223,15 @@ tooslow = 0;
iter_no_improvement_break = 0;
max_no_improvement_break = 1;
if verbose
disp(header)
end
critF = 1.0;
critX = 1.0;
while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex_algo_iterations<=max_simplex_algo_iterations)
% Do we really need to continue?
critF = max(abs(fv(1)-fv(trend_vector_2)));
critX = max(max(abs(v(:,trend_vector_2)-v(:,unit_vector))));
if critF <= max(f_tolerance,10*eps(fv(1))) && critX <= max(x_tolerance,10*eps(max(v(:,1))))
convergence = 1;
end
@ -258,10 +266,7 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
func_count = func_count+1;
if fxe < fxr% xe is even better than xr.
if optimize_expansion_parameter
if verbose>1
skipline(2)
disp('Compute optimal expansion...')
end
% Compute optimal expansion...
xee = xbar + rho*chi*1.01*(xbar-v(:,end));
x = xee;
fxee = feval(objective_function,x,varargin{:});
@ -271,14 +276,8 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
weight = rho*chi*1.02;
fxeee_old = fxee;
xeee_old = xee;
if verbose>1
fprintf(1,'Weight = ');
end
while decrease
weight = 1.02*weight;
if verbose>1
fprintf(1,'\b\b\b\b\b\b\b %6.4f',weight);
end
xeee = xbar + weight*(xbar-v(:,end));
x = xeee;
fxeee = feval(objective_function,x,varargin{:});
@ -290,9 +289,6 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
decrease = 0;
end
end
if verbose>1
fprintf(1,'\n');
end
xe = xeee_old;
fxe = fxeee_old;
else
@ -300,14 +296,8 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
weight = rho*chi;
fxeee_old = fxee;
xeee_old = xee;
if verbose>1
fprintf(1,'Weight = ');
end
while decrease
weight = weight/1.02;
if verbose>1
fprintf(1,'\b\b\b\b\b\b\b %6.4f',weight);
end
xeee = xbar + weight*(xbar-v(:,end));
x = xeee;
fxeee = feval(objective_function,x,varargin{:});
@ -319,20 +309,15 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
decrease = 0;
end
end
if verbose>1
fprintf(1,'\n');
end
xe = xeee_old;
fxe = fxeee_old;
end
if verbose>1
disp('Done!')
skipline(2)
end
move = 'expand-opt';
else
move = 'expand';
end
v(:,end) = xe;
fv(end) = fxe;
move = 'expand';
else% if xe is not better than xr.
v(:,end) = xr;
fv(end) = fxr;
@ -383,37 +368,37 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
% Sort n+1 points by incresing order of the objective function values.
[fv,sort_idx] = sort(fv);
v = v(:,sort_idx);
critF = max(abs(fv(1)-fv(trend_vector_2)));
critX = max(max(abs(v(:,trend_vector_2)-v(:,unit_vector))));
if verbose
if ~mod(simplex_iterations, 50)
skipline()
disp(header)
end
iter = int2str(simplex_iterations);
fval = int2str(func_count);
iter_(1:length(iter)) = iter;
fval_(1:length(fval)) = fval;
if isfinite(fv(end)) && isfinite(fv(1))
if fv(end)<0
disp(sprintf('%s %s %12.7E %12.7E %12.7E %12.7E %s', iter_, fval_, fv(1), fv(end), critF, critX, move))
else
if fv(1)>0
disp(sprintf('%s %s %12.7E %12.7E %12.7E %12.7E %s', iter_, fval_, fv(1), fv(end), critF, critX, move))
else
disp(sprintf('%s %s %12.7E %12.7E %12.7E %12.7E %s', iter_, fval_, fv(1), fv(end), critF, critX, move))
end
end
else
if isfinite(fv(1))
disp(sprintf(['%s %s %12.7E %12.7E %s'], iter_, fval_, fv(1) , critX, move))
else
disp(sprintf('%s %s %12.7E %s', iter_, fval_, critX, move))
end
end
end
iter_count = iter_count + 1;
simplex_iterations = simplex_iterations+1;
if verbose>1
disp(['Simplex iteration number: ' int2str(simplex_iterations) '-' int2str(simplex_init) '-' int2str(simplex_algo_iterations)])
disp(['Simplex move: ' move])
disp(['Objective function value: ' num2str(fv(1))])
disp(['Mode improvement: ' num2str(best_point_score-fv(1))])
disp(['Norm of dx: ' num2str(norm(best_point-v(:,1)))])
disp(['Norm of dSimplex: ' num2str(norm(v-vold,'fro'))])
disp(['Crit. f: ' num2str(critF)])
disp(['Crit. x: ' num2str(critX)])
skipline()
end
if verbose && max(abs(best_point-v(:,1)))>x_tolerance
if verbose<2
disp(['Simplex iteration number: ' int2str(simplex_iterations) '-' int2str(simplex_init) '-' int2str(simplex_algo_iterations)])
disp(['Objective function value: ' num2str(fv(1))])
disp(['Mode improvement: ' num2str(best_point_score-fv(1))])
disp(['Norm of dx: ' num2str(norm(best_point-v(:,1)))])
disp(['Norm of dSimplex: ' num2str(norm(v-vold,'fro'))])
disp(['Crit. f: ' num2str(critF)])
disp(['Crit. x: ' num2str(critX)])
skipline()
end
disp(['Current parameter values: '])
fprintf(1,'%s: \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \n','Names','Best point', 'Worst point', 'Mean values', 'Min values', 'Max values');
for i=1:number_of_variables
fprintf(1,'%s: \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \n',var_names{i}, v(i,1), v(i,end), mean(v(i,:),2), min(v(i,:),[],2), max(v(i,:),[],2));
end
skipline()
end
if abs(best_point_score-fv(1))<f_tolerance
no_improvements = no_improvements+1;
else
@ -424,7 +409,9 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
vold = v;
if no_improvements>max_no_improvements
if verbose
skipline()
disp(['NO SIGNIFICANT IMPROVEMENT AFTER ' int2str(no_improvements) ' ITERATIONS!'])
skipline()
end
if simplex_algo_iterations<=max_simplex_algo_iterations
% Compute the size of the simplex
@ -432,12 +419,9 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
% Compute the new initial simplex.
[v,fv,delta] = simplex_initialization(objective_function,best_point,best_point_score,delta,zero_delta,1,varargin{:});
if verbose
disp(['(Re)Start with a lager simplex around the based on the best current '])
disp(['values for the control variables. '])
disp(['New value of delta (size of the new simplex) is: '])
for i=1:number_of_variables
fprintf(1,'%s: \t\t\t %+8.6f \n',var_names{i}, delta(i));
end
disp('(Re)Start with a lager simplex based on the best current values for the control variables.')
skipline()
disp(header)
end
% Reset counters
no_improvements = 0;
@ -446,22 +430,27 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
iter_no_improvement_break = iter_no_improvement_break + 1;
simplex_init = simplex_init+1;
simplex_iterations = simplex_iterations+1;
skipline(2)
end
end
if ((func_count==max_func_calls) || (iter_count==max_iterations) || (iter_no_improvement_break==max_no_improvement_break) || convergence || tooslow)
[v,fv,delta] = simplex_initialization(objective_function,best_point,best_point_score,DELTA,zero_delta,1,varargin{:});
if func_count==max_func_calls
if verbose
skipline()
disp(['MAXIMUM NUMBER OF OBJECTIVE FUNCTION CALLS EXCEEDED (' int2str(max_func_calls) ')!'])
skipline()
end
elseif iter_count== max_iterations
if verbose
skipline()
disp(['MAXIMUM NUMBER OF ITERATIONS EXCEEDED (' int2str(max_iterations) ')!'])
skipline()
end
elseif iter_no_improvement_break==max_no_improvement_break
if verbose
skipline()
disp(['MAXIMUM NUMBER OF SIMPLEX REINITIALIZATION EXCEEDED (' int2str(max_no_improvement_break) ')!'])
skipline()
end
iter_no_improvement_break = 0;
if simplex_algo_iterations==max_simplex_algo_iterations
@ -469,9 +458,13 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
continue
end
elseif tooslow
skipline()
disp(['CONVERGENCE NOT ACHIEVED AFTER ' int2str(simplex_iterations) ' ITERATIONS! IMPROVING TOO SLOWLY!'])
skipline()
else
skipline()
disp(['CONVERGENCE ACHIEVED AFTER ' int2str(simplex_iterations) ' ITERATIONS!'])
skipline()
end
if simplex_algo_iterations<max_simplex_algo_iterations
% Compute the size of the simplex
@ -479,12 +472,9 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
% Compute the new initial simplex.
[v,fv,delta] = simplex_initialization(objective_function,best_point,best_point_score,delta,zero_delta,1,varargin{:});
if verbose
disp(['(Re)Start with a lager simplex around the based on the best current '])
disp(['values for the control variables. '])
disp(['New value of delta (size of the new simplex) is: '])
for i=1:number_of_variables
fprintf(1,'%s: \t\t\t %+8.6f \n',var_names{i}, delta(i));
end
disp('(Re)Start with a lager simplex based on the best current values for the control variables.')
skipline()
disp(header)
end
% Reset counters
func_count=0;
@ -495,7 +485,6 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
iter_count = iter_count+1;
simplex_iterations = simplex_iterations+1;
simplex_algo_iterations = simplex_algo_iterations+1;
skipline(2)
else
break
end
@ -537,7 +526,7 @@ for j = 1:n
end
v(:,j+1) = y;
x = y;
[fv(j+1),junk1,junk2,nopenalty_flag] = feval(objective_function,x,varargin{:});
[fv(j+1),junk1,nopenalty_flag] = feval(objective_function,x,varargin{:});
if check_delta
while ~nopenalty_flag
if y(j)~=0
@ -553,7 +542,7 @@ for j = 1:n
end
v(:,j+1) = y;
x = y;
[fv(j+1),junk1,junk2,nopenalty_flag] = feval(objective_function,x,varargin{:});
[fv(j+1),junk1,nopenalty_flag] = feval(objective_function,x,varargin{:});
end
end
end

View File

@ -419,14 +419,14 @@ public:
for (unsigned int i = 0; i < endo_name_length; i++)
if (P_endo_names[CHAR_LENGTH*(variable_num+i*nb_endo)] != ' ')
res << P_endo_names[CHAR_LENGTH*(variable_num+i*nb_endo)];
Variable_list.push_back(make_pair(res.str(), make_pair(eEndogenous, variable_num)));
Variable_list.push_back(make_pair(res.str(), make_pair(SymbolType::endogenous, variable_num)));
}
for (unsigned int variable_num = 0; variable_num < (unsigned int) nb_exo; variable_num++)
{
for (unsigned int i = 0; i < exo_name_length; i++)
if (P_exo_names[CHAR_LENGTH*(variable_num+i*nb_exo)] != ' ')
res << P_exo_names[CHAR_LENGTH*(variable_num+i*nb_exo)];
Variable_list.push_back(make_pair(res.str(), make_pair(eExogenous, variable_num)));
Variable_list.push_back(make_pair(res.str(), make_pair(SymbolType::exogenous, variable_num)));
}
}
@ -460,7 +460,7 @@ public:
ostringstream res;
switch (variable_type)
{
case eEndogenous:
case SymbolType::endogenous:
if (variable_num <= nb_endo)
{
for (unsigned int i = 0; i < endo_name_length; i++)
@ -470,8 +470,8 @@ public:
else
mexPrintf("=> Unknown endogenous variable # %d", variable_num);
break;
case eExogenous:
case eExogenousDet:
case SymbolType::exogenous:
case SymbolType::exogenousDet:
if (variable_num <= nb_exo)
{
for (unsigned int i = 0; i < exo_name_length; i++)
@ -481,7 +481,7 @@ public:
else
mexPrintf("=> Unknown exogenous variable # %d", variable_num);
break;
case eParameter:
case SymbolType::parameter:
if (variable_num <= nb_param)
{
for (unsigned int i = 0; i < param_name_length; i++)
@ -518,33 +518,33 @@ public:
break;
case FirstEndoDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to endogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to endogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
break;
case FirstOtherEndoDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to other endogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to other endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to other endogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to other endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
break;
case FirstExoDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to exogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to exogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
break;
case FirstExodetDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to deterministic exogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to deterministic exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to deterministic exogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to deterministic exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
break;
case FirstParamDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to parameter " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_;
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_;
break;
default:
return ("???");
@ -566,33 +566,33 @@ public:
break;
case FirstEndoDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to endogenous variable " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1);
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to endogenous variable " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1);
break;
case FirstOtherEndoDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to other endogenous variable " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to other endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1);
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to other endogenous variable " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to other endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1);
break;
case FirstExoDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to exogenous variable " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1);
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to exogenous variable " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1);
break;
case FirstExodetDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to deterministic exogenous variable " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to deterministic exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1);
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to deterministic exogenous variable " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to deterministic exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1);
break;
case FirstParamDerivative:
if (EQN_block_number > 1)
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to parameter " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1);
else
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(eEndogenous, EQN_dvar1);
Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1);
break;
default:
return ("???");
@ -616,7 +616,7 @@ public:
ExpressionType equation_type = TemporaryTerm;
size_t found;
double *jacob = NULL, *jacob_other_endo = NULL, *jacob_exo = NULL, *jacob_exo_det = NULL;
external_function_type function_type = ExternalFunctionWithoutDerivative;
ExternalFunctionType function_type = ExternalFunctionType::withoutDerivative;
if (evaluate)
{
@ -693,35 +693,35 @@ public:
break;
case FLDV:
//load a variable in the processor
switch (((FLDV_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FLDV_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FLDV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDV_ Param var=%d\n", var);
mexPrintf("get_variable(eParameter, var)=%s\n", get_variable(eParameter, var).c_str());
mexPrintf("get_variable(SymbolType::parameter, var)=%s\n", get_variable(SymbolType::parameter, var).c_str());
mexEvalString("drawnow;");
#endif
Stack.push(get_variable(eParameter, var));
Stack.push(get_variable(SymbolType::parameter, var));
if (compute)
Stackf.push(params[var]);
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FLDV_ *) it_code->second)->get_pos();
lag = ((FLDV_ *) it_code->second)->get_lead_lag();
#ifdef DEBUG
mexPrintf("FLDV_ endo var=%d, lag=%d\n", var, lag);
mexPrintf("get_variable(eEndogenous, var)=%s, compute=%d\n", get_variable(eEndogenous, var).c_str(), compute);
mexPrintf("get_variable(SymbolType::endogenous, var)=%s, compute=%d\n", get_variable(SymbolType::endogenous, var).c_str(), compute);
mexPrintf("it_=%d, lag=%d, y_size=%d, var=%d, y=%x\n", it_, lag, y_size, var, y);
mexEvalString("drawnow;");
#endif
tmp_out.str("");
if (lag > 0)
tmp_out << get_variable(eEndogenous, var) << "(+" << lag << ")";
tmp_out << get_variable(SymbolType::endogenous, var) << "(+" << lag << ")";
else if (lag < 0)
tmp_out << get_variable(eEndogenous, var) << "(" << lag << ")";
tmp_out << get_variable(SymbolType::endogenous, var) << "(" << lag << ")";
else
tmp_out << get_variable(eEndogenous, var);
tmp_out << get_variable(SymbolType::endogenous, var);
Stack.push(tmp_out.str());
if (compute)
{
@ -731,7 +731,7 @@ public:
Stackf.push(y[(it_+lag)*y_size+var]);
}
break;
case eExogenous:
case SymbolType::exogenous:
var = ((FLDV_ *) it_code->second)->get_pos();
lag = ((FLDV_ *) it_code->second)->get_lead_lag();
#ifdef DEBUG
@ -739,14 +739,14 @@ public:
#endif
tmp_out.str("");
if (lag != 0)
tmp_out << get_variable(eExogenous, var) << "(" << lag << ")";
tmp_out << get_variable(SymbolType::exogenous, var) << "(" << lag << ")";
else
tmp_out << get_variable(eExogenous, var);
tmp_out << get_variable(SymbolType::exogenous, var);
Stack.push(tmp_out.str());
if (compute)
Stackf.push(x[it_+lag+var*nb_row_x]);
break;
case eExogenousDet:
case SymbolType::exogenousDet:
var = ((FLDV_ *) it_code->second)->get_pos();
lag = ((FLDV_ *) it_code->second)->get_lead_lag();
#ifdef DEBUG
@ -754,14 +754,14 @@ public:
#endif
tmp_out.str("");
if (lag != 0)
tmp_out << get_variable(eExogenousDet, var) << "(" << lag << ")";
tmp_out << get_variable(SymbolType::exogenousDet, var) << "(" << lag << ")";
else
tmp_out << get_variable(eExogenousDet, var);
tmp_out << get_variable(SymbolType::exogenousDet, var);
Stack.push(tmp_out.str());
if (compute)
Stackf.push(x[it_+lag+var*nb_row_xd]);
break;
case eModelLocalVariable:
case SymbolType::modelLocalVariable:
break;
default:
mexPrintf("FLDV: Unknown variable type\n");
@ -770,23 +770,23 @@ public:
case FLDSV:
case FLDVS:
//load a variable in the processor
switch (((FLDSV_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FLDSV_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FLDSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDSV_ param var=%d", var);
#endif
Stack.push(get_variable(eParameter, var));
Stack.push(get_variable(SymbolType::parameter, var));
if (compute)
Stackf.push(params[var]);
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FLDSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDSV_ endo var=%d", var);
#endif
Stack.push(get_variable(eEndogenous, var));
Stack.push(get_variable(SymbolType::endogenous, var));
if (compute)
{
if (it_code->first == FLDSV)
@ -800,28 +800,28 @@ public:
Stackf.push(steady_y[var]);
}
break;
case eExogenous:
case SymbolType::exogenous:
var = ((FLDSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDSV_ exo var=%d", var);
#endif
Stack.push(get_variable(eExogenous, var));
Stack.push(get_variable(SymbolType::exogenous, var));
#ifdef DEBUG
mexPrintf("oka var=%d, Stack.size()=%d x=%x\n", var, Stack.size(), x);
#endif
if (compute)
Stackf.push(x[var]);
break;
case eExogenousDet:
case SymbolType::exogenousDet:
var = ((FLDSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDSV_ exo_det var=%d", var);
#endif
Stack.push(get_variable(eExogenousDet, var));
Stack.push(get_variable(SymbolType::exogenousDet, var));
if (compute)
Stackf.push(x[var]);
break;
case eModelLocalVariable:
case SymbolType::modelLocalVariable:
break;
default:
mexPrintf("FLDSV: Unknown variable type\n");
@ -913,9 +913,9 @@ public:
case FSTPV:
//load a variable in the processor
go_on = false;
switch (((FSTPV_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FSTPV_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FSTPV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FSTPV_ param var=%d", var);
@ -923,7 +923,7 @@ public:
tmp_out2.str("");
tmp_out2 << Stack.top();
tmp_out.str("");
tmp_out << get_variable(eParameter, var) << " = " << tmp_out2.str();
tmp_out << get_variable(SymbolType::parameter, var) << " = " << tmp_out2.str();
Stack.pop();
if (compute)
{
@ -931,7 +931,7 @@ public:
Stackf.pop();
}
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FSTPV_ *) it_code->second)->get_pos();
lag = ((FSTPV_ *) it_code->second)->get_lead_lag();
#ifdef DEBUG
@ -940,7 +940,7 @@ public:
tmp_out2.str("");
tmp_out2 << Stack.top();
tmp_out.str("");
tmp_out << get_variable(eEndogenous, var);
tmp_out << get_variable(SymbolType::endogenous, var);
if (lag > 0)
tmp_out << "(+" << lag << ")";
else if (lag < 0)
@ -953,7 +953,7 @@ public:
Stackf.pop();
}
break;
case eExogenous:
case SymbolType::exogenous:
var = ((FSTPV_ *) it_code->second)->get_pos();
lag = ((FSTPV_ *) it_code->second)->get_lead_lag();
#ifdef DEBUG
@ -962,7 +962,7 @@ public:
tmp_out2.str("");
tmp_out2 << Stack.top();
tmp_out.str("");
tmp_out << get_variable(eExogenous, var);
tmp_out << get_variable(SymbolType::exogenous, var);
if (lag != 0)
tmp_out << "(" << lag << ")";
tmp_out << " = " << tmp_out2.str();
@ -973,7 +973,7 @@ public:
Stackf.pop();
}
break;
case eExogenousDet:
case SymbolType::exogenousDet:
var = ((FSTPV_ *) it_code->second)->get_pos();
lag = ((FSTPV_ *) it_code->second)->get_lead_lag();
#ifdef DEBUG
@ -982,7 +982,7 @@ public:
tmp_out2.str("");
tmp_out2 << Stack.top();
tmp_out.str("");
tmp_out << get_variable(eExogenousDet, var);
tmp_out << get_variable(SymbolType::exogenousDet, var);
if (lag != 0)
tmp_out << "(" << lag << ")";
tmp_out << " = " << tmp_out2.str();
@ -1000,9 +1000,9 @@ public:
case FSTPSV:
go_on = false;
//load a variable in the processor
switch (((FSTPSV_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FSTPSV_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FSTPSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FSTPSV_ param var=%d", var);
@ -1010,7 +1010,7 @@ public:
tmp_out2.str("");
tmp_out2 << Stack.top();
tmp_out.str("");
tmp_out << get_variable(eParameter, var);
tmp_out << get_variable(SymbolType::parameter, var);
tmp_out << " = " << tmp_out2.str();
Stack.pop();
if (compute)
@ -1019,7 +1019,7 @@ public:
Stackf.pop();
}
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FSTPSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FSTPSV_ endo var=%d", var);
@ -1027,7 +1027,7 @@ public:
tmp_out2.str("");
tmp_out2 << Stack.top();
tmp_out.str("");
tmp_out << get_variable(eEndogenous, var);
tmp_out << get_variable(SymbolType::endogenous, var);
tmp_out << " = " << tmp_out2.str();
Stack.pop();
if (compute)
@ -1036,8 +1036,8 @@ public:
Stackf.pop();
}
break;
case eExogenous:
case eExogenousDet:
case SymbolType::exogenous:
case SymbolType::exogenousDet:
var = ((FSTPSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FSTPSV_ exo var=%d", var);
@ -1045,7 +1045,7 @@ public:
tmp_out2.str("");
tmp_out2 << Stack.top();
tmp_out.str("");
tmp_out << get_variable(eExogenous, var);
tmp_out << get_variable(SymbolType::exogenous, var);
tmp_out << " = " << tmp_out2.str();
Stack.pop();
if (compute)
@ -1251,9 +1251,9 @@ public:
v1f = Stackf.top();
Stackf.pop();
}
switch (op)
switch (static_cast<BinaryOpcode>(op))
{
case oPlus:
case BinaryOpcode::plus:
#ifdef DEBUG
mexPrintf("+");
#endif
@ -1263,7 +1263,7 @@ public:
tmp_out << v1 << " + " << v2;
Stack.push(tmp_out.str());
break;
case oMinus:
case BinaryOpcode::minus:
#ifdef DEBUG
mexPrintf("-");
#endif
@ -1285,7 +1285,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oTimes:
case BinaryOpcode::times:
#ifdef DEBUG
mexPrintf("*");
#endif
@ -1307,7 +1307,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oDivide:
case BinaryOpcode::divide:
#ifdef DEBUG
mexPrintf("/");
#endif
@ -1341,7 +1341,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oLess:
case BinaryOpcode::less:
#ifdef DEBUG
mexPrintf("<");
#endif
@ -1363,7 +1363,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oGreater:
case BinaryOpcode::greater:
#ifdef DEBUG
mexPrintf(">");
#endif
@ -1385,7 +1385,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oLessEqual:
case BinaryOpcode::lessEqual:
#ifdef DEBUG
mexPrintf("<=");
#endif
@ -1407,7 +1407,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oGreaterEqual:
case BinaryOpcode::greaterEqual:
#ifdef DEBUG
mexPrintf(">=");
#endif
@ -1429,7 +1429,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oEqualEqual:
case BinaryOpcode::equalEqual:
#ifdef DEBUG
mexPrintf("==");
#endif
@ -1451,7 +1451,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oDifferent:
case BinaryOpcode::different:
#ifdef DEBUG
mexPrintf("!=");
#endif
@ -1473,7 +1473,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oPower:
case BinaryOpcode::power:
#ifdef DEBUG
mexPrintf("^");
#endif
@ -1506,7 +1506,7 @@ public:
tmp_out << ")";
Stack.push(tmp_out.str());
break;
case oPowerDeriv:
case BinaryOpcode::powerDeriv:
{
v3 = Stack.top();
Stack.pop();
@ -1514,9 +1514,9 @@ public:
{
int derivOrder = int (nearbyint(Stackf.top()));
Stackf.pop();
if (fabs(v1f) < NEAR_ZERO && v2f > 0
if (fabs(v1f) < near_zero && v2f > 0
&& derivOrder > v2f
&& fabs(v2f-nearbyint(v2f)) < NEAR_ZERO)
&& fabs(v2f-nearbyint(v2f)) < near_zero)
{
r = 0.0;
Stackf.push(r);
@ -1547,7 +1547,7 @@ public:
tmp_out << " |PowerDeriv(" << v1 << ", " << v2 << v3 << ")|";
#endif
break;
case oMax:
case BinaryOpcode::max:
#ifdef DEBUG
mexPrintf("max");
#endif
@ -1557,7 +1557,7 @@ public:
tmp_out << "max(" << v1 << ", " << v2 << ")";
Stack.push(tmp_out.str());
break;
case oMin:
case BinaryOpcode::min:
#ifdef DEBUG
mexPrintf("min");
#endif
@ -1567,7 +1567,7 @@ public:
tmp_out << "min(" << v1 << ", " << v2 << ")";
Stack.push(tmp_out.str());
break;
case oEqual:
case BinaryOpcode::equal:
default:
mexPrintf("Error unknown Unary operator=%d\n", op); mexEvalString("drawnow;");
;
@ -1582,23 +1582,23 @@ public:
v1f = Stackf.top();
Stackf.pop();
}
switch (op)
switch (static_cast<UnaryOpcode>(op))
{
case oUminus:
case UnaryOpcode::uminus:
if (compute)
Stackf.push(-v1f);
tmp_out.str("");
tmp_out << " -" << v1;
Stack.push(tmp_out.str());
break;
case oExp:
case UnaryOpcode::exp:
if (compute)
Stackf.push(exp(v1f));
tmp_out.str("");
tmp_out << "exp(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oLog:
case UnaryOpcode::log:
if (compute)
{
r = log(v1f);
@ -1616,7 +1616,7 @@ public:
tmp_out << "log(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oLog10:
case UnaryOpcode::log10:
if (compute)
{
r = log10(v1f);
@ -1634,98 +1634,98 @@ public:
tmp_out << "log10(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oCos:
case UnaryOpcode::cos:
if (compute)
Stackf.push(cos(v1f));
tmp_out.str("");
tmp_out << "cos(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oSin:
case UnaryOpcode::sin:
if (compute)
Stackf.push(sin(v1f));
tmp_out.str("");
tmp_out << "sin(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oTan:
case UnaryOpcode::tan:
if (compute)
Stackf.push(tan(v1f));
tmp_out.str("");
tmp_out << "tan(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oAcos:
case UnaryOpcode::acos:
if (compute)
Stackf.push(acos(v1f));
tmp_out.str("");
tmp_out << "acos(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oAsin:
case UnaryOpcode::asin:
if (compute)
Stackf.push(asin(v1f));
tmp_out.str("");
tmp_out << "asin(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oAtan:
case UnaryOpcode::atan:
if (compute)
Stackf.push(atan(v1f));
tmp_out.str("");
tmp_out << "atan(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oCosh:
case UnaryOpcode::cosh:
if (compute)
Stackf.push(cosh(v1f));
tmp_out.str("");
tmp_out << "cosh(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oSinh:
case UnaryOpcode::sinh:
if (compute)
Stackf.push(sinh(v1f));
tmp_out.str("");
tmp_out << "sinh(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oTanh:
case UnaryOpcode::tanh:
if (compute)
Stackf.push(tanh(v1f));
tmp_out.str("");
tmp_out << "tanh(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oAcosh:
case UnaryOpcode::acosh:
if (compute)
Stackf.push(acosh(v1f));
tmp_out.str("");
tmp_out << "acosh(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oAsinh:
case UnaryOpcode::asinh:
if (compute)
Stackf.push(asinh(v1f));
tmp_out.str("");
tmp_out << "asinh(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oAtanh:
case UnaryOpcode::atanh:
if (compute)
Stackf.push(atanh(v1f));
tmp_out.str("");
tmp_out << "atanh(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oSqrt:
case UnaryOpcode::sqrt:
if (compute)
Stackf.push(sqrt(v1f));
tmp_out.str("");
tmp_out << "sqrt(" << v1 << ")";
Stack.push(tmp_out.str());
break;
case oErf:
case UnaryOpcode::erf:
if (compute)
Stackf.push(erf(v1f));
tmp_out.str("");
@ -1754,16 +1754,16 @@ public:
v1f = Stackf.top();
Stackf.pop();
}
switch (op)
switch (static_cast<TrinaryOpcode>(op))
{
case oNormcdf:
case TrinaryOpcode::normcdf:
if (compute)
Stackf.push(0.5*(1+erf((v1f-v2f)/v3f/M_SQRT2)));
tmp_out.str("");
tmp_out << "normcdf(" << v1 << ", " << v2 << ", " << v3 << ")";
Stack.push(tmp_out.str());
break;
case oNormpdf:
case TrinaryOpcode::normpdf:
if (compute)
Stackf.push(1/(v3f*sqrt(2*M_PI)*exp(pow((v1f-v2f)/v3f, 2)/2)));
tmp_out.str("");
@ -1809,9 +1809,9 @@ public:
mxArray **input_arguments;
switch (function_type)
{
case ExternalFunctionWithoutDerivative:
case ExternalFunctionWithFirstDerivative:
case ExternalFunctionWithFirstandSecondDerivative:
case ExternalFunctionType::withoutDerivative:
case ExternalFunctionType::withFirstDerivative:
case ExternalFunctionType::withFirstAndSecondDerivative:
{
if (compute)
{
@ -1848,7 +1848,7 @@ public:
Stack.push(tmp_out.str());
}
break;
case ExternalFunctionNumericalFirstDerivative:
case ExternalFunctionType::numericalFirstDerivative:
{
if (compute)
{
@ -1902,7 +1902,7 @@ public:
Stack.push(tmp_out.str());
}
break;
case ExternalFunctionFirstDerivative:
case ExternalFunctionType::firstDerivative:
{
if (compute)
{
@ -1933,7 +1933,7 @@ public:
Stack.push(tmp_out.str());
}
break;
case ExternalFunctionNumericalSecondDerivative:
case ExternalFunctionType::numericalSecondDerivative:
{
if (compute)
{
@ -1986,7 +1986,7 @@ public:
Stack.push(tmp_out.str());
}
break;
case ExternalFunctionSecondDerivative:
case ExternalFunctionType::secondDerivative:
{
if (compute)
{
@ -2043,13 +2043,13 @@ public:
tmp_out.str("");
switch (function_type)
{
case ExternalFunctionWithoutDerivative:
case ExternalFunctionType::withoutDerivative:
tmp_out << "TEF(" << var << ") = " << Stack.top();
break;
case ExternalFunctionWithFirstDerivative:
case ExternalFunctionType::withFirstDerivative:
tmp_out << "[TEF(" << var << "), TEFD(" << var << ") ]= " << Stack.top();
break;
case ExternalFunctionWithFirstandSecondDerivative:
case ExternalFunctionType::withFirstAndSecondDerivative:
tmp_out << "[TEF(" << var << "), TEFD(" << var << "), TEFDD(" << var << ") ]= " << Stack.top();
break;
default:
@ -2105,9 +2105,9 @@ public:
Stackf.pop();
}
tmp_out.str("");
if (function_type == ExternalFunctionNumericalFirstDerivative)
if (function_type == ExternalFunctionType::numericalFirstDerivative)
tmp_out << "TEFD(" << indx << ", " << row << ") = " << Stack.top();
else if (function_type == ExternalFunctionFirstDerivative)
else if (function_type == ExternalFunctionType::firstDerivative)
tmp_out << "TEFD(" << indx << ") = " << Stack.top();
Stack.pop();
}
@ -2155,9 +2155,9 @@ public:
Stackf.pop();
}
tmp_out.str("");
if (function_type == ExternalFunctionNumericalSecondDerivative)
if (function_type == ExternalFunctionType::numericalSecondDerivative)
tmp_out << "TEFDD(" << indx << ", " << row << ", " << col << ") = " << Stack.top();
else if (function_type == ExternalFunctionSecondDerivative)
else if (function_type == ExternalFunctionType::secondDerivative)
tmp_out << "TEFDD(" << indx << ") = " << Stack.top();
Stack.pop();
}

View File

@ -120,7 +120,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
double *jacob = NULL, *jacob_other_endo = NULL, *jacob_exo = NULL, *jacob_exo_det = NULL;
EQN_block = block_num;
stack<double> Stack;
external_function_type function_type = ExternalFunctionWithoutDerivative;
ExternalFunctionType function_type = ExternalFunctionType::withoutDerivative;
#ifdef DEBUG
mexPrintf("compute_block_time\n");
@ -310,9 +310,9 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
break;
case FLDV:
//load a variable in the processor
switch (((FLDV_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FLDV_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FLDV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDV Param[var=%d]\n", var);
@ -320,7 +320,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
#endif
Stack.push(params[var]);
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FLDV_ *) it_code->second)->get_pos();
lag = ((FLDV_ *) it_code->second)->get_lead_lag();
#ifdef DEBUG
@ -337,7 +337,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
tmp_out << " y[" << it_+lag << ", " << var << "](" << y[(it_+lag)*y_size+var] << ")";
#endif
break;
case eExogenous:
case SymbolType::exogenous:
var = ((FLDV_ *) it_code->second)->get_pos();
lag = ((FLDV_ *) it_code->second)->get_lead_lag();
#ifdef DEBUG
@ -346,12 +346,12 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
#endif
Stack.push(x[it_+lag+var*nb_row_x]);
break;
case eExogenousDet:
case SymbolType::exogenousDet:
var = ((FLDV_ *) it_code->second)->get_pos();
lag = ((FLDV_ *) it_code->second)->get_lead_lag();
Stack.push(x[it_+lag+var*nb_row_xd]);
break;
case eModelLocalVariable:
case SymbolType::modelLocalVariable:
#ifdef DEBUG
mexPrintf("FLDV a local variable in Block %d Stack.size()=%d", block_num, Stack.size());
mexPrintf(" value=%f\n", Stack.top());
@ -363,9 +363,9 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
break;
case FLDSV:
//load a variable in the processor
switch (((FLDSV_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FLDSV_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FLDSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDSV Param[var=%d]=%f\n", var, params[var]);
@ -373,7 +373,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
#endif
Stack.push(params[var]);
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FLDSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDSV y[var=%d]=%f\n", var, ya[var]);
@ -384,7 +384,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
else
Stack.push(y[var]);
break;
case eExogenous:
case SymbolType::exogenous:
var = ((FLDSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDSV x[var=%d]\n", var);
@ -392,14 +392,14 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
#endif
Stack.push(x[var]);
break;
case eExogenousDet:
case SymbolType::exogenousDet:
var = ((FLDSV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDSV xd[var=%d]\n", var);
#endif
Stack.push(x[var]);
break;
case eModelLocalVariable:
case SymbolType::modelLocalVariable:
#ifdef DEBUG
mexPrintf("FLDSV a local variable in Block %d Stack.size()=%d", block_num, Stack.size());
mexPrintf(" value=%f\n", Stack.top());
@ -411,37 +411,37 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
break;
case FLDVS:
//load a variable in the processor
switch (((FLDVS_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FLDVS_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FLDVS_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("params[%d]\n", var);
#endif
Stack.push(params[var]);
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FLDVS_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDVS steady_y[%d]\n", var);
#endif
Stack.push(steady_y[var]);
break;
case eExogenous:
case SymbolType::exogenous:
var = ((FLDVS_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDVS x[%d] \n", var);
#endif
Stack.push(x[var]);
break;
case eExogenousDet:
case SymbolType::exogenousDet:
var = ((FLDVS_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FLDVS xd[%d]\n", var);
#endif
Stack.push(x[var]);
break;
case eModelLocalVariable:
case SymbolType::modelLocalVariable:
#ifdef DEBUG
mexPrintf("FLDVS a local variable in Block %d Stack.size()=%d", block_num, Stack.size());
mexPrintf(" value=%f\n", Stack.top());
@ -521,9 +521,9 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
break;
case FSTPV:
//load a variable in the processor
switch (((FSTPV_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FSTPV_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FSTPV_ *) it_code->second)->get_pos();
#ifdef DEBUG
mexPrintf("FSTPV params[%d]\n", var);
@ -531,7 +531,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
params[var] = Stack.top();
Stack.pop();
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FSTPV_ *) it_code->second)->get_pos();
lag = ((FSTPV_ *) it_code->second)->get_lead_lag();
y[(it_+lag)*y_size+var] = Stack.top();
@ -542,7 +542,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
#endif
Stack.pop();
break;
case eExogenous:
case SymbolType::exogenous:
var = ((FSTPV_ *) it_code->second)->get_pos();
lag = ((FSTPV_ *) it_code->second)->get_lead_lag();
x[it_+lag+var*nb_row_x] = Stack.top();
@ -554,7 +554,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
Stack.pop();
break;
case eExogenousDet:
case SymbolType::exogenousDet:
var = ((FSTPV_ *) it_code->second)->get_pos();
lag = ((FSTPV_ *) it_code->second)->get_lead_lag();
x[it_+lag+var*nb_row_xd] = Stack.top();
@ -571,14 +571,14 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
break;
case FSTPSV:
//load a variable in the processor
switch (((FSTPSV_ *) it_code->second)->get_type())
switch (static_cast<SymbolType>(((FSTPSV_ *) it_code->second)->get_type()))
{
case eParameter:
case SymbolType::parameter:
var = ((FSTPSV_ *) it_code->second)->get_pos();
params[var] = Stack.top();
Stack.pop();
break;
case eEndogenous:
case SymbolType::endogenous:
var = ((FSTPSV_ *) it_code->second)->get_pos();
y[var] = Stack.top();
#ifdef DEBUG
@ -588,8 +588,8 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
#endif
Stack.pop();
break;
case eExogenous:
case eExogenousDet:
case SymbolType::exogenous:
case SymbolType::exogenousDet:
var = ((FSTPSV_ *) it_code->second)->get_pos();
x[var] = Stack.top();
#ifdef DEBUG
@ -800,27 +800,27 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
Stack.pop();
v1 = Stack.top();
Stack.pop();
switch (op)
switch (static_cast<BinaryOpcode>(op))
{
case oPlus:
case BinaryOpcode::plus:
Stack.push(v1 + v2);
#ifdef DEBUG
tmp_out << " |" << v1 << "+" << v2 << "|";
#endif
break;
case oMinus:
case BinaryOpcode::minus:
Stack.push(v1 - v2);
#ifdef DEBUG
tmp_out << " |" << v1 << "-" << v2 << "|";
#endif
break;
case oTimes:
case BinaryOpcode::times:
Stack.push(v1 * v2);
#ifdef DEBUG
tmp_out << " |" << v1 << "*" << v2 << "|";
#endif
break;
case oDivide:
case BinaryOpcode::divide:
double tmp;
#ifdef DEBUG
mexPrintf("v1=%f / v2=%f\n", v1, v2);
@ -839,43 +839,43 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
tmp_out << " |" << v1 << "/" << v2 << "|";
#endif
break;
case oLess:
case BinaryOpcode::less:
Stack.push(double (v1 < v2));
#ifdef DEBUG
mexPrintf("v1=%f v2=%f v1 < v2 = %f\n", v1, v2, double (v1 < v2));
#endif
break;
case oGreater:
case BinaryOpcode::greater:
Stack.push(double (v1 > v2));
#ifdef DEBUG
tmp_out << " |" << v1 << ">" << v2 << "|";
#endif
break;
case oLessEqual:
case BinaryOpcode::lessEqual:
Stack.push(double (v1 <= v2));
#ifdef DEBUG
tmp_out << " |" << v1 << "<=" << v2 << "|";
#endif
break;
case oGreaterEqual:
case BinaryOpcode::greaterEqual:
Stack.push(double (v1 >= v2));
#ifdef DEBUG
tmp_out << " |" << v1 << ">=" << v2 << "|";
#endif
break;
case oEqualEqual:
case BinaryOpcode::equalEqual:
Stack.push(double (v1 == v2));
#ifdef DEBUG
tmp_out << " |" << v1 << "==" << v2 << "|";
#endif
break;
case oDifferent:
case BinaryOpcode::different:
Stack.push(double (v1 != v2));
#ifdef DEBUG
tmp_out << " |" << v1 << "!=" << v2 << "|";
#endif
break;
case oPower:
case BinaryOpcode::power:
#ifdef DEBUG
mexPrintf("pow\n");
#endif
@ -894,15 +894,15 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
tmp_out << " |" << v1 << "^" << v2 << "|";
#endif
break;
case oPowerDeriv:
case BinaryOpcode::powerDeriv:
{
int derivOrder = int (nearbyint(Stack.top()));
Stack.pop();
try
{
if (fabs(v1) < NEAR_ZERO && v2 > 0
if (fabs(v1) < near_zero && v2 > 0
&& derivOrder > v2
&& fabs(v2-nearbyint(v2)) < NEAR_ZERO)
&& fabs(v2-nearbyint(v2)) < near_zero)
Stack.push(0.0);
else
{
@ -923,19 +923,19 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
tmp_out << " |PowerDeriv(" << v1 << ", " << v2 << ")|";
#endif
break;
case oMax:
case BinaryOpcode::max:
Stack.push(max(v1, v2));
#ifdef DEBUG
tmp_out << " |max(" << v1 << "," << v2 << ")|";
#endif
break;
case oMin:
case BinaryOpcode::min:
Stack.push(min(v1, v2));
#ifdef DEBUG
tmp_out << " |min(" << v1 << "," << v2 << ")|";
#endif
break;
case oEqual:
case BinaryOpcode::equal:
// Nothing to do
break;
default:
@ -954,22 +954,22 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
#ifdef DEBUG
mexPrintf("FUNARY, op=%d\n", op);
#endif
switch (op)
switch (static_cast<UnaryOpcode>(op))
{
case oUminus:
case UnaryOpcode::uminus:
Stack.push(-v1);
#ifdef DEBUG
tmp_out << " |-(" << v1 << ")|";
#endif
break;
case oExp:
case UnaryOpcode::exp:
Stack.push(exp(v1));
#ifdef DEBUG
tmp_out << " |exp(" << v1 << ")|";
#endif
break;
case oLog:
case UnaryOpcode::log:
double tmp;
try
{
@ -987,7 +987,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
tmp_out << " |log(" << v1 << ")|";
#endif
break;
case oLog10:
case UnaryOpcode::log10:
try
{
tmp = log10_1(v1);
@ -1002,85 +1002,85 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
tmp_out << " |log10(" << v1 << ")|";
#endif
break;
case oCos:
case UnaryOpcode::cos:
Stack.push(cos(v1));
#ifdef DEBUG
tmp_out << " |cos(" << v1 << ")|";
#endif
break;
case oSin:
case UnaryOpcode::sin:
Stack.push(sin(v1));
#ifdef DEBUG
tmp_out << " |sin(" << v1 << ")|";
#endif
break;
case oTan:
case UnaryOpcode::tan:
Stack.push(tan(v1));
#ifdef DEBUG
tmp_out << " |tan(" << v1 << ")|";
#endif
break;
case oAcos:
case UnaryOpcode::acos:
Stack.push(acos(v1));
#ifdef DEBUG
tmp_out << " |acos(" << v1 << ")|";
#endif
break;
case oAsin:
case UnaryOpcode::asin:
Stack.push(asin(v1));
#ifdef DEBUG
tmp_out << " |asin(" << v1 << ")|";
#endif
break;
case oAtan:
case UnaryOpcode::atan:
Stack.push(atan(v1));
#ifdef DEBUG
tmp_out << " |atan(" << v1 << ")|";
#endif
break;
case oCosh:
case UnaryOpcode::cosh:
Stack.push(cosh(v1));
#ifdef DEBUG
tmp_out << " |cosh(" << v1 << ")|";
#endif
break;
case oSinh:
case UnaryOpcode::sinh:
Stack.push(sinh(v1));
#ifdef DEBUG
tmp_out << " |sinh(" << v1 << ")|";
#endif
break;
case oTanh:
case UnaryOpcode::tanh:
Stack.push(tanh(v1));
#ifdef DEBUG
tmp_out << " |tanh(" << v1 << ")|";
#endif
break;
case oAcosh:
case UnaryOpcode::acosh:
Stack.push(acosh(v1));
#ifdef DEBUG
tmp_out << " |acosh(" << v1 << ")|";
#endif
break;
case oAsinh:
case UnaryOpcode::asinh:
Stack.push(asinh(v1));
#ifdef DEBUG
tmp_out << " |asinh(" << v1 << ")|";
#endif
break;
case oAtanh:
case UnaryOpcode::atanh:
Stack.push(atanh(v1));
#ifdef DEBUG
tmp_out << " |atanh(" << v1 << ")|";
#endif
break;
case oSqrt:
case UnaryOpcode::sqrt:
Stack.push(sqrt(v1));
#ifdef DEBUG
tmp_out << " |sqrt(" << v1 << ")|";
#endif
break;
case oErf:
case UnaryOpcode::erf:
Stack.push(erf(v1));
#ifdef DEBUG
tmp_out << " |erf(" << v1 << ")|";
@ -1104,15 +1104,15 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
Stack.pop();
v1 = Stack.top();
Stack.pop();
switch (op)
switch (static_cast<TrinaryOpcode>(op))
{
case oNormcdf:
case TrinaryOpcode::normcdf:
Stack.push(0.5*(1+erf((v1-v2)/v3/M_SQRT2)));
#ifdef DEBUG
tmp_out << " |normcdf(" << v1 << ", " << v2 << ", " << v3 << ")|";
#endif
break;
case oNormpdf:
case TrinaryOpcode::normpdf:
Stack.push(1/(v3*sqrt(2*M_PI)*exp(pow((v1-v2)/v3, 2)/2)));
#ifdef DEBUG
tmp_out << " |normpdf(" << v1 << ", " << v2 << ", " << v3 << ")|";
@ -1166,9 +1166,9 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
mxArray **input_arguments;
switch (function_type)
{
case ExternalFunctionWithoutDerivative:
case ExternalFunctionWithFirstDerivative:
case ExternalFunctionWithFirstandSecondDerivative:
case ExternalFunctionType::withoutDerivative:
case ExternalFunctionType::withFirstDerivative:
case ExternalFunctionType::withFirstAndSecondDerivative:
{
input_arguments = (mxArray **) mxMalloc(nb_input_arguments * sizeof(mxArray *));
test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *));
@ -1191,7 +1191,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
double *rr = mxGetPr(output_arguments[0]);
Stack.push(*rr);
if (function_type == ExternalFunctionWithFirstDerivative || function_type == ExternalFunctionWithFirstandSecondDerivative)
if (function_type == ExternalFunctionType::withFirstDerivative || function_type == ExternalFunctionType::withFirstAndSecondDerivative)
{
unsigned int indx = fc->get_indx();
double *FD1 = mxGetPr(output_arguments[1]);
@ -1199,7 +1199,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
for (unsigned int i = 0; i < rows; i++)
TEFD[make_pair(indx, i)] = FD1[i];
}
if (function_type == ExternalFunctionWithFirstandSecondDerivative)
if (function_type == ExternalFunctionType::withFirstAndSecondDerivative)
{
unsigned int indx = fc->get_indx();
double *FD2 = mxGetPr(output_arguments[2]);
@ -1212,7 +1212,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
}
}
break;
case ExternalFunctionNumericalFirstDerivative:
case ExternalFunctionType::numericalFirstDerivative:
{
input_arguments = (mxArray **) mxMalloc((nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *));
test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, (nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *));
@ -1252,7 +1252,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
Stack.push(*rr);
}
break;
case ExternalFunctionFirstDerivative:
case ExternalFunctionType::firstDerivative:
{
input_arguments = (mxArray **) mxMalloc(nb_input_arguments * sizeof(mxArray *));
test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *));
@ -1276,7 +1276,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
TEFD[make_pair(indx, i)] = FD1[i];
}
break;
case ExternalFunctionNumericalSecondDerivative:
case ExternalFunctionType::numericalSecondDerivative:
{
input_arguments = (mxArray **) mxMalloc((nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *));
test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, (nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *));
@ -1315,7 +1315,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
Stack.push(*rr);
}
break;
case ExternalFunctionSecondDerivative:
case ExternalFunctionType::secondDerivative:
{
input_arguments = (mxArray **) mxMalloc(nb_input_arguments * sizeof(mxArray *));
test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *));
@ -1375,7 +1375,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
mexPrintf("FSTPTEFD\n");
mexPrintf("indx=%d Stack.size()=%d\n", indx, Stack.size());
#endif
if (function_type == ExternalFunctionNumericalFirstDerivative)
if (function_type == ExternalFunctionType::numericalFirstDerivative)
{
TEFD[make_pair(indx, row-1)] = Stack.top();
#ifdef DEBUG
@ -1409,7 +1409,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
mexPrintf("FSTPTEFD\n");
mexPrintf("indx=%d Stack.size()=%d\n", indx, Stack.size());
#endif
if (function_type == ExternalFunctionNumericalSecondDerivative)
if (function_type == ExternalFunctionType::numericalSecondDerivative)
{
TEFDD[make_pair(indx, make_pair(row-1, col-1))] = Stack.top();
#ifdef DEBUG

View File

@ -609,7 +609,7 @@ Interpreter::check_for_controlled_exo_validity(FBEGINBLOCK_ *fb, vector<s_plan>
if ((find(endogenous.begin(), endogenous.end(), it->exo_num) != endogenous.end()) && (find(exogenous.begin(), exogenous.end(), it->var_num) == exogenous.end()))
{
ostringstream tmp;
tmp << "\n the conditional forecast involving as constrained variable " << get_variable(eEndogenous, it->exo_num) << " and as endogenized exogenous " << get_variable(eExogenous, it->var_num) << " that do not appear in block=" << Block_Count+1 << ")\n You should not use block in model options\n";
tmp << "\n the conditional forecast involving as constrained variable " << get_variable(SymbolType::endogenous, it->exo_num) << " and as endogenized exogenous " << get_variable(SymbolType::exogenous, it->var_num) << " that do not appear in block=" << Block_Count+1 << ")\n You should not use block in model options\n";
throw FatalExceptionHandling(tmp.str());
}
else if ((find(endogenous.begin(), endogenous.end(), it->exo_num) != endogenous.end()) && (find(exogenous.begin(), exogenous.end(), it->var_num) != exogenous.end()) && ((fb->get_type() == EVALUATE_FORWARD) || (fb->get_type() != EVALUATE_BACKWARD)))
@ -621,7 +621,7 @@ Interpreter::check_for_controlled_exo_validity(FBEGINBLOCK_ *fb, vector<s_plan>
else if (find(previous_block_exogenous.begin(), previous_block_exogenous.end(), it->var_num) != previous_block_exogenous.end())
{
ostringstream tmp;
tmp << "\n the conditional forecast involves in the block " << Block_Count+1 << " the endogenized exogenous " << get_variable(eExogenous, it->var_num) << " that appear also in a previous block\n You should not use block in model options\n";
tmp << "\n the conditional forecast involves in the block " << Block_Count+1 << " the endogenized exogenous " << get_variable(SymbolType::exogenous, it->var_num) << " that appear also in a previous block\n You should not use block in model options\n";
throw FatalExceptionHandling(tmp.str());
}
}

View File

@ -729,9 +729,9 @@ main(int nrhs, const char *prhs[])
char name [100];
mxGetString(tmp, name, 100);
splan[i].var = name;
SymbolType variable_type = eEndogenous;
SymbolType variable_type = SymbolType::endogenous;
int exo_num = emsg.get_ID(name, &variable_type);
if (variable_type == eExogenous || variable_type == eExogenousDet)
if (variable_type == SymbolType::exogenous || variable_type == SymbolType::exogenousDet)
splan[i].var_num = exo_num;
else
{
@ -749,7 +749,7 @@ main(int nrhs, const char *prhs[])
splan[i].exo = name;
SymbolType variable_type;
int exo_num = emsg.get_ID(name, &variable_type);
if (variable_type == eEndogenous)
if (variable_type == SymbolType::endogenous)
splan[i].exo_num = exo_num;
else
{
@ -807,9 +807,9 @@ main(int nrhs, const char *prhs[])
char name [100];
mxGetString(tmp, name, 100);
spfplan[i].var = name;
SymbolType variable_type = eEndogenous;
SymbolType variable_type = SymbolType::endogenous;
int exo_num = emsg.get_ID(name, &variable_type);
if (variable_type == eExogenous || variable_type == eExogenousDet)
if (variable_type == SymbolType::exogenous || variable_type == SymbolType::exogenousDet)
splan[i].var_num = exo_num;
else
{
@ -827,7 +827,7 @@ main(int nrhs, const char *prhs[])
spfplan[i].exo = name;
SymbolType variable_type;
int exo_num = emsg.get_ID(name, &variable_type);
if (variable_type == eEndogenous)
if (variable_type == SymbolType::endogenous)
spfplan[i].exo_num = exo_num;
else
{

@ -1 +1 @@
Subproject commit 15f5f4f1bedbaf289aeda49466e01c6025db4cd0
Subproject commit 49e1c43aed1acd80237d7fe911603ac4dd52d67d

View File

@ -53,8 +53,13 @@ MODFILES = \
ramst.mod \
ramst_a.mod \
ramst_static_tag.mod \
on-the-fly/ex1.mod \
on-the-fly/ex2.mod \
on-the-fly/ex3.mod \
on-the-fly/ex4.mod \
on-the-fly/ex5.mod \
on-the-fly/ex6.mod \
example1.mod \
example1_on_the_fly.mod \
example2.mod \
example1_use_dll.mod \
example1_with_tags.mod \
@ -483,13 +488,13 @@ deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.o.trs: determ
deterministic_simulations/multiple_lead_lags/sim_lead_lag.m.trs: deterministic_simulations/multiple_lead_lags/sim_base.m.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.m.trs
deterministic_simulations/multiple_lead_lags/sim_lead_lag.o.trs: deterministic_simulations/multiple_lead_lags/sim_base.o.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.o.trs
deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.m.trs: ramst.m.trs
deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.m.trs: ramst.m.trs
deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.o.trs: ramst.o.trs
loglinear/example4_loglinear.m.trs: loglinear/example4_exp.m.trs
loglinear/example4_loglinear.o.trs: loglinear/example4_exp.o.trs
loglinear/example4_loglinear_lagged_exogenous_a.m.trs: loglinear/example4_loglinear_lagged_exogenous.m.trs
loglinear/example4_loglinear_lagged_exogenous_a.o.trs: loglinear/example4_loglinear_lagged_exogenous.o.trs
loglinear/example4_loglinear_lagged_exogenous_a.m.trs: loglinear/example4_loglinear_lagged_exogenous.m.trs
loglinear/example4_loglinear_lagged_exogenous_a.o.trs: loglinear/example4_loglinear_lagged_exogenous.o.trs
loglinear/example4_loglinear_histval.m.trs: loglinear/example4_exp_histval.m.trs
loglinear/example4_loglinear_histval.o.trs: loglinear/example4_exp_histval.o.trs
@ -582,6 +587,10 @@ external_function: m/external_function o/external_function
m/external_function: $(patsubst %.mod, %.m.trs, $(filter external_function/%.mod, $(MODFILES)))
o/external_function: $(patsubst %.mod, %.o.trs, $(filter external_function/%.mod, $(MODFILES)))
on-the-fly: m/on-the-fly o/on-the-fly
m/on-the-fly: $(patsubst %.mod, %.m.trs, $(filter on-the-fly/%.mod, $(MODFILES)))
o/on-the-fly: $(patsubst %.mod, %.o.trs, $(filter on-the-fly/%.mod, $(MODFILES)))
trend_var: m/trend_var o/trend_var
m/trend_var: $(patsubst %.mod, %.m.trs, $(filter trend_var/%.mod, $(MODFILES)))
o/trend_var: $(patsubst %.mod, %.o.trs, $(filter trend_var/%.mod, $(MODFILES)))
@ -883,7 +892,7 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES)
%.m.trs %.m.log : %.m
@echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$*... `tput sgr0`"
@DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \
$(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null
$(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null
@echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$* Done!`tput sgr0`"
%.o.trs %.o.log: %.mod
@ -903,7 +912,8 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES)
%.o.trs %.o.log : %.m
@echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$*... `tput sgr0`"
@DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \
$(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1
$(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1 || \
printf ":test-result: FAIL\n:number-tests: 1\n:number-failed-tests: 1\n:list-of-failed-tests: $*.m\n:elapsed-time: 0.0\n" > $*.o.trs
@echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$* Done!`tput sgr0`"
%.m.tls : %.m

View File

@ -1,74 +1,67 @@
var Capital, Output, Labour, Consumption, Investment, Efficiency, efficiency, residual, marginal_utility;
varexo EfficiencyInnovation;
parameters beta, theta, tau, alpha, psi, delta, rho, effstar, sigma;
/*
** Calibration
*/
var k, y, L, c, i, A, a, mu;
varexo epsilon;
parameters beta, theta, tau, alpha, psi, delta, rho, Astar, sigma;
beta = 0.990;
theta = 0.357;
tau = 2.000;
alpha = 0.450;
psi = -0.200;
psi = -2.500;
delta = 0.020;
rho = 0.800;
effstar = 1.000;
rho = 0.998;
Astar = 1.000;
sigma = 0.100;
model;
a = rho*a(-1) + sigma*epsilon;
A = Astar*exp(a);
(c^theta*(1-L)^(1-theta))^(1-tau)/c - mu = beta*((c(+1)^theta*(1-L(+1))^(1-theta))^(1-tau)/c(+1)*(alpha*(y(+1)/k)^(1-psi)+1-delta)-mu(+1)*(1-delta));
((1-theta)/theta)*(c/(1-L)) - (1-alpha)*(y/L)^(1-psi);
y = A*(alpha*(k(-1)^psi)+(1-alpha)*(L^psi))^(1/psi);
k = y-c+(1-delta)*k(-1);
i = k-(1-delta)*k(-1);
efficiency = rho*efficiency(-1) + sigma*EfficiencyInnovation;
Efficiency = effstar*exp(efficiency);
[mcp = 'Investment > 0',name='Investment Euler Equation']
-(((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption + beta*((((Consumption(+1)^theta)*((1-Labour(+1))^(1-theta)))^(1-tau))/Consumption(+1))*(alpha*((Output(+1)/Capital)^(1-psi))+1-delta);
residual = (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption - beta*((((Consumption(+1)^theta)*((1-Labour(+1))^(1-theta)))^(1-tau))/Consumption(+1))*(alpha*((Output(+1)/Capital)^(1-psi))+1-delta);
((1-theta)/theta)*(Consumption/(1-Labour)) - (1-alpha)*(Output/Labour)^(1-psi);
Output = Efficiency*(alpha*(Capital(-1)^psi)+(1-alpha)*(Labour^psi))^(1/psi);
Output = Consumption + Investment;
Investment = Capital - (1-delta)*Capital(-1);
marginal_utility = (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption;
[ mcp = 'i > 0' ]
mu = 0;
end;
steady_state_model;
Efficiency = effstar;
y_k = (Efficiency^(-psi)*(1/beta-1+delta)/alpha)^(1/(1-psi));
c_k = y_k - delta;
n_k = (((y_k/Efficiency)^psi-alpha)/(1-alpha))^(1/psi);
y_n = y_k/n_k;
c_n = c_k/n_k;
Labour = y_k*(1-alpha)/(((1-theta)/theta)*c_k*(alpha*n_k^(-psi)+1-alpha)+y_k*(1-alpha));
Capital = Labour/n_k;
Consumption = c_n*Labour;
Output = Efficiency*(alpha*Capital^psi+(1-alpha)*Labour^psi)^(1/psi);
Investment = delta*Capital;
residual = 0;
marginal_utility = (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption;
end;
a=0;
mu=0;
A=Astar;
resid;
steady;
// Steady state ratios
Output_per_unit_of_Capital=((1/beta-1+delta)/alpha)^(1/(1-psi));
Consumption_per_unit_of_Capital=Output_per_unit_of_Capital-delta;
Labour_per_unit_of_Capital=(((Output_per_unit_of_Capital/A)^psi-alpha)/(1-alpha))^(1/psi);
Output_per_unit_of_Labour=Output_per_unit_of_Capital/Labour_per_unit_of_Capital;
Consumption_per_unit_of_Labour=Consumption_per_unit_of_Capital/Labour_per_unit_of_Capital;
L=1/(1+Consumption_per_unit_of_Labour/((1-alpha)*theta/(1-theta)*Output_per_unit_of_Labour^(1-psi)));
c=Consumption_per_unit_of_Labour*L;
k=L/Labour_per_unit_of_Capital;
y=Output_per_unit_of_Capital*k;
i=delta*k;
end;
shocks;
var EfficiencyInnovation;
periods 1;
values -4;
var epsilon;
periods 10;
values -1;
end;
perfect_foresight_setup(periods=100);
steady;
perfect_foresight_solver(lmmcp);
perfect_foresight_setup(periods=400);
perfect_foresight_solver(lmmcp, maxit=200);
rplot Investment;
n = 40;
figure(2);
subplot(3,2,1); plot(1:n,A(1:n)); title('A');
subplot(3,2,2); plot(2:n,y(2:n)); title('y');
subplot(3,2,3); plot(2:n,L(2:n)); title('L');
subplot(3,2,4); plot(1:n,k(1:n)); title('k');
subplot(3,2,5); plot(2:n,c(2:n)); title('c');
subplot(3,2,6); plot(2:n, y(2:n)-c(2:n)); title('i');
rplot residual;

View File

@ -30,24 +30,16 @@ beta = 0.99;
delta = 0.025;
psi = 0;
theta = 2.95;
phi = 0.1;
initval;
y = 1.08068253095672;
c = 0.80359242014163;
h = 0.29175631001732;
k = 11.08360443260358;
a = 0;
b = 0;
e = 0;
u = 0;
end;
if ~isequal(length(intersect(M_.endo_names, {'c'; 'h'; 'y'; 'k'; 'b'; 'a'})), 6)
error('Endogenous variables are wrong.')
end
shocks;
var e; stderr 0.009;
var u; stderr 0.009;
var e, u = phi*0.009*0.009;
end;
if ~isequal(length(intersect(M_.param_names, {'theta'; 'psi'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 7)
error('Parameters are wrong.')
end
stoch_simul;
if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'})), 2)
error('Exogenous variables are wrong.')
end

38
tests/on-the-fly/ex2.mod Normal file
View File

@ -0,0 +1,38 @@
// --+ options: nostrict +--
/*
** Same as ex1.mod without the first equation -> h is an exogenous variable, psi is not a model object (because it
** is not used in the remaining equations), and theta is an exogenous equation (see the last equation).
*/
model;
//c*theta|p*h|e^(1+psi|p)=(1-alpha)*y;
k|e = beta|p*(((exp(b)*c)/(exp(b(+1))*c(+1)))
*(exp(b(+1))*alpha|p*y(+1)+(1-delta)*k));
y|e = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
k = exp(b)*(y-c|e)+(1-delta|p)*k(-1);
a|e = rho|p*a(-1)+tau*b(-1) + e|x;
b|e = tau|p*a(-1)+rho*b(-1) + u|x + .0*theta; // The last term is here just for testing purpose.
end;
alpha = 0.36;
rho = 0.95;
tau = 0.025;
beta = 0.99;
delta = 0.025;
psi = 0;
// If the following line is uncommented, this will trigger an error from the preprocessor
// because it is not allowed to give a value to an exogenous variable.
//theta = 2.95;
phi = 0.1;
if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'})), 5)
error('Endogenous variables are wrong.')
end
if ~isequal(length(intersect(M_.param_names, {'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 5)
error('Parameters are wrong.')
end
if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'h'; 'theta'})), 4)
error('Exogenous variables are wrong.')
end

40
tests/on-the-fly/ex3.mod Normal file
View File

@ -0,0 +1,40 @@
// --+ options: nostrict +--
/*
** In the following example, we only declare one endogenous variable per equation. Because the other objects are not declared
** they are treated as exogenous variables. An equation tag is used to associate an endogenous variable to each equation.
*/
model;
[endogenous='h']
c*theta*h^(1+psi)=(1-alpha)*y;
[endogenous='k']
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
*(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
[endogenous='y']
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
[endogenous='c']
k = exp(b)*(y-c)+(1-delta)*k(-1);
[endogenous='a']
a = rho*a(-1)+tau*b(-1) + e;
[endogenous='b']
b = tau*a(-1)+rho*b(-1) + u;
end;
if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'; 'h'})), 6)
error('Endogenous variables are wrong.')
end
if isfield(M_, 'param_names')
error('Parameters are wrong.')
end
if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'theta'; 'psi'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 9)
error('Exogenous variables are wrong.')
end

39
tests/on-the-fly/ex4.mod Normal file
View File

@ -0,0 +1,39 @@
// --+ options: nostrict +--
/*
** Same as ex3.mod without the first equation, hours (h) are exogenous.
*/
model;
//[endogenous='h']
//c*theta*h^(1+psi)=(1-alpha)*y;
[endogenous='k']
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
*(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
[endogenous='y']
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
[endogenous='c']
k = exp(b)*(y-c)+(1-delta)*k(-1);
[endogenous='a']
a = rho*a(-1)+tau*b(-1) + e;
[endogenous='b']
b = tau*a(-1)+rho*b(-1) + u;
end;
if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'})), 5)
error('Endogenous variables are wrong.')
end
if isfield(M_, 'param_names')
error('Parameters are wrong.')
end
if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'h'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 8)
error('Exogenous variables are wrong.')
end

36
tests/on-the-fly/ex5.mod Normal file
View File

@ -0,0 +1,36 @@
// --+ options: nostrict +--
/*
** It is possible to associate an endogenous variable to an equation were the variable does not appear (if it makes sense).
*/
parameters a0, a1, b0, b1;
a0 = 1.0;
a1 = 0.1;
b0 = 0.5;
b1 = 0.2;
model;
[endogenous='D']
D = a0 - a1*p;
[endogenous='S']
S = b0 + b1*p;
[endogenous='p']
S = D;
end;
if ~isequal(length(intersect(M_.endo_names, {'D'; 'S'; 'p'})), 3)
error('Endogenous variables are wrong.')
end
if isfield(M_, 'exo_names')
error('Exogenous variables are wrong.')
end

33
tests/on-the-fly/ex6.mod Normal file
View File

@ -0,0 +1,33 @@
// --+ options: nostrict +--
/*
** Same as ex5.mod, but price is treated as an exoenous variable.
*/
parameters a0, a1, b0, b1;
a0 = 1.0;
a1 = 0.1;
b0 = 0.5;
b1 = 0.2;
model;
[endogenous='D']
D = a0 - a1*p;
[endogenous='S']
S = b0 + b1*p;
//[endogenous='p']
//S = D;
end;
if ~isequal(length(intersect(M_.endo_names, {'D'; 'S'})), 2)
error('Endogenous variables are wrong.')
end
if ~isequal(M_.exo_names, {'p'})
error('Exogenous variables are wrong.')
end