code: def _bates_cdf(total_count, low, high, dtype, value):
      """Compute the Bates cdf.
  
      Internally, the (standard, unnormalized) cdf is computed by the formula
  
      ```none
      pdf = sum_{k=0}^j (-1)^k (n choose k) (nx - k)^n
      ```
  
      where
      * `n = total_count`,
      * `x = value` the value to compute the cumulative probability of, and
      * `j = floor(nx)`.
  
      This is shifted to `[low, high]` and normalized. Since the pdf is symmetric,
      we have `cdf(x) = 1 - cdf(1 - x)` for `x > .5`, hence we only compute the left
      half, which keeps the number of terms lower.
  
      Computation is batched, using `tf.math.segment_sum()`. For this reason this is
      not compatible with `tf.vectorized_map()`.
  
      All input parameters should have compatible dtypes and shapes.
  
      Args:
        total_count: `Tensor` with integer values, as given to the `Bates`
          constructor.
        low: Float `Tensor`, as given to the `Bates` constructor.
        high: Float `Tensor`, as given to the `Bates` constructor.
        dtype: The dtype of the output.
        value: Float `Tensor`. Input value to `cdf()`.
      Returns:
        cdf: Float `Tensor`. See above formula.
      """
      total_count = tf.cast(total_count, dtype)
      low = tf.convert_to_tensor(low)
      high = tf.convert_to_tensor(high)
  
      # Warn the user if they try to compute a pdf with high `total_count`.  This
      # warning is here instead of `_parameter_control_dependencies()` because
      # nested calls to `_name_and_control_scope` (e.g. `log_survival_function`) can
      # result in multiple warnings being added and multiple tensor
      # conversions. Also `sample()` does not have the same numerical issues.
      with tf.control_dependencies(
          [_stability_limit_tensor(total_count, dtype)]
      ):
          # Center and adjust `value` using limits and symmetry.
          value_centered = (value - low) / (high - low)
          value_adj = tf.clip_by_value(value_centered, 0.0, 1.0)
          value_adj = tf.where(
              value_adj < 0.5, value_adj, 1.0 - value_adj
          )
          value_adj = tf.where(
              tf.math.is_finite(value_adj), value_adj, 0.0
          )
          # Flatten to make segments; need to broadcast before flattening.
          shape = ps.broadcast_shape(
              ps.shape(value_adj), ps.shape(total_count)
          )
          total_count_b = ps.broadcast_to(total_count, shape)
          total_count_x_value_adj_b = total_count * value_adj
          total_count_f = tf.reshape(total_count_b, [-1])
          total_count_x_value_adj_f = tf.reshape(
              total_count_x_value_adj_b, [-1]
          )
          # Create segmented terms of summation.
          num_terms_f = tf.cast(
              tf.math.floor(total_count_x_value_adj_f + 1),
              dtype=tf.int32,
          )
          term_idx_s = tf.cast(
              _segmented_range(num_terms_f), dtype
          )  # aka `k`
          total_count_s = tf.repeat(total_count_f, num_terms_f)
          total_count_x_value_adj_s = tf.repeat(
              total_count_x_value_adj_f, num_terms_f
          )
          terms = (
              tf.cast(-1.0, dtype) ** term_idx_s
              * (
                  1.0
                  / (
                      (total_count_s + 1.0)
                      * tf.math.exp(
                          special.lbeta(
                              total_count_s - term_idx_s + 1.0,
                              term_idx_s + 1.0,
                          )
                      )
                  )
              )
              * (total_count_x_value_adj_s - term_idx_s)
              ** total_count_s
          )
          # Segment sum.
          segment_ids = tf.repeat(
              tf.range(tf.size(num_terms_f)), num_terms_f
          )
          cdf_s = tf.math.segment_sum(terms, segment_ids)
          # Reshape back.
          cdf = tf.reshape(cdf_s, shape)
          # Normalize.
          cdf = cdf / tf.math.exp(
              tf.math.lgamma(total_count_b + tf.cast(1.0, dtype))
          )
          # cdf symmetry adjustment: cdf(x) = 1 - cdf(1 - x) for x > 0.5
          cdf = tf.where(value_centered > 0.5, 1.0 - cdf, cdf)
          # Fix out-of-support queries.
          cdf = tf.where(value_centered < 0.0, tf.cast(0.0, dtype), cdf)
          cdf = tf.where(value_centered > 1.0, tf.cast(1.0, dtype), cdf)
          cdf = tf.where(tf.math.is_finite(value_centered), cdf, np.nan)
          return cdf
  
imports: import sys
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import sigmoid
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.math import special
label_desc: Use image node_id 2 for calling a global function with example usage: _bates_cdf(total_count, low, high, dtype, value) and returns: cdf