apply_tanh Function

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

Apply tanh activation to 1D array

Applies the hyperbolic tangent function element-wise to input array: f = (exp(x) - exp(-x))/(exp(x) + exp(-x))

Type Bound

tanh_actv_type

Arguments

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

Tanh activation type

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

Input values

Return Value type(array_type), pointer

Activated output values


Source Code

  function apply_tanh(this, val) result(output)
    !! Apply tanh activation to 1D array
    !!
    !! Applies the hyperbolic tangent function element-wise to input array:
    !! f = (exp(x) - exp(-x))/(exp(x) + exp(-x))
    implicit none

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

    if(this%apply_scaling)then
       output => tanh(val) * this%scale
    else
       output => tanh(val)
    end if
  end function apply_tanh