Commit 3a7fa012 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Merge branch 'master' into set-optimization-options

parents 137662d5 5f483c7d
...@@ -75,7 +75,7 @@ if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1)) ...@@ -75,7 +75,7 @@ if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
else else
if B.vobs>C.vobs if B.vobs>C.vobs
idB = 1:B.vobs; idB = 1:B.vobs;
idC = ones(1:B.vobs); idC = ones(1,B.vobs);
elseif B.vobs<C.vobs elseif B.vobs<C.vobs
idB = ones(1,C.vobs); idB = ones(1,C.vobs);
idC = 1:C.vobs; idC = 1:C.vobs;
...@@ -116,6 +116,7 @@ for i=1:A.vobs ...@@ -116,6 +116,7 @@ for i=1:A.vobs
A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']};
end end
A.data = bsxfun(@plus,B.data,C.data); A.data = bsxfun(@plus,B.data,C.data);
A.time = A.init:A.init+A.nobs;
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.
......
...@@ -70,9 +70,7 @@ i_upd = ny+(1:periods*ny); ...@@ -70,9 +70,7 @@ i_upd = ny+(1:periods*ny);
Y = endo_simul(:); Y = endo_simul(:);
disp (['-----------------------------------------------------']) ; disp (['-----------------------------------------------------']) ;
disp (['MODEL SIMULATION :']) ; fprintf('MODEL SIMULATION:\n');
fprintf('\n') ;
model_dynamic = str2func([M_.fname,'_dynamic']); model_dynamic = str2func([M_.fname,'_dynamic']);
z = Y(find(lead_lag_incidence')); z = Y(find(lead_lag_incidence'));
...@@ -115,18 +113,15 @@ for iter = 1:options_.maxit_ ...@@ -115,18 +113,15 @@ for iter = 1:options_.maxit_
end end
err = max(abs(res)); err = max(abs(res));
if options_.debug
fprintf('\nLargest absolute residual at iteration %d: %10.3f\n',iter,err);
if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y))
fprintf('\nWARNING: NaN or Inf detected in the residuals or endogenous variables.\n');
end
skipline()
end
if err < options_.dynatol.f if err < options_.dynatol.f
stop = 1 ; stop = 1 ;
fprintf('\n') ;
disp([' Total time of simulation :' num2str(etime(clock,h1))]) ;
fprintf('\n') ;
disp([' Convergency obtained.']) ;
fprintf('\n') ;
oo_.deterministic_simulation.status = 1;% Convergency obtained.
oo_.deterministic_simulation.error = err;
oo_.deterministic_simulation.iterations = iter;
oo_.endo_simul = reshape(Y,ny,periods+2);
break break
end end
...@@ -137,16 +132,36 @@ for iter = 1:options_.maxit_ ...@@ -137,16 +132,36 @@ for iter = 1:options_.maxit_
end end
if ~stop if stop
fprintf('\n') ; if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y))
disp([' Total time of simulation :' num2str(etime(clock,h1))]) ; oo_.deterministic_simulation.status = 0;% NaN or Inf occurred
fprintf('\n') ; oo_.deterministic_simulation.error = err;
disp(['WARNING : maximum number of iterations is reached (modify options_.maxit_).']) ; oo_.deterministic_simulation.iterations = iter;
fprintf('\n') ; oo_.endo_simul = reshape(Y,ny,periods+2);
skipline();
fprintf('\nSimulation terminated after %d iterations.\n',iter);
fprintf('Total time of simulation : %10.3f\n',etime(clock,h1));
error('Simulation terminated with NaN or Inf in the residuals or endogenous variables. There is most likely something wrong with your model.');
else
skipline();
fprintf('\nSimulation concluded successfully after %d iterations.\n',iter);
fprintf('Total time of simulation : %10.3f\n',etime(clock,h1));
fprintf('Convergency obtained.\n');
oo_.deterministic_simulation.status = 1;% Convergency obtained.
oo_.deterministic_simulation.error = err;
oo_.deterministic_simulation.iterations = iter;
oo_.endo_simul = reshape(Y,ny,periods+2);
end
elseif ~stop
skipline();
fprintf('\nSimulation terminated after %d iterations.\n',iter);
fprintf('Total time of simulation : %10.3f\n',etime(clock,h1));
fprintf('WARNING : maximum number of iterations is reached (modify options_.maxit_).\n') ;
oo_.deterministic_simulation.status = 0;% more iterations are needed. oo_.deterministic_simulation.status = 0;% more iterations are needed.
oo_.deterministic_simulation.error = err; oo_.deterministic_simulation.error = err;
%oo_.deterministic_simulation.errors = c/abs(err) %oo_.deterministic_simulation.errors = c/abs(err)
oo_.deterministic_simulation.iterations = options_.maxit_; oo_.deterministic_simulation.iterations = options_.maxit_;
end end
disp (['-----------------------------------------------------']) ; disp (['-----------------------------------------------------']) ;
skipline();
...@@ -76,7 +76,7 @@ NativeStatement::computingPass() ...@@ -76,7 +76,7 @@ NativeStatement::computingPass()
{ {
using namespace boost::xpressive; using namespace boost::xpressive;
// Return if this is a comment // Return if this is a comment
sregex comment_expr = sregex::compile( "\%.*" ); sregex comment_expr = sregex::compile( "\\s*\%.*" );
match_results<string::const_iterator> results; match_results<string::const_iterator> results;
if (regex_match(native_statement, results, comment_expr)) if (regex_match(native_statement, results, comment_expr))
return; return;
...@@ -93,38 +93,41 @@ NativeStatement::computingPass() ...@@ -93,38 +93,41 @@ NativeStatement::computingPass()
else else
apostrophes.push_back(idx); apostrophes.push_back(idx);
if (apostrophes.size() % 2)
{
cerr << native_statement <<
" seems to be invalid Matlab syntax (an odd number of apostrophes was encountered)" << endl;
exit(EXIT_FAILURE);
}
bool skip = false; bool skip = false;
string newstr = ""; string newstr = "";
int lastidx = 0; sregex date_expr = sregex::compile( "-?[0-9]+[Mm](1[0-2]|[1-9])|-?[0-9]+[Qq][1-4]|-?[0-9]+[Ww]([1-4][0-9]|5[0-2]|[1-9])" );
sregex date_expr = sregex::compile( "-?[0-9]+[Mm]([1-9]|1[0-2])|-?[0-9]+[Qq][1-4]|-?[0-9]+[Ww]([1-9]{1}|[1-4][0-9]|5[0-2])" );
string format( "dynDate('$&')" ); string format( "dynDate('$&')" );
size_t lastidx = 0;
for (size_t i = 0; i < apostrophes.size(); i++) for (size_t i = 0; i < apostrophes.size(); i++)
if (apostrophes[i] == 0) if (apostrophes[i] == 0)
skip = true; skip = true;
else else
{ if (skip)
if (skip) {
{ newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx));
skip = false; lastidx = apostrophes[i];
newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx)); skip = false;
} }
else else
{ {
skip = true; newstr.append(regex_replace(native_statement.substr(lastidx, apostrophes[i] - lastidx),
newstr.append(regex_replace(native_statement.substr(lastidx, apostrophes[i] - lastidx), date_expr, format));
date_expr, format)); lastidx = apostrophes[i];
} skip = true;
lastidx = apostrophes[i]; }
} size_t length = native_statement.length() - lastidx;
newstr.append(regex_replace(native_statement.substr(lastidx, native_statement.size() - lastidx), size_t commentidx = native_statement.substr(lastidx, length).find("%", 0);
date_expr, format)); if (commentidx != string::npos)
length = commentidx;
newstr.append(regex_replace(native_statement.substr(lastidx, length), date_expr, format));
if (commentidx != string::npos)
{
lastidx += commentidx;
newstr.append(native_statement.substr(lastidx, native_statement.length() - lastidx));
}
native_statement = newstr; native_statement = newstr;
} }
......
Supports Markdown
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