class_docstr: Tests for Hager Zhang line search algorithm.
class_docstr_tok: ["Tests","for","Hager","Zhang","line","search","algorithm","."]
code: def test_batch_bracket_failures(self):
      # To bracket successfully, we must find the narrow window with non-negative
      # derivative -- good values are roughly [1.39, 2.72].
      def _fdf(x):
          z = x - 1
          return ValueAndGradient(
              x=x,
              f=tf.math.exp(-z) - tf.math.exp(-z * z),
              df=2 * z * tf.math.exp(-z * z) - tf.math.exp(-z),
          )
  
      start = tf.convert_to_tensor([0.01, 0.1, 1.0, 1.5, 2.0, -5.0])
      results = self.evaluate(
          hager_zhang(_fdf, initial_step_size=start)
      )
  
      # Bracketing will do something like: check `5^0 * start`, `5^1 * start`,
      # `5^2 * start`, ..., looking for a point where the derivative is
      # non-negative. The search will start to fail for negative values where the
      # function is highly positive and goes steeply downward (but since it's far
      # enough out fails to bracket).
      self.assertAllEqual(
          [True, True, True, True, True, False], results.converged
      )
      self.assertAllEqual(
          [False, False, False, False, False, True], results.failed
      )
  
      val_0 = self.evaluate(_fdf(tf.convert_to_tensor(0.0)))
      self.assertAllEqual(
          [False, True, False, True, True, False],
          _is_exact_wolfe(
              results.left.x,
              results.left.f,
              results.left.df,
              val_0.f,
              val_0.df,
              0.1,
              0.9,
          ),
      )
  
imports: import collections
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.optimizer.linesearch.hager_zhang import hager_zhang
label_desc: Use image node_id 4 for calling the HagerZhangTest obj's underlying member method code with example usage: obj.test_batch_bracket_failures() and returns: ValueAndGradient