code: def print_privacy_guarantees(
      epochs, batch_size, samples, noise_multiplier
  ):
      """Tabulating position-dependent privacy guarantees."""
      if noise_multiplier == 0:
          print("No differential privacy (additive noise is 0).")
          return
  
      print(
          "In the conditions of Theorem 34 (https://arxiv.org/abs/1808.06651) "
          "the training procedure results in the following privacy guarantees."
      )
  
      print("Out of the total of {} samples:".format(samples))
  
      steps_per_epoch = samples // batch_size
      orders = np.concatenate(
          [np.linspace(2, 20, num=181), np.linspace(20, 100, num=81)]
      )
      delta = 1e-5
      for p in (0.5, 0.9, 0.99):
          steps = math.ceil(
              steps_per_epoch * p
          )  # Steps in the last epoch.
          coef = (
              2
              * (noise_multiplier * batch_size) ** -2
              * (
                  # Accounting for privacy loss
                  (epochs - 1) / steps_per_epoch
                  + 1  # ... from all-but-last epochs
                  / (steps_per_epoch - steps + 1)
              )
          )  # ... due to the last epoch
          # Using RDP accountant to compute eps. Doing computation analytically is
          # an option.
          rdp = [order * coef for order in orders]
          eps, _ = dp_accounting.rdp.compute_epsilon(orders, rdp, delta)
          print(
              "\t{:g}% enjoy at least ({:.2f}, {})-DP".format(
                  p * 100, eps, delta
              )
          )
  
      accountant = dp_accounting.rdp.RdpAccountant(orders)
      event = dp_accounting.SelfComposedDpEvent(
          dp_accounting.PoissonSampledDpEvent(
              batch_size / samples,
              dp_accounting.GaussianDpEvent(noise_multiplier),
          ),
          epochs * steps_per_epoch,
      )
      accountant.compose(event)
      eps_sgm = accountant.get_epsilon(target_delta=delta)
  
      print(
          "By comparison, DP-SGD analysis for training done with the same "
          "parameters and random shuffling in each epoch guarantees "
          "({:.2f}, {})-DP for all samples.".format(eps_sgm, delta)
      )
  
file_path: privacy/tutorials/mnist_lr_tutorial.py
imports: import math
  from absl import app
  from absl import flags
  from absl import logging
  import dp_accounting
  import numpy
  import tensorflow
  from tensorflow import estimator
  from tensorflow.compat.v1 import estimator
  from tensorflow_privacy.privacy.optimizers import dp_optimizer
label_desc: Use image node_id 4 for calling a global function with example usage: print_privacy_guarantees(epochs, batch_size, samples, noise_multiplier) without return types