def simplex_projection(v, b=1):

    v = np.asarray(v)
    p = len(v)

    # Sort v into u in descending order
    v = (v > 0) * v
    u = np.sort(v)[::-1]
    sv = np.cumsum(u)

    rho = np.where(u > (sv - b) / np.arange(1, p + 1))[0][-1]
    theta = np.max([0, (sv[rho] - b) / (rho + 1)])
    w = (v - theta)
    w[w < 0] = 0
    return w


# Note: this function can be removed if running
# this algorithm on quantopian.com
like getattribute, but values persist
dataset/ETHPy150Open quantopian/zipline/zipline/examples/olmar.py/simplex_projection--crossover with--dataset/ETHPy150Open OrbitzWorldwide/droned/droned/lib/droned/applications/__init__.py/StorageMixin.load