Projection onto the capped simplex

Weiran Wang, Canyi LuarXiv 2015

Abstract

We provide a simple and efficient algorithm for computing the Euclidean projection of a point onto the capped simplex—a simplex with an additional uniform bound on each coordinate—together with an elementary proof. Both the MATLAB and C++ implementations of the proposed algorithm can be downloaded at https://eng.ucmerced.edu/people/wwang5.

Introduction

In many optimization problems—particularly in machine learning and signal processing—it is necessary to project a vector onto a specific feasible set. The most common case is the probability simplex, where elements are non-negative and sum to a constant $s$. However, certain applications require an additional "cap" or upper bound on each element (e.g., $0 \le x_i \le 1$). This set, the intersection of a unit cube and a hyperplane, is known as the capped simplex.

While projecting onto a standard simplex is a solved problem with $O(D \log D)$ complexity, adding the upper bound makes the projection significantly more complex. Standard quadratic programming solvers like MATLAB's lsqlin or general convex toolboxes like CVX can solve this, but they become prohibitively slow or exceed memory limits as the dimensionality $D$ grows into the tens of thousands. This paper presents a simple and highly efficient $O(D^2)$ algorithm for this task.

Methodology

The authors derive their algorithm by analyzing the Karush-Kuhn-Tucker (KKT) conditions of the optimization problem. Their approach relies on several key mathematical observations:

  1. Order Preservation: If the input vector $\mathbf{y}$ is sorted in ascending order, the elements of the optimal solution $\mathbf{x}$ will also be in ascending order.
  2. Three-Segment Partition: Due to the constraints ($0 \le x_i \le 1$), the optimal solution $\mathbf{x}$ naturally splits into three segments: a sequence of 0s, a sequence of values strictly between 0 and 1, and a sequence of 1s.
  3. Search Strategy: Once $\mathbf{y}$ is sorted, the problem reduces to finding the two "split points" ($a$ and $b$) that define these three segments.

The algorithm sorts the input ($O(D \log D)$) and then performs a nested loop to test possible split points ($O(D^2)$). For each pair of split points, it calculates a candidate Lagrange multiplier $\gamma$ and verifies if it satisfies the KKT boundary conditions. Unlike iterative methods like ADMM, this method finds the exact analytical solution in a finite number of steps.

Experimental Setup

The paper focuses on algorithmic efficiency rather than a specific application dataset. To evaluate performance, the authors used synthetically generated data:

  • Input vectors $\mathbf{y}$ were generated using rand(D,1) - 0.5.
  • The sum constraint $s$ was generated as a random integer between 0 and $D$.
  • Dimensions ($D$) tested ranged from small scales ($D=50$) to large scales ($D=100,000$).

Key Results

The performance gains are dramatic, especially in high dimensions. By leveraging the structure of the problem rather than using general-purpose solvers, the proposed method avoids the overhead of high-dimensional continuous search spaces.

Table 1: Comparison of execution time (in seconds) for projecting onto the capped simplex across various dimensions D.

As shown in Table 1, for a vector of size $D=5000$, the proposed C++ implementation takes just 0.021 seconds, while CVX takes 40.94 seconds and lsqlin takes over 5000 seconds. At $D=100,000$, the proposed algorithm finishes in approximately 8.78 seconds (C++), whereas standard solvers typically fail due to memory limits or extreme time requirements. The C++ version is roughly 100x faster than the MATLAB version, highlighting the benefit of low-level implementation for these fundamental optimization building blocks.

Discussion and Limitations

While $O(D^2)$ is significantly faster than general solvers, it remains theoretically slower than the $O(D \log D)$ or $O(D)$ algorithms available for the uncapped probability simplex. This extra complexity stems directly from the upper-bound constraint. Future work might explore if binary search or other heuristics could reduce the $O(D^2)$ search component to something closer to $O(D)$. Additionally, while the algorithm is highly efficient, integrating it into specific high-dimensional machine learning pipelines, such as capped SVMs or sparse coding, remains a task for future implementation.

Summary updated

BibTeX
@misc{wang2015projection,
  author = {Weiran Wang and Canyi Lu},
  title = {{Projection onto the capped simplex}},
  year = {2015},
  eprint = {1503.01002},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1503.01002},
}
Figure