ReLU function --activation function

Let's write the ReLU function in Perl. The ReLU function is one of the activation functions.

The ReLU function is a function that returns a value if it is greater than 0 and 0 if it is less than or equal to 0.

use strict;
use warnings;

#ReLU function
sub relu {
  my ($x) = @_;
  
  my $relu = $x * ($x> 0.0);
  
  return $relu;
}

my $value1 = 0.7;
my $relu1 = relu ($value1);

print "$relu1\n";

my $value2 = -0.4;
my $relu2 = relu ($value2);

print "$relu2\n";

The ReLU function is known as an activation function with simple logic, low complexity, and high effectiveness.

The ReLU function is used as an activation function in the hidden layer, but it can also be used to create output in the output layer.

Derivative of ReLU function

Please refer to the following for the derivative of the ReLU function.

Associated Information