class_docstr: Test class for utils_tf
class_docstr_tok: ["Test","class","for","utils_tf"]
docstr: test_random_lp_vector_l1_l2: Test that `random_lp_vector` returns
  random samples in an l1 or l2 ball.
docstr_tok: ["test_random_lp_vector_l1_l2",":","Test","that","`","random_lp_vector","`","returns","random","samples","in","an","l1","or","l2","ball","."]
code: def test_random_lp_srandom_lp_vector_l1_l2(self):
      """
      test_random_lp_vector_l1_l2: Test that `random_lp_vector` returns
      random samples in an l1 or l2 ball.
      """
  
      eps = 0.5
      d = 10
  
      for ord in [1, 2]:
          r = self.sess.run(
              utils_tf.random_lp_vector((1000, d), ord, eps)
          )
  
          norms = np.linalg.norm(r, axis=-1, ord=ord)
  
          # test that some values are close to the boundaries
          self.assertLessEqual(np.max(norms), eps)
          self.assertGreaterEqual(np.max(norms), 0.95 * eps)
  
          # The expected norm is eps * Exp[U[0,1]^(1/d)] where U is a standard
          # uniform random variable and d is the dimension. The second term is
          # equal to the expected value of a Beta(d, 1) variable which is d/(d+1).
          expected_mean_norm = eps * (d / (d + 1.0))
          self.assertClose(
              np.mean(norms), expected_mean_norm, atol=0.02
          )
  
file_path: cleverhans/cleverhans_v3.1.0/tests_tf/test_utils_tf.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import numpy
  import tensorflow
  from cleverhans import utils_tf
  from cleverhans.devtools.checks import CleverHansTest
label_desc: Use image node_id 9 for calling the TestUtilsTF obj's underlying member method code with example usage: obj.test_random_lp_srandom_lp_vector_l1_l2() without return types