Class: DNN::Activations::ELU
Instance Attribute Summary collapse
#input_shape, #name
Class Method Summary
collapse
Instance Method Summary
collapse
#build, #built?, #call, call, #output_shape
Constructor Details
#initialize(alpha = 1.0) ⇒ ELU
Returns a new instance of ELU.
116
117
118
119
|
# File 'lib/dnn/core/activations.rb', line 116
def initialize(alpha = 1.0)
super()
@alpha = alpha
end
|
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
109
110
111
|
# File 'lib/dnn/core/activations.rb', line 109
def alpha
@alpha
end
|
Class Method Details
.from_hash(hash) ⇒ Object
111
112
113
|
# File 'lib/dnn/core/activations.rb', line 111
def self.from_hash(hash)
self.new(hash[:alpha])
end
|
Instance Method Details
#backward(dy) ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'lib/dnn/core/activations.rb', line 132
def backward(dy)
dx = Xumo::SFloat.ones(@x.shape)
dx[@x < 0] = 0
dx2 = Xumo::SFloat.zeros(@x.shape)
dx2[@x < 0] = 1
dx2 *= @alpha * Xumo::NMath.exp(@x)
dy * (dx + dx2)
end
|
#forward(x) ⇒ Object
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/dnn/core/activations.rb', line 121
def forward(x)
@x = x
x1 = Xumo::SFloat.zeros(x.shape)
x1[x >= 0] = 1
x1 *= x
x2 = Xumo::SFloat.zeros(x.shape)
x2[x < 0] = 1
x2 *= @alpha * Xumo::NMath.exp(x) - @alpha
x1 + x2
end
|
#to_hash ⇒ Object
141
142
143
|
# File 'lib/dnn/core/activations.rb', line 141
def to_hash
super(alpha: @alpha)
end
|