Skip to content

Fix: use alpha + tau as the branch threshold in Huber.prox - #276

Open
raashish1601 wants to merge 1 commit into
PyLops:devfrom
raashish1601:fix/275-huber-prox-threshold
Open

raashish1601 wants to merge 1 commit into
PyLops:devfrom
raashish1601:fix/275-huber-prox-threshold

Conversation

@raashish1601

Copy link
Copy Markdown

Huber.prox picked the branch with |x| > alpha, but for the prox of tau * H_alpha the switch is at |x| = alpha + tau. Inputs with alpha < |x| <= alpha + tau were soft-thresholded instead of scaled, so the result wasn't the minimizer and the prox wasn't monotone (with alpha = tau = 1, x = 1.2 gave 0.2 while x = 1.0 gave 0.5). See #275.

The fix changes the mask to |x| > alpha + tau. With that, the two branches give the closed form (1 - tau / max(|x|, alpha + tau)) * x that was left commented out in prox, so I kept it as a reference and corrected the comment that said it gave a different result. The Notes section now shows the correct thresholds.

Tests: added test_Huber_prox in pytests/test_norms.py, which compares prox with a brute-force minimizer of tau * H(y) + (y - x)^2 / 2 on a grid of x that covers alpha < |x| <= alpha + tau. It fails on dev and passes here. pytests/test_norms.py passes, and ruff check, ruff format --check and mypy are clean on the changed files.

AI assistance: this PR was prepared with an AI coding agent (Claude Code, Anthropic). It reproduced the issue, wrote the fix and tests, and ran them locally as described above.

Closes #275

@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.

Huber.prox uses the wrong branch threshold (|x| > alpha instead of |x| > alpha + tau)

1 participant