Class: DNN::Losses::SigmoidCrossEntropy

Inherits:
Loss
  • Object
show all
Defined in:
lib/dnn/core/losses.rb

Instance Method Summary collapse

Methods inherited from Loss

#d_regularize, #regularize, #to_hash

Instance Method Details

#backward(y) ⇒ Object



111
112
113
# File 'lib/dnn/core/losses.rb', line 111

def backward(y)
  @out - y
end

#forward(x, y) ⇒ Object



105
106
107
108
109
# File 'lib/dnn/core/losses.rb', line 105

def forward(x, y)
  @out = Utils.sigmoid(x)
  batch_size = y.shape[0]
  -(y * NMath.log(@out + 1e-7) + (1 - y) * NMath.log(1 - @out + 1e-7)).sum / batch_size
end