code: def test_obeys_convergence_criterion(self):
      init_x = np.array([0.0, 0.0]).astype(np.float32)
      target_x = np.array([3.0, 4.0]).astype(np.float32)
  
      x = tf.Variable(init_x)
      loss_fn = lambda: tf.reduce_sum((x - target_x) ** 2)
  
      # Check that we can trace the convergence criterion's moving average of
      # decrease in loss.
      trace_fn = lambda tq: (  # pylint: disable=g-long-lambda
          tq.loss,
          tq.convergence_criterion_state.average_decrease_in_loss,
      )
      atol = 0.1
      results = minimize(
          loss_fn,
          num_steps=100,
          optimizer=_get_sgd_optimizer(0.1),
          convergence_criterion=(
              optimizer.convergence_criteria.LossNotDecreasing(
                  atol=atol
              )
          ),
          trace_fn=trace_fn,
          return_full_length_trace=False,
      )
      self.evaluate(tf1.global_variables_initializer())
      losses_, moving_average_decreases_ = self.evaluate(results)
      self.assertLess(moving_average_decreases_[-1], atol)
      self.assertGreater(moving_average_decreases_[-3], atol)
      self.assertAllEqual(losses_.shape, [35])
  
      # Check that the second-step loss decreases from the first step. This could
      # fail in graph mode if we were sloppy with `control_dependencies`, so that
      # the steps ran simultaneously or in the wrong order.
      self.assertGreater(losses_[0] - losses_[1], 1e-4)
  
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 7 for calling the MinimizeTests obj's underlying member method code with example usage: obj.test_obeys_convergence_criterion() without return types