Skip to content

Preserve sparse-group axes and finite zero-group limits - #278

Open
antonsoo wants to merge 1 commit into
PyLops:devfrom
antonsoo:fix/sparse-group-axis-endpoints
Open

antonsoo wants to merge 1 commit into
PyLops:devfrom
antonsoo:fix/sparse-group-axis-endpoints

Conversation

@antonsoo

Copy link
Copy Markdown

Sparse-group shrinkage can return NaNs at its pure L1 limit and raises for row grouping on nonsquare arrays:

import numpy as np
from pyproximal import L21_plus_L1

x = np.array([[0.0, 1.0, 3.0], [0.0, 0.5, -4.0]])
operator = L21_plus_L1(sigma=1, rho=1)
print(operator.prox(x, 0.5))
print(operator.prox(x, 0.5, axis=1))

Dev produces a NaN first column, then raises a broadcasting error. Both calls should return [[0, 0.5, 2.5], [0, 0, -3.5]].

Keep the reduced group dimension for broadcasting, and handle zero norms explicitly in group shrinkage and phase normalization. This also gives finite identity behavior at sigma=0. Added real/complex endpoint and axis regressions, documentation, and an example.

On recorded image patches and audio spectrograms, 21 of 32 direct calls and five of 16 native proximal-gradient runs previously failed or produced nonfinite results. All now match an independent scalar/group calculation within 5.6e-17. The four ordinary mixed-penalty column-grouping controls remain byte-identical. Native solver comparisons use the default column grouping; row grouping is checked through the public proximal method.

The full suite passes (290 tests), as do make lint, make typeannot, and a documentation build with gallery execution disabled, using the project's locked Python 3.11 dependencies. The example was also run directly.

AI assistance: OpenAI Codex was used to investigate, implement and validate this fix and draft this PR.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant