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

Method test_multivariate_normal

numpy/random/tests/test_random.py:767–805  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

765 assert_array_equal(actual, desired)
766
767 def test_multivariate_normal(self):
768 np.random.seed(self.seed)
769 mean = (.123456789, 10)
770 cov = [[1, 0], [0, 1]]
771 size = (3, 2)
772 actual = np.random.multivariate_normal(mean, cov, size)
773 desired = np.array([[[1.463620246718631, 11.73759122771936],
774 [1.622445133300628, 9.771356667546383]],
775 [[2.154490787682787, 12.170324946056553],
776 [1.719909438201865, 9.230548443648306]],
777 [[0.689515026297799, 9.880729819607714],
778 [-0.023054015651998, 9.201096623542879]]])
779
780 assert_array_almost_equal(actual, desired, decimal=15)
781
782 # Check for default size, was raising deprecation warning
783 actual = np.random.multivariate_normal(mean, cov)
784 desired = np.array([0.895289569463708, 9.17180864067987])
785 assert_array_almost_equal(actual, desired, decimal=15)
786
787 # Check that non positive-semidefinite covariance warns with
788 # RuntimeWarning
789 mean = [0, 0]
790 cov = [[1, 2], [2, 1]]
791 assert_warns(RuntimeWarning, np.random.multivariate_normal, mean, cov)
792
793 # and that it doesn't warn with RuntimeWarning check_valid='ignore'
794 assert_no_warnings(np.random.multivariate_normal, mean, cov,
795 check_valid='ignore')
796
797 # and that it raises with RuntimeWarning check_valid='raises'
798 assert_raises(ValueError, np.random.multivariate_normal, mean, cov,
799 check_valid='raise')
800
801 cov = np.array([[1, 0.1], [0.1, 1]], dtype=np.float32)
802 with suppress_warnings() as sup:
803 np.random.multivariate_normal(mean, cov)
804 w = sup.record(RuntimeWarning)
805 assert len(w) == 0
806
807 def test_negative_binomial(self):
808 np.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