Class: DNN::Losses::Hinge

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



89
90
91
92
93
# File 'lib/dnn/core/losses.rb', line 89

def backward(y, t)
  a = Xumo::SFloat.ones(*@a.shape)
  a[@a <= 0] = 0
  a * -t
end

#forward(y, t) ⇒ Object



84
85
86
87
# File 'lib/dnn/core/losses.rb', line 84

def forward(y, t)
  @a = 1 - y * t
  Xumo::SFloat.maximum(0, @a)
end