trunk: increased verbosity of homotopy modes 1,2,3

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2079 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
sebastien 2008-09-16 17:25:42 +00:00
parent e9c7351aee
commit dd7dcca15e
3 changed files with 30 additions and 11 deletions

View File

@ -49,7 +49,7 @@ function homotopy1(values, step_nbr)
ixd = find(values(:,1) == 2); % Exogenous deterministic
if length([ip, ix, ixd]) ~= nv
error('HOMOTOPY: incorrect variable types specified')
error('HOMOTOPY mode 1: incorrect variable types specified')
end
% Construct vector of starting values, using previously initialized values
@ -63,7 +63,7 @@ function homotopy1(values, step_nbr)
oldvalues(ixdn) = oo_.exo_det_steady_state(values(ixdn, 2));
if any(oldvalues == values(:,4))
error('HOMOTOPY: initial and final values should be different')
error('HOMOTOPY mode 1: initial and final values should be different')
end
points = zeros(nv, step_nbr+1);
@ -72,6 +72,7 @@ function homotopy1(values, step_nbr)
end
for i=1:step_nbr+1
disp([ 'HOMOTOPY mode 1: computing step ' int2str(i-1) '/' int2str(step_nbr) '...' ])
M_.params(values(ip,2)) = points(ip,i);
oo_.exo_steady_state(values(ix,2)) = points(ix,i);
oo_.exo_det_steady_state(values(ixd,2)) = points(ixd,i);
@ -83,6 +84,6 @@ function homotopy1(values, step_nbr)
oo_.exo_det_steady_state], M_.params);
if check
error('HOMOTOPY didn''t succeed')
error('HOMOTOPY mode 1: failed')
end
end

View File

@ -70,16 +70,24 @@ function homotopy2(values, step_nbr)
M_.params(values(i,2)) = oldvalues(i);
end
otherwise
error('HOMOTOPY: incorrect variable types specified')
error('HOMOTOPY mode 2: incorrect variable types specified')
end
end
if any(oldvalues == values(:,4))
error('HOMOTOPY: initial and final values should be different')
error('HOMOTOPY mode 2: initial and final values should be different')
end
% Actually do the homotopy
for i = 1:nv
switch values(i,1)
case 1
varname = M_.exo_names(values(i,2), :);
case 2
varname = M_.exo_det_names(values(i,2), :);
case 4
varname = M_.param_names(values(i,2), :);
end
for v = oldvalues(i):(values(i,4)-oldvalues(i))/step_nbr:values(i,4)
switch values(i,1)
case 1
@ -89,7 +97,8 @@ function homotopy2(values, step_nbr)
case 4
M_.params(values(i,2)) = v;
end
disp([ 'HOMOTOPY mode 2: lauching solver with ' strtrim(varname) ' = ' num2str(v) ' ...'])
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...
oo_.steady_state,...
options_.jacobian_flag, ...
@ -97,7 +106,7 @@ function homotopy2(values, step_nbr)
oo_.exo_det_steady_state], M_.params);
if check
error('HOMOTOPY didn''t succeed')
error('HOMOTOPY mode 2: failed')
end
end
end

View File

@ -53,7 +53,7 @@ function homotopy3(values, step_nbr)
ixd = find(values(:,1) == 2); % Exogenous deterministic
if length([ip, ix, ixd]) ~= nv
error('HOMOTOPY: incorrect variable types specified')
error('HOMOTOPY mode 3: incorrect variable types specified')
end
% Construct vector of starting values, using previously initialized values
@ -69,7 +69,7 @@ function homotopy3(values, step_nbr)
targetvalues = values(:,4);
if min(abs(targetvalues - oldvalues)) < tol
error('HOMOTOPY: distance between initial and final values should be at least %e for all variables', tol)
error('HOMOTOPY mode 3: distance between initial and final values should be at least %e for all variables', tol)
end
iplus = find(targetvalues > oldvalues);
iminus = find(targetvalues < oldvalues);
@ -80,8 +80,11 @@ function homotopy3(values, step_nbr)
kminus = [];
old_ss = oo_.steady_state;
disp('HOMOTOPY mode 3: launching solver at initial point...')
iter = 1;
while iter < step_nbr
M_.params(values(ip,2)) = curvalues(ip);
oo_.exo_steady_state(values(ix,2)) = curvalues(ix);
oo_.exo_det_steady_state(values(ixd,2)) = curvalues(ixd);
@ -93,12 +96,18 @@ function homotopy3(values, step_nbr)
oo_.exo_det_steady_state], M_.params);
if check
disp('HOMOTOPY mode 3: failed step, now dividing increment by 2...')
inc = inc/2;
oo_.steady_state = old_ss;
else
if length([kplus; kminus]) == nv
return
end
if iter == 1
disp('HOMOTOPY mode 3: successful step, now jumping to final point...')
else
disp('HOMOTOPY mode 3: successful step, now multiplying increment by 2...')
end
oldvalues = curvalues;
inc = 2*inc;
end
@ -109,9 +118,9 @@ function homotopy3(values, step_nbr)
curvalues(kminus) = targetvalues(kminus);
if max(abs(inc)) < tol
error('HOMOTOPY didn''t succeed')
error('HOMOTOPY mode 3: failed, increment has become too small')
end
iter = iter + 1;
end
error('HOMOTOPY didn''t succeed')
error('HOMOTOPY mode 3: failed, maximum iterations reached')