commit
f12a468bb3
|
@ -244,7 +244,7 @@ switch minimizer_algorithm
|
||||||
Save_files = 0;
|
Save_files = 0;
|
||||||
Verbose = 0;
|
Verbose = 0;
|
||||||
end
|
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
|
%hessian_mat is the plain outer product gradient Hessian
|
||||||
case 6
|
case 6
|
||||||
[opt_par_values, hessian_mat, Scale, fval] = gmhmaxlik(objective_function, start_par_value, ...
|
[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)
|
% function [f0, x, ig] = mr_gstep(h1,x,func0,htol0,varargin)
|
||||||
%
|
%
|
||||||
% Gibbs type step in optimisation
|
% Gibbs type step in optimisation
|
||||||
|
@ -39,6 +39,9 @@ if isempty(htol0)
|
||||||
else
|
else
|
||||||
htol = htol0;
|
htol = htol0;
|
||||||
end
|
end
|
||||||
|
if length(htol)==1,
|
||||||
|
htol=htol*ones(n,1);
|
||||||
|
end
|
||||||
f0=feval(func0,x,varargin{:});
|
f0=feval(func0,x,varargin{:});
|
||||||
|
|
||||||
xh1=x;
|
xh1=x;
|
||||||
|
@ -58,8 +61,8 @@ while i<n
|
||||||
xh1(i)=x(i)-h1(i);
|
xh1(i)=x(i)-h1(i);
|
||||||
fx = feval(func0,xh1,varargin{:});
|
fx = feval(func0,xh1,varargin{:});
|
||||||
f_1(:,i)=fx;
|
f_1(:,i)=fx;
|
||||||
if hcheck && htol<1
|
if hcheck && htol(i)<1
|
||||||
htol=min(1,max(min(abs(dx))*2,htol*10));
|
htol(i)=min(1,max(min(abs(dx))*2,htol(i)*10));
|
||||||
h1(i)=h10;
|
h1(i)=h10;
|
||||||
xh1(i)=x(i);
|
xh1(i)=x(i);
|
||||||
i=i-1;
|
i=i-1;
|
||||||
|
@ -68,7 +71,7 @@ while i<n
|
||||||
hh=gg;
|
hh=gg;
|
||||||
gg(i)=(f1(i)'-f_1(i)')./(2.*h1(i));
|
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)) ));
|
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{:});
|
[f0 x fc retcode] = csminit1(func0,x,f0,gg,0,diag(hh),Verbose,varargin{:});
|
||||||
ig(i)=1;
|
ig(i)=1;
|
||||||
if Verbose
|
if Verbose
|
||||||
|
@ -77,6 +80,7 @@ while i<n
|
||||||
end
|
end
|
||||||
xh1=x;
|
xh1=x;
|
||||||
end
|
end
|
||||||
|
x = check_bounds(x,bounds);
|
||||||
if Save_files
|
if Save_files
|
||||||
save gstep.mat x h1 f0
|
save gstep.mat x h1 f0
|
||||||
end
|
end
|
||||||
|
@ -85,3 +89,19 @@ if Save_files
|
||||||
save gstep.mat x h1 f0
|
save gstep.mat x h1 f0
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
i=0;
|
i=0;
|
||||||
|
hhtol=htol*ones(n,1);
|
||||||
while i<n
|
while i<n
|
||||||
i=i+1;
|
i=i+1;
|
||||||
|
htol=hhtol(i);
|
||||||
h10=h1(i);
|
h10=h1(i);
|
||||||
hcheck=0;
|
hcheck=0;
|
||||||
xh1(i)=x(i)+h1(i);
|
xh1(i)=x(i)+h1(i);
|
||||||
|
@ -164,7 +166,8 @@ while i<n
|
||||||
if hcheck && htol<1
|
if hcheck && htol<1
|
||||||
htol=min(1,max(min(abs(dx))*2,htol*10));
|
htol=min(1,max(min(abs(dx))*2,htol*10));
|
||||||
h1(i)=h10;
|
h1(i)=h10;
|
||||||
i=0;
|
hhtol(i) = htol;
|
||||||
|
i=i-1;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -263,4 +266,4 @@ else
|
||||||
hh1 = [];
|
hh1 = [];
|
||||||
end
|
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)
|
% [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
|
% Optimiser with outer product gradient and with sequences of univariate steps
|
||||||
|
@ -86,8 +86,11 @@ if isempty(hh)
|
||||||
igg=inv(hh);
|
igg=inv(hh);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if htol0>htol
|
if max(htol0)>htol
|
||||||
htol=htol0;
|
skipline()
|
||||||
|
disp_verbose('Numerical noise in the likelihood')
|
||||||
|
disp_verbose('Tolerance has to be relaxed')
|
||||||
|
skipline()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
hh0=hh;
|
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)) );
|
iggx(find(ig),find(ig)) = inv( hhx(find(ig),find(ig)) );
|
||||||
[fvala,x0,fc,retcode] = csminit1(func0,x0,fval,ggx,0,iggx,Verbose,varargin{:});
|
[fvala,x0,fc,retcode] = csminit1(func0,x0,fval,ggx,0,iggx,Verbose,varargin{:});
|
||||||
end
|
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];
|
nig=[nig ig];
|
||||||
disp_verbose('Sequence of univariate steps!!',Verbose)
|
disp_verbose('Sequence of univariate steps!!',Verbose)
|
||||||
fval=fvala;
|
fval=fvala;
|
||||||
|
@ -155,6 +160,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
disp_verbose('Try diagonal Hessian',Verbose)
|
disp_verbose('Try diagonal Hessian',Verbose)
|
||||||
ihh=diag(1./(diag(hhg)));
|
ihh=diag(1./(diag(hhg)));
|
||||||
[fval2,x0,fc,retcode2] = csminit1(func0,x0,fval,gg,0,ihh,Verbose,varargin{:});
|
[fval2,x0,fc,retcode2] = csminit1(func0,x0,fval,gg,0,ihh,Verbose,varargin{:});
|
||||||
|
x0 = check_bounds(x0,bounds);
|
||||||
if (fval-fval2)>=ftol
|
if (fval-fval2)>=ftol
|
||||||
disp_verbose('Diagonal Hessian successful',Verbose)
|
disp_verbose('Diagonal Hessian successful',Verbose)
|
||||||
end
|
end
|
||||||
|
@ -164,6 +170,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
disp_verbose('Try gradient direction',Verbose)
|
disp_verbose('Try gradient direction',Verbose)
|
||||||
ihh0=inx.*1.e-4;
|
ihh0=inx.*1.e-4;
|
||||||
[fval3,x0,fc,retcode3] = csminit1(func0,x0,fval,gg,0,ihh0,Verbose,varargin{:});
|
[fval3,x0,fc,retcode3] = csminit1(func0,x0,fval,gg,0,ihh0,Verbose,varargin{:});
|
||||||
|
x0 = check_bounds(x0,bounds);
|
||||||
if (fval-fval3)>=ftol
|
if (fval-fval3)>=ftol
|
||||||
disp_verbose('Gradient direction successful',Verbose)
|
disp_verbose('Gradient direction successful',Verbose)
|
||||||
end
|
end
|
||||||
|
@ -199,7 +206,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
disp_verbose(['FVAL ',num2str(fval)],Verbose)
|
disp_verbose(['FVAL ',num2str(fval)],Verbose)
|
||||||
disp_verbose(['Improvement ',num2str(fval0(icount)-fval)],Verbose)
|
disp_verbose(['Improvement ',num2str(fval0(icount)-fval)],Verbose)
|
||||||
disp_verbose(['Ftol ',num2str(ftol)],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)
|
disp_verbose(['Gradient norm ',num2str(norm(gg))],Verbose)
|
||||||
ee=eig(hh);
|
ee=eig(hh);
|
||||||
disp_verbose(['Minimum Hessian eigenvalue ',num2str(min(ee))],Verbose)
|
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(['FVAL ',num2str(fval)],Verbose)
|
||||||
disp_verbose(['Improvement ',num2str(df)],Verbose)
|
disp_verbose(['Improvement ',num2str(df)],Verbose)
|
||||||
disp_verbose(['Ftol ',num2str(ftol)],Verbose)
|
disp_verbose(['Ftol ',num2str(ftol)],Verbose)
|
||||||
disp_verbose(['Htol ',num2str(htol0)],Verbose)
|
disp_verbose(['Htol ',num2str(max(htol0))],Verbose)
|
||||||
htol=htol_base;
|
htol=htol_base;
|
||||||
if norm(x(:,icount)-xparam1)>1.e-12 && analytic_derivation==0,
|
if norm(x(:,icount)-xparam1)>1.e-12 && analytic_derivation==0,
|
||||||
try
|
try
|
||||||
|
@ -227,8 +234,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
if isempty(dum),
|
if isempty(dum),
|
||||||
outer_product_gradient=0;
|
outer_product_gradient=0;
|
||||||
end
|
end
|
||||||
if htol0>htol
|
if max(htol0)>htol
|
||||||
htol=htol0;
|
|
||||||
skipline()
|
skipline()
|
||||||
disp_verbose('Numerical noise in the likelihood',Verbose)
|
disp_verbose('Numerical noise in the likelihood',Verbose)
|
||||||
disp_verbose('Tolerance has to be relaxed',Verbose)
|
disp_verbose('Tolerance has to be relaxed',Verbose)
|
||||||
|
@ -297,3 +303,16 @@ if check==1,
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
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