Hi Grant,
Yeah, this normalization is a little impractical. My guess is that the others spent quite some time to optimize with the Lagrangian multiplier that enforces b_i >= 0 but couldn't make it work. There is probably a way but I would imagine it to require some serious calculus-fu (because the authors couldn't figure it out themselves, despite having quite some incentive to do so). So my advice is (unless you really want to train using Lagrangian multipliers), just add the normalization. I ported the simplex_projection.m which seems to work just fine:
import numpy as np
def simplex_projection(v, z=1):
"""Projection vectors to the simplex domain
Implemented according to the paper: Efficient projections onto the
l1-ball for learning in high dimensions, John Duchi, et al. ICML 2008.
Implementation Time: 2011 June 17 by [email protected] AT pmail.ntu.edu.sg
Optimization Problem: min_{w}\| w - v \|_{2}^{2}
s.t. sum_{i=1}^{m}=z, w_{i}\geq 0
Input: A vector v \in R^{m}, and a scalar z > 0 (default=1)
Output: Projection vector w
:Example:
>>> proj = simplex_projection([.4 ,.3, -.4, .5])
>>> print proj
array([ 0.33333333, 0.23333333, 0. , 0.43333333])
>>> print proj.sum()
1.0
Original matlab implementation: Copyright 2011 by Bin
Python-port: Copyright 2012 by Thomas Wiecki ([email protected]).
"""
v = np.asarray(v)
p = len(v)
w = np.zeros_like(v)
# Sort v into u in descending order
u = np.sort(v)[::-1]
idx = np.argsort(v)[::-1]
# Find \rho = max{j \in [n]: u_{j}-(sum(u(1:j, 1))-z)/j >0 }
for j in range(p):
if (u[j] - (np.sum(u[:j])-z) / j <= 0):
break
# Define \theta = (sum(u(1:rho, 1))-z)/rho
theta = (np.sum(u[:j])-z) / j;
# w_{i}=max{ v_{i} - theta }
w[idx[:j]] = v[idx[:j]] - theta
return w
Disclaimer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.