class DNN::Losses::SoftmaxCrossEntropy
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 145 def initialize(eps: 1e-7) @eps = eps end
softmax(y)
click to toggle source
# File lib/dnn/core/losses.rb, line 137 def softmax(y) Xumo::NMath.exp(y) / Xumo::NMath.exp(y).sum(1, keepdims: true) end
Also aliased as: activation
Public Instance Methods
backward_node(d)
click to toggle source
# File lib/dnn/core/losses.rb, line 155 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 149 def forward_node(y, t) @t = t @x = SoftmaxCrossEntropy.softmax(y) -(t * Xumo::NMath.log(@x + @eps)).mean(0).sum end
load_hash(hash)
click to toggle source
# File lib/dnn/core/losses.rb, line 163 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 159 def to_hash super(eps: @eps) end