regularise_l2 Subroutine

private pure subroutine regularise_l2(this, params, gradient, learning_rate)

Regularise the parameters using L2 regularisation

Type Bound

l2_regulariser_type

Arguments

Type IntentOptional Attributes Name
class(l2_regulariser_type), intent(in) :: this

Instance of the L2 regulariser

real(kind=real32), intent(in), dimension(:) :: params

Parameters to regularise

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

Gradient of the parameters

real(kind=real32), intent(in) :: learning_rate

Learning rate


Source Code

  pure subroutine regularise_l2(this, params, gradient, learning_rate)
    !! Regularise the parameters using L2 regularisation
    implicit none

    ! Arguments
    class(l2_regulariser_type), intent(in) :: this
    !! Instance of the L2 regulariser
    real(real32), dimension(:),  intent(in) :: params
    !! Parameters to regularise
    real(real32), dimension(:), intent(inout) :: gradient
    !! Gradient of the parameters
    real(real32), intent(in) :: learning_rate
    !! Learning rate

    gradient = gradient + learning_rate * 2._real32 * this%l2 * params

  end subroutine regularise_l2