Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/bfgsi.m

raw
1 function H = bfgsi(H0,dg,dx)
2 % H = bfgsi(H0,dg,dx)
3 % dg is previous change in gradient; dx is previous change in x;
4 % 6/8/93 version that updates inverse hessian instead of hessian
5 % itself.
6 %
7 %
8 % Copyright (C) 1996 Christopher A. Sims
9 %
10 % This free software: you can redistribute it and/or modify
11 % it under the terms of the GNU General Public License as published by
12 % the Free Software Foundation, either version 3 of the License, or
13 % (at your option) any later version.
14 %
15 % It is distributed in the hope that it will be useful,
16 % but WITHOUT ANY WARRANTY; without even the implied warranty of
17 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 % GNU General Public License for more details.
19 %
20 % If you did not received a copy of the GNU General Public License
21 % with this software, see <http://www.gnu.org/licenses/>.
22 %
23 dispIndx = 1; % 1: turn on all the diplays on the screen; 0: turn off (Added by T. Zha)
24
25 if size(dg,2)>1
26 dg=dg';
27 end
28 if size(dx,2)>1
29 dx=dx';
30 end
31 Hdg = H0*dg;
32 dgdx = dg'*dx;
33 if (abs(dgdx) >1e-12)
34 H = H0 + (1+(dg'*Hdg)/dgdx)*(dx*dx')/dgdx - (dx*Hdg'+Hdg*dx')/dgdx;
35 else
36 if dispIndx
37 disp('bfgs update failed.')
38 disp(['|dg| = ' num2str(sqrt(dg'*dg)) '|dx| = ' num2str(sqrt(dx'*dx))]);
39 disp(['dg''*dx = ' num2str(dgdx)])
40 disp(['|H*dg| = ' num2str(Hdg'*Hdg)])
41 end
42 H=H0;
43 end
44 save H.dat H