Skip to content

Implement activation params type #124

Closed
@milancurcic

Description

@milancurcic

Some activation functions like leaky ReLU (#123) require one or more additional parameters.

To allow passing activation functions as procedure pointers, all functions must have the same interface. A proposed general solution (thank @jvdp1) is to:

  1. Define a derived type activation_params or similar that defines any possible extra parameters that may be needed by activation functions; set default values of activation parameters in the type definition.
type :: activation_params
real :: alpha = 0.3
end type activation_params
  1. Make each activation function have a type(activation_params), intent(in) optional :: params dummy argument (instead of the current alpha). Inside activation function definitions, function that use one or more activation parameters access them directly; those that don't simply ignore it.
  pure function leaky_relu(x, params) result(res)
    !! Leaky Rectified Linear Unit (Leaky ReLU) activation function.
    real, intent(in) :: x(:)
    type(activation_params), intent(in), optional :: params
    real :: res(size(x))
    res = max(params % alpha * x, x)
  end function leaky_relu
  1. Make activation_params an attribute of dense and conv2d layers (and later any other layers that activate).
  2. Pass the attributes to the activation procedure associated with the layer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions