class_docstr: Tests regularizer methods.
docstr: Tests virtual_adv_regularizer with num_approx_steps=0.
docstr_tok: ["Tests","virtual_adv_regularizer","with","num_approx_steps=0","."]
code: def testVirtualAdvRegularizerRandomPerturbation(self):
      """Tests virtual_adv_regularizer with num_approx_steps=0."""
      input_layer = tf.constant([[1.0, -1.0]])
      embedding_fn = lambda x: x
      step_size = 0.1
      vadv_config = configs.VirtualAdvConfig(
          adv_neighbor_config=configs.AdvNeighborConfig(
              feature_mask=None,
              adv_step_size=step_size,
              adv_grad_norm=configs.NormType.L2,
          ),
          distance_config=configs.DistanceConfig(
              distance_type=configs.DistanceType.L2, sum_over_axis=-1
          ),
          num_approx_steps=0,
      )
      vadv_loss = regularizer.virtual_adv_regularizer(
          input_layer, embedding_fn, vadv_config
      )
      actual_loss = self.evaluate(vadv_loss)
  
      # The identity embedding_fn makes the virtual adversarial loss immune to the
      # direction of the perturbation, only the size matters.
      expected_loss = step_size**2  # square loss
      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 4 for calling the RegularizerTest obj's underlying member method code with example usage: obj.testVirtualAdvRegularizerRandomPerturbation() without return types