Class: DNN::Losses::HuberLoss
Instance Method Summary
collapse
#backward, #forward
Methods inherited from Loss
call, #call, #clean, #forward, from_hash, #load_hash, #loss, #regularizers_backward, #regularizers_forward, #to_hash
Instance Method Details
#backward_node(d) ⇒ Object
127
128
129
130
131
132
133
134
|
# File 'lib/dnn/core/losses.rb', line 127
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
120
121
122
123
124
125
|
# File 'lib/dnn/core/losses.rb', line 120
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
|