Merge branch 'optimizer' of git.dynare.org:JohannesPfeifer/dynare
commit
3e7c0b1eef
|
@ -274,7 +274,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
|
||||||
if compute_hessian
|
if compute_hessian
|
||||||
crit = options_.newrat.tolerance.f;
|
crit = options_.newrat.tolerance.f;
|
||||||
newratflag = newratflag>0;
|
newratflag = newratflag>0;
|
||||||
hh = reshape(mr_hessian(xparam1,objective_function,fval,newratflag,crit,new_rat_hess_info,[bounds.lb bounds.ub],bayestopt_.p2,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_), nx, nx);
|
hh = reshape(mr_hessian(xparam1,objective_function,fval,newratflag,crit,new_rat_hess_info,[bounds.lb bounds.ub],bayestopt_.p2,0,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_), nx, nx);
|
||||||
end
|
end
|
||||||
options_.kalman_algo = kalman_algo0;
|
options_.kalman_algo = kalman_algo0;
|
||||||
end
|
end
|
||||||
|
|
|
@ -129,7 +129,6 @@ else
|
||||||
done=0;
|
done=0;
|
||||||
factor=3;
|
factor=3;
|
||||||
shrink=1;
|
shrink=1;
|
||||||
lambdaMin=0;
|
|
||||||
lambdaMax=inf;
|
lambdaMax=inf;
|
||||||
lambdaPeak=0;
|
lambdaPeak=0;
|
||||||
fPeak=f0;
|
fPeak=f0;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
function [hessian_mat, gg, htol1, ihh, hh_mat0, hh1, hess_info] = mr_hessian(x,func,penalty,hflag,htol0,hess_info,bounds,prior_std,varargin)
|
function [hessian_mat, gg, htol1, ihh, hh_mat0, hh1, hess_info] = mr_hessian(x,func,penalty,hflag,htol0,hess_info,bounds,prior_std,Save_files,varargin)
|
||||||
% function [hessian_mat, gg, htol1, ihh, hh_mat0, hh1, hess_info] = mr_hessian(x,func,penalty,hflag,htol0,hess_info,bounds,prior_std,varargin)
|
% function [hessian_mat, gg, htol1, ihh, hh_mat0, hh1, hess_info] = mr_hessian(x,func,penalty,hflag,htol0,hess_info,bounds,prior_std,Save_files,varargin)
|
||||||
% numerical gradient and Hessian, with 'automatic' check of numerical
|
% numerical gradient and Hessian, with 'automatic' check of numerical
|
||||||
% error
|
% error
|
||||||
%
|
%
|
||||||
% adapted from Michel Juillard original routine hessian.m
|
% adapted from Michel Juillard original routine hessian.m
|
||||||
%
|
%
|
||||||
% Inputs:
|
% Inputs:
|
||||||
|
% - x parameter values
|
||||||
% - func function handle. The function must give two outputs:
|
% - func function handle. The function must give two outputs:
|
||||||
% the log-likelihood AND the single contributions at times t=1,...,T
|
% the log-likelihood AND the single contributions at times t=1,...,T
|
||||||
% of the log-likelihood to compute outer product gradient
|
% of the log-likelihood to compute outer product gradient
|
||||||
% - x parameter values
|
|
||||||
% - penalty penalty due to error code
|
% - penalty penalty due to error code
|
||||||
% - hflag 0: Hessian computed with outer product gradient, one point
|
% - hflag 0: Hessian computed with outer product gradient, one point
|
||||||
% increments for partial derivatives in gradients
|
% increments for partial derivatives in gradients
|
||||||
|
@ -26,6 +26,7 @@ function [hessian_mat, gg, htol1, ihh, hh_mat0, hh1, hess_info] = mr_hessian(x,f
|
||||||
% computation of Hessian
|
% computation of Hessian
|
||||||
% - bounds prior bounds of parameters
|
% - bounds prior bounds of parameters
|
||||||
% - prior_std prior standard devation of parameters (can be NaN)
|
% - prior_std prior standard devation of parameters (can be NaN)
|
||||||
|
% - Save_files indicator whether files should be saved
|
||||||
% - varargin other inputs
|
% - varargin other inputs
|
||||||
% e.g. in dsge_likelihood
|
% e.g. in dsge_likelihood
|
||||||
% varargin{1} --> DynareDataset
|
% varargin{1} --> DynareDataset
|
||||||
|
@ -99,11 +100,7 @@ while i<n
|
||||||
h10=hess_info.h1(i);
|
h10=hess_info.h1(i);
|
||||||
hcheck=0;
|
hcheck=0;
|
||||||
xh1(i)=x(i)+hess_info.h1(i);
|
xh1(i)=x(i)+hess_info.h1(i);
|
||||||
try
|
[fx,exit_flag,ffx]=penalty_objective_function(xh1,func,penalty,varargin{:});
|
||||||
[fx,exit_flag,ffx]=penalty_objective_function(xh1,func,penalty,varargin{:});
|
|
||||||
catch
|
|
||||||
fx=1.e8;
|
|
||||||
end
|
|
||||||
it=1;
|
it=1;
|
||||||
dx=(fx-f0);
|
dx=(fx-f0);
|
||||||
ic=0;
|
ic=0;
|
||||||
|
@ -120,21 +117,13 @@ while i<n
|
||||||
hess_info.h1(i) = min(hess_info.h1(i),0.5*hmax(i));
|
hess_info.h1(i) = min(hess_info.h1(i),0.5*hmax(i));
|
||||||
hess_info.h1(i) = max(hess_info.h1(i),1.e-10);
|
hess_info.h1(i) = max(hess_info.h1(i),1.e-10);
|
||||||
xh1(i)=x(i)+hess_info.h1(i);
|
xh1(i)=x(i)+hess_info.h1(i);
|
||||||
try
|
[fx,exit_flag,ffx]=penalty_objective_function(xh1,func,penalty,varargin{:});
|
||||||
[fx,exit_flag,ffx]=penalty_objective_function(xh1,func,penalty,varargin{:});
|
|
||||||
catch
|
|
||||||
fx=1.e8;
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if abs(dx(it))>(3*hess_info.htol)
|
if abs(dx(it))>(3*hess_info.htol)
|
||||||
hess_info.h1(i)= hess_info.htol/abs(dx(it))*hess_info.h1(i);
|
hess_info.h1(i)= hess_info.htol/abs(dx(it))*hess_info.h1(i);
|
||||||
hess_info.h1(i) = max(hess_info.h1(i),1e-10);
|
hess_info.h1(i) = max(hess_info.h1(i),1e-10);
|
||||||
xh1(i)=x(i)+hess_info.h1(i);
|
xh1(i)=x(i)+hess_info.h1(i);
|
||||||
try
|
[fx,exit_flag,ffx]=penalty_objective_function(xh1,func,penalty,varargin{:});
|
||||||
[fx,exit_flag,ffx]=penalty_objective_function(xh1,func,penalty,varargin{:});
|
|
||||||
catch
|
|
||||||
fx=1.e8;
|
|
||||||
end
|
|
||||||
iter=0;
|
iter=0;
|
||||||
while (fx-f0)==0 && iter<50
|
while (fx-f0)==0 && iter<50
|
||||||
hess_info.h1(i)= hess_info.h1(i)*2;
|
hess_info.h1(i)= hess_info.h1(i)*2;
|
||||||
|
@ -188,7 +177,7 @@ gg=(f1'-f_1')./(2.*hess_info.h1);
|
||||||
|
|
||||||
if outer_product_gradient
|
if outer_product_gradient
|
||||||
if hflag==2
|
if hflag==2
|
||||||
gg=(f1'-f_1')./(2.*hess_info.h1);
|
% full numerical Hessian
|
||||||
hessian_mat = zeros(size(f0,1),n*n);
|
hessian_mat = zeros(size(f0,1),n*n);
|
||||||
for i=1:n
|
for i=1:n
|
||||||
if i > 1
|
if i > 1
|
||||||
|
@ -209,19 +198,17 @@ if outer_product_gradient
|
||||||
xh1(j)=x(j);
|
xh1(j)=x(j);
|
||||||
xh_1(i)=x(i);
|
xh_1(i)=x(i);
|
||||||
xh_1(j)=x(j);
|
xh_1(j)=x(j);
|
||||||
j=j+1;
|
|
||||||
end
|
end
|
||||||
i=i+1;
|
|
||||||
end
|
end
|
||||||
elseif hflag==1
|
elseif hflag==1
|
||||||
|
% full numerical 2nd order derivs only in diagonal
|
||||||
hessian_mat = zeros(size(f0,1),n*n);
|
hessian_mat = zeros(size(f0,1),n*n);
|
||||||
for i=1:n
|
for i=1:n
|
||||||
dum = (f1(:,i)+f_1(:,i)-2*f0)./(hess_info.h1(i)*h_1(i));
|
dum = (f1(:,i)+f_1(:,i)-2*f0)./(hess_info.h1(i)*h_1(i));
|
||||||
if dum>eps
|
hessian_mat(:,(i-1)*n+i)=dum;
|
||||||
hessian_mat(:,(i-1)*n+i)=dum;
|
if any(dum<=eps)
|
||||||
else
|
hessian_mat(dum<=eps,(i-1)*n+i)=max(eps, gg(i)^2);
|
||||||
hessian_mat(:,(i-1)*n+i)=max(eps, gg(i)^2);
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -230,26 +217,27 @@ if outer_product_gradient
|
||||||
hh_mat0=ggh'*ggh; % outer product hessian
|
hh_mat0=ggh'*ggh; % outer product hessian
|
||||||
A=diag(2.*hess_info.h1); % rescaling matrix
|
A=diag(2.*hess_info.h1); % rescaling matrix
|
||||||
% igg=inv(hh_mat); % inverted rescaled outer product hessian
|
% igg=inv(hh_mat); % inverted rescaled outer product hessian
|
||||||
ihh=A'*(hh_mat\A); % inverted outer product hessian
|
ihh=A'*(hh_mat\A); % inverted outer product hessian (based on rescaling)
|
||||||
if hflag>0 && min(eig(reshape(hessian_mat,n,n)))>0
|
if hflag>0 && min(eig(reshape(hessian_mat,n,n)))>0
|
||||||
hh0 = A*reshape(hessian_mat,n,n)*A'; %rescaled second order derivatives
|
hh0 = A*reshape(hessian_mat,n,n)*A'; %rescaled second order derivatives
|
||||||
hh = reshape(hessian_mat,n,n); %rescaled second order derivatives
|
hh = reshape(hessian_mat,n,n); %second order derivatives
|
||||||
sd0=sqrt(diag(hh0)); %rescaled 'standard errors' using second order derivatives
|
sd0=sqrt(diag(hh0)); %rescaled 'standard errors' using second order derivatives
|
||||||
sd=sqrt(diag(hh_mat)); %rescaled 'standard errors' using outer product
|
sd=sqrt(diag(hh_mat)); %rescaled 'standard errors' using outer product
|
||||||
hh_mat=hh_mat./(sd*sd').*(sd0*sd0'); %rescaled inverse outer product with 'true' std's
|
hh_mat=hh_mat./(sd*sd').*(sd0*sd0'); %rescaled inverse outer product with 'true' std's
|
||||||
igg=inv(hh_mat); % rescaled outer product hessian with 'true' std's
|
ihh=A'*(hh_mat\A); % update inverted outer product hessian with 'true' std's
|
||||||
ihh=A'*(hh_mat\A); % inverted outer product hessian
|
|
||||||
hh_mat0=inv(A)'*hh_mat*inv(A); % outer product hessian with 'true' std's
|
|
||||||
sd=sqrt(diag(ihh)); %standard errors
|
sd=sqrt(diag(ihh)); %standard errors
|
||||||
sdh=sqrt(1./diag(hh)); %diagonal standard errors
|
sdh=sqrt(1./diag(hh)); %diagonal standard errors
|
||||||
for j=1:length(sd)
|
for j=1:length(sd)
|
||||||
|
% some heuristic normalizations of the standard errors that
|
||||||
|
% avoid numerical issues in outer product
|
||||||
sd0(j,1)=min(prior_std(j), sd(j)); %prior std
|
sd0(j,1)=min(prior_std(j), sd(j)); %prior std
|
||||||
sd0(j,1)=10^(0.5*(log10(sd0(j,1))+log10(sdh(j,1))));
|
sd0(j,1)=10^(0.5*(log10(sd0(j,1))+log10(sdh(j,1))));
|
||||||
end
|
end
|
||||||
|
inv_A=inv(A);
|
||||||
ihh=ihh./(sd*sd').*(sd0*sd0'); %inverse outer product with modified std's
|
ihh=ihh./(sd*sd').*(sd0*sd0'); %inverse outer product with modified std's
|
||||||
igg=inv(A)'*ihh*inv(A); % inverted rescaled outer product hessian with modified std's
|
igg=inv_A'*ihh*inv_A; % inverted rescaled outer product hessian with modified std's
|
||||||
hh_mat=inv(igg); % outer product rescaled hessian with modified std's
|
% hh_mat=inv(igg); % outer product rescaled hessian with modified std's
|
||||||
hh_mat0=inv(A)'*hh_mat*inv(A); % outer product hessian with modified std's
|
hh_mat0=inv_A'/igg*inv_A; % outer product hessian with modified std's
|
||||||
% sd0=sqrt(1./diag(hh0)); %rescaled 'standard errors' using second order derivatives
|
% sd0=sqrt(1./diag(hh0)); %rescaled 'standard errors' using second order derivatives
|
||||||
% sd=sqrt(diag(igg)); %rescaled 'standard errors' using outer product
|
% sd=sqrt(diag(igg)); %rescaled 'standard errors' using outer product
|
||||||
% igg=igg./(sd*sd').*(sd0*sd0'); %rescaled inverse outer product with 'true' std's
|
% igg=igg./(sd*sd').*(sd0*sd0'); %rescaled inverse outer product with 'true' std's
|
||||||
|
@ -267,7 +255,9 @@ if outer_product_gradient
|
||||||
hessian_mat=hh_mat0(:);
|
hessian_mat=hh_mat0(:);
|
||||||
end
|
end
|
||||||
hh1=hess_info.h1;
|
hh1=hess_info.h1;
|
||||||
save hess.mat hessian_mat
|
if Save_files
|
||||||
|
save('hess.mat','hessian_mat')
|
||||||
|
end
|
||||||
else
|
else
|
||||||
hessian_mat=[];
|
hessian_mat=[];
|
||||||
ihh=[];
|
ihh=[];
|
||||||
|
|
|
@ -70,7 +70,7 @@ nx=length(x);
|
||||||
xparam1=x;
|
xparam1=x;
|
||||||
%ftol0=1.e-6;
|
%ftol0=1.e-6;
|
||||||
htol_base = max(1.e-7, ftol0);
|
htol_base = max(1.e-7, ftol0);
|
||||||
flagit=0; % mode of computation of hessian in each iteration
|
flagit=0; % mode of computation of hessian in each iteration; hard-coded outer-product of gradients as it performed best in tests
|
||||||
ftol=ftol0;
|
ftol=ftol0;
|
||||||
gtol=1.e-3;
|
gtol=1.e-3;
|
||||||
htol=htol_base;
|
htol=htol_base;
|
||||||
|
@ -84,13 +84,17 @@ end
|
||||||
% func0 = str2func([func2str(func0),'_hh']);
|
% func0 = str2func([func2str(func0),'_hh']);
|
||||||
% func0 = func0;
|
% func0 = func0;
|
||||||
[fval0,exit_flag,gg,hh]=penalty_objective_function(x,func0,penalty,varargin{:});
|
[fval0,exit_flag,gg,hh]=penalty_objective_function(x,func0,penalty,varargin{:});
|
||||||
|
if ~exit_flag
|
||||||
|
disp_verbose('Bad initial parameter.',Verbose)
|
||||||
|
return
|
||||||
|
end
|
||||||
fval=fval0;
|
fval=fval0;
|
||||||
|
|
||||||
% initialize mr_gstep and mr_hessian
|
% initialize mr_gstep and mr_hessian
|
||||||
|
|
||||||
outer_product_gradient=1;
|
outer_product_gradient=1;
|
||||||
if isempty(hh)
|
if isempty(hh)
|
||||||
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(x,func0,penalty,flagit,htol,hess_info,bounds,prior_std,varargin{:});
|
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(x,func0,penalty,flagit,htol,hess_info,bounds,prior_std,Save_files,varargin{:});
|
||||||
if isempty(dum)
|
if isempty(dum)
|
||||||
outer_product_gradient=0;
|
outer_product_gradient=0;
|
||||||
igg = 1e-4*eye(nx);
|
igg = 1e-4*eye(nx);
|
||||||
|
@ -117,15 +121,16 @@ else
|
||||||
h1=[];
|
h1=[];
|
||||||
end
|
end
|
||||||
H = igg;
|
H = igg;
|
||||||
disp_verbose(['Gradient norm ',num2str(norm(gg))],Verbose)
|
if Verbose
|
||||||
ee=eig(hh);
|
disp_eigenvalues_gradient(gg,hh);
|
||||||
disp_verbose(['Minimum Hessian eigenvalue ',num2str(min(ee))],Verbose)
|
end
|
||||||
disp_verbose(['Maximum Hessian eigenvalue ',num2str(max(ee))],Verbose)
|
|
||||||
g=gg;
|
g=gg;
|
||||||
check=0;
|
check=0;
|
||||||
if max(eig(hh))<0
|
if Verbose
|
||||||
disp_verbose('Negative definite Hessian! Local maximum!',Verbose)
|
if max(eig(hh))<0
|
||||||
pause
|
disp('Negative definite Hessian! Local maximum!')
|
||||||
|
pause
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if Save_files
|
if Save_files
|
||||||
save('m1.mat','x','hh','g','hhg','igg','fval0')
|
save('m1.mat','x','hh','g','hhg','igg','fval0')
|
||||||
|
@ -135,7 +140,9 @@ igrad=1;
|
||||||
igibbs=1;
|
igibbs=1;
|
||||||
inx=eye(nx);
|
inx=eye(nx);
|
||||||
jit=0;
|
jit=0;
|
||||||
nig=[];
|
if Save_files
|
||||||
|
nig=[];
|
||||||
|
end
|
||||||
ig=ones(nx,1);
|
ig=ones(nx,1);
|
||||||
ggx=zeros(nx,1);
|
ggx=zeros(nx,1);
|
||||||
while norm(gg)>gtol && check==0 && jit<nit
|
while norm(gg)>gtol && check==0 && jit<nit
|
||||||
|
@ -156,22 +163,25 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
fval=fval1;
|
fval=fval1;
|
||||||
x0=x01;
|
x0=x01;
|
||||||
end
|
end
|
||||||
if length(find(ig))<nx
|
ig_pos=find(ig);
|
||||||
ggx=ggx*0;
|
if length(ig_pos)<nx
|
||||||
ggx(find(ig))=gg(find(ig));
|
ggx=ggx*0;
|
||||||
|
ggx(ig_pos)=gg(ig_pos);
|
||||||
if analytic_derivation || ~outer_product_gradient
|
if analytic_derivation || ~outer_product_gradient
|
||||||
hhx=hh;
|
hhx=hh;
|
||||||
else
|
else
|
||||||
hhx = reshape(dum,nx,nx);
|
hhx = reshape(dum,nx,nx);
|
||||||
end
|
end
|
||||||
iggx=eye(length(gg));
|
iggx=eye(length(gg));
|
||||||
iggx(find(ig),find(ig)) = inv( hhx(find(ig),find(ig)) );
|
iggx(ig_pos,ig_pos) = inv( hhx(ig_pos,ig_pos) );
|
||||||
[fvala,x0,fc,retcode] = csminit1(func0,x0,penalty,fval,ggx,0,iggx,Verbose,varargin{:});
|
[fvala,x0,fc,retcode] = csminit1(func0,x0,penalty,fval,ggx,0,iggx,Verbose,varargin{:});
|
||||||
end
|
end
|
||||||
x0 = check_bounds(x0,bounds);
|
x0 = check_bounds(x0,bounds);
|
||||||
[fvala, x0, ig] = mr_gstep(h1,x0,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon, parameter_names,varargin{:});
|
[fvala, x0, ig] = mr_gstep(h1,x0,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon, parameter_names,varargin{:});
|
||||||
x0 = check_bounds(x0,bounds);
|
x0 = check_bounds(x0,bounds);
|
||||||
nig=[nig ig];
|
if Save_files
|
||||||
|
nig=[nig ig];
|
||||||
|
end
|
||||||
disp_verbose('Sequence of univariate steps!!',Verbose)
|
disp_verbose('Sequence of univariate steps!!',Verbose)
|
||||||
fval=fvala;
|
fval=fvala;
|
||||||
if (fval0(icount)-fval)<ftol && flagit==0
|
if (fval0(icount)-fval)<ftol && flagit==0
|
||||||
|
@ -208,7 +218,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
if flagit==2
|
if flagit==2
|
||||||
hh=hh0;
|
hh=hh0;
|
||||||
elseif flagg>0
|
elseif flagg>0
|
||||||
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagg,ftol0,hess_info,bounds,prior_std,varargin{:});
|
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagg,ftol0,hess_info,bounds,prior_std,Save_files,varargin{:});
|
||||||
if flagg==2
|
if flagg==2
|
||||||
hh = reshape(dum,nx,nx);
|
hh = reshape(dum,nx,nx);
|
||||||
ee=eig(hh);
|
ee=eig(hh);
|
||||||
|
@ -220,15 +230,14 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
disp_verbose(['Actual dxnorm ',num2str(norm(x(:,end)-x(:,end-1)))],Verbose)
|
if Verbose
|
||||||
disp_verbose(['FVAL ',num2str(fval)],Verbose)
|
disp(['Actual dxnorm ',num2str(norm(x(:,end)-x(:,end-1)))])
|
||||||
disp_verbose(['Improvement ',num2str(fval0(icount)-fval)],Verbose)
|
disp(['FVAL ',num2str(fval)])
|
||||||
disp_verbose(['Ftol ',num2str(ftol)],Verbose)
|
disp(['Improvement ',num2str(fval0(icount)-fval)])
|
||||||
disp_verbose(['Htol ',num2str(max(htol0))],Verbose)
|
disp(['Ftol ',num2str(ftol)])
|
||||||
disp_verbose(['Gradient norm ',num2str(norm(gg))],Verbose)
|
disp(['Htol ',num2str(max(htol0))])
|
||||||
ee=eig(hh);
|
disp_eigenvalues_gradient(gg,hh);
|
||||||
disp_verbose(['Minimum Hessian eigenvalue ',num2str(min(ee))],Verbose)
|
end
|
||||||
disp_verbose(['Maximum Hessian eigenvalue ',num2str(max(ee))],Verbose)
|
|
||||||
g(:,icount+1)=gg;
|
g(:,icount+1)=gg;
|
||||||
else
|
else
|
||||||
df = fval0(icount)-fval;
|
df = fval0(icount)-fval;
|
||||||
|
@ -248,7 +257,7 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
save('m1.mat','x','fval0','nig')
|
save('m1.mat','x','fval0','nig')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagit,htol,hess_info,bounds,prior_std,varargin{:});
|
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagit,htol,hess_info,bounds,prior_std,Save_files,varargin{:});
|
||||||
if isempty(dum)
|
if isempty(dum)
|
||||||
outer_product_gradient=0;
|
outer_product_gradient=0;
|
||||||
end
|
end
|
||||||
|
@ -280,13 +289,11 @@ while norm(gg)>gtol && check==0 && jit<nit
|
||||||
hhg=hh;
|
hhg=hh;
|
||||||
H = inv(hh);
|
H = inv(hh);
|
||||||
end
|
end
|
||||||
disp_verbose(['Gradient norm ',num2str(norm(gg))],Verbose)
|
if Verbose
|
||||||
ee=eig(hh);
|
if max(eig(hh))<0
|
||||||
disp_verbose(['Minimum Hessian eigenvalue ',num2str(min(ee))],Verbose)
|
disp('Negative definite Hessian! Local maximum!')
|
||||||
disp_verbose(['Maximum Hessian eigenvalue ',num2str(max(ee))],Verbose)
|
pause(1)
|
||||||
if max(eig(hh))<0
|
end
|
||||||
disp_verbose('Negative definite Hessian! Local maximum!',Verbose)
|
|
||||||
pause(1)
|
|
||||||
end
|
end
|
||||||
t=toc(tic1);
|
t=toc(tic1);
|
||||||
disp_verbose(['Elapsed time for iteration ',num2str(t),' s.'],Verbose)
|
disp_verbose(['Elapsed time for iteration ',num2str(t),' s.'],Verbose)
|
||||||
|
@ -334,3 +341,10 @@ inx = find(x<=bounds(:,1));
|
||||||
if ~isempty(inx)
|
if ~isempty(inx)
|
||||||
x(inx) = bounds(inx,1)+eps;
|
x(inx) = bounds(inx,1)+eps;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ee=disp_eigenvalues_gradient(gg,hh)
|
||||||
|
|
||||||
|
disp(['Gradient norm ',num2str(norm(gg))])
|
||||||
|
ee=eig(hh);
|
||||||
|
disp(['Minimum Hessian eigenvalue ',num2str(min(ee))])
|
||||||
|
disp(['Maximum Hessian eigenvalue ',num2str(max(ee))])
|
||||||
|
|
Loading…
Reference in New Issue