Statistiques
| Révision :

root / src / Hupdate_MS.f90 @ 3

Historique | Voir | Annoter | Télécharger (2,93 ko)

1
! Hessian - or its inverse - update
2
! We use the Murtagh-Sargent update, also called Symmetric Rank 1
3
!
4
! input:
5
!  - nfree: number of coordinates
6
!  - ds: GeomOld-Geom (expressed in the optimization coord.)
7
!  - dgrad: GradOld-Grad  (expressed in the optimization coord.)
8
!
9
!  input/output:
10
!  - Hess: old Hessian in input, replaced by updated Hessian on output
11
!             (or inverse Hessian)
12
!
13
!
14
!!!!!!!!!!!!!!!!!!!!!!
15
! The update formula for the Hessian is:
16
! (following Fletcher, approximate Hessian is denoted by B)
17
! B(k+1)=B+[(y-Bs){(y-Bs)T}]/[{(y-Bs)T}s]
18
!
19
! it is self dual, ie for the inverse Hessian, denote by H:
20
! H(k+1)=H+[(s-Hy){(s-Hy)T}]/[{(s-Hy)T}y]
21
!
22
! 
23
! We decompose the computation in two steps:
24
! first we compute the update, and then we add it to Hess to get the
25
! new Hessian.
26
! This allows us to introduce a scaling factor if needed later.
27
!
28
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29

    
30
SUBROUTINE Hupdate_MS(Nfree,ds,dgrad,Hess)
31

    
32
  IMPLICIT NONE
33

    
34
  INTEGER, PARAMETER :: KINT=KIND(1)
35
  INTEGER, PARAMETER :: KREAL=KIND(1.D0)
36

    
37
  INTEGER(KINT), INTENT(IN) :: NFREE
38
  REAL(KREAL), INTENT(INOUT) :: Hess(Nfree,Nfree)
39
  REAL(KREAL), INTENT(IN) :: ds(Nfree)
40
  REAL(KREAL), INTENT(IN) :: dGrad(Nfree)
41

    
42

    
43
  REAL(KREAL), ALLOCATABLE  :: HessOld(:, :) 
44
  REAL(KREAL), ALLOCATABLE  :: Hup(:,:)
45
  REAL(KREAL), ALLOCATABLE  :: HupInt(:)
46
  REAL(KREAL), ALLOCATABLE  :: HS(:), Num(:,:)
47
  REAL(KREAL) :: Den, NormDS
48
  INTEGER(KINT) :: i,j, idx
49

    
50
  LOGICAL :: debug
51

    
52
  interface
53
     function valid(string) result (isValid)
54
       logical                  :: isValid
55
       character(*), intent(in) :: string
56
     end function valid
57

    
58
  end interface
59

    
60

    
61

    
62

    
63
  debug=valid("Hupdate").OR.Valid("Hupdate_MS")
64

    
65
  if (debug) Call Header("Entering Hupdate_MS")
66

    
67
  ALLOCATE(HessOld(nfree,nfree),  &
68
       Hup(nfree,nfree), &
69
       HupInt(nfree), HS(nfree),  &
70
       Num(nfree,nfree))
71

    
72
  HessOld=Hess
73

    
74
  if (debug) THEN
75
     WRITE(*,*) 'DBG Hupdate HessOld'
76
     Idx=min(12,Nfree)
77
     DO I=1,NFree
78
        WRITE(*,'(12(1X,F8.4))') HessOld(I,1:Idx)
79
     END DO
80
     WRITE(*,*) 'DBG Hupdate ds'
81
     WRITE(*,'(12(1X,F8.4))') ds(1:Idx)
82
     WRITE(*,*) 'DBG Hupdate dGrad'
83
     WRITE(*,'(12(1X,F8.4))') dGrad(1:Idx)
84
  END IF
85

    
86
  NormDS=sqrt(DOT_PRODUCT(DS,DS))
87
  if (NormDS>=1e-6) THEN
88

    
89
     HS=0
90
     DO I=1,nfree
91
        DO J=1,nfree
92
           HS(I)=HS(I)+HessOld(i,j)*Ds(j)
93
        END DO
94
     END DO
95

    
96
     if (debug) WRITE(*,*) "HS:",HS
97
     HupInt=DGrad-HS
98

    
99
     ! WE calculate the MS update
100
     Num=0.
101
     Den=0.
102
     DO I=1,nfree
103
        DO J=1,nfree
104
           Num(I,J)=HUpInt(i)*HupInt(j)
105
        END DO
106
        Den=Den+Hupint(i)*Ds(i)
107
     END DO
108
     if (debug) WRITE(*,*) "Den:",Den,1./Den
109

    
110
     Hup=Num/Den
111

    
112
     Hess=HessOld+Hup
113
  ELSE
114
     Hess=HessOld
115
  END IF
116
  !     WRITE(*,*) 'New hess'
117
  !     DO I=1,nfree
118
  !        WRITE(*,fmt) Hess(i,:)
119
  !     END DO
120

    
121
  DEALLOCATE(HessOld,Hup, HupInt, HS, Num )
122

    
123
  if (debug) Call Header("Hupdate_MS Over")
124

    
125
END SUBROUTINE Hupdate_MS