class DNN::Layers::ELU
Attributes
alpha[R]
Public Class Methods
new(alpha = 1.0)
click to toggle source
@param [Float] alpha The slope when the output value is negative.
Calls superclass method
# File lib/dnn/core/layers/activations.rb, line 119 def initialize(alpha = 1.0) super() @alpha = alpha end
Public Instance Methods
backward_node(dy)
click to toggle source
# File lib/dnn/core/layers/activations.rb, line 135 def backward_node(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_node(x)
click to toggle source
# File lib/dnn/core/layers/activations.rb, line 124 def forward_node(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
load_hash(hash)
click to toggle source
# File lib/dnn/core/layers/activations.rb, line 148 def load_hash(hash) initialize(hash[:alpha]) end
to_hash()
click to toggle source
Calls superclass method
# File lib/dnn/core/layers/activations.rb, line 144 def to_hash super(alpha: @alpha) end