Skip to content

Finish PR 734 : typo in \text{max_nz} in ot.utils.projection_sparse_simplex #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 28, 2025
Merged
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Clean references in documentation (PR #722)
- Clean documentation for `ot.gromov.gromov_wasserstein` (PR #737)
- Debug wheels building (PR #739)
- Fix doc for projection sparse simplex (PR #734, PR #746)

## 0.9.5

Expand Down
17 changes: 11 additions & 6 deletions ot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,29 @@ def projection_sparse_simplex(V, max_nz, z=1, axis=None, nx=None):
r"""Projection of :math:`\mathbf{V}` onto the simplex with cardinality constraint (maximum number of non-zero elements) and then scaled by `z`.

.. math::
P\left(\mathbf{V}, max_nz, z\right) = \mathop{\arg \min}_{\substack{\mathbf{y} >= 0 \\ \sum_i \mathbf{y}_i = z} \\ ||p||_0 \le \text{max_nz}} \quad \|\mathbf{y} - \mathbf{V}\|^2
P\left(\mathbf{V}, \text{max_nz}, z\right) = \mathop{\arg \min}_{\substack{\mathbf{y} >= 0 \\ \sum_i \mathbf{y}_i = z} \\ ||p||_0 \le \text{max_nz}} \quad \|\mathbf{y} - \mathbf{V}\|^2

Parameters
----------
V: 1-dim or 2-dim ndarray
max_nz: int
Maximum number of non-zero elements in the projection.
If `max_nz` is larger than the number of elements in `V`, then
the projection is equivalent to `proj_simplex(V, z)`.
z: float or array
If array, len(z) must be compatible with :math:`\mathbf{V}`
axis: None or int
- axis=None: project :math:`\mathbf{V}` by :math:`P(\mathbf{V}.\mathrm{ravel}(), max_nz, z)`
- axis=1: project each :math:`\mathbf{V}_i` by :math:`P(\mathbf{V}_i, max_nz, z_i)`
- axis=0: project each :math:`\mathbf{V}_{:, j}` by :math:`P(\mathbf{V}_{:, j}, max_nz, z_j)`
- axis=None: project :math:`\mathbf{V}` by :math:`P(\mathbf{V}.\mathrm{ravel}(), \text{max_nz}, z)`
- axis=1: project each :math:`\mathbf{V}_i` by :math:`P(\mathbf{V}_i, \text{max_nz}, z_i)`
- axis=0: project each :math:`\mathbf{V}_{:, j}` by :math:`P(\mathbf{V}_{:, j}, \text{max_nz}, z_j)`

Returns
-------
projection: ndarray, shape :math:`\mathbf{V}`.shape

References:
Sparse projections onto the simplex
References
----------
.. [1] Sparse projections onto the simplex
Anastasios Kyrillidis, Stephen Becker, Volkan Cevher and, Christoph Koch
ICML 2013
https://arxiv.org/abs/1206.1529
Expand Down
Loading