code: def mix_over_posterior_draws(means, variances):
      """Construct a predictive normal distribution that mixes over posterior draws.
  
      Args:
        means: float `Tensor` of shape
          `[num_posterior_draws, ..., num_timesteps]`.
        variances: float `Tensor` of shape
          `[num_posterior_draws, ..., num_timesteps]`.
  
      Returns:
        mixture_dist: `tfd.MixtureSameFamily(tfd.Independent(tfd.Normal))` instance
          representing a uniform mixture over the posterior samples, with
          `batch_shape = [..., num_timesteps]` and `event_shape = []`.
  
      """
      # The inputs `means`, `variances` have shape
      #   `concat([
      #      [num_posterior_draws],
      #      sample_shape,
      #      batch_shape,
      #      [num_timesteps]])`
      # Because MixtureSameFamily mixes over the rightmost batch dimension,
      # we need to move the `num_posterior_draws` dimension to be rightmost
      # in the batch shape.
      # TODO(b/120245392): enhance `MixtureSameFamily` to reduce along an
      # arbitrary axis, and eliminate `move_dimension` calls here.
  
      with tf.name_scope("mix_over_posterior_draws"):
          num_posterior_draws = ps.shape(means)[0]
  
          component_observations = normal.Normal(
              loc=dist_util.move_dimension(means, 0, -1),
              scale=tf.sqrt(dist_util.move_dimension(variances, 0, -1)),
          )
  
          return mixture_same_family.MixtureSameFamily(
              mixture_distribution=categorical.Categorical(
                  logits=tf.zeros(
                      [num_posterior_draws],
                      dtype=component_observations.dtype,
                  )
              ),
              components_distribution=component_observations,
          )
  
imports: import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import mixture_same_family
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import mvn_linear_operator
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.sts.internal import missing_values_util
label_desc: Use image node_id 9 for calling a global function with example usage: mix_over_posterior_draws(means, variances) and returns: mixture_same_family