apply_piecewise Function

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

Apply piecewise activation to 1D array

Computes piecewise function: f = 0 if x ≤ min f = scale if x ≥ max f = scale * x + intercept otherwise

Type Bound

piecewise_actv_type

Arguments

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

Piecewise activation type

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

Input values

Return Value type(array_type), pointer

Activated output values


Source Code

  function apply_piecewise(this, val) result(output)
    !! Apply piecewise activation to 1D array
    !!
    !! Computes piecewise function:
    !! f = 0 if x ≤ min
    !! f = scale if x ≥ max
    !! f = scale * x + intercept otherwise
    implicit none

    ! Arguments
    class(piecewise_actv_type), intent(in) :: this
    !! Piecewise activation type
    type(array_type), intent(in) :: val
    !! Input values
    type(array_type), pointer :: output
    !! Activated output values

    if(this%apply_scaling)then
       output => piecewise(val, this%gradient, this%limit) * this%scale
    else
       output => piecewise(val, this%gradient, this%limit)
    end if
  end function apply_piecewise