MCPcopy Create free account
hub / github.com/numpy/numpy / test_multivariate_normal

Method test_multivariate_normal

numpy/random/tests/test_randomstate.py:982–1031  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

980 assert_array_equal(actual, desired)
981
982 def test_multivariate_normal(self):
983 random.seed(self.seed)
984 mean = (.123456789, 10)
985 cov = [[1, 0], [0, 1]]
986 size = (3, 2)
987 actual = random.multivariate_normal(mean, cov, size)
988 desired = np.array([[[1.463620246718631, 11.73759122771936],
989 [1.622445133300628, 9.771356667546383]],
990 [[2.154490787682787, 12.170324946056553],
991 [1.719909438201865, 9.230548443648306]],
992 [[0.689515026297799, 9.880729819607714],
993 [-0.023054015651998, 9.201096623542879]]])
994
995 assert_array_almost_equal(actual, desired, decimal=15)
996
997 # Check for default size, was raising deprecation warning
998 actual = random.multivariate_normal(mean, cov)
999 desired = np.array([0.895289569463708, 9.17180864067987])
1000 assert_array_almost_equal(actual, desired, decimal=15)
1001
1002 # Check that non positive-semidefinite covariance warns with
1003 # RuntimeWarning
1004 mean = [0, 0]
1005 cov = [[1, 2], [2, 1]]
1006 assert_warns(RuntimeWarning, random.multivariate_normal, mean, cov)
1007
1008 # and that it doesn't warn with RuntimeWarning check_valid='ignore'
1009 assert_no_warnings(random.multivariate_normal, mean, cov,
1010 check_valid='ignore')
1011
1012 # and that it raises with RuntimeWarning check_valid='raises'
1013 assert_raises(ValueError, random.multivariate_normal, mean, cov,
1014 check_valid='raise')
1015
1016 cov = np.array([[1, 0.1], [0.1, 1]], dtype=np.float32)
1017 with suppress_warnings() as sup:
1018 random.multivariate_normal(mean, cov)
1019 w = sup.record(RuntimeWarning)
1020 assert len(w) == 0
1021
1022 mu = np.zeros(2)
1023 cov = np.eye(2)
1024 assert_raises(ValueError, random.multivariate_normal, mean, cov,
1025 check_valid='other')
1026 assert_raises(ValueError, random.multivariate_normal,
1027 np.zeros((2, 1, 1)), cov)
1028 assert_raises(ValueError, random.multivariate_normal,
1029 mu, np.empty((3, 2)))
1030 assert_raises(ValueError, random.multivariate_normal,
1031 mu, np.eye(3))
1032
1033 def test_negative_binomial(self):
1034 random.seed(self.seed)

Callers

nothing calls this directly

Calls 6

assert_warnsFunction · 0.90
assert_no_warningsFunction · 0.90
assert_raisesFunction · 0.90
suppress_warningsClass · 0.90
recordMethod · 0.80

Tested by

no test coverage detected