Class: DNN::Activations::LeakyReLU

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

Instance Method Summary collapse

Constructor Details

#initialize(alpha = 0.3) ⇒ LeakyReLU

Returns a new instance of LeakyReLU.



53
54
55
# File 'lib/dnn/core/activations.rb', line 53

def initialize(alpha = 0.3)
  @alpha = alpha
end

Instance Method Details

#backward(dout) ⇒ Object



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

def backward(dout)
  @x[@x > 0] = 1
  @x[@x <= 0] = @alpha
  dout * @x
end

#forward(x) ⇒ Object



57
58
59
60
61
62
# File 'lib/dnn/core/activations.rb', line 57

def forward(x)
  @x = x.clone
  a = Numo::SFloat.ones(x.shape)
  a[x <= 0] = @alpha
  x * a
end