class_docstr: Test if PrivateGradValues group data into microbatches correctly.
class_docstr_tok: ["Test","if","PrivateGradValues","group","data","into","microbatches","correctly","."]
docstr: Initialize the test class.
docstr_tok: ["Initialize","the","test","class","."]
code: def __init__(self, methodname):
      """Initialize the test class."""
      super().__init__(methodname)
  
      data = np.array(
          [[2], [3], [5], [-14], [8], [-4]], dtype=np.float32
      )
      w = objax.TrainVar(jn.zeros(1))
  
      # Squared loss: average of 0.5*(w - x)**2. Gradient is -x at w=0.
      def loss(x):
          return 0.5 * ((x - w.value) ** 2).mean()
  
      # Procedure to get private gradient given microbatch and l2_norm_clip.
      noise_multiplier = 0.0
  
      def get_g(
          microbatch,
          l2_norm_clip,
          use_norm_accumulation,
          batch_axis=(0,),
      ):
          gv_priv = objax.privacy.dpsgd.PrivateGradValues(
              loss,
              objax.VarCollection({"w": w}),
              noise_multiplier,
              l2_norm_clip,
              microbatch,
              batch_axis=batch_axis,
              use_norm_accumulation=use_norm_accumulation,
          )
          g_priv, v_priv = gv_priv(data)
          return g_priv
  
      self.get_g = get_g
  
imports: import inspect
  import unittest
  from typing import Tuple, Dict, List
  import jax
  import jax.numpy
  import numpy
  from scipy.stats.distributions import chi2
  import objax
  from objax.typing import JaxArray
  from objax.zoo.dnnet import DNNet
label_desc: Use image node_id 1 to create a new TestPrivateGradValuesAxis object from inherited base classes: unittest with example: obj = TestPrivateGradValuesAxis(methodname)