Skip to content
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

Fix limit of log1mexp gradient at zero and improve numerical stablity #725

Merged
merged 1 commit into from
Jan 5, 2022

Conversation

ricardoV94
Copy link
Contributor

@ricardoV94 ricardoV94 commented Jan 5, 2022

The grad of log1mexp was evaluating to +inf for inputs of 0, due to specific number/order of operations and the fact that 1/-0.0 == -np.inf vs 1/0.0 == np.inf.

This PR fixes this edge case and also improves numerical stability for values close to zero, relative to the previous implementation and relative to the gradient obtained from the equivalent symbolic graph at.log(1-at.exp(x))

This showed up here first: pymc-devs/pymc#5289

@codecov
Copy link

codecov bot commented Jan 5, 2022

Codecov Report

Merging #725 (2f6c33d) into main (cfa867b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #725   +/-   ##
=======================================
  Coverage   78.17%   78.17%           
=======================================
  Files         152      152           
  Lines       47716    47718    +2     
  Branches    10893    10893           
=======================================
+ Hits        37300    37302    +2     
  Misses       7848     7848           
  Partials     2568     2568           
Impacted Files Coverage Δ
aesara/scalar/math.py 84.97% <100.00%> (+0.04%) ⬆️

@ricardoV94 ricardoV94 changed the title Fix limit of log1mexp gradient at zero and improve numerical precision Fix limit of log1mexp gradient at zero and improve numerical stablity Jan 5, 2022
@brandonwillard brandonwillard added bug Something isn't working enhancement New feature or request labels Jan 5, 2022
@brandonwillard brandonwillard merged commit e476ebc into aesara-devs:main Jan 5, 2022
@ricardoV94 ricardoV94 deleted the fix_log1mexp_grad branch January 19, 2022 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants