Repository navigation
Description
Describe the bug
In Debian unstable and Debian testing (both statsmodels 0.13.2), the tests intermittently fail.
The difference is small, so I suspect rounding error (possibly the intermittency is hardware dependence? i.e. which test server happens to run it) and my first guess at what to do is to ignore it i.e. lower the required accuracy, but I don't know why the required accuracy on that test is set so high.
Code Sample, a copy-pastable example if possible
The standard test suite.
Example failure output:
=================================== FAILURES ===================================
_______________________ TestMVDistributions.test_mvn_pdf _______________________
self = <statsmodels.sandbox.distributions.tests.test_multivariate.TestMVDistributions object at 0x7fa1b57c1cf0>
def test_mvn_pdf(self):
cov3 = self.cov3
mvn3 = self.mvn3
r_val = [-7.667977543898155, -6.917977543898155, -5.167977543898155]
assert_array_almost_equal(mvn3.logpdf(cov3), r_val, decimal=14)
# decimal 18
r_val = [0.000467562492721686, 0.000989829804859273,
0.005696077243833402]
assert_array_almost_equal(mvn3.pdf(cov3), r_val, decimal=17)
E AssertionError:
E Arrays are not almost equal to 17 decimals
E
E Mismatched elements: 1 / 3 (33.3%)
E Max absolute difference: 1.56125113e-17
E Max relative difference: 4.40579422e-15
E x: array([0.00046756249272168, 0.00098982980485927, 0.00569607724383339])
E y: array([0.00046756249272169, 0.00098982980485927, 0.0056960772438334 ])
/usr/lib/python3/dist-packages/statsmodels/sandbox/distributions/tests/test_multivariate.py:136: AssertionError
Expected Output
The tests should all pass.
Output of import statsmodels.api as sm; sm.show_versions()
This is from unstable, with the test failing in Python 3.10.3; note that there have also been passing runs with Python 3.10 and numpy 1.21.
Activity
josef-pkt commentedon Mar 26, 2022
decimal=17 is too strict
I guess it was a tight bound when I wrote this. Since then I usually added more slack for differences across machines and linalg libraries.
based on the test failure message, we should switch to something like
assert_allclose(mvn3.pdf(cov3), r_val, rtol=1e-13)Same change can be applied to all 3 asserts in the test function/method.
Our usage of assert_array_almost_equal predates the existence of numpy assert_allclose
MAINT: Relax overly tight tolerance
MAINT: Relax overly tight tolerance
MAINT: Relax overly tight tolerance
MAINT: Relax overly tight tolerance