code: def _test_bitstring_length_matches_entropy(
      self, prior_fn, base_prior_fn, scale
  ):
      em = universal.UniversalIndexedEntropyModel(
          prior_fn=prior_fn,
          index_ranges=(10, 10),
          parameter_fns=dict(
              loc=lambda i: (i[..., 0] - 5.0) / 10.0,
              scale=lambda i: scale * tf.exp(-i[..., 1]),
          ),
          coding_rank=1,
          compression=True,
          tail_mass=1e-5,
          num_noise_levels=15,
      )
      num_symbols = 10000
      base_df = base_prior_fn(loc=0.0, scale=scale)
      x = base_df.sample((1, 1, num_symbols), seed=0)
      # We predict the distribution correctly.
      indexes = tf.concat(
          (
              5 * tf.ones((1, 1, num_symbols, 1)),
              0 * tf.ones((1, 1, num_symbols, 1)),
          ),
          axis=-1,
      )
      bitstring = em.compress(x, indexes)
      bits = len(bitstring.numpy()[0, 0]) * 8
      bits_per_symbol = bits / num_symbols
  
      df = prior_fn(loc=0.0, scale=scale)
  
      # Lets estimate entropy via sampling the distribution.
      samples = df.sample(num_symbols, seed=0)
      log_probs = df.log_prob(samples) / tf.math.log(2.0)
      entropy = -tf.reduce_mean(log_probs)
      rtol = 0.01  # Maximum relative error 1%.
      atol = 16 / num_symbols  # Maximum 2 bytes absolute error.
      self.assertLessEqual(bits_per_symbol, entropy * (1 + rtol) + atol)
  
imports: from absl.testing import parameterized
  import scipy.stats
  import tensorflow
  import tensorflow_probability
  from tensorflow_compression.python.distributions import deep_factorized
  from tensorflow_compression.python.distributions import uniform_noise
  from tensorflow_compression.python.entropy_models import universal
label_desc: Use image node_id 6 for calling the UniversalIndexedEntropyModelTest obj's underlying member method code with example usage: obj._test_bitstring_length_matches_entropy(prior_fn, base_prior_fn, scale) without return types