Skip to content

multivariate_normal not consistent between mkl and nomkl numpy #13358

Closed

Description

@horta

Steps to reproduce

$ docker run -it continuumio/anaconda3:latest /bin/bash
$ conda create -n test_mkl python=3.7 numpy --yes
$ conda activate test_mkl
$ wget https://srv-file1.gofile.io/download/USEQai/41e47ac59aa2fea4dd9645dce24021ca/script.py
$ python script.py
[-0.70229542  0.73599141  2.13543129  1.64404824  2.12712574 -1.58018728
 -0.38363905 -2.45019446 -1.69595713 -0.82972203  1.10545712 -0.17479736]
$ conda create -n test_nomkl python=3.7 --yes
$ conda activate test_nomkl
$ pip install numpy
$ python script.py
[-0.70052624  0.7301344   2.14324804  1.64546151  2.13153172 -1.58305101
 -0.39244538 -2.43923923 -1.6997689  -0.82137822  1.10012343 -0.1871725 ]

The script it downloads and run is the following:

import urllib.request
import numpy as np

url = "https://srv-file1.gofile.io/download/0CZT37/41e47ac59aa2fea4dd9645dce24021ca/K.npy"
urllib.request.urlretrieve(url, "K.npy")
K = np.load("K.npy")
mvn = np.random.RandomState(0).multivariate_normal
print(mvn(np.zeros(K.shape[0]), K))

Matrix K is very small to the point I could reproduce the error.

Activity

  1. horta commented on Apr 17, 2019

    @horta
    Author

    The problem lies in numpy.dual.svd:

    $ docker run -it continuumio/anaconda3:latest /bin/bash
    $ conda create -n test_mkl python=3.7 numpy --yes
    $ conda activate test_mkl
    $ wget https://srv-file1.gofile.io/download/bRLqH7/41e47ac59aa2fea4dd9645dce24021ca/script-save.py
    $ python script-save.py
    $ conda create -n test_nomkl python=3.7 --yes
    $ conda activate test_nomkl
    $ pip install numpy
    $ wget https://srv-file1.gofile.io/download/JlJCVt/41e47ac59aa2fea4dd9645dce24021ca/script-load.py
    $ python script-load.py
    2.3534794732541338
    2.3068937965514184e-15
    2.3534794732541626

    The scripts are:

    # script-save.py
    import urllib.request
    import numpy as np
    import numpy.dual
    
    url = "https://srv-file1.gofile.io/download/0CZT37/41e47ac59aa2fea4dd9645dce24021ca/K.npy"
    urllib.request.urlretrieve(url, "K.npy")
    K = np.load("K.npy")
    S, V, D = np.dual.svd(K)
    np.save("S", S)
    np.save("V", V)
    np.save("D", D)
    # script-load.py
    import numpy as np
    import numpy.dual
    
    S = np.load("S.npy")
    V = np.load("V.npy")
    D = np.load("D.npy")
    
    S2, V2, D2 = np.dual.svd(np.load("K.npy"))
    
    print(np.linalg.norm(S - S2))
    print(np.linalg.norm(V - V2))
    print(np.linalg.norm(D - D2))
  2. bashtage commented on Apr 20, 2019

    @bashtage
    Contributor

    This is inevitable since it depends on a SVD, and so the result conditional on the linear algebra library.

  3. horta commented on Apr 22, 2019

    @horta
    Author

    We could replace SVD decomposition with pivoted Cholesky decomposition. Please, refer to the above issue I just created.

  4. bashtage commented on Sep 13, 2019

    @bashtage
    Contributor

    @horta Since does pivoted Cholesky ultimately use BLAS routines? If it does, then this type of non-determinacy might not be easy to resolve.

  5. horta commented on Sep 13, 2019

    @horta
    Author

    There are multiple (infinite) SVD decompositions for semi-definite positive matrices, whereas pivoted Cholesky decomposition has a single one, as far as I know.

    (rounding error is not being tackled by the above proposition...)

  6. rossbar commented on May 20, 2020

    @rossbar
    Contributor

    It's been a few months since this was reported - given the deprecation of dual in #16156 and the improvements in #14197, is this still an issue?

  7. horta commented on May 21, 2020

    @horta
    Author

    I'm fine with closing it.

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions