def ramp_loss(z): """ Ramp loss function. l(z) = 1 if z <= -1 l(z) = (1-z) / 2 if -1 < z <= 1 l(z) = 0 if 1 < z """ return F.hard_sigmoid(- 2.5 * z)