From 63421c2a514658896444bde714882d0f64d02176 Mon Sep 17 00:00:00 2001 From: David Minton Date: Thu, 20 May 2021 11:47:11 -0400 Subject: [PATCH] Normalize the H matrix in BFGS to prevent it from blowing up, while still doing what it needs to do. --- src/util/util_minimize_bfgs.f90 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/util/util_minimize_bfgs.f90 b/src/util/util_minimize_bfgs.f90 index 229f90a6e..7338499ab 100644 --- a/src/util/util_minimize_bfgs.f90 +++ b/src/util/util_minimize_bfgs.f90 @@ -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" @@ -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