athena__actv_layer Module

Module containing implementation of the activation layer

This module wraps various activation functions into a layer type, applying element-wise non-linear transformations to inputs.

Mathematical operation: y = σ(x)

where σ is one of: relu, sigmoid, tanh, softmax, linear, etc.

Properties: - No learnable parameters (fixed non-linearity) - Element-wise operation (preserves shape) - Enables networks to learn non-linear functions - Choice of activation affects gradient flow and convergence


Uses


Interfaces

public interface actv_layer_type

Interface for the activation layer type

  • private module function layer_setup(activation, input_shape, verbose) result(layer)

    Set up the activation layer

    Arguments

    Type IntentOptional Attributes Name
    class(*), intent(in) :: activation

    Activation function

    integer, intent(in), optional, dimension(:) :: input_shape

    Input shape

    integer, intent(in), optional :: verbose

    Verbosity level

    Return Value type(actv_layer_type)

    Instance of the activation layer


Derived Types

type, public, extends(base_layer_type) ::  actv_layer_type

Layer type for activation layers

Components

Type Visibility Attributes Name Initial
class(base_actv_type), public, allocatable :: activation

Activation function

type(graph_type), public, allocatable, dimension(:) :: graph

Graph structure of input data

integer, public :: id

Unique identifier

logical, public :: inference = .false.

Inference mode

integer, public :: input_rank = 0

Rank of input data

integer, public, allocatable, dimension(:) :: input_shape

Input shape

character(len=:), public, allocatable :: name

Layer name

class(array_type), public, allocatable, dimension(:,:) :: output

Output

integer, public :: output_rank = 0

Rank of output data

integer, public, allocatable, dimension(:) :: output_shape

Output shape

character(len=20), public :: subtype = repeat(" ", 20)
character(len=4), public :: type = 'base'

Layer type

logical, public :: use_graph_input = .false.

Use graph input

logical, public :: use_graph_output = .false.

Use graph output

Constructor

Interface for the activation layer type

private module function layer_setup (activation, input_shape, verbose)

Set up the activation layer

Type-Bound Procedures

procedure, public, pass(this) :: build_from_onnx => build_from_onnx_actv

Build activation layer from ONNX node and initialiser

procedure, public, pass(this) :: emit_onnx_graph_inputs => emit_onnx_graph_inputs_base

Emit graph input tensor declarations for this layer

procedure, public, pass(this) :: emit_onnx_nodes => emit_onnx_nodes_base

Emit ONNX JSON nodes for this layer (format-aware and polymorphic)

procedure, public, pass(this) :: extract_output => extract_output_base

Extract the output of the layer as a standard real array

procedure, public, pass(this) :: forward => forward_actv

Forward propagation derived type handler

procedure, public, pass(this) :: forward_eval => forward_eval_base

Forward pass of layer and return output for evaluation

procedure, public, pass(this) :: get_attributes => get_attributes_base

Get the attributes of the layer (for ONNX export)

procedure, public, pass(this) :: get_num_params => get_num_params_base

Get the number of parameters in the layer

procedure, public, pass(this) :: init => init_actv

Initialise layer

procedure, public, pass(this) :: nullify_graph => nullify_graph_base

Nullify the forward pass data of the layer to free memory

Read more…
procedure, public, pass(this) :: print => print_base

Print the layer to a file with additional information

procedure, public, pass(this) :: print_to_unit => print_to_unit_actv

Print layer to unit

procedure, public, pass(this) :: read => read_actv

Read layer from file

procedure, public, pass(this) :: set_graph => set_graph_base

Set the graph structure of the input data !! this is adjacency and edge weighting

procedure, public, pass(this) :: set_hyperparams => set_hyperparams_actv

Set hyperparameters

procedure, public, pass(this) :: set_rank => set_rank_actv

Set the input and output ranks of the layer

procedure, public, pass(this) :: set_shape => set_shape_base

Set the input shape of the layer


Functions

public function create_from_onnx_actv_layer(node, initialisers, value_info, verbose) result(layer)

Build activation layer from attributes and return layer

Arguments

Type IntentOptional Attributes Name
type(onnx_node_type), intent(in) :: node

ONNX node information

type(onnx_initialiser_type), intent(in), dimension(:) :: initialisers

ONNX initialiser information

type(onnx_tensor_type), intent(in), dimension(:) :: value_info

ONNX value info

integer, intent(in), optional :: verbose

Verbosity level

Return Value class(base_layer_type), allocatable

Instance of the activation layer

public function read_actv_layer(unit, verbose) result(layer)

Read activation layer from file

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit

File unit

integer, intent(in), optional :: verbose

Verbosity level

Return Value class(base_layer_type), allocatable

Instance of the activation layer

private module function layer_setup(activation, input_shape, verbose) result(layer)

Set up the activation layer

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: activation

Activation function

integer, intent(in), optional, dimension(:) :: input_shape

Input shape

integer, intent(in), optional :: verbose

Verbosity level

Return Value type(actv_layer_type)

Instance of the activation layer


Subroutines

private subroutine build_from_onnx_actv(this, node, initialisers, value_info, verbose)

Read ONNX attributes for activation layer

Arguments

Type IntentOptional Attributes Name
class(actv_layer_type), intent(inout) :: this

Instance of the activation layer

type(onnx_node_type), intent(in) :: node

ONNX node information

type(onnx_initialiser_type), intent(in), dimension(:) :: initialisers

ONNX initialiser information

type(onnx_tensor_type), intent(in), dimension(:) :: value_info

ONNX value info

integer, intent(in) :: verbose

Verbosity level

private subroutine forward_actv(this, input)

Forward propagation

Arguments

Type IntentOptional Attributes Name
class(actv_layer_type), intent(inout) :: this

Instance of the fully connected layer

class(array_type), intent(in), dimension(:,:) :: input

Input values

private subroutine init_actv(this, input_shape, verbose)

Initialise activation layer

Arguments

Type IntentOptional Attributes Name
class(actv_layer_type), intent(inout) :: this

Instance of the activation layer

integer, intent(in), dimension(:) :: input_shape

Input shape

integer, intent(in), optional :: verbose

Verbosity level

private subroutine print_to_unit_actv(this, unit)

Print activation layer to unit

Arguments

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

Instance of the activation layer

integer, intent(in) :: unit

File unit

private subroutine read_actv(this, unit, verbose)

Read activation layer from file don't look for "e" due to scientific notation of numbers ... i.e. exponent (E+00)

Arguments

Type IntentOptional Attributes Name
class(actv_layer_type), intent(inout) :: this

Instance of the activation layer

integer, intent(in) :: unit

File unit

integer, intent(in), optional :: verbose

Verbosity level

private subroutine set_hyperparams_actv(this, activation, input_rank, verbose)

Set hyperparameters for activation layer

Arguments

Type IntentOptional Attributes Name
class(actv_layer_type), intent(inout) :: this

Instance of the activation layer

class(base_actv_type), intent(in), allocatable :: activation

Activation function

integer, intent(in), optional :: input_rank

Input rank

integer, intent(in), optional :: verbose

Verbosity level

private subroutine set_rank_actv(this, input_rank, output_rank)

Set the input and output ranks of the activation layer

Arguments

Type IntentOptional Attributes Name
class(actv_layer_type), intent(inout) :: this

Instance of the activation layer

integer, intent(in) :: input_rank

Input rank

integer, intent(in) :: output_rank

Output rank