summaryrefslogtreecommitdiff
path: root/numpy/random/tests/test_random.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-03-13 16:07:31 -0600
committerCharles Harris <charlesr.harris@gmail.com>2014-03-22 17:34:42 -0600
commit1c825f38d74bd9435c0b0c691dbea0a36a1ab0af (patch)
treec5f07246b0af0955d6c6de030b673baa9b3bed3f /numpy/random/tests/test_random.py
parentd36f81372229aac3455dcb69b784e1363d290239 (diff)
downloadnumpy-1c825f38d74bd9435c0b0c691dbea0a36a1ab0af.tar.gz
TST: Add some tests for random.multivariate_normal.
Explicitly Test that the default shape does not raise a DeprecationWarning. Check that a covariance matrix that is not positive-semidefinite raises a RuntimeWarning.
Diffstat (limited to 'numpy/random/tests/test_random.py')
-rw-r--r--numpy/random/tests/test_random.py33
1 files changed, 23 insertions, 10 deletions
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index 1b18713cf..c30037e1e 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -1,10 +1,11 @@
from __future__ import division, absolute_import, print_function
-from numpy.testing import TestCase, run_module_suite, assert_,\
- assert_raises, assert_equal
+import numpy as np
+from numpy.testing import (
+ TestCase, run_module_suite, assert_, assert_raises, assert_equal,
+ assert_warns)
from numpy import random
from numpy.compat import asbytes
-import numpy as np
class TestBinomial(TestCase):
@@ -427,20 +428,32 @@ class TestRandomDist(TestCase):
def test_multivariate_normal(self):
np.random.seed(self.seed)
mean= (.123456789, 10)
+ # Hmm... not even symmetric.
cov = [[1, 0], [1, 0]]
size = (3, 2)
actual = np.random.multivariate_normal(mean, cov, size)
- desired = np.array([[[ -1.47027513018564449, 10. ],
- [ -1.65915081534845532, 10. ]],
- [[ -2.29186329304599745, 10. ],
- [ -1.77505606019580053, 10. ]],
- [[ -0.54970369430044119, 10. ],
- [ 0.29768848031692957, 10. ]]])
+ desired = np.array([[[-1.47027513018564449, 10.],
+ [-1.65915081534845532, 10.]],
+ [[-2.29186329304599745, 10.],
+ [-1.77505606019580053, 10.]],
+ [[-0.54970369430044119, 10.],
+ [ 0.29768848031692957, 10.]]])
np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+ # Check for default size, was raising deprecation warning
+ actual = np.random.multivariate_normal(mean, cov)
+ desired = np.array([-0.79441224511977482, 10.])
+ np.testing.assert_array_almost_equal(actual, desired, decimal=15)
+
+ # Check that non positive-semidefinite covariance raises warning
+ mean= [0, 0]
+ cov = [[1, 1 + 1e-10], [1 + 1e-10, 1]]
+ rng = np.random.multivariate_normal
+ assert_warns(RuntimeWarning, np.random.multivariate_normal, mean, cov)
+
def test_negative_binomial(self):
np.random.seed(self.seed)
- actual = np.random.negative_binomial(n = 100, p = .12345, size = (3, 2))
+ actual = np.random.negative_binomial(n=100, p=.12345, size=(3, 2))
desired = np.array([[848, 841],
[892, 611],
[779, 647]])