Class: DNN::Activations::LeakyReLU

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

Instance Attribute Summary collapse

Attributes inherited from Layers::Layer

#input_shape, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layers::Layer

#build, #built?, #call, call, #output_shape

Constructor Details

#initialize(alpha = 0.3) ⇒ LeakyReLU

Returns a new instance of LeakyReLU.

Parameters:

  • alpha (Float) (defaults to: 0.3) —

    The slope when the output value is negative.



84
85
86
87
# File 'lib/dnn/core/activations.rb', line 84

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

Instance Attribute Details

#alpha ⇒ Object (readonly)

Returns the value of attribute alpha.



77
78
79
# File 'lib/dnn/core/activations.rb', line 77

def alpha
  @alpha
end

Class Method Details

.from_hash(hash) ⇒ Object



79
80
81
# File 'lib/dnn/core/activations.rb', line 79

def self.from_hash(hash)
  self.new(hash[:alpha])
end

Instance Method Details

#backward(dy) ⇒ Object



96
97
98
99
100
# File 'lib/dnn/core/activations.rb', line 96

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

#forward(x) ⇒ Object



89
90
91
92
93
94
# File 'lib/dnn/core/activations.rb', line 89

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

#to_hash ⇒ Object



102
103
104
# File 'lib/dnn/core/activations.rb', line 102

def to_hash
  super(alpha: @alpha)
end