class_docstr: Tests the Autoregressive distribution.
class_docstr_tok: ["Tests","the","Autoregressive","distribution","."]
docstr: Demonstrates equivalence between TD, Bijector approach and AR dist.
docstr_tok: ["Demonstrates","equivalence","between","TD",",","Bijector","approach","and","AR","dist","."]
code: def testCompareToBijector(self):
      """Demonstrates equivalence between TD, Bijector approach and AR dist."""
      sample_shape = np.int32([4, 5])
      batch_shape = np.int32([])
      event_size = np.int32(2)
      batch_event_shape = np.concatenate(
          [batch_shape, [event_size]], axis=0
      )
      sample0 = tf.zeros(batch_event_shape)
      affine = scale_matvec_tril.ScaleMatvecTriL(
          scale_tril=self._random_scale_tril(event_size),
          validate_args=True,
      )
      ar = autoregressive.Autoregressive(
          self._normal_fn(affine), sample0, validate_args=True
      )
      ar_flow = masked_autoregressive.MaskedAutoregressiveFlow(
          is_constant_jacobian=True,
          shift_and_log_scale_fn=lambda x: [None, affine.forward(x)],
          validate_args=True,
      )
      td = transformed_distribution.TransformedDistribution(
          # TODO(b/137665504): Use batch-adding meta-distribution to set the batch
          # shape instead of tf.zeros.
          distribution=sample_lib.Sample(
              normal.Normal(tf.zeros(batch_shape), 1.0), [event_size]
          ),
          bijector=ar_flow,
          validate_args=True,
      )
      x_shape = np.concatenate(
          [sample_shape, batch_shape, [event_size]], axis=0
      )
      x = (
          2.0 * self._rng.random_sample(x_shape).astype(np.float32)
          - 1.0
      )
      td_log_prob_, ar_log_prob_ = self.evaluate(
          [td.log_prob(x), ar.log_prob(x)]
      )
      self.assertAllClose(
          td_log_prob_, ar_log_prob_, atol=0.0, rtol=1e-6
      )
  
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 6 for calling the AutoregressiveTest obj's underlying member method code with example usage: obj.testCompareToBijector() without return types