Repository navigation
Ignore zero weights in immediate mean and variance updates - #71
Open
trestoncuzzort wants to merge 1 commit into
Open
trestoncuzzort wants to merge 1 commit into
trestoncuzzort wants to merge 1 commit into
Conversation
Skip zero-weight updates in the immediate mean so an initial zero weight does not leave a NaN that poisons later samples. Apply the variance recurrence only when both the new weight and the previous total weight are nonzero, avoiding its zero denominator after an initial zero weight. Cover leading, interleaved and trailing zeros, variates, integer and floating weights, and finite values whose squared deviation overflows. Document that extraction with zero total weight is undefined. Assisted-by: OpenAI Codex
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 #44.
An immediate weighted-variance accumulator fed
(99, weight=0),(2, weight=1),(4, weight=1)returns NaN for both mean and variance instead of 3 and 1. The initial zero weight poisons the immediate mean, and the variance recurrence later divides by the previous total weight, which is still zero.Ignore zero-weight updates in the immediate mean, including variates. Guard the variance recurrence against a zero current weight or zero previous total weight. This also avoids squaring a large unused sample before multiplying by zero. Observation counts still include zero-weight samples. Document that extraction with zero total weight remains undefined.
Extend the existing mean and variance tests with leading, interleaved and trailing zeros, integer/floating weights, variates and large finite zero-weight samples.
Validation on Linux:
int,float,doubleandlong doublesample/weight pairs, compared with an independent two-pass batch calculation: immediate mean and variance each have 13,500 failures before, zero after. The lazy calculation and observation counts match throughout. The check rejects nonfinite results explicitly.git diff --checkpasses. Native Windows and 32-bit builds were not run; generated documentation was not rebuilt.OpenAI Codex assisted with investigation, implementation and tests. dawnr checked the recurrence guard's denominator conditions with seven provers under an exact-integer, nonnegative-weight abstraction. That does not prove floating-point variance accuracy or the generic/compiled C++ implementation.