Skip to content

TST: stats.rdist: skip failing xslow test #21953

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

Merged
merged 1 commit into from
Nov 27, 2024
Merged

Conversation

mdhaber
Copy link
Contributor

@mdhaber mdhaber commented Nov 26, 2024

Reference issue

Closes gh-21949

What does this implement/fix?

gh-21949 reported an xslow fit test failure. We changed from passing an integer seed to differential_evolution via rng instead of random_state, so it makes sense that we'd get some change in this test. We already adjusted tests after that (gh-21822), so this is something different.

Additional information

This generic test is performed for all distributions, but since our optimization techniques do not guarantee convergence to the global optimum for all possible problems, some tests fail. Sometimes we'll skip the generic test for a distribution and replace it with another one that is slightly easier for the optimizer to solve, e.g.

import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
from scipy.optimize import differential_evolution as de
from scipy.stats.tests.test_fit import assert_nlff_less_or_close

N = 1000
rng = np.random.default_rng(23854582452784625)
dist = stats.rdist
shapes = (1., 2., 3.)
data = dist.rvs(*shapes, size=N, random_state=rng)
shape_bounds = {'loc': (0.1, 10), 'scale': (0.1, 10), 'c': (0.1, 10)}
res = stats.fit(dist, data, shape_bounds, method='mse',
                optimizer=lambda *args, **kwds: de(*args, rng=rng, **kwds))
assert_nlff_less_or_close(dist, data, res.params, shapes, nlff_name='_penalized_nlpsf')
res.plot()
plt.show()
image

In this case, I think it's safe to just skip the test. beta has always had trouble, so it's not so surprising that rdist (symmetric beta) has trouble, and beta has a distribution-specific test, so I don't know that we need a separate one for a special case distribution.

@mdhaber mdhaber added scipy.optimize maintenance Items related to regular maintenance tasks labels Nov 26, 2024
@dschmitz89 dschmitz89 merged commit 36e349b into scipy:main Nov 27, 2024
1 check passed
@j-bowhay j-bowhay added this to the 1.15.0 milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.optimize scipy.stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: stats: XSLOW test failure in scipy.stats.tests.test_fit::TestFit
3 participants