Class: DNN::Activations::LeakyReLU
- Includes:
- Numo
- Defined in:
- lib/dnn/core/activations.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
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.
51 52 53 |
# File 'lib/dnn/core/activations.rb', line 51 def initialize(alpha = 0.3) @alpha = alpha end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
49 50 51 |
# File 'lib/dnn/core/activations.rb', line 49 def alpha @alpha end |
Class Method Details
.load_hash(hash) ⇒ Object
55 56 57 |
# File 'lib/dnn/core/activations.rb', line 55 def self.load_hash(hash) self.new(hash[:alpha]) end |
Instance Method Details
#backward(dout) ⇒ Object
66 67 68 69 70 |
# File 'lib/dnn/core/activations.rb', line 66 def backward(dout) @x[@x > 0] = 1 @x[@x <= 0] = @alpha dout * @x end |
#forward(x) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/dnn/core/activations.rb', line 59 def forward(x) @x = x.clone a = SFloat.ones(x.shape) a[x <= 0] = @alpha x * a end |
#to_hash ⇒ Object
72 73 74 |
# File 'lib/dnn/core/activations.rb', line 72 def to_hash {name: self.class.name, alpha: alpha} end |