fix: mask degenerate windows in Rsquare expanding path (N=0) - #2341
Open
tongflau-dongzhu wants to merge 1 commit into
Open
fix: mask degenerate windows in Rsquare expanding path (N=0)#2341tongflau-dongzhu wants to merge 1 commit into
tongflau-dongzhu wants to merge 1 commit into
Conversation
Near-constant input made var(y) ~= 0, so the expanding rsquare kernel leaked inf / garbage values. The NaN guard (isclose(std, 0)) existed only on the rolling branch; mirror it on the expanding branch. Fixes microsoft#2297
Author
|
@microsoft-github-policy-service agree |
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.
What
Mirrors the existing near-constant-window NaN guard from the rolling branch onto the expanding (N == 0) branch of Rsquare in qlib/data/ops.py.
Near-constant input makes �ar(y) ~= 0, so expanding_rsquare (kernel:
um / sqrt(var_x * var_y)) leaks inf / garbage values on the expanding path, while the rolling path already masks those windows:
`python
rolling branch (already guarded):
series.loc[np.isclose(_series.rolling(self.N, min_periods=1).std(), 0, atol=2e-05)] = np.nan
`
This PR applies the equivalent guard with expanding(min_periods=1).std() on the N == 0 branch.
Tests
Added ests/ops/test_rsquare.py:
The tests use a mocked feature (no data download / no qlib.init needed).
Fixes #2297