Skip to content

Commit 725e8c8

Browse files
authored
Merge pull request statsmodels#5196 from bashtage/fix-zero-inflated-poisson-minimize
TST: Set seed when using basin hopping
2 parents 5c9b6a4 + f5c79c8 commit 725e8c8

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

statsmodels/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import pytest
23

34

@@ -68,3 +69,24 @@ def close():
6869

6970
yield close
7071
close()
72+
73+
74+
@pytest.fixture()
75+
def reset_randomstate():
76+
"""
77+
Fixture that set the global RandomState to the fixed seed 1
78+
79+
Notes
80+
-----
81+
Used by passing as an argument to the function that uses the global
82+
RandomState
83+
84+
def test_some_plot(reset_randomstate):
85+
<test code>
86+
87+
Returns the state after the test function exits
88+
"""
89+
state = np.random.get_state()
90+
np.random.seed(1)
91+
yield
92+
np.random.set_state(state)

statsmodels/discrete/tests/test_count_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def test_t(self):
269269
t_test = self.res1.t_test(unit_matrix)
270270
assert_allclose(self.res1.tvalues, t_test.tvalue)
271271

272-
def test_minimize(self):
272+
def test_minimize(self, reset_randomstate):
273273
# check additional optimizers using the `minimize` option
274274
model = self.res1.model
275275
# use the same start_params, but avoid recomputing
@@ -380,7 +380,7 @@ def test_fit_regularized(self):
380380
atol=1e-1, rtol=1e-1)
381381

382382
# possibly slow, adds 25 seconds
383-
def test_minimize(self):
383+
def test_minimize(self, reset_randomstate):
384384
# check additional optimizers using the `minimize` option
385385
model = self.res1.model
386386
# use the same start_params, but avoid recomputing

statsmodels/discrete/tests/test_discrete.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def setup_class(cls):
424424
res2.probit()
425425
cls.res2 = res2
426426
fit = Probit(data.endog, data.exog).fit
427+
np.random.seed(1)
427428
cls.res1 = fit(method="basinhopping", disp=0, niter=5,
428429
minimizer={'method' : 'L-BFGS-B', 'tol' : 1e-8})
429430

statsmodels/tsa/tests/test_holtwinters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_invalid_start_param_length():
327327
mod.fit(start_params=np.array([0.5]))
328328

329329

330-
def test_basin_hopping():
330+
def test_basin_hopping(reset_randomstate):
331331
mod = ExponentialSmoothing(housing_data, trend='add')
332332
res = mod.fit()
333333
res2 = mod.fit(use_basinhopping=True)

0 commit comments

Comments
 (0)