コード例 #1
0
 def testInitFromOtherSeedStream(self):
   strm1 = tfp.util.SeedStream(seed=4, salt='salt')
   strm2 = tfp.util.SeedStream(strm1, salt='salt')
   strm3 = tfp.util.SeedStream(strm1, salt='another salt')
   out1 = [samplers.get_integer_seed(strm1()) for _ in range(50)]
   out2 = [samplers.get_integer_seed(strm2()) for _ in range(50)]
   out3 = [samplers.get_integer_seed(strm3()) for _ in range(50)]
   self.assertAllEqual(out1, out2)
   self.assertAllUnique(out1 + out3)
コード例 #2
0
 def testReproducibility(self):
   strm1 = tfp.util.SeedStream(seed=4, salt='salt')
   strm2 = tfp.util.SeedStream(seed=4, salt='salt')
   strm3 = tfp.util.SeedStream(seed=4, salt='salt')
   outputs = [samplers.get_integer_seed(strm1()) for _ in range(50)]
   self.assertEqual(outputs,
                    [samplers.get_integer_seed(strm2()) for _ in range(50)])
   self.assertEqual(outputs,
                    [samplers.get_integer_seed(strm3()) for _ in range(50)])
コード例 #3
0
 def testNestingRobustness(self):
   # SeedStreams started from generated seeds should not collide with
   # the initial seed or with each other, even if the salts are the same.
   strm1 = tfp.util.SeedStream(seed=4, salt='salt')
   strm2 = tfp.util.SeedStream(strm1(), salt='salt')
   strm3 = tfp.util.SeedStream(strm1(), salt='salt')
   outputs = [samplers.get_integer_seed(strm1()) for _ in range(50)]
   self.assertAllUnique(
       outputs + [samplers.get_integer_seed(strm2()) for _ in range(50)] +
       [samplers.get_integer_seed(strm3()) for _ in range(50)])
コード例 #4
0
 def testNonRepetition(self):
   # The probability of repetitions in a short stream from a correct
   # PRNG is negligible; this test catches bugs that prevent state
   # updates.
   strm = tfp.util.SeedStream(seed=4, salt='salt')
   output = [samplers.get_integer_seed(strm()) for _ in range(50)]
   self.assertEqual(sorted(output), sorted(list(set(output))))
コード例 #5
0
 def testSaltedDistinctness(self):
   strm1 = tfp.util.SeedStream(seed=4, salt='salt')
   strm2 = tfp.util.SeedStream(seed=4, salt='another salt')
   self.assertAllUnique(
       [samplers.get_integer_seed(strm1()) for _ in range(50)] +
       [samplers.get_integer_seed(strm2()) for _ in range(50)])