def testDistributionOfStatelessRandomUniform(self): """Use Pearson's Chi-squared test to test for uniformity.""" with self.cached_session() as sess, self.test_scope(): for dtype in self._random_types(): seed_t = array_ops.placeholder(dtypes.int32, shape=[2]) n = 1000 x = stateless.stateless_random_uniform(shape=[n], seed=seed_t, dtype=dtype) y = sess.run(x, {seed_t: [565656, 121212]}) # Tests that the values are distributed amongst 10 bins with equal # probability. 16.92 is the Chi^2 value for 9 degrees of freedom with # p=0.05. This test is probabilistic and would be flaky if the random # seed were not fixed. self.assertLess(random_test_util.chi_squared(y, 10), 16.92)
def testDistributionOfUniform(self, dtype): """Use Pearson's Chi-squared test to test for uniformity.""" n = 1000 seed = 12 gen = random.Generator(seed=seed) maxval = 1 if dtype.is_integer: maxval = 100 x = gen.uniform(shape=[n], maxval=maxval, dtype=dtype).numpy() if maxval > 1: # Normalize y to range [0, 1). x = x.astype(float) / maxval # Tests that the values are distributed amongst 10 bins with equal # probability. 16.92 is the Chi^2 value for 9 degrees of freedom with # p=0.05. This test is probabilistic and would be flaky if the random # seed were not fixed. val = random_test_util.chi_squared(x, 10) self.assertLess(val, 16.92)
def testDistributionOfStatelessRandomUniform(self): """Use Pearson's Chi-squared test to test for uniformity.""" with self.session() as sess, self.test_scope(): for dtype in self._random_types(include_int=True): seed_t = array_ops.placeholder(dtypes.int32, shape=[2]) n = 1000 maxval = 1 if dtype.is_integer: maxval = 100 x = stateless.stateless_random_uniform( shape=[n], seed=seed_t, maxval=maxval, dtype=dtype) y = sess.run(x, {seed_t: [565656, 121212]}) # Convert y to float and normalize its value to range [0, 1) when # maxval != 1. y = y.astype(float) / maxval # Tests that the values are distributed amongst 10 bins with equal # probability. 16.92 is the Chi^2 value for 9 degrees of freedom with # p=0.05. This test is probabilistic and would be flaky if the random # seed were not fixed. self.assertLess(random_test_util.chi_squared(y, 10), 16.92)
def testDistributionOfStatelessRandomUniform(self): """Use Pearson's Chi-squared test to test for uniformity.""" with self.cached_session() as sess, self.test_scope(): for dtype in self._random_types(include_int=True): seed_t = array_ops.placeholder(dtypes.int32, shape=[2]) n = 1000 maxval = 1 if dtype.is_integer: maxval = 100 x = stateless.stateless_random_uniform( shape=[n], seed=seed_t, maxval=maxval, dtype=dtype) y = sess.run(x, {seed_t: [565656, 121212]}) if maxval > 1: # Normalize y to range [0, 1). y = y.astype(float) / maxval # Tests that the values are distributed amongst 10 bins with equal # probability. 16.92 is the Chi^2 value for 9 degrees of freedom with # p=0.05. This test is probabilistic and would be flaky if the random # seed were not fixed. self.assertLess(random_test_util.chi_squared(y, 10), 16.92)