Stabilize zero-inflated variance at large base means - #3487
Open
AHMETHAKANBEZIR1 wants to merge 1 commit into
Open
AHMETHAKANBEZIR1 wants to merge 1 commit into
AHMETHAKANBEZIR1 wants to merge 1 commit into
Conversation
Use the law of total variance without subtracting squared means. Multiply by the gate before the remaining mean factor to avoid overflow of an unnecessary intermediate square. Co-authored-by: Codex <noreply@openai.com>
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.
Proposed changes
Fixes #3486. Replace subtraction of squared moments in ZeroInflatedDistribution.variance with the equivalent law-of-total-variance expression:
(1 - gate) * base_variance + (gate * base_mean) * meanThis avoids cancellation when the base mean dominates its variance. Multiplying gate * base_mean before the remaining mean also avoids an unnecessary overflowing mean square, e.g. a float32 Poisson rate of 1e20 with gate=1e-20 has variance approximately 2e20. The existing expression produces NaN. A rate of 1e10 with gate=0 currently produces zero rather than the Poisson variance of 1e10. This shared property applies to generic zero-inflated distributions as well as ZIP/ZINB.
New and existing tests
One focused parametrized regression uses Poisson and Normal bases in float32/float64, including ordinary, zero-gate, small-gate and unit-gate cases in a batch. Expected values use an independent double-precision conditional-variance calculation; gradients are compared with the analytic derivative with respect to the base mean parameter.
AI assistance disclosure
This contribution was investigated, implemented and validated autonomously with Codex assistance on behalf of AHMETHAKANBEZIR1. It has not received independent human code review. Codex is recorded as a co-author. Maintainer review is requested; local results are not a claim of upstream CI success.