diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index a4aff3bfa..79a02ef9f 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -244,7 +244,7 @@ switch minimizer_algorithm Save_files = 0; Verbose = 0; end - [opt_par_values,hessian_mat,gg,fval,invhess] = newrat(objective_function,start_par_value,analytic_grad,crit,nit,0,Verbose, Save_files,varargin{:}); + [opt_par_values,hessian_mat,gg,fval,invhess] = newrat(objective_function,start_par_value,bounds,analytic_grad,crit,nit,0,Verbose, Save_files,varargin{:}); %hessian_mat is the plain outer product gradient Hessian case 6 [opt_par_values, hessian_mat, Scale, fval] = gmhmaxlik(objective_function, start_par_value, ... diff --git a/matlab/optimization/mr_gstep.m b/matlab/optimization/mr_gstep.m index 51bfb09c4..a2335e1b8 100644 --- a/matlab/optimization/mr_gstep.m +++ b/matlab/optimization/mr_gstep.m @@ -1,4 +1,4 @@ -function [f0, x, ig] = mr_gstep(h1,x,func0,htol0,Verbose,Save_files,varargin) +function [f0, x, ig] = mr_gstep(h1,x,bounds,func0,htol0,Verbose,Save_files,varargin) % function [f0, x, ig] = mr_gstep(h1,x,func0,htol0,varargin) % % Gibbs type step in optimisation @@ -39,6 +39,9 @@ if isempty(htol0) else htol = htol0; end +if length(htol)==1, + htol=htol*ones(n,1); +end f0=feval(func0,x,varargin{:}); xh1=x; @@ -58,8 +61,8 @@ while i htol + if gg(i)*(hh(i)*gg(i))/2 > htol(i) [f0 x fc retcode] = csminit1(func0,x,f0,gg,0,diag(hh),Verbose,varargin{:}); ig(i)=1; if Verbose @@ -77,6 +80,7 @@ while i=bounds(:,2)); +if ~isempty(inx), + x(inx) = bounds(inx,2)-eps; +end + +inx = find(x<=bounds(:,1)); +if ~isempty(inx), + x(inx) = bounds(inx,1)+eps; +end + + diff --git a/matlab/optimization/mr_hessian.m b/matlab/optimization/mr_hessian.m index 109c0147c..040472437 100644 --- a/matlab/optimization/mr_hessian.m +++ b/matlab/optimization/mr_hessian.m @@ -86,8 +86,10 @@ if outer_product_gradient end i=0; +hhtol=htol*ones(n,1); while ihtol - htol=htol0; + if max(htol0)>htol + skipline() + disp_verbose('Numerical noise in the likelihood') + disp_verbose('Tolerance has to be relaxed') + skipline() end else hh0=hh; @@ -147,7 +150,9 @@ while norm(gg)>gtol && check==0 && jitgtol && check==0 && jit=ftol disp_verbose('Diagonal Hessian successful',Verbose) end @@ -164,6 +170,7 @@ while norm(gg)>gtol && check==0 && jit=ftol disp_verbose('Gradient direction successful',Verbose) end @@ -199,7 +206,7 @@ while norm(gg)>gtol && check==0 && jitgtol && check==0 && jit1.e-12 && analytic_derivation==0, try @@ -227,8 +234,7 @@ while norm(gg)>gtol && check==0 && jithtol - htol=htol0; + if max(htol0)>htol skipline() disp_verbose('Numerical noise in the likelihood',Verbose) disp_verbose('Tolerance has to be relaxed',Verbose) @@ -297,3 +303,16 @@ if check==1, end return + + +function x = check_bounds(x,bounds) + +inx = find(x>=bounds(:,2)); +if ~isempty(inx), + x(inx) = bounds(inx,2)-eps; +end + +inx = find(x<=bounds(:,1)); +if ~isempty(inx), + x(inx) = bounds(inx,1)+eps; +end