-
Notifications
You must be signed in to change notification settings - Fork 325
[BUG] Guard default RidgeClassifierCV against LAPACK SVD overflow #3755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aashoday
wants to merge
7
commits into
aeon-toolkit:main
Choose a base branch
from
aashoday:fix/3737-large-memory-precision
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f5d06a3
[BUG] Guard default RidgeClassifierCV against 32-bit LAPACK SVD overflow
aashoday 7a8cec4
[BUG] Add tests for LAPACK SVD overflow check
aashoday 5996be3
[DOC] Add check_lapack_svd_safe to API reference (#3737)
aashoday 7e8cadf
[BUG] Fix RocketClassifier predict_proba passing raw 3D X to estimato…
aashoday 6eac085
[BUG] Skip MultiRocketHydraClassifier LAPACK tests when torch is unav…
aashoday 3382635
trigger CI re-run
aashoday 6ae364c
Merge branch 'main' into fix/3737-large-memory-precision
aashoday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
53 changes: 53 additions & 0 deletions
53
aeon/classification/convolution_based/tests/test_mr_hydra.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """MultiRocketHydra classifier tests.""" | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from sklearn.linear_model import RidgeClassifier | ||
|
|
||
| from aeon.classification.convolution_based import MultiRocketHydraClassifier | ||
| from aeon.testing.data_generation import make_example_3d_numpy | ||
| from aeon.utils.validation._dependencies import _check_soft_dependencies | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not _check_soft_dependencies("torch", severity="none"), | ||
| reason="skip test if required soft dependency not available", | ||
| ) | ||
| def test_mrhydra_calls_lapack_check_with_default_estimator(): | ||
| """Check LAPACK safety when using the default estimator. | ||
|
|
||
| MultiRocketHydra should call check_lapack_svd_safe when estimator is None. | ||
| """ | ||
| X, y = make_example_3d_numpy(n_cases=10, n_channels=1, n_timepoints=12) | ||
| clf = MultiRocketHydraClassifier(n_kernels=2, n_groups=2) | ||
|
|
||
| with patch( | ||
| "aeon.classification.convolution_based._mr_hydra.check_lapack_svd_safe" | ||
| ) as mock_check: | ||
| clf.fit(X, y) | ||
|
|
||
| mock_check.assert_called_once() | ||
| args, _ = mock_check.call_args | ||
| assert args[2] == "MultiRocketHydraClassifier" | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not _check_soft_dependencies("torch", severity="none"), | ||
| reason="skip test if required soft dependency not available", | ||
| ) | ||
| def test_mrhydra_skips_lapack_check_with_custom_estimator(): | ||
| """Skip the LAPACK safety check with a custom estimator. | ||
|
|
||
| MultiRocketHydra should not call check_lapack_svd_safe when a custom | ||
| estimator is supplied. | ||
| """ | ||
| X, y = make_example_3d_numpy(n_cases=10, n_channels=1, n_timepoints=12) | ||
| clf = MultiRocketHydraClassifier(n_kernels=2, estimator=RidgeClassifier()) | ||
|
|
||
| with patch( | ||
| "aeon.classification.convolution_based._mr_hydra.check_lapack_svd_safe" | ||
| ) as mock_check: | ||
| clf.fit(X, y) | ||
|
|
||
| mock_check.assert_not_called() |
36 changes: 36 additions & 0 deletions
36
aeon/classification/convolution_based/tests/test_rocket.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """Rocket classifier tests.""" | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| from sklearn.linear_model import RidgeClassifier | ||
|
|
||
| from aeon.classification.convolution_based import RocketClassifier | ||
| from aeon.testing.data_generation import make_example_3d_numpy | ||
|
|
||
|
|
||
| def test_rocket_calls_lapack_check_with_default_estimator(): | ||
| """RocketClassifier should call check_lapack_svd_safe when estimator is None.""" | ||
| X, y = make_example_3d_numpy(n_cases=10, n_channels=1, n_timepoints=12) | ||
| clf = RocketClassifier(n_kernels=20) | ||
|
|
||
| with patch( | ||
| "aeon.classification.convolution_based._rocket.check_lapack_svd_safe" | ||
| ) as mock_check: | ||
| clf.fit(X, y) | ||
|
|
||
| mock_check.assert_called_once() | ||
| args, _ = mock_check.call_args | ||
| assert args[2] == "RocketClassifier" | ||
|
|
||
|
|
||
| def test_rocket_skips_lapack_check_with_custom_estimator(): | ||
| """RocketClassifier should not call check_lapack_svd_safe with custom estimator.""" | ||
| X, y = make_example_3d_numpy(n_cases=10, n_channels=1, n_timepoints=12) | ||
| clf = RocketClassifier(n_kernels=20, estimator=RidgeClassifier()) | ||
|
|
||
| with patch( | ||
| "aeon.classification.convolution_based._rocket.check_lapack_svd_safe" | ||
| ) as mock_check: | ||
| clf.fit(X, y) | ||
|
|
||
| mock_check.assert_not_called() |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how relevant this is in this context but it is not necessary that LAPACK will overflow for more than 2**31 - 1 elements, it is only the case in the default LP64 scipy build. However, now SciPy supports ILP64 builds which can accomodate far large matrices (upto 64 bit integer indices), see these release notes, if we add these checks it will mostly work okay in the default SciPy but will restrict user who specifically use ILP64 SciPy builds.
Therefore, the more robust way would be to query scipy: