Repository navigation
Conversation
With nested duals, dividing by `bval * bval` divides by a dual number again, so the n-th derivative divides by `y^(2^n)`, which overflows or underflows long before the derivatives do (#866). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #867 +/- ##
=======================================
Coverage 91.17% 91.17%
=======================================
Files 11 11
Lines 1077 1077
=======================================
Hits 982 982
Misses 95 95 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #866.
For dual numbers
xandy, the partials ofx / yare computed as(a - (aval / bval) * b) / bvalinstead ofinv(bval) * a - (aval / (bval * bval)) * b. With nested duals,bvalis a dual number, so dividing bybval * bvaldivides by a dual number again, and then-th derivative divides byy^(2^n). This overflows or underflows long before the derivatives do. For example, the third derivative ofx / (x^2 + x^3)is-Infatx = 1e-30instead of about-6e120, and the gradient of a Laplace approximation in #866 is-Infinstead of about-386.29. Dividing bybvaltwice avoids the square. The same issue affects first-order derivatives wheny^2over- or underflows: the derivative of2x / xis-Infatx = 1e-200and2e-200atx = 1e200(instead of 0).The change is extracted from #858, where it is unrelated to the NaN-safe mode.
Tests:
test/DerivativeTest.jl: first derivatives of2x / xandzero(x) / xat1e-200,1e-310and1e200(from Enable NaN-safe mode by default #858), and third derivatives ofx / (x^2 + x^3)at1e-20,1e-30and1e-40(from Third-order derivatives ofx / yareInforNaNfor smally, e.g. in gradients of Laplace approximations #866).test/PartialsTest.jl: the reference expression of_div_partials(from Enable NaN-safe mode by default #858).I bumped the version to 1.4.7.
This pull request was written with the assistance of generative AI (Claude Code).
🤖 Generated with Claude Code