fix: reduce_factors NaN aggregation silently corrupted other observables - #127
Merged
Conversation
…les (#119) reduce_factors aggregated per-factor importance across observables via np.maximum, which propagates NaN (np.maximum(4.05, nan) == nan). A single observable that's legitimately undefined in some regimes (e.g. a Type-I rate, only meaningful when the null hypothesis is true -- a completely reasonable, common Scorer pattern) silently erased a real, significant importance value found via a *different* observable for the same factor, dropping it from reduce_factors' output with no warning or error. Found in practice: yoavram-lab/pp-eigentest's Phase 1a screen had a factor (alpha) with a real, large Morris importance (mu*=4.05, far above threshold) on one observable, silently excluded because a different NaN-valued observable happened to appear later in the importance dict's iteration order. Worked around locally there (filtering NaN observables before the call); this is the actual fix. Uses np.fmax (NaN-safe) instead, seeded with NaN rather than zero so a factor with zero valid measurements across every observable stays NaN throughout rather than settling at a falsely-confident 0.0 -- and warns when that happens, since it reflects missing data, not confirmed unimportance. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.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.
Summary
Closes #119.
reduce_factors()aggregated per-factor importance across observables vianp.maximum, which propagates NaN (np.maximum(4.05, nan) == nan). A single observable that's legitimately undefined in some regimes (e.g. a Type-I error rate, only meaningful when the null hypothesis is true -- a completely reasonable, commonScorerpattern) silently erased a real, significant importance value found via a different observable for the same factor, dropping it from the output with no warning or error.Where this surfaced
yoavram-lab/pp-eigentest's Phase 1a Morris screen had a factor (
alpha) with a real, large importance (mu*=4.05, far above threshold) onmae_seq, silently excluded fromreduce_factors' output because a different, NaN-valued observable (type_i_rate_*, NaN by design outside null regimes) happened to appear later in theimportancedict's iteration order. Worked around locally there at the time (filtering NaN-containing observables before the call); this PR is the actual upstream fix.Change
np.fmax(NaN-safe: ignores NaN in either operand) instead ofnp.maximum.NaN, not0.0: a factor with zero valid (non-NaN) measurements across every observable now correctly staysNaNthroughout rather than silently settling at a falsely-confident0.0(which would look identical to "tested and found unimportant").threshold), but now visibly, since that's missing data, not confirmed unimportance.Test plan
just cipasses,design.pyat 99% coverage🤖 Generated with Claude Code