unit ureluprelu;

{$mode delphi}

interface

uses
  Classes, SysUtils, xmatdefs;


// Rectified Linear Unit(ReLU) Activation Function
// result = max( 0, x )
function ReLu(x: NReal): Nreal;

// Derivada de relu = ( x > 0 )
function dev_ReLu(x: NReal): NReal;

// result = max( 0, x ) + beta min( 0, x )
function PReLu( x, beta: NReal ): NReal;

// result = 1 si x > 0 y beta si x < 0
function def_PReLu( x, beta: NReal ): NReal;


implementation

// Rectified Linear Unit(ReLU) Activation Function
// result = max( 0, x )
function relu(x: NReal): Nreal;
begin
  if x > 0 then
    Result := x
  else
    Result := 0;
end;

// Derivada de relu = ( x > 0 )
function dev_relu(x: NReal): NReal;
begin
  if x > 0 then
    Result := 1
  else
    Result := 0;
end;



// result = max( 0, x ) + beta min( 0, x )
function PReLu( x, beta: NReal ): NReal;
begin
  if x >= 0 then
    result:= x
  else
    result:= beta*x;
end;

// result = 1 si x > 0 y beta si x < 0
function def_PReLu( x, beta: NReal ): NReal;
begin
  if x >= 0 then
    result:= 1
  else
    result:= beta;
end;

end.
