Class: DNN::Activations::LeakyReLU

Inherits:
Layers::Layer show all
Defined in:
lib/dnn/core/activations.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layers::Layer

#build, #built?, #prev_layer, #shape

Constructor Details

#initialize(alpha = 0.3) ⇒ LeakyReLU

Returns a new instance of LeakyReLU.



88
89
90
# File 'lib/dnn/core/activations.rb', line 88

def initialize(alpha = 0.3)
  @alpha = alpha
end

Instance Attribute Details

#alphaObject (readonly)

Returns the value of attribute alpha.



86
87
88
# File 'lib/dnn/core/activations.rb', line 86

def alpha
  @alpha
end

Class Method Details

.load_hash(hash) ⇒ Object



92
93
94
# File 'lib/dnn/core/activations.rb', line 92

def self.load_hash(hash)
  self.new(hash[:alpha])
end

Instance Method Details

#backward(dout) ⇒ Object



103
104
105
106
107
# File 'lib/dnn/core/activations.rb', line 103

def backward(dout)
  @x[@x > 0] = 1
  @x[@x <= 0] = @alpha
  dout * @x
end

#forward(x) ⇒ Object



96
97
98
99
100
101
# File 'lib/dnn/core/activations.rb', line 96

def forward(x)
  @x = x.clone
  a = Xumo::SFloat.ones(x.shape)
  a[x <= 0] = @alpha
  x * a
end

#to_hashObject



109
110
111
# File 'lib/dnn/core/activations.rb', line 109

def to_hash
  {class: self.class.name, alpha: alpha}
end