Class: DNN::Activations::LeakyReLU

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(alpha = 0.3) ⇒ LeakyReLU

Returns a new instance of LeakyReLU.



45
46
47
# File 'lib/dnn/core/activations.rb', line 45

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

Instance Attribute Details

#alpha ⇒ Object (readonly)

Returns the value of attribute alpha.



43
44
45
# File 'lib/dnn/core/activations.rb', line 43

def alpha
  @alpha
end

Class Method Details

.load_hash(hash) ⇒ Object



49
50
51
# File 'lib/dnn/core/activations.rb', line 49

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

Instance Method Details

#backward(dout) ⇒ Object



60
61
62
63
64
# File 'lib/dnn/core/activations.rb', line 60

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

#forward(x) ⇒ Object



53
54
55
56
57
58
# File 'lib/dnn/core/activations.rb', line 53

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

#to_hash ⇒ Object



66
67
68
# File 'lib/dnn/core/activations.rb', line 66

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