def test_average_no_noise(self): record1 = tf.constant([5.0, 0.0]) # Clipped to [3.0, 0.0]. record2 = tf.constant([-1.0, 2.0]) # Not clipped. query = quantile_adaptive_clip_sum_query.QuantileAdaptiveClipAverageQuery( initial_l2_norm_clip=3.0, noise_multiplier=0.0, denominator=2.0, target_unclipped_quantile=1.0, learning_rate=0.0, clipped_count_stddev=0.0, expected_num_records=2.0) query_result, _ = test_utils.run_query(query, [record1, record2]) result = query_result.numpy() expected_average = [1.0, 1.0] self.assertAllClose(result, expected_average)
def test_average_with_noise(self): record1, record2 = 2.71828, 3.14159 sum_stddev = 1.0 denominator = 2.0 clip = 3.0 query = quantile_adaptive_clip_sum_query.QuantileAdaptiveClipAverageQuery( initial_l2_norm_clip=clip, noise_multiplier=sum_stddev / clip, denominator=denominator, target_unclipped_quantile=1.0, learning_rate=0.0, clipped_count_stddev=0.0, expected_num_records=2.0) noised_averages = [] for _ in range(1000): query_result, _ = test_utils.run_query(query, [record1, record2]) noised_averages.append(query_result.numpy()) result_stddev = np.std(noised_averages) avg_stddev = sum_stddev / denominator self.assertNear(result_stddev, avg_stddev, 0.1)