Class: DNN::Layers::LeakyReLU

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

Instance Attribute Summary collapse

Attributes inherited from Layer

#input_shape, #output_shape

Instance Method Summary collapse

Methods included from LayerNode

#forward

Methods inherited from Layer

#<<, #build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash

Constructor Details

#initialize(alpha = 0.3) ⇒ LeakyReLU

Returns a new instance of LeakyReLU.

Parameters:

  • alpha (Float) (defaults to: 0.3)

    The slope when the output value is negative.



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

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

Instance Attribute Details

#alphaObject (readonly)

Returns the value of attribute alpha.



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

def alpha
  @alpha
end

Instance Method Details

#backward_node(dy) ⇒ Object



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

def backward_node(dy)
  dx = Xumo::SFloat.ones(@x.shape)
  dx[@x <= 0] = @alpha
  dy * dx
end

#forward_node(x) ⇒ Object



91
92
93
94
95
96
# File 'lib/dnn/core/layers/activations.rb', line 91

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

#load_hash(hash) ⇒ Object



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

def load_hash(hash)
  initialize(hash[:alpha])
end

#to_hashObject



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

def to_hash
  super(alpha: @alpha)
end