Class: DNN::Activations::LeakyReLU

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

Instance Attribute Summary collapse

Attributes inherited from Layers::Layer

#input_shape

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layers::Layer

#build, #built?, #output_shape

Constructor Details

#initialize(alpha = 0.3) ⇒ LeakyReLU

Returns a new instance of LeakyReLU.



80
81
82
# File 'lib/dnn/core/activations.rb', line 80

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

Instance Attribute Details

#alphaObject (readonly)

Returns the value of attribute alpha.



78
79
80
# File 'lib/dnn/core/activations.rb', line 78

def alpha
  @alpha
end

Class Method Details

.load_hash(hash) ⇒ Object



84
85
86
# File 'lib/dnn/core/activations.rb', line 84

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

Instance Method Details

#backward(dout) ⇒ Object



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

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

#forward(x) ⇒ Object



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

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

#to_hashObject



101
102
103
# File 'lib/dnn/core/activations.rb', line 101

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