Class: DNN::Activations::ReLU

Inherits:
Layers::Layer show all
Defined in:
lib/dnn/core/activations.rb

Instance Attribute Summary

Attributes inherited from Layers::Layer

#input_shape, #name

Instance Method Summary collapse

Methods inherited from Layers::Layer

#build, #built?, #call, call, #initialize, #output_shape, #to_hash

Constructor Details

This class inherits a constructor from DNN::Layers::Layer

Instance Method Details

#backward(dy) ⇒ Object



68
69
70
71
72
# File 'lib/dnn/core/activations.rb', line 68

def backward(dy)
  dx = Xumo::SFloat.ones(@x.shape)
  dx[@x <= 0] = 0
  dy * dx
end

#forward(x) ⇒ Object



63
64
65
66
# File 'lib/dnn/core/activations.rb', line 63

def forward(x)
  @x = x
  Xumo::SFloat.maximum(0, x)
end