Class: DNN::Layers::Mish

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

Instance Attribute Summary

Attributes inherited from Layer

#input_shape

Instance Method Summary collapse

Methods inherited from Layer

#build, #built?, call, #call, #clean, from_hash, #initialize, #load_hash, #output_shape, #to_hash

Constructor Details

This class inherits a constructor from DNN::Layers::Layer

Instance Method Details

#backward(dy) ⇒ Object



143
144
145
146
147
# File 'lib/dnn/core/layers/activations.rb', line 143

def backward(dy)
  omega = 4 * (@x + 1) + 4 * Xumo::NMath.exp(2 * @x) + Xumo::NMath.exp(3 * @x) + Xumo::NMath.exp(@x) * (4 * @x + 6)
  delta = 2 * Xumo::NMath.exp(@x) + Xumo::NMath.exp(2 * @x) + 2
  dy * (Xumo::NMath.exp(@x) * omega) / delta**2
end

#forward(x) ⇒ Object



138
139
140
141
# File 'lib/dnn/core/layers/activations.rb', line 138

def forward(x)
  @x = x
  x * Xumo::NMath.tanh(Softplus.new.forward(x))
end