def expected_squared_hinge(target, prediction): target = 2 * target - 1 pred_mean, pred_var = unpack_mean_var(prediction) mean_unsqrd, var_unsqrd = transfer.rectifier( margin - target * pred_mean, pred_var) # See Murphy, "Machine Learning: A Probabilist Perspective", Eq (2.26) # for the following step. mean = var_unsqrd + mean_unsqrd ** 2 return mean
def expected_hinge(target, prediction): target = 2 * target - 1 pred_mean, pred_var = unpack_mean_var(prediction) mean, _ = transfer.rectifier(margin - target * pred_mean, pred_var) return mean