Class: DNN::Losses::HuberLoss

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

Instance Method Summary collapse

Methods included from DNN::Layers::LayerNode

#forward

Methods inherited from Loss

call, #call, #clean, #forward, from_hash, #load_hash, #loss, #regularizers_forward, #to_hash

Instance Method Details

#backward_node(d) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/dnn/core/losses.rb', line 121

def backward_node(d)
  dy = (@y - @t)
  if @loss_value > 1
    dy[dy >= 0] = 1
    dy[dy < 0] = -1
  end
  d * dy / @y.shape[0]
end

#forward_node(y, t) ⇒ Object



114
115
116
117
118
119
# File 'lib/dnn/core/losses.rb', line 114

def forward_node(y, t)
  @y = y
  @t = t
  loss_l1_value = (y - t).abs.mean(0).sum
  @loss_value = loss_l1_value > 1 ? loss_l1_value : 0.5 * ((y - t)**2).mean(0).sum
end