2020-07-08 11:34:40 +02:00
|
|
|
function [xparam1, hh, gg, fval, igg, hess_info] = newrat(func0, x, bounds, analytic_derivation, ftol0, nit, flagg, Verbose, Save_files, hess_info, prior_std, gradient_epsilon, parameter_names, varargin)
|
|
|
|
% [xparam1, hh, gg, fval, igg, hess_info] = newrat(func0, x, bounds, analytic_derivation, ftol0, nit, flagg, Verbose, Save_files, hess_info, gradient_epsilon, parameter_names, varargin)
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% Optimiser with outer product gradient and with sequences of univariate steps
|
|
|
|
% uses Chris Sims subroutine for line search
|
|
|
|
%
|
2016-06-06 11:37:01 +02:00
|
|
|
% Inputs:
|
|
|
|
% - func0 name of the function that also outputs the single contributions at times t=1,...,T
|
|
|
|
% of the log-likelihood to compute outer product gradient
|
|
|
|
% - x starting guess
|
2020-06-23 15:04:11 +02:00
|
|
|
% - bounds prior bounds of parameters
|
2016-06-06 11:37:01 +02:00
|
|
|
% - analytic_derivation 1 if analytic derivatives, 0 otherwise
|
|
|
|
% - ftol0 termination criterion for function change
|
|
|
|
% - nit maximum number of iterations
|
2017-05-16 15:10:20 +02:00
|
|
|
% - flagg Indicator how to compute final Hessian (In each iteration, Hessian is computed with outer product gradient)
|
2016-06-06 11:37:01 +02:00
|
|
|
% 0: final Hessian computed with outer product gradient
|
2017-05-16 15:10:20 +02:00
|
|
|
% 1: final 'mixed' Hessian: diagonal elements computed with
|
|
|
|
% numerical second order derivatives with correlation structure
|
2016-06-06 11:37:01 +02:00
|
|
|
% as from outer product gradient
|
|
|
|
% 2: full numerical Hessian
|
|
|
|
% - Verbose 1 if explicit output is requested
|
2017-05-16 15:10:20 +02:00
|
|
|
% - Save_files 1 if intermediate output is to be saved
|
2016-06-06 11:37:01 +02:00
|
|
|
% - hess_info structure storing the step sizes for
|
|
|
|
% computation of Hessian
|
2020-06-23 15:04:11 +02:00
|
|
|
% - prior_std prior standard devation of parameters (can be NaN);
|
|
|
|
% passed to mr_hessian
|
2020-07-08 11:34:40 +02:00
|
|
|
% - gradient_epsilon [double] step size in gradient
|
|
|
|
% - parameter_names [cell] names of parameters for error messages
|
2020-06-23 15:04:11 +02:00
|
|
|
% - varargin other inputs
|
|
|
|
% e.g. in dsge_likelihood and others:
|
2016-06-06 11:37:01 +02:00
|
|
|
% varargin{1} --> DynareDataset
|
|
|
|
% varargin{2} --> DatasetInfo
|
|
|
|
% varargin{3} --> DynareOptions
|
|
|
|
% varargin{4} --> Model
|
|
|
|
% varargin{5} --> EstimatedParameters
|
|
|
|
% varargin{6} --> BayesInfo
|
|
|
|
% varargin{7} --> Bounds
|
|
|
|
% varargin{8} --> DynareResults
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2016-06-06 11:37:01 +02:00
|
|
|
% Outputs
|
|
|
|
% - xparam1 parameter vector at optimum
|
|
|
|
% - hh hessian
|
|
|
|
% - gg gradient
|
|
|
|
% - fval function value
|
|
|
|
% - igg inverted outer product hessian
|
|
|
|
% - hess_info structure with updated step length
|
2014-06-20 11:21:30 +02:00
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2004-2017 Dynare Team
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
% initialize variable penalty
|
2016-06-01 18:22:51 +02:00
|
|
|
penalty = 1e8;
|
2015-05-13 20:58:47 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
icount=0;
|
|
|
|
nx=length(x);
|
|
|
|
xparam1=x;
|
|
|
|
%ftol0=1.e-6;
|
2011-11-07 09:21:36 +01:00
|
|
|
htol_base = max(1.e-7, ftol0);
|
2021-01-27 22:02:45 +01:00
|
|
|
flagit=0; % mode of computation of hessian in each iteration; hard-coded outer-product of gradients as it performed best in tests
|
2009-12-16 18:17:34 +01:00
|
|
|
ftol=ftol0;
|
|
|
|
gtol=1.e-3;
|
|
|
|
htol=htol_base;
|
|
|
|
htol0=htol_base;
|
|
|
|
|
2016-06-01 18:22:51 +02:00
|
|
|
% force fcn, grad to function handle
|
|
|
|
if ischar(func0)
|
|
|
|
func0 = str2func(func0);
|
|
|
|
end
|
|
|
|
|
2012-04-27 15:50:12 +02:00
|
|
|
% func0 = str2func([func2str(func0),'_hh']);
|
|
|
|
% func0 = func0;
|
2016-06-01 18:22:51 +02:00
|
|
|
[fval0,exit_flag,gg,hh]=penalty_objective_function(x,func0,penalty,varargin{:});
|
2021-01-21 19:34:47 +01:00
|
|
|
if ~exit_flag
|
|
|
|
disp_verbose('Bad initial parameter.',Verbose)
|
|
|
|
return
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
fval=fval0;
|
2011-10-03 12:19:41 +02:00
|
|
|
|
2010-04-19 16:40:28 +02:00
|
|
|
% initialize mr_gstep and mr_hessian
|
|
|
|
|
2012-06-08 14:23:18 +02:00
|
|
|
outer_product_gradient=1;
|
2009-12-16 18:17:34 +01:00
|
|
|
if isempty(hh)
|
2021-01-21 21:26:06 +01:00
|
|
|
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(x,func0,penalty,flagit,htol,hess_info,bounds,prior_std,Save_files,varargin{:});
|
2017-05-16 12:42:01 +02:00
|
|
|
if isempty(dum)
|
2012-05-31 14:42:52 +02:00
|
|
|
outer_product_gradient=0;
|
|
|
|
igg = 1e-4*eye(nx);
|
|
|
|
else
|
|
|
|
hh0 = reshape(dum,nx,nx);
|
|
|
|
hh=hhg;
|
|
|
|
if min(eig(hh0))<0
|
|
|
|
hh0=hhg; %generalized_cholesky(hh0);
|
|
|
|
elseif flagit==2
|
|
|
|
hh=hh0;
|
|
|
|
igg=inv(hh);
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2015-10-13 11:07:01 +02:00
|
|
|
if max(htol0)>htol
|
|
|
|
skipline()
|
2015-11-28 14:06:10 +01:00
|
|
|
disp_verbose('Numerical noise in the likelihood',Verbose)
|
|
|
|
disp_verbose('Tolerance has to be relaxed',Verbose)
|
2015-10-13 11:07:01 +02:00
|
|
|
skipline()
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
hh0=hh;
|
|
|
|
hhg=hh;
|
|
|
|
igg=inv(hh);
|
2012-06-08 14:23:18 +02:00
|
|
|
h1=[];
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2011-02-14 11:51:15 +01:00
|
|
|
H = igg;
|
2021-01-27 22:02:45 +01:00
|
|
|
if Verbose
|
|
|
|
disp_eigenvalues_gradient(gg,hh);
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
g=gg;
|
|
|
|
check=0;
|
2021-01-27 22:02:45 +01:00
|
|
|
if Verbose
|
|
|
|
if max(eig(hh))<0
|
|
|
|
disp('Negative definite Hessian! Local maximum!')
|
|
|
|
pause
|
|
|
|
end
|
2015-05-13 20:58:47 +02:00
|
|
|
end
|
|
|
|
if Save_files
|
2016-06-01 18:22:51 +02:00
|
|
|
save('m1.mat','x','hh','g','hhg','igg','fval0')
|
2015-05-13 20:58:47 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
igrad=1;
|
|
|
|
igibbs=1;
|
|
|
|
inx=eye(nx);
|
|
|
|
jit=0;
|
2021-01-27 22:02:45 +01:00
|
|
|
if Save_files
|
|
|
|
nig=[];
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
ig=ones(nx,1);
|
|
|
|
ggx=zeros(nx,1);
|
2011-10-03 12:19:41 +02:00
|
|
|
while norm(gg)>gtol && check==0 && jit<nit
|
2009-12-16 18:17:34 +01:00
|
|
|
jit=jit+1;
|
2015-10-10 11:08:52 +02:00
|
|
|
tic1 = tic;
|
2009-12-16 18:17:34 +01:00
|
|
|
icount=icount+1;
|
2016-06-01 18:22:51 +02:00
|
|
|
penalty = fval0(icount);
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose([' '],Verbose)
|
|
|
|
disp_verbose(['Iteration ',num2str(icount)],Verbose)
|
2016-06-01 18:22:51 +02:00
|
|
|
[fval,x0,fc,retcode] = csminit1(func0,xparam1,penalty,fval0(icount),gg,0,H,Verbose,varargin{:});
|
2011-10-03 12:19:41 +02:00
|
|
|
if igrad
|
2016-06-01 18:22:51 +02:00
|
|
|
[fval1,x01,fc,retcode1] = csminit1(func0,x0,penalty,fval,gg,0,inx,Verbose,varargin{:});
|
2011-10-03 12:19:41 +02:00
|
|
|
if (fval-fval1)>1
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Gradient step!!',Verbose)
|
2009-12-16 18:17:34 +01:00
|
|
|
else
|
|
|
|
igrad=0;
|
|
|
|
end
|
|
|
|
fval=fval1;
|
2011-10-03 12:19:41 +02:00
|
|
|
x0=x01;
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2021-01-21 21:26:06 +01:00
|
|
|
ig_pos=find(ig);
|
|
|
|
if length(ig_pos)<nx
|
|
|
|
ggx=ggx*0;
|
|
|
|
ggx(ig_pos)=gg(ig_pos);
|
2017-10-10 10:14:59 +02:00
|
|
|
if analytic_derivation || ~outer_product_gradient
|
2015-10-09 14:22:26 +02:00
|
|
|
hhx=hh;
|
|
|
|
else
|
|
|
|
hhx = reshape(dum,nx,nx);
|
|
|
|
end
|
2014-06-20 11:21:30 +02:00
|
|
|
iggx=eye(length(gg));
|
2021-01-21 21:26:06 +01:00
|
|
|
iggx(ig_pos,ig_pos) = inv( hhx(ig_pos,ig_pos) );
|
2016-06-01 18:22:51 +02:00
|
|
|
[fvala,x0,fc,retcode] = csminit1(func0,x0,penalty,fval,ggx,0,iggx,Verbose,varargin{:});
|
2014-06-20 11:21:30 +02:00
|
|
|
end
|
2015-10-13 11:07:01 +02:00
|
|
|
x0 = check_bounds(x0,bounds);
|
2020-07-08 11:34:40 +02:00
|
|
|
[fvala, x0, ig] = mr_gstep(h1,x0,bounds,func0,penalty,htol0,Verbose,Save_files,gradient_epsilon, parameter_names,varargin{:});
|
2015-10-13 11:07:01 +02:00
|
|
|
x0 = check_bounds(x0,bounds);
|
2021-01-27 22:02:45 +01:00
|
|
|
if Save_files
|
|
|
|
nig=[nig ig];
|
|
|
|
end
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Sequence of univariate steps!!',Verbose)
|
2014-06-20 11:21:30 +02:00
|
|
|
fval=fvala;
|
2011-10-03 12:19:41 +02:00
|
|
|
if (fval0(icount)-fval)<ftol && flagit==0
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Try diagonal Hessian',Verbose)
|
2011-10-03 12:19:41 +02:00
|
|
|
ihh=diag(1./(diag(hhg)));
|
2016-06-01 18:22:51 +02:00
|
|
|
[fval2,x0,fc,retcode2] = csminit1(func0,x0,penalty,fval,gg,0,ihh,Verbose,varargin{:});
|
2015-10-13 11:07:01 +02:00
|
|
|
x0 = check_bounds(x0,bounds);
|
2011-10-03 12:19:41 +02:00
|
|
|
if (fval-fval2)>=ftol
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Diagonal Hessian successful',Verbose)
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
fval=fval2;
|
2011-10-03 12:19:41 +02:00
|
|
|
end
|
|
|
|
if (fval0(icount)-fval)<ftol && flagit==0
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Try gradient direction',Verbose)
|
2011-10-03 12:19:41 +02:00
|
|
|
ihh0=inx.*1.e-4;
|
2016-06-01 18:22:51 +02:00
|
|
|
[fval3,x0,fc,retcode3] = csminit1(func0,x0,penalty,fval,gg,0,ihh0,Verbose,varargin{:});
|
2015-10-13 11:07:01 +02:00
|
|
|
x0 = check_bounds(x0,bounds);
|
2011-10-03 12:19:41 +02:00
|
|
|
if (fval-fval3)>=ftol
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Gradient direction successful',Verbose)
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
fval=fval3;
|
2011-10-03 12:19:41 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
xparam1=x0;
|
|
|
|
x(:,icount+1)=xparam1;
|
|
|
|
fval0(icount+1)=fval;
|
2011-10-03 12:19:41 +02:00
|
|
|
if (fval0(icount)-fval)<ftol
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('No further improvement is possible!',Verbose)
|
2009-12-16 18:17:34 +01:00
|
|
|
check=1;
|
2017-05-16 12:42:01 +02:00
|
|
|
if analytic_derivation
|
2016-06-01 18:22:51 +02:00
|
|
|
[fvalx,exit_flag,gg,hh]=penalty_objective_function(xparam1,func0,penalty,varargin{:});
|
2012-06-08 14:23:18 +02:00
|
|
|
hhg=hh;
|
2014-06-20 11:21:30 +02:00
|
|
|
H = inv(hh);
|
2012-06-08 14:23:18 +02:00
|
|
|
else
|
2017-05-16 15:10:20 +02:00
|
|
|
if flagit==2
|
|
|
|
hh=hh0;
|
|
|
|
elseif flagg>0
|
2021-01-21 21:26:06 +01:00
|
|
|
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagg,ftol0,hess_info,bounds,prior_std,Save_files,varargin{:});
|
2017-05-16 15:10:20 +02:00
|
|
|
if flagg==2
|
|
|
|
hh = reshape(dum,nx,nx);
|
|
|
|
ee=eig(hh);
|
|
|
|
if min(ee)<0
|
|
|
|
hh=hhg;
|
|
|
|
end
|
|
|
|
else
|
2009-12-16 18:17:34 +01:00
|
|
|
hh=hhg;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-01-27 22:02:45 +01:00
|
|
|
if Verbose
|
|
|
|
disp(['Actual dxnorm ',num2str(norm(x(:,end)-x(:,end-1)))])
|
|
|
|
disp(['FVAL ',num2str(fval)])
|
|
|
|
disp(['Improvement ',num2str(fval0(icount)-fval)])
|
|
|
|
disp(['Ftol ',num2str(ftol)])
|
|
|
|
disp(['Htol ',num2str(max(htol0))])
|
|
|
|
disp_eigenvalues_gradient(gg,hh);
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
g(:,icount+1)=gg;
|
|
|
|
else
|
|
|
|
df = fval0(icount)-fval;
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose(['Actual dxnorm ',num2str(norm(x(:,end)-x(:,end-1)))],Verbose)
|
|
|
|
disp_verbose(['FVAL ',num2str(fval)],Verbose)
|
|
|
|
disp_verbose(['Improvement ',num2str(df)],Verbose)
|
|
|
|
disp_verbose(['Ftol ',num2str(ftol)],Verbose)
|
2015-10-13 11:07:01 +02:00
|
|
|
disp_verbose(['Htol ',num2str(max(htol0))],Verbose)
|
2011-03-15 15:27:41 +01:00
|
|
|
htol=htol_base;
|
2017-05-16 12:42:01 +02:00
|
|
|
if norm(x(:,icount)-xparam1)>1.e-12 && analytic_derivation==0
|
2011-10-03 12:19:41 +02:00
|
|
|
try
|
2015-05-13 20:58:47 +02:00
|
|
|
if Save_files
|
2016-06-01 18:22:51 +02:00
|
|
|
save('m1.mat','x','fval0','nig','-append')
|
2015-05-13 20:58:47 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
catch
|
2015-05-13 20:58:47 +02:00
|
|
|
if Save_files
|
2016-06-01 18:22:51 +02:00
|
|
|
save('m1.mat','x','fval0','nig')
|
2015-05-13 20:58:47 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2021-01-21 21:26:06 +01:00
|
|
|
[dum, gg, htol0, igg, hhg, h1, hess_info]=mr_hessian(xparam1,func0,penalty,flagit,htol,hess_info,bounds,prior_std,Save_files,varargin{:});
|
2017-05-16 12:42:01 +02:00
|
|
|
if isempty(dum)
|
2012-05-31 14:42:52 +02:00
|
|
|
outer_product_gradient=0;
|
|
|
|
end
|
2015-10-13 11:07:01 +02:00
|
|
|
if max(htol0)>htol
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Numerical noise in the likelihood',Verbose)
|
|
|
|
disp_verbose('Tolerance has to be relaxed',Verbose)
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2017-05-16 12:42:01 +02:00
|
|
|
if ~outer_product_gradient
|
2015-05-13 20:58:47 +02:00
|
|
|
H = bfgsi1(H,gg-g(:,icount),xparam1-x(:,icount),Verbose,Save_files);
|
2012-05-31 14:42:52 +02:00
|
|
|
hh=inv(H);
|
|
|
|
hhg=hh;
|
|
|
|
else
|
|
|
|
hh0 = reshape(dum,nx,nx);
|
|
|
|
hh=hhg;
|
|
|
|
if flagit==2
|
|
|
|
if min(eig(hh0))<=0
|
|
|
|
hh0=hhg; %generalized_cholesky(hh0);
|
|
|
|
else
|
|
|
|
hh=hh0;
|
|
|
|
igg=inv(hh);
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2012-05-31 14:42:52 +02:00
|
|
|
H = igg;
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2017-05-16 12:42:01 +02:00
|
|
|
elseif analytic_derivation
|
2016-06-01 18:22:51 +02:00
|
|
|
[fvalx,exit_flag,gg,hh]=penalty_objective_function(xparam1,func0,penalty,varargin{:});
|
2012-06-08 14:23:18 +02:00
|
|
|
hhg=hh;
|
|
|
|
H = inv(hh);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2021-01-27 22:02:45 +01:00
|
|
|
if Verbose
|
|
|
|
if max(eig(hh))<0
|
|
|
|
disp('Negative definite Hessian! Local maximum!')
|
|
|
|
pause(1)
|
|
|
|
end
|
2015-05-13 20:58:47 +02:00
|
|
|
end
|
2015-10-10 11:08:52 +02:00
|
|
|
t=toc(tic1);
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose(['Elapsed time for iteration ',num2str(t),' s.'],Verbose)
|
2009-12-16 18:17:34 +01:00
|
|
|
g(:,icount+1)=gg;
|
2015-05-13 20:58:47 +02:00
|
|
|
if Save_files
|
2016-06-01 18:22:51 +02:00
|
|
|
save('m1.mat','x','hh','g','hhg','igg','fval0','nig','H')
|
2015-05-13 20:58:47 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
end
|
2015-05-13 20:58:47 +02:00
|
|
|
if Save_files
|
2016-06-01 18:22:51 +02:00
|
|
|
save('m1.mat','x','hh','g','hhg','igg','fval0','nig')
|
2015-05-13 20:58:47 +02:00
|
|
|
end
|
2011-10-03 12:19:41 +02:00
|
|
|
if ftol>ftol0
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Numerical noise in the likelihood',Verbose)
|
|
|
|
disp_verbose('Tolerance had to be relaxed',Verbose)
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2011-10-03 12:19:41 +02:00
|
|
|
if jit==nit
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('Maximum number of iterations reached',Verbose)
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2011-10-03 12:19:41 +02:00
|
|
|
if norm(gg)<=gtol
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose(['Estimation ended:'],Verbose)
|
|
|
|
disp_verbose(['Gradient norm < ', num2str(gtol)],Verbose)
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2017-05-16 12:42:01 +02:00
|
|
|
if check==1
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose(['Estimation successful.'],Verbose)
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2015-05-13 20:58:47 +02:00
|
|
|
return
|
2015-10-13 11:07:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
function x = check_bounds(x,bounds)
|
|
|
|
|
|
|
|
inx = find(x>=bounds(:,2));
|
2017-05-16 12:42:01 +02:00
|
|
|
if ~isempty(inx)
|
2015-10-13 11:07:01 +02:00
|
|
|
x(inx) = bounds(inx,2)-eps;
|
|
|
|
end
|
|
|
|
|
|
|
|
inx = find(x<=bounds(:,1));
|
2017-05-16 12:42:01 +02:00
|
|
|
if ~isempty(inx)
|
2015-10-13 11:07:01 +02:00
|
|
|
x(inx) = bounds(inx,1)+eps;
|
|
|
|
end
|
2021-01-27 22:02:45 +01:00
|
|
|
|
|
|
|
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))])
|