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.
55 56 57 |
# File 'lib/dnn/core/activations.rb', line 55 def initialize(alpha = 0.3) @alpha = alpha end |
Class Method Details
.load_hash(hash) ⇒ Object
59 60 61 |
# File 'lib/dnn/core/activations.rb', line 59 def self.load_hash(hash) self.new(hash[:alpha]) end |
Instance Method Details
#backward(dout) ⇒ Object
70 71 72 73 74 |
# File 'lib/dnn/core/activations.rb', line 70 def backward(dout) @x[@x > 0] = 1 @x[@x <= 0] = @alpha dout * @x end |
#forward(x) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/dnn/core/activations.rb', line 63 def forward(x) @x = x.clone a = SFloat.ones(x.shape) a[x <= 0] = @alpha x * a end |
#to_hash ⇒ Object
76 77 78 |
# File 'lib/dnn/core/activations.rb', line 76 def to_hash {name: self.class.name, alpha: alpha} end |