Class: DNN::Layers::LeakyReLU
- Inherits:
-
Layer
- Object
- Layer
- DNN::Layers::LeakyReLU
show all
- Defined in:
- lib/dnn/core/activations.rb
Instance Attribute Summary collapse
Attributes inherited from Layer
#input_shape, #name
Instance Method Summary
collapse
Methods inherited from Layer
#build, #built?, #call, call, from_hash, #output_shape
Constructor Details
#initialize(alpha = 0.3) ⇒ LeakyReLU
Returns a new instance of LeakyReLU.
72
73
74
75
|
# File 'lib/dnn/core/activations.rb', line 72
def initialize(alpha = 0.3)
super()
@alpha = alpha
end
|
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
69
70
71
|
# File 'lib/dnn/core/activations.rb', line 69
def alpha
@alpha
end
|
Instance Method Details
#backward(dy) ⇒ Object
84
85
86
87
88
|
# File 'lib/dnn/core/activations.rb', line 84
def backward(dy)
dx = Xumo::SFloat.ones(@x.shape)
dx[@x <= 0] = @alpha
dy * dx
end
|
#forward(x) ⇒ Object
77
78
79
80
81
82
|
# File 'lib/dnn/core/activations.rb', line 77
def forward(x)
@x = x
a = Xumo::SFloat.ones(x.shape)
a[x <= 0] = @alpha
x * a
end
|
#load_hash(hash) ⇒ Object
94
95
96
|
# File 'lib/dnn/core/activations.rb', line 94
def load_hash(hash)
initialize(hash[:alpha])
end
|
#to_hash ⇒ Object
90
91
92
|
# File 'lib/dnn/core/activations.rb', line 90
def to_hash
super(alpha: @alpha)
end
|