class_docstr: Tests the Autoregressive distribution.
class_docstr_tok: ["Tests","the","Autoregressive","distribution","."]
code: def testSampleIndependenceWithoutSeedBug(self):
      # Under eager, there was a bug where subsequent samples for position 0 would
      # be erroneously independent of the first sample when a seed was not
      # provided.
  
      # A pithy example: A simple 1-Markov autoregressive sequence for which the
      # first frame is either 0 or 1 with equal probability and all subsequent
      # frames copy the previous frame. Thus the overall sequence-level
      # distribution is 0000 with probability 0.5 and 1111 with probability 0.5.
      def distribution_fn(sample):
          num_frames = sample.shape[-1]
          mask = tf.one_hot(0, num_frames)[:, tf.newaxis]
          probs = tf.roll(tf.one_hot(sample, 3), shift=1, axis=-2)
          probs = (
              probs * (1.0 - mask)
              + tf.convert_to_tensor([0.5, 0.5, 0]) * mask
          )
          return independent.Independent(
              categorical.Categorical(probs=probs),
              reinterpreted_batch_ndims=1,
          )
  
      ar = autoregressive.Autoregressive(
          distribution_fn,
          sample0=tf.constant([2, 2, 2, 2]),
          num_steps=4,
      )
      samps = self.evaluate(ar.sample(10))
      for s in samps:
          self.assertIn(np.mean(s), (0.0, 1.0), msg=str(s))
  
imports: import warnings
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import masked_autoregressive
  from tensorflow_probability.python.bijectors import scale_matvec_tril
  from tensorflow_probability.python.distributions import autoregressive
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import linalg
label_desc: Use image node_id 5 for calling the AutoregressiveTest obj's underlying member method code with example usage: obj.testSampleIndependenceWithoutSeedBug() and returns: independent