class_docstr: Common methods for testing ADVI surrogate posteriors.
class_docstr_tok: ["Common","methods","for","testing","ADVI","surrogate","posteriors","."]
code: def _test_shapes(
      self, surrogate_posterior, batch_shape, event_shape, seed
  ):
      posterior_sample = surrogate_posterior.sample(seed=seed)
  
      # Test that the posterior has the specified event shape(s).
      posterior_event_shape = self.evaluate(
          surrogate_posterior.event_shape_tensor()
      )
      event_shape = nest.map_structure_up_to(
          surrogate_posterior.event_shape_tensor(),
          ps.convert_to_shape_tensor,
          event_shape,
          check_types=False,
      )
      self.assertAllEqualNested(event_shape, posterior_event_shape)
  
      # Test that all sample Tensors have the expected shapes.
      sample_shape = nest.map_structure(
          lambda s: ps.concat([batch_shape, s], axis=0), event_shape
      )
      self.assertAllEqualNested(
          nest.map_structure(ps.shape, posterior_sample), sample_shape
      )
  
      # Test that the posterior components have the specified batch shape, which
      # is also the shape of `log_prob` of a sample.
      self.assertAllAssertsNested(
          lambda s: self.assertAllEqual(s, batch_shape),
          self.evaluate(surrogate_posterior.batch_shape_tensor()),
      )
      self.assertAllEqual(
          batch_shape,
          ps.shape(surrogate_posterior.log_prob(posterior_sample)),
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import exp
  from tensorflow_probability.python.bijectors import fill_triangular
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.bijectors import joint_map
  from tensorflow_probability.python.bijectors import masked_autoregressive
  from tensorflow_probability.python.bijectors import sigmoid
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import deterministic
  from tensorflow_probability.python.distributions import exponential
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import joint_distribution_coroutine
  from tensorflow_probability.python.distributions import joint_distribution_named
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.distributions import laplace
  from tensorflow_probability.python.distributions import logistic
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.distributions import student_t
  from tensorflow_probability.python.experimental.vi import surrogate_posteriors
  from tensorflow_probability.python.internal import nest_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.internal import tf_keras
  from tensorflow_probability.python.vi import optimization
  from tensorflow.python.util import nest
label_desc: Use image node_id 2 for calling the _SurrogatePosterior obj's underlying member method code with example usage: obj._test_shapes(surrogate_posterior, batch_shape, event_shape, seed) without return types