code: def test_compute_dp_sgd_privacy(
      self,
      n,
      batch_size,
      noise_multiplier,
      epochs,
      delta,
      expected_eps,
      expected_order,
  ):
      eps, order = compute_dp_sgd_privacy_lib.compute_dp_sgd_privacy(
          n, batch_size, noise_multiplier, epochs, delta
      )
      self.assertAlmostEqual(eps, expected_eps)
      self.assertEqual(order, expected_order)
  
      # We perform an additional sanity check on the hard-coded test values.
      # We do a back-of-the-envelope calculation to obtain a lower bound.
      # Specifically, we make the approximation that subsampling a q-fraction is
      # equivalent to multiplying noise scale by 1/q.
      # This is only an approximation, but can be justified by the central limit
      # theorem in the Gaussian Differential Privacy framework; see
      # https://arxiv.org/1911.11607
      # The approximation error is one-sided and provides a lower bound, which is
      # the basis of this sanity check. This is confirmed in the above paper.
      q = batch_size / n
      steps = epochs * n / batch_size
      sigma = noise_multiplier * math.sqrt(steps) / q
      # We compute the optimal guarantee for Gaussian
      # using https://arxiv.org/abs/1805.06530 Theorem 8 (in v2).
      low_delta = 0.5 * math.erfc(
          (eps * sigma - 0.5 / sigma) / math.sqrt(2)
      )
      if eps < 100:  # Skip this if it causes overflow; error is minor.
          low_delta -= (
              math.exp(eps)
              * 0.5
              * math.erfc((eps * sigma + 0.5 / sigma) / math.sqrt(2))
          )
      self.assertLessEqual(low_delta, delta)
  
file_path: privacy/tensorflow_privacy/privacy/analysis/compute_dp_sgd_privacy_test.py
imports: import math
  from absl.testing import absltest
  from absl.testing import parameterized
  from tensorflow_privacy.privacy.analysis import compute_dp_sgd_privacy_lib
label_desc: Use image node_id 1 for calling the ComputeDpSgdPrivacyTest obj's underlying member method code with example usage: obj.test_compute_dp_sgd_privacy(n, batch_size, noise_multiplier, epochs, delta, expected_eps, expected_order) without return types