comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/random/tests/test_regression.py @ 87:2a2c65a20a8b

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