check_jac_fp Subroutine

public subroutine check_jac_fp(fcn, n, m, np, q, beta, xplusd, ifixb, ifixx, ldifx, eta, tol, nrow, j, lq, iswrtb, fd, typj, pvpstp, stp0, curve, pv, d, diffj, msg, istop, nfev, wrk1, wrk2, wrk6)

Uses

  • proc~~check_jac_fp~~UsesGraph proc~check_jac_fp check_jac_fp module~odrpack_kinds odrpack_kinds proc~check_jac_fp->module~odrpack_kinds iso_fortran_env iso_fortran_env module~odrpack_kinds->iso_fortran_env

Check whether finite precision arithmetic could be the cause of the disagreement between the derivatives.

Arguments

Type IntentOptional Attributes Name
procedure(fcn_t) :: fcn

User supplied subroutine for evaluating the model.

integer, intent(in) :: n

Number of observations.

integer, intent(in) :: m

Number of columns of data in the explanatory variable.

integer, intent(in) :: np

Number of function parameters.

integer, intent(in) :: q

Number of responses per observation.

real(kind=wp), intent(inout) :: beta(np)

Function parameters.

real(kind=wp), intent(inout) :: xplusd(n,m)

Values of x + delta.

integer, intent(in) :: ifixb(np)

Values designating whether the elements of beta are fixed at their input values or not.

integer, intent(in) :: ifixx(ldifx,m)

Values designating whether the elements of x are fixed at their input values or not.

integer, intent(in) :: ldifx

Leading dimension of array ifixx.

real(kind=wp), intent(in) :: eta

Relative noise in the model.

real(kind=wp), intent(in) :: tol

Agreement tolerance.

integer, intent(in) :: nrow

Row number of the explanatory variable array at which the derivative is to be checked.

integer, intent(in) :: j

Index of the partial derivative being examined.

integer, intent(in) :: lq

Response currently being examined.

logical, intent(in) :: iswrtb

Variable designating whether the derivatives wrt beta (iswrtb = .true.) or delta (iswrtb = .false.) are being checked.

real(kind=wp), intent(out) :: fd

Forward difference derivative wrt the j-th parameter.

real(kind=wp), intent(in) :: typj

Typical size of the j-th unknown beta or delta.

real(kind=wp), intent(out) :: pvpstp

Predicted value for row nrow of the model based on the current parameter estimates for all but the j-th parameter value, which is beta(j) + stp0.

real(kind=wp), intent(in) :: stp0

Step size for the finite difference derivative.

real(kind=wp), intent(inout) :: curve

A measure of the curvature in the model.

real(kind=wp), intent(in) :: pv

Predicted value for row nrow.

real(kind=wp), intent(in) :: d

Derivative with respect to the j-th unknown parameter.

real(kind=wp), intent(out) :: diffj

Relative differences between the user supplied and finite difference derivatives for the derivative being checked.

integer, intent(out) :: msg(q,j)

Error checking results.

integer, intent(out) :: istop

Variable designating whether there are problems computing the function at the current beta and delta.

integer, intent(inout) :: nfev

Number of function evaluations.

real(kind=wp), intent(out) :: wrk1(n,m,q)

A work array of (n, m, q) elements.

real(kind=wp), intent(out) :: wrk2(n,q)

A work array of (n, q) elements.

real(kind=wp), intent(out) :: wrk6(n,np,q)

A work array of (n, np, q) elements.


Calls

proc~~check_jac_fp~~CallsGraph proc~check_jac_fp check_jac_fp proc~fpvb fpvb proc~check_jac_fp->proc~fpvb proc~fpvd fpvd proc~check_jac_fp->proc~fpvd

Called by

proc~~check_jac_fp~~CalledByGraph proc~check_jac_fp check_jac_fp proc~check_jac_curv check_jac_curv proc~check_jac_curv->proc~check_jac_fp proc~check_jac_value check_jac_value proc~check_jac_value->proc~check_jac_curv proc~check_jac check_jac proc~check_jac->proc~check_jac_value proc~odr odr proc~odr->proc~check_jac proc~odr_long_c odr_long_c proc~odr_long_c->proc~odr proc~odr_medium_c odr_medium_c proc~odr_medium_c->proc~odr proc~odr_short_c odr_short_c proc~odr_short_c->proc~odr program~example1 example1 program~example1->proc~odr program~example2 example2 program~example2->proc~odr program~example3 example3 program~example3->proc~odr program~example4 example4 program~example4->proc~odr program~example5 example5 program~example5->proc~odr

Variables

Type Visibility Attributes Name Initial
real(kind=wp), public, parameter :: p1 = 0.1_wp
real(kind=wp), public :: stp
logical, public :: large

Source Code

   subroutine check_jac_fp &
      (fcn, &
       n, m, np, q, &
       beta, xplusd, ifixb, ifixx, ldifx, &
       eta, tol, nrow, j, lq, iswrtb, &
       fd, typj, pvpstp, stp0, curve, pv, d, &
       diffj, msg, istop, nfev, &
       wrk1, wrk2, wrk6)
   !! Check whether finite precision arithmetic could be the cause of the disagreement between
   !! the derivatives.
      ! Adapted from STARPAC subroutine DCKFPA.

      use odrpack_kinds, only: one, two, hundred

      procedure(fcn_t) :: fcn
         !! User supplied subroutine for evaluating the model.
      integer, intent(in) :: n
         !! Number of observations.
      integer, intent(in) :: m
         !! Number of columns of data in the explanatory variable.
      integer, intent(in) :: np
         !! Number of function parameters.
      integer, intent(in) :: q
         !! Number of responses per observation.
      real(wp), intent(inout) :: beta(np)
         !! Function parameters.
      real(wp), intent(inout) :: xplusd(n, m)
         !! Values of `x + delta`.
      integer, intent(in) :: ifixb(np)
         !! Values designating whether the elements of `beta` are fixed at their input values or not.
      integer, intent(in) :: ifixx(ldifx, m)
         !! Values designating whether the elements of `x` are fixed at their input values or not.
      integer, intent(in) :: ldifx
         !! Leading dimension of array `ifixx`.
      real(wp), intent(in) :: eta
         !! Relative noise in the model.
      real(wp), intent(in) :: tol
         !! Agreement tolerance.
      integer, intent(in) :: nrow
         !! Row number of the explanatory variable array at which the derivative is to be checked.
      integer, intent(in) :: j
         !! Index of the partial derivative being examined.
      integer, intent(in) :: lq
         !! Response currently being examined.
      logical, intent(in) :: iswrtb
         !! Variable designating whether the derivatives wrt `beta` (`iswrtb = .true.`)
         !! or `delta` (`iswrtb = .false.`) are being checked.
      real(wp), intent(out) :: fd
         !! Forward difference derivative wrt the `j`-th parameter.
      real(wp), intent(in) :: typj
         !! Typical size of the `j`-th unknown `beta` or `delta`.
      real(wp), intent(out) :: pvpstp
         !! Predicted value for row `nrow` of the model based on the current parameter
         !! estimates for all but the `j`-th parameter value, which is `beta(j) + stp0`.
      real(wp), intent(in) :: stp0
         !! Step size for the finite difference derivative.
      real(wp), intent(inout) :: curve
         !! A measure of the curvature in the model.
      real(wp), intent(in) :: pv
         !! Predicted value for row `nrow`.
      real(wp), intent(in) :: d
         !! Derivative with respect to the `j`-th unknown parameter.
      real(wp), intent(out) :: diffj
         !! Relative differences between the user supplied and finite difference derivatives
         !! for the derivative being checked.
      integer, intent(out) :: msg(q, j)
         !! Error checking results.
      integer, intent(out) :: istop
         !! Variable designating whether there are problems computing the function at the
         !! current `beta` and `delta`.
      integer, intent(inout) :: nfev
         !! Number of function evaluations.
      real(wp), intent(out) :: wrk1(n, m, q)
         !! A work array of `(n, m, q)` elements.
      real(wp), intent(out) :: wrk2(n, q)
         !! A work array of `(n, q)` elements.
      real(wp), intent(out) :: wrk6(n, np, q)
         !! A work array of `(n, np, q)` elements.

      ! Local scalars
      real(wp), parameter :: p1 = 0.1_wp
      real(wp) :: stp
      logical :: large

      ! Variable Definitions (alphabetically)
      !  LARGE:   The value designating whether the recommended increase in the step size would
      !           be greater than TYPJ.
      !  STP:     A step size for the finite difference derivative.

      ! Finite precision arithmetic could be the problem.
      ! Try a larger step size based on estimate of condition error.
      stp = eta*(abs(pv) + abs(pvpstp))/(tol*abs(d))
      if (stp > abs(p1*stp0)) then
         stp = max(stp, hundred*abs(stp0))
      end if
      if (stp > typj) then
         stp = typj
         large = .true.
      else
         large = .false.
      end if

      if (iswrtb) then
         ! Perform computations for derivatives wrt BETA
         stp = (stp*sign(one, beta(j)) + beta(j)) - beta(j)
         call fpvb(fcn, &
                   n, m, np, q, &
                   beta, xplusd, ifixb, ifixx, ldifx, &
                   nrow, j, lq, stp, &
                   istop, nfev, pvpstp, &
                   wrk1, wrk2, wrk6)
      else
         ! Perform computations for derivatives wrt DELTA
         stp = (stp*sign(one, xplusd(nrow, j)) + xplusd(nrow, j)) - xplusd(nrow, j)
         call fpvd(fcn, &
                   n, m, np, q, &
                   beta, xplusd, ifixb, ifixx, ldifx, &
                   nrow, j, lq, stp, &
                   istop, nfev, pvpstp, &
                   wrk1, wrk2, wrk6)
      end if
      if (istop /= 0) then
         return
      end if

      fd = (pvpstp - pv)/stp
      diffj = min(diffj, abs(fd - d)/abs(d))

      ! Check for agreement
      if ((abs(fd - d)) <= tol*abs(d)) then
         ! Forward difference quotient and analytic derivatives agree.
         msg(lq, j) = 0

      elseif ((abs(fd - d) <= abs(two*curve*stp)) .or. large) then
         ! Curvature may be the culprit (fudge factor = 2)
         if (large) then
            msg(lq, j) = 4
         else
            msg(lq, j) = 5
         end if
      end if

   end subroutine check_jac_fp