code: def test_convergence_criterion_follows_batch_reduction(self):
      init_x = np.zeros([100]).astype(np.float32)
      target_x = np.arange(100).astype(np.float32)
  
      x = tf.Variable(init_x)
      loss_fn = lambda: (x - target_x) ** 2
  
      # Stop the optimization when 70% of the threads have converged.
      target_portion_converged = 0.7
      batch_convergence_reduce_fn = (
          lambda has_converged: tf.reduce_mean(  # pylint: disable=g-long-lambda
              tf.cast(has_converged, tf.float32)
          )
          > target_portion_converged
      )
      results = minimize(
          loss_fn,
          num_steps=200,
          optimizer=_get_adam_optimizer(1.0),
          convergence_criterion=(
              optimizer.convergence_criteria.LossNotDecreasing(atol=0.1)
          ),
          batch_convergence_reduce_fn=batch_convergence_reduce_fn,
          trace_fn=lambda traceable: traceable.has_converged,
          return_full_length_trace=False,
      )
      self.evaluate(tf1.global_variables_initializer())
      has_converged_by_step = self.evaluate(results)
  
      self.assertLessEqual(
          np.mean(has_converged_by_step[-2]), target_portion_converged
      )
      self.assertGreater(
          np.mean(has_converged_by_step[-1]), target_portion_converged
      )
  
imports: import collections
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python import optimizer
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.internal import tf_keras
  from tensorflow_probability.python.math.minimize import minimize
  from tensorflow_probability.python.math.minimize import minimize_stateless
label_desc: Use image node_id 8 for calling the MinimizeTests obj's underlying member method code with example usage: obj.test_convergence_criterion_follows_batch_reduction() without return types