KL Divergence: use epsilon smoothing for zero-frequency events#141
Open
taserz wants to merge 1 commit into
Open
KL Divergence: use epsilon smoothing for zero-frequency events#141taserz wants to merge 1 commit into
taserz wants to merge 1 commit into
Conversation
Fixes evllabs#139. The divergence function was iterating only over events in the unknown histogram and silently skipping any event where the known histogram frequency was zero. Events present in the unknown document but absent in the known one were dropped entirely, understating the divergence and discarding a real authorship signal. Now iterates over the union of both histograms and substitutes epsilon (1e-10) for any zero known-frequency term instead of skipping it. Behavior is unchanged for events where both frequencies are positive. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
342bee9 to
0a6d906
Compare
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 #139
The divergence function was only iterating over events in the unknown histogram and skipping any event where the known histogram had a frequency of zero. So if a word appears in the unknown document but not the known one, that term gets dropped entirely. That understates the divergence and throws away a real signal.
Switched to iterating over the union of both histograms and substituting epsilon (1e-10) for any zero known-frequency term instead of skipping it. For events where both frequencies are already positive nothing changes, so existing test values are unaffected.