Changeset 6664

Show
Ignore:
Timestamp:
03/14/09 15:18:53 (18 months ago)
Author:
charris
Message:

Fix tickets #921 and #923. Add regression tests.

Location:
trunk/numpy/random
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/numpy/random/mtrand/distributions.c

    r6596 r6664  
    815815     
    816816    /* another fix from rv.py to allow sample to exceed popsize/2 */ 
    817     if (m < sample) Z = bad - Z; 
     817    if (m < sample) Z = good - Z; 
    818818     
    819819    return Z; 
     
    877877            } 
    878878        } 
    879         if (V <= q) { 
     879        if (V >= q) { 
    880880            return 1; 
    881881        } 
  • trunk/numpy/random/tests/test_random.py

    r6596 r6664  
    22from numpy import random 
    33import numpy as np 
     4 
     5class TestRegression(TestCase): 
     6 
     7    def test_VonMises_range(self): 
     8        """Make sure generated random variables are in [-pi, pi]. 
     9 
     10        Regression test for ticket #986. 
     11        """ 
     12        for mu in np.linspace(-7., 7., 5): 
     13            r = random.mtrand.vonmises(mu,1,50) 
     14            assert np.all(r > -np.pi) and np.all(r <= np.pi) 
     15 
     16    def test_hypergeometric_range(self) : 
     17        """Test for ticket #921""" 
     18        assert_(np.all(np.random.hypergeometric(3, 18, 11, size=10) < 4)) 
     19        assert_(np.all(np.random.hypergeometric(18, 3, 11, size=10) > 0)) 
     20 
     21    def test_logseries_convergence(self) : 
     22        """Test for ticket #923""" 
     23        N = 100000 
     24        rvsn = np.random.logseries(0.8, size=N) 
     25        # these two frequency counts should be close to theoretical 
     26        # numbers with this large sample 
     27        # theoretical large N result is 0.49706795 
     28        freq = np.sum(rvsn == 1) / float(N) 
     29        msg = "Obsevered frequency was %f, should be > 0.45" % freq 
     30        assert_(freq > 0.45, msg) 
     31        # theoretical large N result is 0.19882718 
     32        freq = np.sum(rvsn == 2) / float(N) 
     33        msg = "Obsevered frequency was %f, should be < 0.23" % freq 
     34        assert_(freq < 0.23, msg) 
     35 
    436 
    537class TestMultinomial(TestCase): 
     
    1547        assert np.all(-5 <= x) 
    1648        assert np.all(x < -1) 
    17  
    18 class TestVonMises(TestCase): 
    19     def test_output_domain(self): 
    20         """Make sure generated random variables are in [-pi, pi]. 
    21  
    22         Regression test for ticket #986. 
    23         """ 
    24         for mu in np.linspace(-7., 7., 5):         
    25             r = random.mtrand.vonmises(mu,1,50) 
    26             assert np.all(r>-np.pi) and np.all(r<=np.pi) 
    2749 
    2850