code: def test_follows_tolerances(
      self, atol, rtol, expected_num_steps, pass_inputs_as_tensors
  ):
      with self.assertRaisesRegexp(
          ValueError, "Must specify at least one of"
      ):
          loss_not_decreasing.LossNotDecreasing()
  
      window_size = 2
      criterion = loss_not_decreasing.LossNotDecreasing(
          window_size=window_size, atol=atol, rtol=rtol, min_num_steps=4
      )
  
      losses = (
          1e2,
          30.0,
          10.0,
          9.0,
          8.95,
          8.96,
          8.93,
          8.92,
          8.93,
          8.94,
          8.91,
      )
      step = 0
      auxiliary_state = criterion.bootstrap(
          tf.convert_to_tensor(losses[0]), [], []
      )
      for step, loss in zip(range(1, len(losses)), losses[1:]):
          has_converged, auxiliary_state = criterion.one_step(
              tf.convert_to_tensor(step)
              if pass_inputs_as_tensors
              else step,
              tf.convert_to_tensor(loss)
              if pass_inputs_as_tensors
              else loss,
              [],
              [],
              auxiliary_state,
          )
          has_converged = self.evaluate(has_converged)
          if has_converged:
              break
      self.assertEqual(has_converged, True)
      self.assertEqual(step, expected_num_steps - 1)
  
      decreases_in_loss = -np.diff(losses)
      average_decreases = [1.0 / window_size * decreases_in_loss[0]]
      for loss_decrease in decreases_in_loss[1:step]:
          average_decreases.append(
              (
                  (window_size - 1) * average_decreases[-1]
                  + loss_decrease
              )
              / window_size
          )
      self.assertAllClose(
          self.evaluate(
              (
                  auxiliary_state.previous_loss,
                  auxiliary_state.average_decrease_in_loss,
                  auxiliary_state.average_initial_decrease_in_loss,
              )
          ),
          [
              losses[step],
              average_decreases[-1],
              average_decreases[window_size - 1],
          ],
      )
  
file_path: probability/tensorflow_probability/python/optimizer/convergence_criteria/loss_not_decreasing_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.optimizer.convergence_criteria import loss_not_decreasing
label_desc: Use image node_id 1 for calling the LossNotDecreasingTests obj's underlying member method code with example usage: obj.test_follows_tolerances(atol, rtol, expected_num_steps, pass_inputs_as_tensors) without return types