Skip to content

Commit

Permalink
231021.202651.HKT fortran: lincoa: update dnorm_rec and `accrate_mo…
Browse files Browse the repository at this point in the history
…d`; update comments regarding `dnorm/moderr_rec`
  • Loading branch information
zaikunzhang committed Oct 21, 2023
1 parent eacc71d commit 26f0226
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .development
12 changes: 6 additions & 6 deletions fortran/bobyqa/bobyqb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm

! When D is short, make a choice between reducing RHO and improving the geometry depending
! on whether or not our work with the current RHO seems complete. RHO is reduced if the
! errors in the quadratic model at the last three interpolation points compare favourably
! errors in the quadratic model at the recent interpolation points compare favourably
! with predictions of likely improvements to the model within distance HALF*RHO of XOPT.
! Why do we reduce RHO when SHORTD is true and the entries of MODERR_REC and DNORM_REC are all
! small? The reason is well explained by the BOBYQA paper in the paragraphs surrounding
Expand Down Expand Up @@ -326,10 +326,10 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
end if

! Update DNORM_REC and MODERR_REC.
! DNORM_REC records the DNORM of the latest 3 function evaluations with the current RHO.
! DNORM_REC records the DNORM of the recent function evaluations with the current RHO.
dnorm_rec = [dnorm_rec(2:size(dnorm_rec)), dnorm]
! MODERR is the error of the current model in predicting the change in F due to D.
! MODERR_REC records the prediction errors of the latest 3 models with the current RHO.
! MODERR_REC records the prediction errors of the recent models with the current RHO.
moderr = f - fval(kopt) + qred
moderr_rec = [moderr_rec(2:size(moderr_rec)), moderr]

Expand Down Expand Up @@ -518,13 +518,13 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
end if

! Update DNORM_REC and MODERR_REC.
! DNORM_REC records the DNORM of the latest 3 function evaluations with the current RHO.
! DNORM_REC records the DNORM of the recent function evaluations with the current RHO.
! Powell's code does not update DNORM. Therefore, DNORM is the length of the last
! trust-region trial step, inconsistent with MODERR_REC. The same problem exists in NEWUOA.
dnorm = min(delbar, norm(d))
dnorm_rec = [dnorm_rec(2:size(dnorm_rec)), dnorm]
! MODERR is the error of the current model in predicting the change in F due to D.
! MODERR_REC records the prediction errors of the latest 3 models with the current RHO.
! MODERR_REC records the prediction errors of the recent models with the current RHO.
moderr = f - fval(kopt) - quadinc(d, xpt, gopt, pq, hq) ! QRED = Q(XOPT) - Q(XOPT + D)
moderr_rec = [moderr_rec(2:size(moderr_rec)), moderr]

Expand Down Expand Up @@ -552,7 +552,7 @@ subroutine bobyqb(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
rho = redrho(rho, rhoend)
! Print a message about the reduction of RHO according to IPRINT.
call rhomsg(solver, iprint, nf, delta, fval(kopt), rho, xbase + xpt(:, kopt))
! DNORM_REC and MODERR_REC are corresponding to the latest 3 function evaluations with
! DNORM_REC and MODERR_REC are corresponding to the recent function evaluations with
! the current RHO. Update them after reducing RHO.
dnorm_rec = REALMAX
moderr_rec = REALMAX
Expand Down
12 changes: 6 additions & 6 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: Tuesday, October 17, 2023 PM02:52:22
! Last Modified: Saturday, October 21, 2023 PM08:06:39
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -182,7 +182,7 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
real(RP) :: delta
real(RP) :: distsq(npt)
real(RP) :: dnorm
real(RP) :: dnorm_rec(4) ! Powell's implementation uses 5
real(RP) :: dnorm_rec(3) ! Powell's implementation: DNORM_REC(5)
real(RP) :: ffilt(maxfilt)
real(RP) :: fval(npt)
real(RP) :: galt(size(x))
Expand Down Expand Up @@ -368,9 +368,9 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
! !SHORTD = (DNORM < HALF * RHO)
!------------------------------------------------------------------------------------------!

! DNORM_REC records the DNORM of last few (five) trust-region iterations. It will be used to
! decide whether we should improve the geometry of the interpolation set or reduce RHO when
! SHORTD is TRUE. Note that it does not record the geometry steps.
! DNORM_REC records the DNORM of recent trust-region iterations. It will be used to decide
! whether we should improve the geometry of the interpolation set or reduce RHO when SHORTD
! is TRUE. Note that it does not record the geometry steps.
dnorm_rec = [dnorm_rec(2:size(dnorm_rec)), dnorm]

! In some cases, we reset DNORM_REC to REALMAX. This indicates a preference of improving the
Expand Down Expand Up @@ -485,7 +485,7 @@ subroutine lincob(calfun, iprint, maxfilt, maxfun, npt, Aeq, Aineq, amat, beq, b
! verify a curvature condition that really indicates that recent models are sufficiently
! accurate. Here, however, we are not really sure whether they are accurate or not. Therefore,
! ACCURATE_MOD is not the best name, but we keep it to align with the other solvers.
accurate_mod = all(dnorm_rec <= HALF * rho) .or. all(dnorm_rec(3:size(dnorm_rec)) <= 0.2 * rho)
accurate_mod = all(dnorm_rec <= rho) .or. all(dnorm_rec(2:size(dnorm_rec)) <= 0.2 * rho)
! Powell's version (note that size(dnorm_rec) = 5 in his implementation):
!accurate_mod = all(dnorm_rec <= HALF * rho) .or. all(dnorm_rec(3:size(dnorm_rec)) <= TENTH * rho)
! CLOSE_ITPSET: Are the interpolation points close to XOPT?
Expand Down
10 changes: 5 additions & 5 deletions fortran/newuoa/newuob.f90
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
end if

! Update DNORM_REC and MODERR_REC.
! DNORM_REC records the DNORM of the latest 3 function evaluations with the current RHO.
! DNORM_REC records the DNORM of the recent function evaluations with the current RHO.
dnorm_rec = [dnorm_rec(2:size(dnorm_rec)), dnorm]
! MODERR is the error of the current model in predicting the change in F due to D.
! MODERR_REC records the prediction errors of the latest 3 models with the current RHO.
! MODERR_REC records the prediction errors of the recent models with the current RHO.
moderr = f - fval(kopt) + qred
moderr_rec = [moderr_rec(2:size(moderr_rec)), moderr]

Expand Down Expand Up @@ -523,12 +523,12 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
end if

! Update DNORM_REC and MODERR_REC. (Should we?)
! DNORM_REC contains the DNORM of the latest 3 function evaluations with the current RHO.
! DNORM_REC contains the DNORM of the recent function evaluations with the current RHO.
dnorm = min(delbar, norm(d)) ! In theory, DNORM = DELBAR in this case.
dnorm_rec = [dnorm_rec(2:size(dnorm_rec)), dnorm]

! MODERR is the error of the current model in predicting the change in F due to D.
! MODERR_REC is the prediction errors of the latest 3 models with the current RHO.
! MODERR_REC is the prediction errors of the recent models with the current RHO.
moderr = f - fval(kopt) - quadinc(d, xpt, gopt, pq, hq)
moderr_rec = [moderr_rec(2:size(moderr_rec)), moderr]
!------------------------------------------------------------------------------------------!
Expand Down Expand Up @@ -561,7 +561,7 @@ subroutine newuob(calfun, iprint, maxfun, npt, eta1, eta2, ftarget, gamma1, gamm
rho = redrho(rho, rhoend)
! Print a message about the reduction of RHO according to IPRINT.
call rhomsg(solver, iprint, nf, delta, fval(kopt), rho, xbase + xpt(:, kopt))
! DNORM_REC and MODERR_REC are corresponding to the latest 3 function evaluations with
! DNORM_REC and MODERR_REC are corresponding to the recent function evaluations with
! the current RHO. Update them after reducing RHO.
dnorm_rec = REALMAX
moderr_rec = REALMAX
Expand Down
10 changes: 5 additions & 5 deletions fortran/uobyqa/uobyqb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ subroutine uobyqb(calfun, iprint, maxfun, eta1, eta2, ftarget, gamma1, gamma2, r
end if

! Update DNORM_REC and MODERR_REC.
! DNORM_REC records the DNORM of the latest 3 function evaluations with the current RHO.
! DNORM_REC records the DNORM of the recent function evaluations with the current RHO.
dnorm_rec = [dnorm_rec(2:size(dnorm_rec)), dnorm]
! MODERR is the error of the current model in predicting the change in F due to D.
! MODERR_REC records the prediction errors of the latest 3 models with the current RHO.
! MODERR_REC records the prediction errors of the recent models with the current RHO.
moderr = f - fval(kopt) + qred
moderr_rec = [moderr_rec(2:size(moderr_rec)), moderr]

Expand Down Expand Up @@ -423,11 +423,11 @@ subroutine uobyqb(calfun, iprint, maxfun, eta1, eta2, ftarget, gamma1, gamma2, r
end if

! Update DNORM_REC and MODERR_REC.
! DNORM_REC records the DNORM of the latest 3 function evaluations with the current RHO.
! DNORM_REC records the DNORM of the recent function evaluations with the current RHO.
dnorm = min(delbar, norm(d)) ! In theory, DNORM = DELBAR in this case.
dnorm_rec = [dnorm_rec(2:size(dnorm_rec)), dnorm]
! MODERR is the error of the current model in predicting the change in F due to D.
! MODERR_REC records the prediction errors of the latest 3 models with the current RHO.
! MODERR_REC records the prediction errors of the recent models with the current RHO.
moderr = f - fval(kopt) - quadinc(pq, d, xpt(:, kopt)) ! QUADINC = Q(XOPT + D) - Q(XOPT)
moderr_rec = [moderr_rec(2:size(moderr_rec)), moderr]

Expand All @@ -446,7 +446,7 @@ subroutine uobyqb(calfun, iprint, maxfun, eta1, eta2, ftarget, gamma1, gamma2, r
rho = redrho(rho, rhoend)
! Print a message about the reduction of RHO according to IPRINT.
call rhomsg(solver, iprint, nf, delta, fval(kopt), rho, xbase + xpt(:, kopt))
! DNORM_REC and MODERR_REC are corresponding to the latest 3 function evaluations with
! DNORM_REC and MODERR_REC are corresponding to the recent function evaluations with
! the current RHO. Update them after reducing RHO.
dnorm_rec = REALMAX
moderr_rec = REALMAX
Expand Down

0 comments on commit 26f0226

Please sign in to comment.