class_docstr: Tests for Hager Zhang line search algorithm.
class_docstr_tok: ["Tests","for","Hager","Zhang","line","search","algorithm","."]
docstr: Tests that the results are consistent.
docstr_tok: ["Tests","that","the","results","are","consistent","."]
code: def test_consistency(self):
      """Tests that the results are consistent."""
  
      def rastrigin(x, use_np=False):
          z = x - 0.25
          sin, cos = (np.sin, np.cos) if use_np else (tf.sin, tf.cos)
          return ValueAndGradient(
              x=x,
              f=(10.0 + z * z - 10 * cos(2 * np.pi * z)),
              df=(2 * z + 10 * 2 * np.pi * sin(2 * np.pi * z)),
          )
  
      start = tf.constant(0.1, dtype=tf.float64)
      results = self.evaluate(
          hager_zhang(
              rastrigin,
              initial_step_size=start,
              sufficient_decrease_param=0.1,
              curvature_param=0.9,
              threshold_use_approximate_wolfe_condition=1e-6,
          )
      )
      self.assertTrue(results.converged)
      x = results.left.x
      actual = rastrigin(x, use_np=True)
      self.assertAlmostEqual(actual.f, results.left.f)
      self.assertAlmostEqual(actual.df, results.left.df)
  
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 11 for calling the HagerZhangTest obj's underlying member method code with example usage: obj.test_consistency() and returns: ValueAndGradient