code: def _expansion_fn(
      objective_function,
      simplex,
      objective_values,
      worst_index,
      reflected,
      objective_at_reflected,
      face_centroid,
      expansion,
  ):
      """Creates the condition function pair for an expansion."""
  
      def _expand_and_maybe_replace():
          """Performs the expansion step."""
          expanded = face_centroid + expansion * (
              reflected - face_centroid
          )
          expanded_objective_value = objective_function(expanded)
          expanded_is_better = (
              expanded_objective_value < objective_at_reflected
          )
          accept_expanded_fn = lambda: (
              expanded,
              expanded_objective_value,
          )
          accept_reflected_fn = lambda: (
              reflected,
              objective_at_reflected,
          )
          next_pt, next_objective_value = ps.cond(
              expanded_is_better,
              accept_expanded_fn,
              accept_reflected_fn,
          )
          next_simplex = _replace_at_index(
              simplex, worst_index, next_pt
          )
          next_objective_at_simplex = _replace_at_index(
              objective_values, worst_index, next_objective_value
          )
          return (
              False,
              next_simplex,
              next_objective_at_simplex,
              np.int32(1),
          )
  
      return _expand_and_maybe_replace
  
imports: import collections
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 4 for calling a global function with example usage: _expansion_fn(objective_function, simplex, objective_values, worst_index, reflected, objective_at_reflected, face_centroid, expansion) and returns: _expand_and_maybe_replace, False,  next_simplex,  next_objective_at_simplex,  np