2015-05-13 20:58:47 +02:00
|
|
|
function H = bfgsi1(H0,dg,dx,Verbose,Save_files)
|
|
|
|
% H = bfgsi1(H0,dg,dx,Verbose,Save_files)
|
2015-04-16 17:50:02 +02:00
|
|
|
% Update Inverse Hessian matrix
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2015-04-16 17:50:02 +02:00
|
|
|
% Inputs:
|
|
|
|
% H0 [npar by npar] initial inverse Hessian matrix
|
|
|
|
% dg [npar by 1] previous change in gradient
|
|
|
|
% dx [npar by 1] previous change in x;
|
2015-05-13 20:58:47 +02:00
|
|
|
% Verbose [scalar] Indicator for silent mode
|
2017-05-16 15:10:20 +02:00
|
|
|
% Save_files [scalar] Indicator whether to save files
|
|
|
|
%
|
2015-05-13 20:58:47 +02:00
|
|
|
% 6/8/93 version that updates inverse Hessian instead of Hessian
|
2005-02-18 20:54:39 +01:00
|
|
|
% itself.
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2008-09-02 17:18:05 +02:00
|
|
|
% Original file downloaded from:
|
|
|
|
% http://sims.princeton.edu/yftp/optimize/mfiles/bfgsi.m
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 1993-2009 Christopher Sims
|
|
|
|
% Copyright © 2009-2017 Dynare Team
|
2008-08-01 15:28:14 +02: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/>.
|
2008-08-01 15:28:14 +02:00
|
|
|
|
2005-02-18 20:54:39 +01:00
|
|
|
if size(dg,2)>1
|
2009-12-16 18:17:34 +01:00
|
|
|
dg=dg';
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
|
|
|
if size(dx,2)>1
|
2009-12-16 18:17:34 +01:00
|
|
|
dx=dx';
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
|
|
|
Hdg = H0*dg;
|
|
|
|
dgdx = dg'*dx;
|
|
|
|
if (abs(dgdx) >1e-12)
|
2009-12-16 18:17:34 +01:00
|
|
|
H = H0 + (1+(dg'*Hdg)/dgdx)*(dx*dx')/dgdx - (dx*Hdg'+Hdg*dx')/dgdx;
|
2005-02-18 20:54:39 +01:00
|
|
|
else
|
2015-05-13 20:58:47 +02:00
|
|
|
disp_verbose('bfgs update failed.',Verbose)
|
|
|
|
disp_verbose(['|dg| = ' num2str(sqrt(dg'*dg)) '|dx| = ' num2str(sqrt(dx'*dx))],Verbose);
|
|
|
|
disp_verbose(['dg''*dx = ' num2str(dgdx)],Verbose)
|
|
|
|
disp_verbose(['|H*dg| = ' num2str(Hdg'*Hdg)],Verbose)
|
2009-12-16 18:17:34 +01:00
|
|
|
H=H0;
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
2015-05-13 20:58:47 +02:00
|
|
|
if Save_files
|
|
|
|
save('H.dat','H')
|
|
|
|
end
|