class_docstr: Tests for Hager Zhang line search algorithm.
class_docstr_tok: ["Tests","for","Hager","Zhang","line","search","algorithm","."]
code: def test_batched_multiple_minima(self):
      # This function has two minima in the direction of positive x.
      # The first is around x=0.46 and the second around 2.65.
      def fdf(x):
          x = tf.convert_to_tensor(x)
          val = (
              0.988 * x**5
              - 4.96 * x**4
              + 4.978 * x**3
              + 5.015 * x**2
              - 6.043 * x
              - 1
          )
          dval = (
              4.94 * x**4
              - 19.84 * x**3
              + 14.934 * x**2
              + 10.03 * x
              - 6.043
          )
          return ValueAndGradient(x, val, dval)
  
      starts = np.array([0.1, 1.5, 2.0, 4.0])
  
      results_batched = self.evaluate(
          hager_zhang(fdf, initial_step_size=starts)
      )
      results_mapped = [
          self.evaluate(hager_zhang(fdf, initial_step_size=x))
          for x in starts
      ]
      results_mapped_left = np.array([r.left.x for r in results_mapped])
      results_mapped_right = np.array(
          [r.right.x for r in results_mapped]
      )
  
      # Both matched and mapped results converged.
      self.assertTrue(np.all(results_batched.converged))
      self.assertTrue(all(r.converged for r in results_mapped))
  
      # They got the same results.
      self.assertArrayNear(
          results_batched.left.x, results_mapped_left, 1e-5
      )
      self.assertArrayNear(
          results_batched.right.x, results_mapped_right, 1e-5
      )
  
      # Batching is more efficient than mapping.
      self.assertLess(
          results_batched.func_evals,
          sum(r.func_evals for r in results_mapped),
      )
  
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 3 for calling the HagerZhangTest obj's underlying member method code with example usage: obj.test_batched_multiple_minima() and returns: ValueAndGradient