minimise_sgd Subroutine

private pure subroutine minimise_sgd(this, param, gradient)

Apply gradients to parameters to minimise loss using SGD optimiser Adaptive learning method

Type Bound

sgd_optimiser_type

Arguments

Type IntentOptional Attributes Name
class(sgd_optimiser_type), intent(inout) :: this

Instance of the SGD optimiser

real(kind=real32), intent(inout), dimension(:) :: param

Parameters

real(kind=real32), intent(inout), dimension(:) :: gradient

Gradients


Source Code

  pure subroutine minimise_sgd(this, param, gradient)
    !! Apply gradients to parameters to minimise loss using SGD optimiser
    implicit none

    ! Arguments
    class(sgd_optimiser_type), intent(inout) :: this
    !! Instance of the SGD optimiser
    real(real32), dimension(:), intent(inout) :: param
    !! Parameters
    real(real32), dimension(:), intent(inout) :: gradient
    !! Gradients

    ! Local variables
    real(real32) :: learning_rate
    !! Learning rate


    ! Decay learning rate and update iteration
    learning_rate = this%lr_decay%get_lr(this%learning_rate, this%iter)

    ! Apply regularisation
    if(this%regularisation) &
         call this%regulariser%regularise( param, gradient, learning_rate )

    gradient = - learning_rate * gradient
    ! Update parameters
    if(this%momentum.gt.1.E-8_real32)then
       !! Adaptive learning method
       this%velocity = this%momentum * this%velocity + gradient
       if(this%nesterov)then
          param = param + this%momentum * this%velocity + gradient
       else
          param = param + this%velocity
       end if
    else
       ! Standard learning method
       this%velocity = gradient
       param = param + this%velocity
    end if
  end subroutine minimise_sgd