Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Normalize the H matrix in BFGS to prevent it from blowing up, while still doing what it needs to do.
  • Loading branch information
daminton committed May 20, 2021
1 parent 0a36937 commit 63421c2
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/util/util_minimize_bfgs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ function util_minimize_bfgs(f, N, x0_d, eps_d, lerr) result(x1_d)
exit
end if
S(:) = -matmul(H(:,:), grad1(:))
! normalize gradient
!S(:) = S(:) / norm2(S(:))
astar = minimize1D(f, x1, S, N, gradeps, lerr)
if (lerr) then
write(*,*) "Exiting BFGS with error in minimize1D step"
Expand Down Expand Up @@ -104,11 +102,8 @@ function util_minimize_bfgs(f, N, x0_d, eps_d, lerr) result(x1_d)
end do
! update H matrix
H(:,:) = H(:,:) + ((1._QP - yHy / Py) * PP(:,:) - PyH(:,:) - HyP(:,:)) / Py
if (any(H(:,:) > sqrt(huge(1._QP)) / N)) then
lerr = .true.
write(*,*) 'BFGS did not converge after ',i,'iterations: H too big'
exit
end if
! Normalize to prevent it from blowing up if it takes many iterations to find a solution
H(:,:) = H(:,:) / norm2(H(:,:))
! Stop everything if there are any exceptions to allow the routine to fail gracefully
call ieee_get_flag(ieee_usual, fpe_flag)
if (any(fpe_flag)) exit
Expand Down

0 comments on commit 63421c2

Please sign in to comment.