Skip to content

TestMVDistributions.test_mvn_pdf intermittently failing - rounding error? #8195

Closed

Description

@rebecca-palmer

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.

Details Setting up python3-numpy (1:1.21.5-1) ... Setting up python3-statsmodels-lib:amd64 (0.13.2+dfsg-1) ... Setting up python3-scipy (1.7.3-2) ... Setting up python3-pytest (6.2.5-2) ... Setting up python3-pandas-lib:amd64 (1.3.5+dfsg-3) ... Setting up python3-patsy (0.5.2-2) ... Setting up python3-pandas (1.3.5+dfsg-3) ... Setting up python3-statsmodels (0.13.2+dfsg-1) ... Setting up python3-fonttools (4.29.1-2) ... Setting up python3-pil.imagetk:amd64 (9.0.1-1) ... Setting up python3-ufolib2 (0.13.1+dfsg1-1) ... Setting up python3-pil:amd64 (9.0.1-1) ... Setting up python3-matplotlib (3.5.1-2+b1) ...

Activity

  1. added this to the 0.14 milestone on Mar 26, 2022
  2. josef-pkt commented on Mar 26, 2022

    @josef-pkt
    Member

    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

  3. added 4 commits that reference this issue on Apr 6, 2022
    b97cd18
    e2ed5cf
    d782800
    7af32db
  4. modified the milestones: 0.14, 0.13.2, 0.13.3 on Oct 30, 2022
  5. modified the milestones: 0.13.3, 0.14 on Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions