code: def _do_maximum_mean(samples, envelope, high, name=None):
      """Common code between maximum_mean and minimum_mean."""
      with tf.name_scope(name or "do_maximum_mean"):
          dtype = dtype_util.common_dtype(
              [samples, envelope, high], tf.float32
          )
          samples = tf.convert_to_tensor(
              value=samples, name="samples", dtype=dtype
          )
          envelope = tf.convert_to_tensor(
              value=envelope, name="envelope", dtype=dtype
          )
          high = tf.convert_to_tensor(
              value=high, name="high", dtype=dtype
          )
          n = tf.rank(samples)
          # Move the batch dimension of `samples` to the rightmost position,
          # where the _batch_sort_vector function wants it.
          perm = tf.concat([tf.range(1, n), [0]], axis=0)
          samples = tf.transpose(a=samples, perm=perm)
  
          samples = _batch_sort_vector(samples)
  
          # The maximum mean is given by taking `envelope`-worth of
          # probability from the smallest samples and moving it to the
          # maximum value.  This amounts to:
          # - ignoring the smallest k samples, where `k/n < envelope`
          # - taking a `1/n - (envelope - k/n)` part of the index k sample
          # - taking all the other samples
          # - and adding `envelope * high` at the end.
          # The following is a vectorized and batched way of computing this.
          # `max_mean_contrib` is a mask implementing the previous.
          batch_size = tf.shape(samples)[-1]
          batch_size = tf.cast(batch_size, dtype=dtype)
          step = 1.0 / batch_size
          cum_steps = step * tf.range(1, batch_size + 1, dtype=dtype)
          max_mean_contrib = tf.clip_by_value(
              cum_steps - envelope[..., tf.newaxis],
              clip_value_min=0.0,
              clip_value_max=step,
          )
          return (
              tf.reduce_sum(samples * max_mean_contrib, axis=-1)
              + envelope * high
          )
  
imports: import functools
  import itertools
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.util.seed_stream import SeedStream
label_desc: Use image node_id 9 for calling a global function with example usage: _do_maximum_mean(samples, envelope, high, name) and returns: unknown