Class: DNN::Losses::MeanAbsoluteError

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

Instance Method Summary collapse

Methods inherited from Loss

#forward, #regularizes_backward, #to_hash

Instance Method Details

#backward(y) ⇒ Object



59
60
61
62
63
64
# File 'lib/dnn/core/losses.rb', line 59

def backward(y)
  dout = @out - y
  dout[dout >= 0] = 1
  dout[dout < 0] = -1
  dout
end

#loss(out, y) ⇒ Object



53
54
55
56
57
# File 'lib/dnn/core/losses.rb', line 53

def loss(out, y)
  @out = out
  batch_size = y.shape[0]
  (out - y).abs.sum / batch_size
end