class_docstr: Tests for Nelder-Mead optimization algorithm.
class_docstr_tok: ["Tests","for","Nelder-Mead","optimization","algorithm","."]
docstr: Tests that max iteration bound specification works as expected.
docstr_tok: ["Tests","that","max","iteration","bound","specification","works","as","expected","."]
code: def test_max_iteration_bounds_work(self):
      """Tests that max iteration bound specification works as expected."""
  
      def beale(coord):
          """The Beale function in two dimensions.
  
          Beale function is another standard test function for optimization. It is
          characterized by having a single minimum at (3, 0.5) which lies is
          a very flat region surrounded by steep walls.
  
          Args:
            coord: A Tensor of shape [2]. The coordinate of the point to evaluate
              the function at.
  
          Returns:
            fv: A scalar tensor containing the value of the Beale function at
              the supplied point.
          """
          x, y = coord[0], coord[1]
          fv = (
              (1.5 - x + x * y) ** 2
              + (2.25 - x + x * y**2) ** 2
              + (2.625 - x + x * y**3) ** 2
          )
          return tf.cast(fv, x.dtype)
  
      start = tf.constant([0.1, 1.0])
      # First evaluate without any iteration bounds to find the number of
      # iterations it takes to converge.
      unbounded_results = self.evaluate(
          nelder_mead.minimize(
              beale,
              initial_vertex=start,
              func_tolerance=1e-12,
              batch_evaluate_objective=False,
          )
      )
      # Check that this converged.
      self.assertTrue(unbounded_results.converged)
      minimum = [3, 0.5]
      self.assertArrayNear(unbounded_results.position, minimum, 1e-5)
  
      # Next we evaluate this with exactly the number of iterations it should
      # take and assert it converges.
      bounded_converged_results = self.evaluate(
          nelder_mead.minimize(
              beale,
              initial_vertex=start,
              func_tolerance=1e-12,
              batch_evaluate_objective=False,
              max_iterations=unbounded_results.num_iterations,
          )
      )
      self.assertTrue(bounded_converged_results.converged)
      self.assertEqual(
          bounded_converged_results.num_iterations,
          unbounded_results.num_iterations,
      )
      # Next, we reduce the number of allowed iterations to be one less than
      # needed and check that it doesn't converge.
      bounded_unconverged_results = self.evaluate(
          nelder_mead.minimize(
              beale,
              initial_vertex=start,
              func_tolerance=1e-12,
              batch_evaluate_objective=False,
              max_iterations=unbounded_results.num_iterations - 1,
          )
      )
      self.assertFalse(bounded_unconverged_results.converged)
      self.assertEqual(
          bounded_unconverged_results.num_iterations,
          unbounded_results.num_iterations - 1,
      )
  
imports: import numpy
  from scipy.stats import special_ortho_group
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.optimizer import nelder_mead
label_desc: Use image node_id 13 for calling the NelderMeadTest obj's underlying member method code with example usage: obj.test_max_iteration_bounds_work() and returns: tf