class_docstr: Tests for Hager Zhang line search algorithm.
class_docstr_tok: ["Tests","for","Hager","Zhang","line","search","algorithm","."]
docstr: Tests appropriate usage of approximate Wolfe conditions.
docstr_tok: ["Tests","appropriate","usage","of","approximate","Wolfe","conditions","."]
code: def test_approx_wolfe(self):
      """Tests appropriate usage of approximate Wolfe conditions."""
      # The approximate Wolfe conditions only kick in when we are very close to
      # the minimum. The following function is based on the discussion in Hager
      # Zhang, "A new conjugate gradient method with guaranteed descent and an
      # efficient line search" (2005). The argument of the function has been
      # shifted so that the minimum is extremely close to zero.
      dtype = np.float64
  
      def fdf(x):
          shift = dtype(0.99999999255000149)
          fv = dtype(1) - dtype(2) * (x + shift) + (x + shift) ** 2
          dfv = -dtype(2) + dtype(2) * (x + shift)
          return ValueAndGradient(x, fv, dfv)
  
      start = tf.constant(dtype(1e-8))
      results = self.evaluate(
          hager_zhang(
              fdf,
              initial_step_size=start,
              sufficient_decrease_param=0.1,
              curvature_param=0.9,
              threshold_use_approximate_wolfe_condition=1e-6,
          )
      )
      self.assertTrue(results.converged)
      val_0 = fdf(0.0)
      self.assertFalse(
          _is_exact_wolfe(
              results.left.x,
              results.left.f,
              results.left.df,
              val_0.f,
              val_0.df,
              0.1,
              0.9,
          )
      )
      self.assertTrue(
          _is_approx_wolfe(
              results.left.x,
              results.left.f,
              results.left.df,
              val_0.f,
              val_0.df,
              0.1,
              0.9,
              1e-6,
          )
      )
  
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 9 for calling the HagerZhangTest obj's underlying member method code with example usage: obj.test_approx_wolfe() and returns: ValueAndGradient