lib/dnn/core/activations.rb in ruby-dnn-0.5.12 vs lib/dnn/core/activations.rb in ruby-dnn-0.6.0
- old
+ new
@@ -1,32 +1,31 @@
module DNN
module Activations
- Layer = Layers::Layer
- class Sigmoid < Layer
+ class Sigmoid < Layers::Layer
def forward(x)
@out = 1 / (1 + Xumo::NMath.exp(-x))
end
def backward(dout)
dout * (1 - @out) * @out
end
end
- class Tanh < Layer
+ class Tanh < Layers::Layer
def forward(x)
@out = Xumo::NMath.tanh(x)
end
def backward(dout)
dout * (1 - @out**2)
end
end
- class ReLU < Layer
+ class ReLU < Layers::Layer
def forward(x)
@x = x.clone
x[x < 0] = 0
x
end
@@ -37,11 +36,11 @@
dout * @x
end
end
- class LeakyReLU < Layer
+ class LeakyReLU < Layers::Layer
attr_reader :alpha
def initialize(alpha = 0.3)
@alpha = alpha
end
@@ -62,10 +61,10 @@
@x[@x <= 0] = @alpha
dout * @x
end
def to_hash
- {name: self.class.name, alpha: alpha}
+ {class: self.class.name, alpha: alpha}
end
end
class IdentityMSE < Layers::OutputLayer