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))
else
if B.vobs>C.vobs
idB = 1:B.vobs;
idC = ones(1:B.vobs);
idC = ones(1,B.vobs);
elseif B.vobs<C.vobs
idB = ones(1,C.vobs);
idC = 1:C.vobs;
......@@ -116,6 +116,7 @@ for i=1:A.vobs
A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']};
end
A.data = bsxfun(@plus,B.data,C.data);
A.time = A.init:A.init+A.nobs;
%@test:1
%$ % Define a datasets.
......
......@@ -70,9 +70,7 @@ i_upd = ny+(1:periods*ny);
Y = endo_simul(:);
disp (['-----------------------------------------------------']) ;
disp (['MODEL SIMULATION :']) ;
fprintf('\n') ;
fprintf('MODEL SIMULATION:\n');
model_dynamic = str2func([M_.fname,'_dynamic']);
z = Y(find(lead_lag_incidence'));
......@@ -115,18 +113,15 @@ for iter = 1:options_.maxit_
end
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
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
end
......@@ -137,16 +132,36 @@ for iter = 1:options_.maxit_
end
if ~stop
fprintf('\n') ;
disp([' Total time of simulation :' num2str(etime(clock,h1))]) ;
fprintf('\n') ;
disp(['WARNING : maximum number of iterations is reached (modify options_.maxit_).']) ;
fprintf('\n') ;
if stop
if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y))
oo_.deterministic_simulation.status = 0;% NaN or Inf occurred
oo_.deterministic_simulation.error = err;
oo_.deterministic_simulation.iterations = iter;
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.error = err;
%oo_.deterministic_simulation.errors = c/abs(err)
oo_.deterministic_simulation.iterations = options_.maxit_;
end
disp (['-----------------------------------------------------']) ;
skipline();
......@@ -76,7 +76,7 @@ NativeStatement::computingPass()
{
using namespace boost::xpressive;
// Return if this is a comment
sregex comment_expr = sregex::compile( "\%.*" );
sregex comment_expr = sregex::compile( "\\s*\%.*" );
match_results<string::const_iterator> results;
if (regex_match(native_statement, results, comment_expr))
return;
......@@ -93,38 +93,41 @@ NativeStatement::computingPass()
else
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;
string newstr = "";
int lastidx = 0;
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])" );
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])" );
string format( "dynDate('$&')" );
size_t lastidx = 0;
for (size_t i = 0; i < apostrophes.size(); i++)
if (apostrophes[i] == 0)
skip = true;
else
{
if (skip)
{
skip = false;
newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx));
}
else
{
skip = true;
newstr.append(regex_replace(native_statement.substr(lastidx, apostrophes[i] - lastidx),
date_expr, format));
}
lastidx = apostrophes[i];
}
newstr.append(regex_replace(native_statement.substr(lastidx, native_statement.size() - lastidx),
date_expr, format));
if (skip)
{
newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx));
lastidx = apostrophes[i];
skip = false;
}
else
{
newstr.append(regex_replace(native_statement.substr(lastidx, apostrophes[i] - lastidx),
date_expr, format));
lastidx = apostrophes[i];
skip = true;
}
size_t length = native_statement.length() - lastidx;
size_t commentidx = native_statement.substr(lastidx, length).find("%", 0);
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;
}
......
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