Class: DNN::Losses::MeanAbsoluteError

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

Instance Method Summary collapse

Methods inherited from Loss

from_hash, #load_hash, #loss, #regularizers_backward, #regularizers_forward, #to_hash

Instance Method Details

#backward(y, t) ⇒ Object



75
76
77
78
79
80
# File 'lib/dnn/core/losses.rb', line 75

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

#forward(y, t) ⇒ Object



70
71
72
73
# File 'lib/dnn/core/losses.rb', line 70

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