commit
f12a468bb3
|
@ -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, ...
|
||||
|
|
|
@ -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<n
|
|||
xh1(i)=x(i)-h1(i);
|
||||
fx = feval(func0,xh1,varargin{:});
|
||||
f_1(:,i)=fx;
|
||||
if hcheck && htol<1
|
||||
htol=min(1,max(min(abs(dx))*2,htol*10));
|
||||
if hcheck && htol(i)<1
|
||||
htol(i)=min(1,max(min(abs(dx))*2,htol(i)*10));
|
||||
h1(i)=h10;
|
||||
xh1(i)=x(i);
|
||||
i=i-1;
|
||||
|
@ -68,7 +71,7 @@ while i<n
|
|||
hh=gg;
|
||||
gg(i)=(f1(i)'-f_1(i)')./(2.*h1(i));
|
||||
hh(i) = 1/max(1.e-9,abs( (f1(i)+f_1(i)-2*f0)./(h1(i)*h1(i)) ));
|
||||
if gg(i)*(hh(i)*gg(i))/2 > 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<n
|
|||
end
|
||||
xh1=x;
|
||||
end
|
||||
x = check_bounds(x,bounds);
|
||||
if Save_files
|
||||
save gstep.mat x h1 f0
|
||||
end
|
||||
|
@ -85,3 +89,19 @@ if Save_files
|
|||
save gstep.mat x h1 f0
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -86,8 +86,10 @@ if outer_product_gradient
|
|||
end
|
||||
|
||||
i=0;
|
||||
hhtol=htol*ones(n,1);
|
||||
while i<n
|
||||
i=i+1;
|
||||
htol=hhtol(i);
|
||||
h10=h1(i);
|
||||
hcheck=0;
|
||||
xh1(i)=x(i)+h1(i);
|
||||
|
@ -164,7 +166,8 @@ while i<n
|
|||
if hcheck && htol<1
|
||||
htol=min(1,max(min(abs(dx))*2,htol*10));
|
||||
h1(i)=h10;
|
||||
i=0;
|
||||
hhtol(i) = htol;
|
||||
i=i-1;
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -263,4 +266,4 @@ else
|
|||
hh1 = [];
|
||||
end
|
||||
|
||||
htol1=htol;
|
||||
htol1=hhtol;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function [xparam1, hh, gg, fval, igg] = newrat(func0, x, analytic_derivation, ftol0, nit, flagg, Verbose, Save_files, varargin)
|
||||
function [xparam1, hh, gg, fval, igg] = newrat(func0, x, bounds, analytic_derivation, ftol0, nit, flagg, Verbose, Save_files, varargin)
|
||||
% [xparam1, hh, gg, fval, igg] = newrat(func0, x, hh, gg, igg, ftol0, nit, flagg, varargin)
|
||||
%
|
||||
% Optimiser with outer product gradient and with sequences of univariate steps
|
||||
|
@ -86,8 +86,11 @@ if isempty(hh)
|
|||
igg=inv(hh);
|
||||
end
|
||||
end
|
||||
if htol0>htol
|
||||
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 && jit<nit
|
|||
iggx(find(ig),find(ig)) = inv( hhx(find(ig),find(ig)) );
|
||||
[fvala,x0,fc,retcode] = csminit1(func0,x0,fval,ggx,0,iggx,Verbose,varargin{:});
|
||||
end
|
||||
[fvala, x0, ig] = mr_gstep(h1,x0,func0,htol,Verbose,Save_files,varargin{:});
|
||||
x0 = check_bounds(x0,bounds);
|
||||
[fvala, x0, ig] = mr_gstep(h1,x0,bounds,func0,htol0,Verbose,Save_files,varargin{:});
|
||||
x0 = check_bounds(x0,bounds);
|
||||
nig=[nig ig];
|
||||
disp_verbose('Sequence of univariate steps!!',Verbose)
|
||||
fval=fvala;
|
||||
|
@ -155,6 +160,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
|||
disp_verbose('Try diagonal Hessian',Verbose)
|
||||
ihh=diag(1./(diag(hhg)));
|
||||
[fval2,x0,fc,retcode2] = csminit1(func0,x0,fval,gg,0,ihh,Verbose,varargin{:});
|
||||
x0 = check_bounds(x0,bounds);
|
||||
if (fval-fval2)>=ftol
|
||||
disp_verbose('Diagonal Hessian successful',Verbose)
|
||||
end
|
||||
|
@ -164,6 +170,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
|||
disp_verbose('Try gradient direction',Verbose)
|
||||
ihh0=inx.*1.e-4;
|
||||
[fval3,x0,fc,retcode3] = csminit1(func0,x0,fval,gg,0,ihh0,Verbose,varargin{:});
|
||||
x0 = check_bounds(x0,bounds);
|
||||
if (fval-fval3)>=ftol
|
||||
disp_verbose('Gradient direction successful',Verbose)
|
||||
end
|
||||
|
@ -199,7 +206,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
|||
disp_verbose(['FVAL ',num2str(fval)],Verbose)
|
||||
disp_verbose(['Improvement ',num2str(fval0(icount)-fval)],Verbose)
|
||||
disp_verbose(['Ftol ',num2str(ftol)],Verbose)
|
||||
disp_verbose(['Htol ',num2str(htol0)],Verbose)
|
||||
disp_verbose(['Htol ',num2str(max(htol0))],Verbose)
|
||||
disp_verbose(['Gradient norm ',num2str(norm(gg))],Verbose)
|
||||
ee=eig(hh);
|
||||
disp_verbose(['Minimum Hessian eigenvalue ',num2str(min(ee))],Verbose)
|
||||
|
@ -211,7 +218,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
|||
disp_verbose(['FVAL ',num2str(fval)],Verbose)
|
||||
disp_verbose(['Improvement ',num2str(df)],Verbose)
|
||||
disp_verbose(['Ftol ',num2str(ftol)],Verbose)
|
||||
disp_verbose(['Htol ',num2str(htol0)],Verbose)
|
||||
disp_verbose(['Htol ',num2str(max(htol0))],Verbose)
|
||||
htol=htol_base;
|
||||
if norm(x(:,icount)-xparam1)>1.e-12 && analytic_derivation==0,
|
||||
try
|
||||
|
@ -227,8 +234,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
|||
if isempty(dum),
|
||||
outer_product_gradient=0;
|
||||
end
|
||||
if htol0>htol
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue