@staticmethod
def _projection2simplex(y):
    '\n        Given y, it solves argmin_z |y-z|_2 st \\sum z = 1 , 1 >= z_i >= 0 for all i\n        '
    m = len(y)
    sorted_y = np.flip(np.sort(y), axis=0)
    tmpsum = 0.0
    tmax_f = ((np.sum(y) - 1.0) / m)
    for i in range((m - 1)):
        tmpsum += sorted_y[i]
        tmax = ((tmpsum - 1) / (i + 1.0))
        if (tmax > sorted_y[(i + 1)]):
            tmax_f = tmax
            break
    return np.maximum((y - tmax_f), np.zeros(y.shape))
Given y, it solves argmin_z |y-z|_2 st \sum z = 1 , 1 >= z_i >= 0 for all i
@staticmethod
def _projection2simplex(y):
    '\n        Given y, it solves argmin_z |y-z|_2 st \\sum z = 1 , 1 >= z_i >= 0 for all i\n        '
    m = len(y)
    sorted_y = np.flip(np.sort(y), axis=0)
    tmpsum = 0.0
    tmax_f = ((np.sum(y) - 1.0) / m)
    for i in range((m - 1)):
        tmpsum += sorted_y[i]
        tmax = ((tmpsum - 1) / (i + 1.0))
        if (tmax > sorted_y[(i + 1)]):
            tmax_f = tmax
            break
    return np.maximum((y - tmax_f), np.zeros(y.shape))