docstr: Test the noise level of the sum of discrete Gaussians applied locally.
  
  The sum of discrete Gaussians is not a discrete Gaussian, but it will be
  extremely close for sigma >= 2. We will thus compare the aggregated noise
  to a central discrete Gaussian noise with appropriately scaled stddev with
  some reasonable tolerance.
  
  Args:
    local_stddev: The stddev of the local discrete Gaussian noise.
    num_records: The number of records to be aggregated.
docstr_tok: ["Test","the","noise","level","of","the","sum","of","discrete","Gaussians","applied","locally",".","The","sum","of","discrete","Gaussians","is","not","a","discrete","Gaussian",",","but","it","will","be","extremely","close","for","sigma",">","=","2",".","We","will","thus","compare","the","aggregated","noise","to","a","central","discrete","Gaussian","noise","with","appropriately","scaled","stddev","with","some","reasonable","tolerance",".","Args",":","local_stddev",":","The","stddev","of","the","local","discrete","Gaussian","noise",".","num_records",":","The","number","of","records","to","be","aggregated","."]
code: def test_sum_local_noise_shares(self, local_stddev, num_records):
      """Test the noise level of the sum of discrete Gaussians applied locally.
  
      The sum of discrete Gaussians is not a discrete Gaussian, but it will be
      extremely close for sigma >= 2. We will thus compare the aggregated noise
      to a central discrete Gaussian noise with appropriately scaled stddev with
      some reasonable tolerance.
  
      Args:
        local_stddev: The stddev of the local discrete Gaussian noise.
        num_records: The number of records to be aggregated.
      """
      # Aggregated local noises.
      num_trials = 1000
      record = tf.zeros([num_trials], dtype=tf.int32)
      sample = [record] * num_records
      query = ddg_sum_query(
          l2_norm_bound=10.0, local_stddev=local_stddev
      )
      query_result, _ = test_utils.run_query(query, sample)
  
      # Central discrete Gaussian noise.
      central_stddev = np.sqrt(num_records) * local_stddev
      central_noise = discrete_gaussian_utils.sample_discrete_gaussian(
          scale=tf.cast(tf.round(central_stddev), record.dtype),
          shape=tf.shape(record),
          dtype=record.dtype,
      )
  
      agg_noise, central_noise = self.evaluate(
          [query_result, central_noise]
      )
  
      mean_stddev = central_stddev * np.sqrt(num_trials) / num_trials
      atol = 3.5 * mean_stddev
  
      # Use the atol for mean as a rough default atol for stddev/percentile.
      self.assertAllClose(
          np.mean(agg_noise), np.mean(central_noise), atol=atol
      )
      self.assertAllClose(
          np.std(agg_noise), np.std(central_noise), atol=atol
      )
      self.assertAllClose(
          np.percentile(agg_noise, [25, 50, 75]),
          np.percentile(central_noise, [25, 50, 75]),
          atol=atol,
      )
  
file_path: privacy/tensorflow_privacy/privacy/dp_query/distributed_discrete_gaussian_query_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils
  from tensorflow_privacy.privacy.dp_query import distributed_discrete_gaussian_query
  from tensorflow_privacy.privacy.dp_query import test_utils
label_desc: Use image node_id 7 for calling the DistributedDiscreteGaussianQueryTest obj's underlying member method code with example usage: obj.test_sum_local_noise_shares(local_stddev, num_records) without return types