Skip to content

[MRG] Shift before exponentiating in coordinate_grad_semi_dual (closes #264) - #866

Open
deeb01 wants to merge 3 commits into
PythonOT:masterfrom
deeb01:fix-264-stochastic-overflow
Open

deeb01 wants to merge 3 commits into
PythonOT:masterfrom
deeb01:fix-264-stochastic-overflow

Conversation

@deeb01

@deeb01 deeb01 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Types of changes

Bug fix (non-breaking change which fixes an issue).

Motivation and context / Related issue

Closes #264.

coordinate_grad_semi_dual computes exp(-(M[i] - beta) / reg) directly. Once beta grows that overflows, the normalisation divides inf by inf, and khi comes back all-NaN — the behaviour reported in the issue.

c_transform_entropic in the same module already guards this by subtracting min(r) before exponentiating. This applies the same shift. It cancels in the ratio, so the gradient is unchanged wherever the old code did not overflow; verified to 1.7e-16 across a range of beta.

How has this been tested (if it applies)

Two tests: the gradient is finite at large beta without warning (verified to fail on master), and its values are pinned against the unshifted formula in the regime where that formula is valid. Full suite green, pre-commit clean.

PR checklist

  • I have read the CONTRIBUTING document.
  • The documentation is up-to-date with the changes I made (check build artifacts).
  • All tests passed, and additional code has been covered with new tests.
  • I have added the PR and Issue fix to the RELEASES.md file.

…onOT#264)

The semi-dual gradient computed exp(-(M[i] - beta) / reg) directly. Once
beta grows, that overflows, the normalisation divides inf by inf, and khi
comes back all-NaN, which is what makes the stochastic solvers unusable at
the sizes reported in the issue.

c_transform_entropic in the same module already guards against this by
subtracting min(r) before exponentiating. This applies the same shift to
coordinate_grad_semi_dual. It cancels in the ratio, so the returned
gradient is unchanged wherever the old code did not overflow; verified to
1.7e-16 across a range of beta.

Adds a test that the gradient is finite at large beta without even warning,
and a test pinning the values against the unshifted formula in the regime
where that formula is valid.
@github-actions github-actions Bot added the Tests label Sep 18, 2026
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.87%. Comparing base (98d09a1) to head (0e07f13).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #866   +/-   ##
=======================================
  Coverage   96.86%   96.87%           
=======================================
  Files         128      128           
  Lines       26304    26326   +22     
=======================================
+ Hits        25480    25502   +22     
  Misses        824      824           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nan values and division by zero warnings on stochastic solvers

1 participant