apply_softmax Function

private function apply_softmax(this, val) result(output)

Apply softmax activation to 1D array

Computes: f = exp(x-max)/sum(exp(x-max))

Type Bound

softmax_actv_type

Arguments

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

Softmax activation type

type(array_type), intent(in) :: val

Input values

Return Value type(array_type), pointer

Normalised probability distribution output

compute softmax values


Source Code

  function apply_softmax(this, val) result(output)
    !! Apply softmax activation to 1D array
    !!
    !! Computes: f = exp(x-max)/sum(exp(x-max))
    implicit none

    ! Arguments
    class(softmax_actv_type), intent(in) :: this
    !! Softmax activation type
    type(array_type), intent(in) :: val
    !! Input values
    type(array_type), pointer :: output
    !! Normalised probability distribution output

    !! compute softmax values
    if(this%apply_scaling)then
       output => softmax(val, dim=2) * this%scale
    else
       output => softmax(val, dim=2)
    end if
  end function apply_softmax