Skip to content

Commit

Permalink
240315.162150.HKT fortran: 1. All solvers but cobyla now return if …
Browse files Browse the repository at this point in the history
…the model contains `Inf`/`NaN`. This is because the model is updated based on the version in the last iteration; if the model contains `Inf`/`NaN`, then it will not recover, causing the trust step to fail always, and the solver will take geometry steps until `rho` reaches `rhoend` or `maxfun` is exhausted. This was observed when `RP=REAL16`. 2. Do not take the Newton-Raphson step unless it is long enough.
  • Loading branch information
zaikunzhang committed Mar 15, 2024
1 parent 4d6d34c commit f3149e0
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 72 deletions.
35 changes: 22 additions & 13 deletions fortran/bobyqa/bobyqb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module bobyqb_mod
!
! Started: February 2022
!
! Last Modified: Thursday, March 14, 2024 PM02:01:09
! Last Modified: Friday, March 15, 2024 PM03:09:17
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -82,7 +82,8 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
use, non_intrinsic :: evaluate_mod, only : evaluate
use, non_intrinsic :: history_mod, only : savehist, rangehist
use, non_intrinsic :: infnan_mod, only : is_nan, is_finite, is_posinf
use, non_intrinsic :: infos_mod, only : INFO_DFT, SMALL_TR_RADIUS, MAXTR_REACHED, DAMAGING_ROUNDING, CALLBACK_TERMINATE
use, non_intrinsic :: infos_mod, only : INFO_DFT, SMALL_TR_RADIUS, MAXTR_REACHED, DAMAGING_ROUNDING,&
& NAN_INF_MODEL, CALLBACK_TERMINATE
use, non_intrinsic :: linalg_mod, only : norm
use, non_intrinsic :: message_mod, only : retmsg, rhomsg, fmsg
use, non_intrinsic :: pintrf_mod, only : OBJ, CALLBACK
Expand Down Expand Up @@ -232,6 +233,16 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
x = xinbd(xbase, xpt(:, kopt), xl, xu, sl, su) ! In precise arithmetic, X = XBASE + XOPT.
f = fval(kopt)

! Initialize [BMAT, ZMAT], representing the inverse of the KKT matrix of the interpolation system.
call inith(ij, xpt, bmat, zmat)

! Initialize the quadratic represented by [GOPT, HQ, PQ], so that its gradient at XBASE+XOPT is
! GOPT; its Hessian is HQ + sum_{K=1}^NPT PQ(K)*XPT(:, K)*XPT(:, K)'.
call initq(ij, fval, xpt, gopt, hq, pq)
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
subinfo = NAN_INF_MODEL
end if

! Check whether to return due to abnormal cases that may occur during the initialization.
if (subinfo /= INFO_DFT) then
info = subinfo
Expand All @@ -242,16 +253,6 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
return
end if

! Initialize [BMAT, ZMAT], representing the inverse of the KKT matrix of the interpolation system.
call inith(ij, xpt, bmat, zmat)

! Initialize the quadratic represented by [GOPT, HQ, PQ], so that its gradient at XBASE+XOPT is
! GOPT; its Hessian is HQ + sum_{K=1}^NPT PQ(K)*XPT(:, K)*XPT(:, K)'.
call initq(ij, fval, xpt, gopt, hq, pq)

! After initializing GOPT, HQ, PQ, BMAT, ZMAT, one can also choose to return if these arrays contain
! NaN. We do not do it here. The code will continue to run and possibly recovers by geometry steps.

! Set some more initial values.
! We must initialize RATIO. Otherwise, when SHORTD = TRUE, compilers may raise a run-time error that
! RATIO is undefined. But its value will not be used: when SHORTD = FALSE, its value will be
Expand Down Expand Up @@ -417,6 +418,10 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
! Try whether to replace the new quadratic model with the alternative model, namely the
! least Frobenius norm interpolant.
call tryqalt(bmat, fval - fval(kopt), ratio, sl, su, xpt(:, kopt), xpt, zmat, itest, gopt, hq, pq)
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
info = NAN_INF_MODEL
exit
end if
end if
end if ! End of IF (SHORTD .OR. TRFAIL). The normal trust-region calculation ends.

Expand Down Expand Up @@ -571,6 +576,10 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
call updateh(knew_geo, kopt, d, xpt, bmat, zmat)
call updatexf(knew_geo, ximproved, f, max(sl, min(su, xosav + d)), kopt, fval, xpt)
call updateq(knew_geo, ximproved, bmat, d, moderr, xdrop, xosav, xpt, zmat, gopt, hq, pq)
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
info = NAN_INF_MODEL
exit
end if
end if
end if ! End of IF (IMPROVE_GEO). The procedure of improving geometry ends.

Expand Down Expand Up @@ -616,7 +625,7 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
end do ! End of DO TR = 1, MAXTR. The iterative procedure ends.

! Return from the calculation, after trying the Newton-Raphson step if it has not been tried yet.
if (info == SMALL_TR_RADIUS .and. shortd .and. nf < maxfun) then
if (info == SMALL_TR_RADIUS .and. shortd .and. dnorm >= TENTH * rhoend .and. nf < maxfun) then
x = xinbd(xbase, xpt(:, kopt) + d, xl, xu, sl, su) ! In precise arithmetic, X = XBASE + XOPT + D.
call evaluate(calfun, x, f)
nf = nf + 1_IK
Expand Down
2 changes: 1 addition & 1 deletion fortran/bobyqa/update.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module update_bobyqa_mod
!
! Started: February 2022
!
! Last Modified: Tuesday, March 12, 2024 PM08:42:04
! Last Modified: Friday, March 15, 2024 PM12:15:35
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down
9 changes: 5 additions & 4 deletions fortran/cobyla/cobylb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module cobylb_mod
!
! Started: July 2021
!
! Last Modified: Wednesday, March 13, 2024 PM11:56:56
! Last Modified: Friday, March 15, 2024 PM03:42:46
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -45,7 +45,7 @@ subroutine cobylb(calcfc, iprint, maxfilt, maxfun, amat, bvec, ctol, cweight, et
use, non_intrinsic :: debug_mod, only : assert
use, non_intrinsic :: evaluate_mod, only : evaluate
use, non_intrinsic :: history_mod, only : savehist, rangehist
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf, is_finite
use, non_intrinsic :: infos_mod, only : INFO_DFT, MAXTR_REACHED, SMALL_TR_RADIUS, DAMAGING_ROUNDING, CALLBACK_TERMINATE
use, non_intrinsic :: linalg_mod, only : inprod, matprod, norm, maximum
use, non_intrinsic :: message_mod, only : retmsg, rhomsg, fmsg
Expand Down Expand Up @@ -180,10 +180,11 @@ subroutine cobylb(calcfc, iprint, maxfilt, maxfun, amat, bvec, ctol, cweight, et
! Preconditions
if (DEBUGGING) then
call assert(abs(iprint) <= 3, 'IPRINT is 0, 1, -1, 2, -2, 3, or -3', srname)
call assert(m >= 0, 'M >= 0', srname)
call assert(m >= m_lcon .and. m_lcon >= 0, 'M >= M_LCON >= 0', srname)
call assert(n >= 1, 'N >= 1', srname)
call assert(maxfun >= n + 2, 'MAXFUN >= N + 2', srname)
call assert(rhobeg >= rhoend .and. rhoend > 0, 'RHOBEG >= RHOEND > 0', srname)
call assert(all(is_finite(x)), 'X is finite', srname)
call assert(eta1 >= 0 .and. eta1 <= eta2 .and. eta2 < 1, '0 <= ETA1 <= ETA2 < 1', srname)
call assert(gamma1 > 0 .and. gamma1 < 1 .and. gamma2 > 1, '0 < GAMMA1 < 1 < GAMMA2', srname)
call assert(ctol >= 0, 'CTOL >= 0', srname)
Expand Down Expand Up @@ -621,7 +622,7 @@ subroutine cobylb(calcfc, iprint, maxfilt, maxfun, amat, bvec, ctol, cweight, et
end do ! End of DO TR = 1, MAXTR. The iterative procedure ends.

! Return from the calculation, after trying the last trust-region step if it has not been tried yet.
if (info == SMALL_TR_RADIUS .and. shortd .and. nf < maxfun) then
if (info == SMALL_TR_RADIUS .and. shortd .and. dnorm >= TENTH * rhoend .and. nf < maxfun) then
! Zaikun 20230615: UPDATEXFC or UPDATEPOLE is not called since the last trust-region step. Hence
! SIM(:, N + 1) remains unchanged. Otherwise, SIM(:, N + 1) + D would not make sense.
x = sim(:, n + 1) + d
Expand Down
4 changes: 2 additions & 2 deletions fortran/cobyla/geometry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module geometry_cobyla_mod
!
! Started: July 2021
!
! Last Modified: Thursday, March 14, 2024 PM02:41:58
! Last Modified: Thursday, March 14, 2024 PM07:23:41
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -410,7 +410,7 @@ function geostep(jdrop, amat, bvec, conmat, cpen, cval, delta, fval, factor_gamm

! Preconditions
if (DEBUGGING) then
call assert(m >= 0, 'M >= 0', srname)
call assert(m >= m_lcon .and. m >= 0, 'M >= 0', srname)
call assert(n >= 1, 'N >= 1', srname)
call assert(delta > 0, 'DELTA > 0', srname)
call assert(cpen > 0, 'CPEN > 0', srname)
Expand Down
2 changes: 1 addition & 1 deletion fortran/examples/bobyqa/bobyqa_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Thursday, March 14, 2024 PM02:02:18
! Last Modified: Friday, March 15, 2024 PM02:04:34
!--------------------------------------------------------------------------------------------------!


Expand Down
2 changes: 1 addition & 1 deletion fortran/examples/cobyla/cobyla_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Wednesday, March 13, 2024 PM09:39:50
! Last Modified: Friday, March 15, 2024 PM02:05:11
!--------------------------------------------------------------------------------------------------!


Expand Down
2 changes: 1 addition & 1 deletion fortran/examples/lincoa/lincoa_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Wednesday, March 13, 2024 AM12:11:31
! Last Modified: Friday, March 15, 2024 PM02:06:02
!--------------------------------------------------------------------------------------------------!


Expand Down
2 changes: 1 addition & 1 deletion fortran/examples/newuoa/newuoa_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Wednesday, March 13, 2024 AM12:02:42
! Last Modified: Friday, March 15, 2024 PM02:06:18
!--------------------------------------------------------------------------------------------------!


Expand Down
2 changes: 1 addition & 1 deletion fortran/examples/uobyqa/uobyqa_example_2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! Started: July 2020
!
! Last Modified: Tuesday, March 12, 2024 PM11:59:34
! Last Modified: Friday, March 15, 2024 PM02:06:51
!--------------------------------------------------------------------------------------------------!


Expand Down
42 changes: 27 additions & 15 deletions fortran/lincoa/lincob.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module lincob_mod
!
! Started: February 2022
!
! Last Modified: Saturday, March 09, 2024 PM09:22:48
! Last Modified: Friday, March 15, 2024 PM03:44:40
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -77,8 +77,8 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
use, non_intrinsic :: debug_mod, only : assert
use, non_intrinsic :: evaluate_mod, only : evaluate
use, non_intrinsic :: history_mod, only : savehist, rangehist
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf
use, non_intrinsic :: infos_mod, only : INFO_DFT, MAXTR_REACHED, SMALL_TR_RADIUS, CALLBACK_TERMINATE
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf, is_finite
use, non_intrinsic :: infos_mod, only : INFO_DFT, MAXTR_REACHED, SMALL_TR_RADIUS, CALLBACK_TERMINATE, NAN_INF_MODEL
use, non_intrinsic :: linalg_mod, only : matprod, maximum, eye, trueloc, linspace, norm, trueloc
use, non_intrinsic :: memory_mod, only : safealloc
use, non_intrinsic :: message_mod, only : fmsg, rhomsg, retmsg
Expand Down Expand Up @@ -230,6 +230,7 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
call assert(eta1 >= 0 .and. eta1 <= eta2 .and. eta2 < 1, '0 <= ETA1 <= ETA2 < 1', srname)
call assert(gamma1 > 0 .and. gamma1 < 1 .and. gamma2 > 1, '0 < GAMMA1 < 1 < GAMMA2', srname)
call assert(rhobeg >= rhoend .and. rhoend > 0, 'RHOBEG >= RHOEND > 0', srname)
call assert(all(is_finite(x)), 'X is finite', srname)
call assert(size(xl) == n .and. size(xu) == n, 'SIZE(XL) == N == SIZE(XU)', srname)
call assert(maxfilt >= min(MIN_MAXFILT, maxfun) .and. maxfilt <= maxfun, &
& 'MIN(MIN_MAXFILT, MAXFUN) <= MAXFILT <= MAXFUN', srname)
Expand Down Expand Up @@ -286,6 +287,20 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
end if
end do

! Initialize [BMAT, ZMAT, IDZ], representing the inverse of the KKT matrix of the interpolation system.
call inith(ij, xpt, idz, bmat, zmat)

! Initialize the quadratic represented by [GOPT, HQ, PQ], so that its gradient at XBASE+XOPT is
! GOPT; its Hessian is HQ + sum_{K=1}^NPT PQ(K)*XPT(:, K)*XPT(:, K)'.
hq = ZERO
pq = omega_mul(idz, zmat, fval)
gopt = matprod(bmat(:, 1:npt), fval) + hess_mul(xpt(:, kopt), xpt, pq)
pqalt = pq
galt = gopt
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
subinfo = NAN_INF_MODEL
end if

! Check whether to return due to abnormal cases that may occur during the initialization.
if (subinfo /= INFO_DFT) then
info = subinfo
Expand All @@ -303,17 +318,6 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
return
end if

! Initialize [BMAT, ZMAT, IDZ], representing the inverse of the KKT matrix of the interpolation system.
call inith(ij, xpt, idz, bmat, zmat)

! Initialize the quadratic represented by [GOPT, HQ, PQ], so that its gradient at XBASE+XOPT is
! GOPT; its Hessian is HQ + sum_{K=1}^NPT PQ(K)*XPT(:, K)*XPT(:, K)'.
hq = ZERO
pq = omega_mul(idz, zmat, fval)
gopt = matprod(bmat(:, 1:npt), fval) + hess_mul(xpt(:, kopt), xpt, pq)
pqalt = pq
galt = gopt

! Initialize RESCON.
rescon = max(b - matprod(xpt(:, kopt), amat), ZERO)
rescon(trueloc(rescon >= rhobeg)) = -rescon(trueloc(rescon >= rhobeg))
Expand Down Expand Up @@ -478,6 +482,10 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
! the current model with the alternative model if the recent few (three) alternative
! models are more accurate in predicting the function value of XOPT + D.
call tryqalt(idz, bmat, fval - fval(kopt), xpt(:, kopt), xpt, zmat, qalt_better, gopt, pq, hq, galt, pqalt)
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
info = NAN_INF_MODEL
exit
end if

! Update RESCON if XOPT is changed.
! Zaikun 20221115: Shouldn't we do it after DELTA is updated?
Expand Down Expand Up @@ -619,6 +627,10 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
! more accurate in predicting the function value of XOPT + D.
! N.B.: Powell's code does this only if XOPT + D is feasible.
call tryqalt(idz, bmat, fval - fval(kopt), xpt(:, kopt), xpt, zmat, qalt_better, gopt, pq, hq, galt, pqalt)
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
info = NAN_INF_MODEL
exit
end if

! Update RESCON. Zaikun 20221115: Currently, UPDATERES does not update RESCON if XIMPROVED
! is FALSE. Shouldn't we do it whenever DELTA is updated? Have we MISUNDERSTOOD RESCON?
Expand Down Expand Up @@ -665,7 +677,7 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
end do ! End of DO TR = 1, MAXTR. The iterative procedure ends.

! Return from the calculation, after trying the Newton-Raphson step if it has not been tried yet.
if (info == SMALL_TR_RADIUS .and. shortd .and. nf < maxfun) then
if (info == SMALL_TR_RADIUS .and. shortd .and. dnorm >= TENTH * rhoend .and. nf < maxfun) then
x = xbase + (xpt(:, kopt) + d)
call evaluate(calfun, x, f)
nf = nf + 1_IK
Expand Down
2 changes: 1 addition & 1 deletion fortran/lincoa/update.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module update_lincoa_mod
!
! Started: February 2022
!
! Last Modified: Monday, August 07, 2023 AM03:56:25
! Last Modified: Friday, March 15, 2024 PM03:35:14
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down
37 changes: 23 additions & 14 deletions fortran/newuoa/newuob.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module newuob_mod
!
! Started: July 2020
!
! Last Modified: Saturday, March 09, 2024 PM09:23:29
! Last Modified: Friday, March 15, 2024 PM03:38:08
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -56,8 +56,8 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
use, non_intrinsic :: debug_mod, only : assert
use, non_intrinsic :: evaluate_mod, only : evaluate
use, non_intrinsic :: history_mod, only : savehist, rangehist
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf
use, non_intrinsic :: infos_mod, only : INFO_DFT, MAXTR_REACHED, SMALL_TR_RADIUS, CALLBACK_TERMINATE
use, non_intrinsic :: infnan_mod, only : is_nan, is_posinf, is_finite
use, non_intrinsic :: infos_mod, only : INFO_DFT, MAXTR_REACHED, SMALL_TR_RADIUS, CALLBACK_TERMINATE, NAN_INF_MODEL
use, non_intrinsic :: linalg_mod, only : norm
use, non_intrinsic :: message_mod, only : retmsg, rhomsg, fmsg
use, non_intrinsic :: pintrf_mod, only : OBJ, CALLBACK
Expand Down Expand Up @@ -162,6 +162,7 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
call assert(n >= 1 .and. npt >= n + 2, 'N >= 1, NPT >= N + 2', srname)
call assert(maxfun >= npt + 1, 'MAXFUN >= NPT + 1', srname)
call assert(rhobeg >= rhoend .and. rhoend > 0, 'RHOBEG >= RHOEND > 0', srname)
call assert(all(is_finite(x)), 'X is finite', srname)
call assert(eta1 >= 0 .and. eta1 <= eta2 .and. eta2 < 1, '0 <= ETA1 <= ETA2 < 1', srname)
call assert(gamma1 > 0 .and. gamma1 < 1 .and. gamma2 > 1, '0 < GAMMA1 < 1 < GAMMA2', srname)
call assert(maxhist >= 0 .and. maxhist <= maxfun, '0 <= MAXHIST <= MAXFUN', srname)
Expand Down Expand Up @@ -190,6 +191,16 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
x = xbase + xpt(:, kopt)
f = fval(kopt)

! Initialize [BMAT, ZMAT, IDZ], representing the inverse of the KKT matrix of the interpolation system.
call inith(ij, xpt, idz, bmat, zmat)

! Initialize the quadratic represented by [GOPT, HQ, PQ], so that its gradient at XBASE+XOPT is
! GOPT; its Hessian is HQ + sum_{K=1}^NPT PQ(K)*XPT(:, K)*XPT(:, K)'.
call initq(ij, fval, xpt, gopt, hq, pq)
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
subinfo = NAN_INF_MODEL
end if

! Check whether to return due to abnormal cases that may occur during the initialization.
if (subinfo /= INFO_DFT) then
info = subinfo
Expand All @@ -213,16 +224,6 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
return
end if

! Initialize [BMAT, ZMAT, IDZ], representing the inverse of the KKT matrix of the interpolation system.
call inith(ij, xpt, idz, bmat, zmat)

! Initialize the quadratic represented by [GOPT, HQ, PQ], so that its gradient at XBASE+XOPT is
! GOPT; its Hessian is HQ + sum_{K=1}^NPT PQ(K)*XPT(:, K)*XPT(:, K)'.
call initq(ij, fval, xpt, gopt, hq, pq)

! After initializing GOPT, HQ, PQ, BMAT, ZMAT, one can also choose to return if these arrays contain
! NaN. We do not do it here. The code will continue to run and possibly recovers by geometry steps.

! Set some more initial values.
! We must initialize RATIO. Otherwise, when SHORTD = TRUE, compilers may raise a run-time error that
! RATIO is undefined. But its value will not be used: when SHORTD = FALSE, its value will be
Expand Down Expand Up @@ -364,6 +365,10 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
! has been revised after the last function evaluation.
! 5. Powell's code tries Q_alt only when DELTA == RHO.
call tryqalt(idz, bmat, fval - fval(kopt), ratio, xpt(:, kopt), xpt, zmat, itest, gopt, hq, pq)
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
info = NAN_INF_MODEL
exit
end if
end if
end if ! End of IF (SHORTD .OR. TRFAIL). The normal trust-region calculation ends.

Expand Down Expand Up @@ -565,6 +570,10 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
call updateh(knew_geo, kopt, d, xpt, idz, bmat, zmat)
call updatexf(knew_geo, ximproved, f, xosav + d, kopt, fval, xpt)
call updateq(idz, knew_geo, ximproved, bmat, d, moderr, xdrop, xosav, xpt, zmat, gopt, hq, pq)
if (.not. (all(is_finite(gopt)) .and. all(is_finite(hq)) .and. all(is_finite(pq)))) then
info = NAN_INF_MODEL
exit
end if
end if ! End of IF (IMPROVE_GEO). The procedure of improving geometry ends.

! The calculations with the current RHO are complete. Enhance the resolution of the algorithm
Expand Down Expand Up @@ -604,7 +613,7 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
end do ! End of DO TR = 1, MAXTR. The iterative procedure ends.

! Return from the calculation, after trying the Newton-Raphson step if it has not been tried yet.
if (info == SMALL_TR_RADIUS .and. shortd .and. nf < maxfun) then
if (info == SMALL_TR_RADIUS .and. shortd .and. dnorm >= TENTH * rhoend .and. nf < maxfun) then
x = xbase + (xpt(:, kopt) + d)
call evaluate(calfun, x, f)
nf = nf + 1_IK
Expand Down
Loading

0 comments on commit f3149e0

Please sign in to comment.