Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 42add1e

Browse files
author
ariddell
committed
TST: adjust ess test for new accept rate in 2.15
In 2.15, @betanalpha "changed the way the accept rate was calculated by excluding the initial state from the numerator and denominator."[^1] This lowers the ess considerably for the simple model used in this test. [^1] http://discourse.mc-stan.org/t/much-lower-effective-sample-size-with-2-15/348
1 parent 814dba6 commit 42add1e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

pystan/tests/test_ess.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
import pystan.chains
55
import pystan._chains
66

7-
# NOTE: This test is fragile because there is no guarantee that samples are
8-
# consistent between Stan releases (even with fixed random seeds). Consider
9-
# this a smoke test.
7+
# NOTE: This test is fragile because the default sampling algorithm used by Stan
8+
# may change in significant ways.
9+
1010

1111
class TestESS(unittest.TestCase):
1212

1313
@classmethod
1414
def setUpClass(cls):
1515
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
16-
model = pystan.StanModel(model_code=model_code, model_name="normal2")
17-
cls.fit = model.sampling(iter=4000, chains=2, seed=5)
16+
model = pystan.StanModel(model_code=model_code)
17+
cls.fits = [model.sampling(iter=4000, chains=2, seed=i) for i in range(10)]
1818

1919
def test_ess(self):
20-
sim = self.fit.sim
21-
ess = pystan.chains.ess(sim, sim['fnames_oi'].index('y'))
22-
self.assertGreater(ess, 2000)
20+
sims = [fit.sim for fit in self.fits]
21+
esses = [pystan.chains.ess(sim, sim['fnames_oi'].index('y')) for sim in sims]
22+
# in Stan 2.15 the default acceptance rate was changed, ess dropped
23+
self.assertGreater(sum(esses) / len(esses), 1200)

0 commit comments

Comments
 (0)