class_docstr: Tests regularizer methods.
docstr: Tests virtual_adv_regularizer with multi-step approximation.
docstr_tok: ["Tests","virtual_adv_regularizer","with","multi-step","approximation","."]
code: def testVirtualAdvRegularizerMultiStepApproximation(self):
      """Tests virtual_adv_regularizer with multi-step approximation."""
      np_input = np.array([[0.28, -0.96]])
      tf_input = tf.constant(np_input)
      embedding_fn = lambda x: x
      vadv_config = configs.VirtualAdvConfig(
          adv_neighbor_config=configs.AdvNeighborConfig(
              feature_mask=None,
              adv_step_size=1,
              adv_grad_norm=configs.NormType.L2,
          ),
          distance_config=configs.DistanceConfig(
              distance_type=configs.DistanceType.COSINE,
              sum_over_axis=-1,
          ),
          num_approx_steps=20,
          approx_difference=1,
      )
      np_seed = np.array([[0.6, 0.8]])
      tf_seed = tf.constant(np_seed)
      vadv_loss = regularizer._virtual_adv_regularizer(
          tf_input,
          embedding_fn,
          vadv_config,
          embedding_fn(tf_input),
          tf_seed,
      )
  
      actual_loss = self.evaluate(vadv_loss)
  
      x = np_input
      hessian = np.dot(x, x.T) * np.identity(2) - np.dot(x.T, x)
      hessian /= np.linalg.norm(x) ** 4
      approx = np.matmul(np_seed, hessian)
      approx /= np.linalg.norm(approx, axis=-1, keepdims=True)
      expected_loss = np.matmul(
          np.matmul(approx, hessian), np.transpose(approx)
      )
      self.assertNear(actual_loss, expected_loss, err=1e-5)
  
file_path: neural-structured-learning/neural_structured_learning/lib/regularizer_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import neural_structured_learning.configs
  from neural_structured_learning.lib import regularizer
  import numpy
  import tensorflow
label_desc: Use image node_id 3 for calling the RegularizerTest obj's underlying member method code with example usage: obj.testVirtualAdvRegularizerMultiStepApproximation() without return types