Class: DNN::Losses::MeanAbsoluteError

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

Instance Method Summary collapse

Methods inherited from Loss

#loss, #regularizers_backward, #regularizers_forward, #to_hash

Instance Method Details

#backward(y, t) ⇒ Object



63
64
65
66
67
68
# File 'lib/dnn/core/losses.rb', line 63

def backward(y, t)
  dy = y - t
  dy[dy >= 0] = 1
  dy[dy < 0] = -1
  dy
end

#forward(y, t) ⇒ Object



58
59
60
61
# File 'lib/dnn/core/losses.rb', line 58

def forward(y, t)
  batch_size = t.shape[0]
  (y - t).abs.sum / batch_size
end