regularise_l1l2 Subroutine

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

Regularise the parameters using L1 and L2 regularisation

Type Bound

l1l2_regulariser_type

Arguments

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

Instance of the L1 and 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_l1l2(this, params, gradient, learning_rate)
    !! Regularise the parameters using L1 and L2 regularisation
    implicit none

    ! Arguments
    class(l1l2_regulariser_type), intent(in) :: this
    !! Instance of the L1 and 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 * &
         (this%l1 * sign(1._real32,params) + 2._real32 * this%l2 * params)

  end subroutine regularise_l1l2