Back to index

python3.2  3.2.2
Public Member Functions
test.test_random.TestDistributions Class Reference

List of all members.

Public Member Functions

def test_zeroinputs
def test_avg_std

Detailed Description

Definition at line 430 of file test_random.py.


Member Function Documentation

Definition at line 449 of file test_random.py.

00449 
00450     def test_avg_std(self):
00451         # Use integration to test distribution average and standard deviation.
00452         # Only works for distributions which do not consume variates in pairs
00453         g = random.Random()
00454         N = 5000
00455         x = [i/float(N) for i in range(1,N)]
00456         for variate, args, mu, sigmasqrd in [
00457                 (g.uniform, (1.0,10.0), (10.0+1.0)/2, (10.0-1.0)**2/12),
00458                 (g.triangular, (0.0, 1.0, 1.0/3.0), 4.0/9.0, 7.0/9.0/18.0),
00459                 (g.expovariate, (1.5,), 1/1.5, 1/1.5**2),
00460                 (g.paretovariate, (5.0,), 5.0/(5.0-1),
00461                                   5.0/((5.0-1)**2*(5.0-2))),
00462                 (g.weibullvariate, (1.0, 3.0), gamma(1+1/3.0),
00463                                   gamma(1+2/3.0)-gamma(1+1/3.0)**2) ]:
00464             g.random = x[:].pop
00465             y = []
00466             for i in range(len(x)):
00467                 try:
00468                     y.append(variate(*args))
00469                 except IndexError:
00470                     pass
00471             s1 = s2 = 0
00472             for e in y:
00473                 s1 += e
00474                 s2 += (e - mu) ** 2
00475             N = len(y)
00476             self.assertAlmostEqual(s1/N, mu, places=2)
00477             self.assertAlmostEqual(s2/(N-1), sigmasqrd, places=2)

Here is the call graph for this function:

Definition at line 431 of file test_random.py.

00431 
00432     def test_zeroinputs(self):
00433         # Verify that distributions can handle a series of zero inputs'
00434         g = random.Random()
00435         x = [g.random() for i in range(50)] + [0.0]*5
00436         g.random = x[:].pop; g.uniform(1,10)
00437         g.random = x[:].pop; g.paretovariate(1.0)
00438         g.random = x[:].pop; g.expovariate(1.0)
00439         g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
00440         g.random = x[:].pop; g.normalvariate(0.0, 1.0)
00441         g.random = x[:].pop; g.gauss(0.0, 1.0)
00442         g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
00443         g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
00444         g.random = x[:].pop; g.gammavariate(0.01, 1.0)
00445         g.random = x[:].pop; g.gammavariate(1.0, 1.0)
00446         g.random = x[:].pop; g.gammavariate(200.0, 1.0)
00447         g.random = x[:].pop; g.betavariate(3.0, 3.0)
00448         g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0)


The documentation for this class was generated from the following file: