Class: DNN::Activations::LeakyReLU
- Includes:
- Numo
- Defined in:
- lib/dnn/core/activations.rb
Class Method Summary collapse
Instance Method Summary collapse
- #backward(dout) ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(alpha = 0.3) ⇒ LeakyReLU
constructor
A new instance of LeakyReLU.
- #to_hash ⇒ Object
Constructor Details
#initialize(alpha = 0.3) ⇒ LeakyReLU
Returns a new instance of LeakyReLU.
49 50 51 |
# File 'lib/dnn/core/activations.rb', line 49 def initialize(alpha = 0.3) @alpha = alpha end |
Class Method Details
.load_hash(hash) ⇒ Object
53 54 55 |
# File 'lib/dnn/core/activations.rb', line 53 def self.load_hash(hash) self.new(hash[: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 = SFloat.ones(x.shape) a[x <= 0] = @alpha x * a end |
#to_hash ⇒ Object
70 71 72 |
# File 'lib/dnn/core/activations.rb', line 70 def to_hash {name: self.class.name, alpha: alpha} end |