class DNN::Losses::SigmoidCrossEntropy
Attributes
eps[RW]
Public Class Methods
new(eps: 1e-7)
click to toggle source
@param [Float] eps Value to avoid nan.
# File lib/dnn/core/losses.rb, line 182 def initialize(eps: 1e-7) @eps = eps end
sigmoid(y)
click to toggle source
# File lib/dnn/core/losses.rb, line 174 def sigmoid(y) Layers::Sigmoid.new.forward_node(y) end
Also aliased as: activation
Public Instance Methods
backward_node(d)
click to toggle source
# File lib/dnn/core/losses.rb, line 192 def backward_node(d) d * (@x - @t) / @x.shape[0] end
forward_node(y, t)
click to toggle source
# File lib/dnn/core/losses.rb, line 186 def forward_node(y, t) @t = t @x = SigmoidCrossEntropy.sigmoid(y) -(t * Xumo::NMath.log(@x + @eps) + (1 - t) * Xumo::NMath.log(1 - @x + @eps)).mean(0).sum end
load_hash(hash)
click to toggle source
# File lib/dnn/core/losses.rb, line 200 def load_hash(hash) initialize(eps: hash[:eps]) end
to_hash()
click to toggle source
Calls superclass method
DNN::Losses::Loss#to_hash
# File lib/dnn/core/losses.rb, line 196 def to_hash super(eps: @eps) end