fix(maths): eliminate cancellation error in exact parameter info-gain weight#415
Open
gauraaansh wants to merge 1 commit into
Open
fix(maths): eliminate cancellation error in exact parameter info-gain weight#415gauraaansh wants to merge 1 commit into
gauraaansh wants to merge 1 commit into
Conversation
… weight Replaces the direct-expansion form of eq. (D.15) with an algebraically equivalent form using the digamma recurrence, removing the reciprocal terms that caused catastrophic cancellation for small Dirichlet counts. Fixes infer-actively#340
Collaborator
|
weirdly it appears the 3.14 unit tests are timing out on the |
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 #340
_exact_wnormcomputes eq. (D.15) from Da Costa et al. 2020 as:As A shrinks toward MINVAL,
1/Aanddigamma(A)both diverge with oppositesign and are supposed to cancel down to an O(1) value. In float32 that
cancellation is inexact, so the term comes out wrong by several orders of
magnitude for small Dirichlet counts. The error is also erratic rather than
a smooth degradation, matching the oscillating behavior described in the
issue.
Using the digamma recurrence
digamma(x+1) = digamma(x) + 1/x, substitutefor
1/Aand1/sumA:The
digamma(A)anddigamma(sumA)terms cancel exactly, leaving:This reformulation is algebraically identical to the original expression. It
changes only the numerical evaluation order. The divergent terms are removed
before any floating-point evaluation happens, so the implementation no
longer depends on cancellation between divergent quantities.
Testing
logarithmic sweep from 1e-20 to 1e3: the original formula's error grows to
roughly six orders of magnitude near the clipping threshold, while the
rewritten version stays within float32's ordinary rounding error across the
same range.
agent.py use for policy inference), including the zero-entry case from
Bayesian model reduction.
hand-copied version of the same pre-fix formula, so it would pass
regardless of correctness. Added a test against
-log(K), the closed-formlimit eq. (D.15) converges to for a symmetric Dirichlet as concentration
goes to zero. This reference is independent of either formula.
failure from a missing
numpyrodependency).ruff checkis clean.