Repository navigation
fix(reweighing): preserve zero weights in zero-mass cells - #586
Open
Hanabi9248 wants to merge 1 commit into
Open
Hanabi9248 wants to merge 1 commit into
Hanabi9248 wants to merge 1 commit into
Conversation
Signed-off-by: Hanabi <317387557+Hanabi9248@users.noreply.github.com>
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.
Reweighing currently tests whether a (group, label) cell contains rows, then divides by its summed sample weight. A cell containing only zero-weight rows produces inf/NaN, so ReweighingMeta passes NaN sample weights into otherwise valid estimators. For groups [0,0,1,1], labels [0,1,0,1] and weights [1,1,1,0], the last output weight becomes NaN instead of staying zero.
When total mass is positive and all weights in that cell are exactly zero, keep its output weights zero and leave the undefined cell factor NaN, as for an absent cell. Other cells use the original formula unchanged. This follows zero-weight sample removal semantics; it does not add mass to missing group/class combinations or claim independence on incomplete support. No epsilon/default factor or policy for all-zero total weights, negative weights or positive/negative cancellation is added.
Actual validation against main 3487791 on Python 3.11.16:
Run: python tests/test_reweighing_zero_weight.py -v
Full repository, existing Adult/download fixtures, other estimators/solvers/Python versions and negative/all-zero weight behavior were not tested. Existing optional rpy2/torch imports warn that unrelated algorithms are unavailable; these modules were not replaced or installed. AI assistance was used for preparation/review; reported test results are actual local executions.