annotate DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/random/tests/test_regression.py @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2a2c65a20a8b
children
rev   line source
Chris@87 1 from __future__ import division, absolute_import, print_function
Chris@87 2
Chris@87 3 from numpy.testing import (TestCase, run_module_suite, assert_,
Chris@87 4 assert_array_equal)
Chris@87 5 from numpy import random
Chris@87 6 from numpy.compat import long
Chris@87 7 import numpy as np
Chris@87 8
Chris@87 9
Chris@87 10 class TestRegression(TestCase):
Chris@87 11
Chris@87 12 def test_VonMises_range(self):
Chris@87 13 # Make sure generated random variables are in [-pi, pi].
Chris@87 14 # Regression test for ticket #986.
Chris@87 15 for mu in np.linspace(-7., 7., 5):
Chris@87 16 r = random.mtrand.vonmises(mu, 1, 50)
Chris@87 17 assert_(np.all(r > -np.pi) and np.all(r <= np.pi))
Chris@87 18
Chris@87 19 def test_hypergeometric_range(self):
Chris@87 20 # Test for ticket #921
Chris@87 21 assert_(np.all(np.random.hypergeometric(3, 18, 11, size=10) < 4))
Chris@87 22 assert_(np.all(np.random.hypergeometric(18, 3, 11, size=10) > 0))
Chris@87 23
Chris@87 24 def test_logseries_convergence(self):
Chris@87 25 # Test for ticket #923
Chris@87 26 N = 1000
Chris@87 27 np.random.seed(0)
Chris@87 28 rvsn = np.random.logseries(0.8, size=N)
Chris@87 29 # these two frequency counts should be close to theoretical
Chris@87 30 # numbers with this large sample
Chris@87 31 # theoretical large N result is 0.49706795
Chris@87 32 freq = np.sum(rvsn == 1) / float(N)
Chris@87 33 msg = "Frequency was %f, should be > 0.45" % freq
Chris@87 34 assert_(freq > 0.45, msg)
Chris@87 35 # theoretical large N result is 0.19882718
Chris@87 36 freq = np.sum(rvsn == 2) / float(N)
Chris@87 37 msg = "Frequency was %f, should be < 0.23" % freq
Chris@87 38 assert_(freq < 0.23, msg)
Chris@87 39
Chris@87 40 def test_permutation_longs(self):
Chris@87 41 np.random.seed(1234)
Chris@87 42 a = np.random.permutation(12)
Chris@87 43 np.random.seed(1234)
Chris@87 44 b = np.random.permutation(long(12))
Chris@87 45 assert_array_equal(a, b)
Chris@87 46
Chris@87 47 def test_randint_range(self):
Chris@87 48 # Test for ticket #1690
Chris@87 49 lmax = np.iinfo('l').max
Chris@87 50 lmin = np.iinfo('l').min
Chris@87 51 try:
Chris@87 52 random.randint(lmin, lmax)
Chris@87 53 except:
Chris@87 54 raise AssertionError
Chris@87 55
Chris@87 56 def test_shuffle_mixed_dimension(self):
Chris@87 57 # Test for trac ticket #2074
Chris@87 58 for t in [[1, 2, 3, None],
Chris@87 59 [(1, 1), (2, 2), (3, 3), None],
Chris@87 60 [1, (2, 2), (3, 3), None],
Chris@87 61 [(1, 1), 2, 3, None]]:
Chris@87 62 np.random.seed(12345)
Chris@87 63 shuffled = list(t)
Chris@87 64 random.shuffle(shuffled)
Chris@87 65 assert_array_equal(shuffled, [t[0], t[3], t[1], t[2]])
Chris@87 66
Chris@87 67 def test_call_within_randomstate(self):
Chris@87 68 # Check that custom RandomState does not call into global state
Chris@87 69 m = np.random.RandomState()
Chris@87 70 res = np.array([0, 8, 7, 2, 1, 9, 4, 7, 0, 3])
Chris@87 71 for i in range(3):
Chris@87 72 np.random.seed(i)
Chris@87 73 m.seed(4321)
Chris@87 74 # If m.state is not honored, the result will change
Chris@87 75 assert_array_equal(m.choice(10, size=10, p=np.ones(10)/10.), res)
Chris@87 76
Chris@87 77 def test_multivariate_normal_size_types(self):
Chris@87 78 # Test for multivariate_normal issue with 'size' argument.
Chris@87 79 # Check that the multivariate_normal size argument can be a
Chris@87 80 # numpy integer.
Chris@87 81 np.random.multivariate_normal([0], [[0]], size=1)
Chris@87 82 np.random.multivariate_normal([0], [[0]], size=np.int_(1))
Chris@87 83 np.random.multivariate_normal([0], [[0]], size=np.int64(1))
Chris@87 84
Chris@87 85 if __name__ == "__main__":
Chris@87 86 run_module_suite()