From 53b4c6abcb6ae31f4c05adc3c823d977daa2a96d Mon Sep 17 00:00:00 2001 From: Differential Privacy Team Date: Tue, 7 Nov 2023 23:43:52 -0800 Subject: [PATCH] Migrate Java to the API that accepts double delta, fix bugs in C++ Overall: - Update Bazel to 6.4.0 C++: - Remove incorrect assumptions about the default capacity of hashtables. With small buffer optimization in swisstable, default capacity is no longer guaranteed to be 0 - Fix a typo in algorithm.h - Fix use of uninitialized value - Update boringssl dependency - Update external absl dependency Java: - Use the new DP lib aggregations API that accepts double delta - Use the new Noise.addNoise() methods that accept double delta. The methods that accept @Nullable Double delta were deprecated Change-Id: I289fc97e33c964b78af0013b52c267ba7e73ef52 GitOrigin-RevId: 2da05a4be29a39fc0c55a006365d31c31e93a7f5 --- .bazelversion | 2 +- cc/.bazelversion | 2 +- cc/algorithms/algorithm.h | 2 +- cc/algorithms/bounded-mean.h | 1 + cc/algorithms/internal/BUILD | 2 + cc/algorithms/internal/bounded-mean-ci.cc | 10 + .../internal/bounded-mean-ci_test.cc | 16 ++ cc/algorithms/internal/count-tree_test.cc | 11 - cc/cc_differential_privacy_deps.bzl | 14 +- cc/postgres/.bazelversion | 2 +- cc/proto/util.h | 9 +- examples/cc/.bazelversion | 2 +- examples/go/.bazelversion | 2 +- examples/java/.bazelversion | 2 +- go/.bazelversion | 2 +- java/.bazelversion | 2 +- .../BoundedVarianceTest.java | 220 +++++++++--------- .../DiscreteLaplaceNoiseTest.java | 30 +-- .../GaussianNoiseTest.java | 2 +- .../differentialprivacy/LaplaceNoiseTest.java | 44 ++-- .../LongBoundedSumConfidenceIntervalTest.java | 8 +- .../statistical/BoundedMeanDpTest.java | 4 +- .../statistical/BoundedQuantilesDpTest.java | 4 +- .../statistical/BoundedSumDpTest.java | 4 +- .../statistical/BoundedVarianceDpTest.java | 4 +- .../statistical/CountDpTest.java | 4 +- .../statistical/LaplaceClosenessTest.java | 2 +- .../statistical/LongBoundedSumDpTest.java | 4 +- learning/.bazelversion | 2 +- privacy-on-beam/.bazelversion | 2 +- python/.bazelversion | 2 +- 31 files changed, 219 insertions(+), 198 deletions(-) diff --git a/.bazelversion b/.bazelversion index 024b066c..19b860c1 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/cc/.bazelversion b/cc/.bazelversion index 024b066c..19b860c1 100644 --- a/cc/.bazelversion +++ b/cc/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/cc/algorithms/algorithm.h b/cc/algorithms/algorithm.h index f9f1adec..f2631ade 100644 --- a/cc/algorithms/algorithm.h +++ b/cc/algorithms/algorithm.h @@ -129,7 +129,7 @@ class Algorithm { // algorithm used. The summary proto cannot be empty. virtual absl::Status Merge(const Summary& summary) = 0; - // Returns an estimate for the currrent memory consumption of the algorithm in + // Returns an estimate for the current memory consumption of the algorithm in // bytes. Intended to be used for distribution frameworks to prevent // out-of-memory errors. virtual int64_t MemoryUsed() = 0; diff --git a/cc/algorithms/bounded-mean.h b/cc/algorithms/bounded-mean.h index c9878735..5c1d9e28 100644 --- a/cc/algorithms/bounded-mean.h +++ b/cc/algorithms/bounded-mean.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include diff --git a/cc/algorithms/internal/BUILD b/cc/algorithms/internal/BUILD index fc8c723a..13911c28 100644 --- a/cc/algorithms/internal/BUILD +++ b/cc/algorithms/internal/BUILD @@ -57,6 +57,8 @@ cc_test( deps = [ ":bounded-mean-ci", "//algorithms:numerical-mechanisms", + "//base/testing:proto_matchers", + "//base/testing:status_matchers", "@com_google_absl//absl/log:check", "@com_google_absl//absl/status:statusor", "@com_google_differential_privacy//proto:confidence_interval_cc_proto", diff --git a/cc/algorithms/internal/bounded-mean-ci.cc b/cc/algorithms/internal/bounded-mean-ci.cc index f09082e6..50ac50ea 100644 --- a/cc/algorithms/internal/bounded-mean-ci.cc +++ b/cc/algorithms/internal/bounded-mean-ci.cc @@ -17,6 +17,7 @@ #include "algorithms/internal/bounded-mean-ci.h" #include +#include #include #include "algorithms/numerical-mechanisms.h" @@ -100,8 +101,17 @@ NoiseConfidenceIntervalForFixedNumAndDenom( // // This implementation uses a brute force search for confidenceLevelNum that // minimizes the size of the confidence interval of bounded mean. +// +// In case one of the input parameters is not finite, this function will return +// a default-constructed ConfidenceInterval with no values set. ConfidenceInterval BoundedMeanConfidenceInterval( const BoundedMeanConfidenceIntervalParams ¶ms) { + if (!std::isfinite(params.confidence_level) || + !std::isfinite(params.noised_sum) || !std::isfinite(params.lower_bound) || + !std::isfinite(params.upper_bound) || + !std::isfinite(params.noised_count)) { + return ConfidenceInterval(); + } NumericalMechanism::NoiseConfidenceIntervalResult tightest_ci; double tightest_ci_size = std::numeric_limits::max(); for (int i = 1; i < kNumStepsOptMeanConfidenceInterval; ++i) { diff --git a/cc/algorithms/internal/bounded-mean-ci_test.cc b/cc/algorithms/internal/bounded-mean-ci_test.cc index a71f044e..61569a5c 100644 --- a/cc/algorithms/internal/bounded-mean-ci_test.cc +++ b/cc/algorithms/internal/bounded-mean-ci_test.cc @@ -17,9 +17,12 @@ #include "algorithms/internal/bounded-mean-ci.h" #include +#include #include #include +#include "base/testing/proto_matchers.h" +#include "base/testing/status_matchers.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/log/check.h" @@ -35,6 +38,7 @@ using ::testing::_; using ::testing::AtLeast; using ::testing::DoubleEq; using ::testing::DoubleNear; +using ::differential_privacy::base::testing::EqualsProto; using ::testing::Gt; using ::testing::Lt; using ::testing::StrictMock; @@ -246,6 +250,18 @@ TEST(BoundedMeanCiTest, EXPECT_GT(ci_fewer_units.upper_bound(), ci_more_units.upper_bound()); } +TEST(BoundedMeanCiTest, InfiniteNoisedParamsReturnsDefaultCi) { + BoundedMeanConfidenceIntervalParams params; + params.lower_bound = -1.0; + params.upper_bound = 1.0; + params.noised_sum = std::numeric_limits::infinity(); + params.noised_count = std::numeric_limits::infinity(); + params.sum_mechanism = nullptr; + params.count_mechanism = nullptr; + + EXPECT_THAT(BoundedMeanConfidenceInterval(params), EqualsProto("")); +} + } // namespace } // namespace internal } // namespace differential_privacy diff --git a/cc/algorithms/internal/count-tree_test.cc b/cc/algorithms/internal/count-tree_test.cc index 006d6f82..74209167 100644 --- a/cc/algorithms/internal/count-tree_test.cc +++ b/cc/algorithms/internal/count-tree_test.cc @@ -144,17 +144,6 @@ TEST(CountTreeTest, MisatchMergeFails) { StatusIs(absl::StatusCode::kInternal, HasSubstr("Branching"))); } -TEST(CountTreeTest, MemoryUsed) { - CountTree empty(3, 5); - CountTree single(3, 5); - CountTree twice(3, 5); - single.IncrementNode(1); - twice.IncrementNode(9); - twice.IncrementNode(9); - EXPECT_GT(single.MemoryUsed(), empty.MemoryUsed()); - EXPECT_EQ(twice.MemoryUsed(), single.MemoryUsed()); -} - TEST(CountTreeTest, ClearNodes) { CountTree test1(3, 5); test1.IncrementNode(1); diff --git a/cc/cc_differential_privacy_deps.bzl b/cc/cc_differential_privacy_deps.bzl index c35b19c4..3c4212c5 100644 --- a/cc/cc_differential_privacy_deps.bzl +++ b/cc/cc_differential_privacy_deps.bzl @@ -26,9 +26,9 @@ def cc_differential_privacy_deps(): # Abseil http_archive( name = "com_google_absl", - url = "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz", - sha256 = "5366d7e7fa7ba0d915014d387b66d0d002c03236448e1ba9ef98122c13b35c36", - strip_prefix = "abseil-cpp-20230125.3", + url = "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.1.tar.gz", + sha256 = "987ce98f02eefbaf930d6e38ab16aa05737234d7afbab2d5c4ea7adbe50c28ed", + strip_prefix = "abseil-cpp-20230802.1", ) # Common bazel rules. Also required for Abseil. @@ -69,11 +69,11 @@ def cc_differential_privacy_deps(): # BoringSSL for cryptographic PRNG http_archive( name = "boringssl", - # Commit date: 2023-03-17 + # Commit date: 2023-10-26 # Note for updating: we need to use a commit from the `master-with-bazel` branch. - url = "https://github.com/google/boringssl/archive/e0648e015f039ef88801ff0cf84dcb5944b8b5ab.tar.gz", - sha256 = "b9ba36d3c309cfee56df70da8e8700f9ac65d4c0460f78bf8a4e580300b7f59d", - strip_prefix = "boringssl-e0648e015f039ef88801ff0cf84dcb5944b8b5ab", + url = "https://github.com/google/boringssl/archive/add3674f646bcc3dfa828f308454fb3b37919512.tar.gz", + sha256 = "f8b81f1741667e4a5aa9f0cc3e873875f7f832b3b141b8ee3a5d5863f992b8ba", + strip_prefix = "boringssl-add3674f646bcc3dfa828f308454fb3b37919512", ) # Supports `./configure && make` style packages to become dependencies. diff --git a/cc/postgres/.bazelversion b/cc/postgres/.bazelversion index 024b066c..19b860c1 100644 --- a/cc/postgres/.bazelversion +++ b/cc/postgres/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/cc/proto/util.h b/cc/proto/util.h index 868d5fa3..f59cf95a 100644 --- a/cc/proto/util.h +++ b/cc/proto/util.h @@ -132,13 +132,8 @@ void AddToOutput(Output* output, const T& value, const ConfidenceInterval& noise_confidence_interval) { Output_Element* element = output->add_elements(); SetValue(element->mutable_value(), value); - // Use the copy constructor here since operator= (or CopyFrom) would use an - // uninitialized value, perhaps as ConfidenceInterval is a proto3 message - // inside a proto2 message. - ConfidenceInterval* ci_copy = - new ConfidenceInterval(noise_confidence_interval); - // Transfers ownership of ci_copy to element. - element->set_allocated_noise_confidence_interval(ci_copy); + element->mutable_noise_confidence_interval()->CopyFrom( + noise_confidence_interval); } } // namespace differential_privacy diff --git a/examples/cc/.bazelversion b/examples/cc/.bazelversion index 024b066c..19b860c1 100644 --- a/examples/cc/.bazelversion +++ b/examples/cc/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/examples/go/.bazelversion b/examples/go/.bazelversion index 024b066c..19b860c1 100644 --- a/examples/go/.bazelversion +++ b/examples/go/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/examples/java/.bazelversion b/examples/java/.bazelversion index 84197c89..19b860c1 100644 --- a/examples/java/.bazelversion +++ b/examples/java/.bazelversion @@ -1 +1 @@ -5.3.2 +6.4.0 diff --git a/go/.bazelversion b/go/.bazelversion index 024b066c..19b860c1 100644 --- a/go/.bazelversion +++ b/go/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/java/.bazelversion b/java/.bazelversion index 024b066c..19b860c1 100644 --- a/java/.bazelversion +++ b/java/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/java/tests/com/google/privacy/differentialprivacy/BoundedVarianceTest.java b/java/tests/com/google/privacy/differentialprivacy/BoundedVarianceTest.java index 9bf6e05b..43c07c5d 100644 --- a/java/tests/com/google/privacy/differentialprivacy/BoundedVarianceTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/BoundedVarianceTest.java @@ -58,21 +58,18 @@ public class BoundedVarianceTest { private static final double EPSILON = 1.0; private static final double DELTA = 0.123; @Rule public final MockitoRule mocks = MockitoJUnit.rule(); - @Mock private Noise noise; - private BoundedVariance variance; + @Mock private Noise gaussianNoiseMock; + private BoundedVariance varianceWithZeroNoise; @Before public void setUp() { - when(noise.getMechanismType()).thenReturn(MechanismType.GAUSSIAN); - // Mock the noise mechanism so that it does not add any noise. - mockDoubleNoise(0); - mockLongNoise(0); + when(gaussianNoiseMock.getMechanismType()).thenReturn(MechanismType.GAUSSIAN); - variance = + varianceWithZeroNoise = BoundedVariance.builder() .epsilon(EPSILON) .delta(DELTA) - .noise(noise) + .noise(new ZeroNoise()) .maxPartitionsContributed(1) .maxContributionsPerPartition(1) .lower(1.0) @@ -82,56 +79,62 @@ public void setUp() { @Test public void addEntry() { - variance.addEntry(2.0); - variance.addEntry(4.0); - variance.addEntry(6.0); - variance.addEntry(8.0); + varianceWithZeroNoise.addEntry(2.0); + varianceWithZeroNoise.addEntry(4.0); + varianceWithZeroNoise.addEntry(6.0); + varianceWithZeroNoise.addEntry(8.0); - assertThat(variance.computeResult()).isEqualTo(5.0); + assertThat(varianceWithZeroNoise.computeResult()).isEqualTo(5.0); } @Test public void addEntry_nan_ignored() { // Add NaN - no exception is thrown. - variance.addEntry(NaN); + varianceWithZeroNoise.addEntry(NaN); // Add any values (let's say 7 and 9). Verify that the result is equal to their variance. - variance.addEntry(7); - variance.addEntry(9); - assertThat(variance.computeResult()).isEqualTo(1.0); + varianceWithZeroNoise.addEntry(7); + varianceWithZeroNoise.addEntry(9); + + assertThat(varianceWithZeroNoise.computeResult()).isEqualTo(1.0); } @Test public void addEntry_calledAfterComputeResult_throwsException() { - variance.computeResult(); - assertThrows(IllegalStateException.class, () -> variance.addEntry(0.0)); + varianceWithZeroNoise.computeResult(); + + assertThrows(IllegalStateException.class, () -> varianceWithZeroNoise.addEntry(0.0)); } @Test public void addEntries() { - variance.addEntries(ImmutableList.of(2.0, 4.0, 6.0, 8.0)); - assertThat(variance.computeResult()).isEqualTo(5.0); + varianceWithZeroNoise.addEntries(ImmutableList.of(2.0, 4.0, 6.0, 8.0)); + + assertThat(varianceWithZeroNoise.computeResult()).isEqualTo(5.0); } @Test public void addEntries_calledAfterComputeResult_throwsException() { - variance.computeResult(); - assertThrows(IllegalStateException.class, () -> variance.addEntries(ImmutableList.of(0.0))); + varianceWithZeroNoise.computeResult(); + + assertThrows( + IllegalStateException.class, () -> varianceWithZeroNoise.addEntries(ImmutableList.of(0.0))); } @Test public void computeResult_multipleCalls_throwsException() { - variance.computeResult(); - assertThrows(IllegalStateException.class, () -> variance.computeResult()); + varianceWithZeroNoise.computeResult(); + + assertThrows(IllegalStateException.class, () -> varianceWithZeroNoise.computeResult()); } // Input values are clamped to the upper and lower bounds. @Test public void addEntry_clampsInput() { - variance = + BoundedVariance variance = BoundedVariance.builder() .epsilon(EPSILON) .delta(DELTA) - .noise(noise) + .noise(new ZeroNoise()) .maxPartitionsContributed(1) .maxContributionsPerPartition(1) .lower(0.0) @@ -148,35 +151,40 @@ public void addEntry_clampsInput() { @Test public void computeResult_singleInput_returnsZero() { - variance.addEntry(3.0); - assertThat(variance.computeResult()).isEqualTo(0.0); + varianceWithZeroNoise.addEntry(3.0); + + assertThat(varianceWithZeroNoise.computeResult()).isEqualTo(0.0); } @Test public void computeResult_noInput_returnsZero() { - assertThat(variance.computeResult()).isEqualTo(0.0); + assertThat(varianceWithZeroNoise.computeResult()).isEqualTo(0.0); } @Test public void computeResult_callsNoiseCorrectly() { + // Arrange. int maxPartitionsContributed = 1; int maxContributionsPerPartition = 3; - variance = + BoundedVariance varianceWithNoiseMock = BoundedVariance.builder() .epsilon(3.0) .delta(0.9) - .noise(noise) + .noise(gaussianNoiseMock) .maxPartitionsContributed(maxPartitionsContributed) .maxContributionsPerPartition(maxContributionsPerPartition) .lower(1.0) .upper(9.0) .build(); - variance.addEntry(2.0); - variance.addEntry(4.0); - variance.computeResult(); + varianceWithNoiseMock.addEntry(2.0); + varianceWithNoiseMock.addEntry(4.0); + + // Act. + varianceWithNoiseMock.computeResult(); + // Assert. // Noising normalized sum of squares. - verify(noise) + verify(gaussianNoiseMock) .addNoise( eq(/* (x1 - midpoint)^2 + (x2 - midpoint)^2 = (2 - 5)^2 + (4 - 5)^2 */ 10.0), eq(maxPartitionsContributed), @@ -186,7 +194,7 @@ public void computeResult_callsNoiseCorrectly() { doubleThat(closeTo(/* delta */ 0.3))); // Noising normalized sum. - verify(noise) + verify(gaussianNoiseMock) .addNoise( eq(/* x1 + x2 - midpoint * count = 2 + 4 - 5 * 2 */ -4.0), eq(maxPartitionsContributed), @@ -195,7 +203,7 @@ public void computeResult_callsNoiseCorrectly() { doubleThat(closeTo(/* delta */ 0.3))); // Noising count. - verify(noise) + verify(gaussianNoiseMock) .addNoise( eq(/* count */ 2L), eq(maxPartitionsContributed), @@ -212,20 +220,20 @@ public void computeResult_addsNoiseToSum() { mockDoubleNoise(-10); // Mock the noise mechanism so that it adds noise to the count == 0. mockLongNoise(0); - - variance = + BoundedVariance varianceWithNoiseMock = BoundedVariance.builder() .epsilon(EPSILON) .delta(DELTA) - .noise(noise) + .noise(gaussianNoiseMock) .maxPartitionsContributed(1) .maxContributionsPerPartition(1) .lower(-100) .upper(100) .build(); - variance.addEntry(10); - variance.addEntry(10); + varianceWithNoiseMock.addEntry(10); + varianceWithNoiseMock.addEntry(10); + // midpoint = (lower + upper) / 2 = 0, // noised_normalized_sum_of_squares = (x1 - midpoint)^2 + (x2 - midpoint)^2 + noise = 10^2 + // 10^2 - 10 = 190, @@ -233,7 +241,7 @@ public void computeResult_addsNoiseToSum() { // noised_count = count + noise = 2 + 0 = 2, // BoundedVariance.computeResult() = noised_normalized_sum_of_squares / noised_count - // (noised_normalized_sum / noised_count)^2 = 190 / 2 - (10 / 2)^2 = 70 - assertThat(variance.computeResult()).isEqualTo(70.0); + assertThat(varianceWithNoiseMock.computeResult()).isEqualTo(70.0); } @Test @@ -242,20 +250,20 @@ public void computeResult_addsNoiseToCount() { mockDoubleNoise(0); // Mock the noise mechanism so that it adds noise to the count == 2. mockLongNoise(2); - - variance = + BoundedVariance varianceWithNoiseMock = BoundedVariance.builder() .epsilon(EPSILON) .delta(DELTA) - .noise(noise) + .noise(gaussianNoiseMock) .maxPartitionsContributed(1) .maxContributionsPerPartition(1) .lower(-100) .upper(100) .build(); - variance.addEntry(20); - variance.addEntry(20); + varianceWithNoiseMock.addEntry(20); + varianceWithNoiseMock.addEntry(20); + // midpoint = (lower + upper) / 2 = 0, // noised_normalized_sum_of_squares = (x1 - midpoint)^2 + (x2 - midpoint)^2 + noise = 20^2 + // 20^2 = 800, @@ -263,7 +271,7 @@ public void computeResult_addsNoiseToCount() { // noised_count = count + noise = 2 + 2 = 4, // BoundedVariance.computeResult() = noised_normalized_sum_of_squares / noised_count - // (noised_normalized_sum / noised_count)^2 = 800 / 4 - (40 / 4)^2 = 100 - assertThat(variance.computeResult()).isEqualTo(100.0); + assertThat(varianceWithNoiseMock.computeResult()).isEqualTo(100.0); } @Test @@ -276,19 +284,20 @@ public void computeResult_clampsTooHighVariance() { // The noise added to count is 0. mockLongNoise(0); - variance = + BoundedVariance varianceWithNoiseMock = BoundedVariance.builder() .epsilon(EPSILON) .delta(DELTA) - .noise(noise) + .noise(gaussianNoiseMock) .maxPartitionsContributed(1) .maxContributionsPerPartition(1) .lower(0.0) .upper(0.25) .build(); - variance.addEntry(0.25); - variance.addEntry(0.25); + varianceWithNoiseMock.addEntry(0.25); + varianceWithNoiseMock.addEntry(0.25); + // midpoint = (lower + upper) / 2 = 0.125, // noised_normalized_sum_of_squares = (x1 - midpoint)^2 + (x2 - midpoint)^2 + noise = 1.03125, // noised_normalized_sum = (x1 + x2) - midpoint * count + noise = 0.25 + 0.25 - 0.125 * 2 + 1 = @@ -298,7 +307,7 @@ public void computeResult_clampsTooHighVariance() { // (noised_normalized_sum / noised_count)^2 = 1.03125 / 2 - (1.25 / 2)^2 = 0.125 // BoundedVariance.computeResult = clamp(non_clamped_variance) = (0.25 - 0)^2 / 4 = 0.015625 // (upper bound). - assertThat(variance.computeResult()).isEqualTo(0.015625); + assertThat(varianceWithNoiseMock.computeResult()).isEqualTo(0.015625); } @Test @@ -311,19 +320,20 @@ public void computeResult_clampsTooLowVariance() { // The noise added to count is 0. mockLongNoise(0); - variance = + BoundedVariance varianceWithNoiseMock = BoundedVariance.builder() .epsilon(EPSILON) .delta(DELTA) - .noise(noise) + .noise(gaussianNoiseMock) .maxPartitionsContributed(1) .maxContributionsPerPartition(1) .lower(0) .upper(10) .build(); - variance.addEntry(5.0); - variance.addEntry(5.0); + varianceWithNoiseMock.addEntry(5.0); + varianceWithNoiseMock.addEntry(5.0); + // midpoint = (lower + upper) / 2 = 5, // noised_normalized_sum_of_squares = (x1 - midpoint)^2 + (x2 - midpoint)^2 + noise = -100, // noised_normalized_sum = (x1 + x2) - midpoint * count + noise = 5 + 5 - 5 * 2 - 100 = -100, @@ -331,7 +341,7 @@ public void computeResult_clampsTooLowVariance() { // non_clamped_variance = noised_normalized_sum_of_squares / noised_count - // (noised_normalized_sum / noised_count)^2 = -100 / 2 - (-100 / 2)^2 = -2550 // BoundedVariance.computeResult = clamp(non_clamped_variance) = 0 (lower bound). - assertThat(variance.computeResult()).isEqualTo(0.0); + assertThat(varianceWithNoiseMock.computeResult()).isEqualTo(0.0); } /** @@ -346,7 +356,7 @@ public void computeResult_resultAlwaysInsideProvidedBoundaries() { double lower = random.nextDouble() * 100; double upper = lower + random.nextDouble() * 100; - variance = + BoundedVariance varianceWithLaplaceNoise = BoundedVariance.builder() .epsilon(EPSILON) .noise(new LaplaceNoise()) @@ -364,46 +374,37 @@ public void computeResult_resultAlwaysInsideProvidedBoundaries() { .boxed() .collect(toImmutableList()); - variance.addEntries(dataset); + varianceWithLaplaceNoise.addEntries(dataset); assertWithMessage( "lower = %s\nupper = %s\ndataset = [%s]", lower, upper, dataset.stream().map(x -> Double.toString(x)).collect(joining(",\n"))) - .that(variance.computeResult()) + .that(varianceWithLaplaceNoise.computeResult()) .isIn(Range.closed(0.0, (upper - lower) * (upper - lower) / 4.0)); } } @Test public void getSerializableSummary_calledAfterComputeResult_throwsException() { - variance.computeResult(); + varianceWithZeroNoise.computeResult(); - assertThrows(IllegalStateException.class, () -> variance.getSerializableSummary()); + assertThrows(IllegalStateException.class, () -> varianceWithZeroNoise.getSerializableSummary()); } @Test public void getSerializableSummary_multipleCalls_returnsSameSummary() { - variance = - BoundedVariance.builder() - .epsilon(EPSILON) - .noise(new LaplaceNoise()) - .maxPartitionsContributed(1) - .maxContributionsPerPartition(1) - .lower(0.0) - .upper(1.0) - .build(); - variance.addEntry(0.5); + varianceWithZeroNoise.addEntry(0.5); - byte[] summary1 = variance.getSerializableSummary(); - byte[] summary2 = variance.getSerializableSummary(); + byte[] summary1 = varianceWithZeroNoise.getSerializableSummary(); + byte[] summary2 = varianceWithZeroNoise.getSerializableSummary(); assertThat(summary1).isEqualTo(summary2); } @Test public void mergeWith_anotherValue_computesVarianceOfTwoValues() { - BoundedVariance targetVariance = getVarianceBuilder().build(); - BoundedVariance sourceVariance = getVarianceBuilder().build(); + BoundedVariance targetVariance = getVarianceWithZeroNoiseBuilder().build(); + BoundedVariance sourceVariance = getVarianceWithZeroNoiseBuilder().build(); targetVariance.addEntry(1); sourceVariance.addEntry(9); @@ -414,9 +415,9 @@ public void mergeWith_anotherValue_computesVarianceOfTwoValues() { @Test public void mergeWith_calledTwice_computesVarianceOfAllValues() { - BoundedVariance targetVariance = getVarianceBuilder().build(); - BoundedVariance sourceVariance1 = getVarianceBuilder().build(); - BoundedVariance sourceVariance2 = getVarianceBuilder().build(); + BoundedVariance targetVariance = getVarianceWithZeroNoiseBuilder().build(); + BoundedVariance sourceVariance1 = getVarianceWithZeroNoiseBuilder().build(); + BoundedVariance sourceVariance2 = getVarianceWithZeroNoiseBuilder().build(); targetVariance.addEntry(1); sourceVariance1.addEntry(4); sourceVariance2.addEntry(7); @@ -429,8 +430,8 @@ public void mergeWith_calledTwice_computesVarianceOfAllValues() { @Test public void mergeWith_epsilonMismatch_throwsException() { - BoundedVariance targetVariance = getVarianceBuilder().epsilon(EPSILON).build(); - BoundedVariance sourceVariance = getVarianceBuilder().epsilon(2 * EPSILON).build(); + BoundedVariance targetVariance = getVarianceWithZeroNoiseBuilder().epsilon(EPSILON).build(); + BoundedVariance sourceVariance = getVarianceWithZeroNoiseBuilder().epsilon(2 * EPSILON).build(); assertThrows( IllegalArgumentException.class, @@ -440,9 +441,9 @@ public void mergeWith_epsilonMismatch_throwsException() { @Test public void mergeWith_nullDelta_mergesWithoutException() { BoundedVariance targetVariance = - getVarianceBuilder().noise(new LaplaceNoise()).delta(null).build(); + getVarianceWithZeroNoiseBuilder().noise(new LaplaceNoise()).delta(0.0).build(); BoundedVariance sourceVariance = - getVarianceBuilder().noise(new LaplaceNoise()).delta(null).build(); + getVarianceWithZeroNoiseBuilder().noise(new LaplaceNoise()).delta(0.0).build(); // No exception should be thrown. targetVariance.mergeWith(sourceVariance.getSerializableSummary()); @@ -450,8 +451,10 @@ public void mergeWith_nullDelta_mergesWithoutException() { @Test public void mergeWith_deltaMismatch_throwsException() { - BoundedVariance targetVariance = getVarianceBuilder().delta(DELTA).build(); - BoundedVariance sourceVariance = getVarianceBuilder().delta(2 * DELTA).build(); + BoundedVariance targetVariance = + getVarianceWithZeroNoiseBuilder().noise(new GaussianNoise()).delta(DELTA).build(); + BoundedVariance sourceVariance = + getVarianceWithZeroNoiseBuilder().noise(new GaussianNoise()).delta(2 * DELTA).build(); assertThrows( IllegalArgumentException.class, @@ -461,8 +464,9 @@ public void mergeWith_deltaMismatch_throwsException() { @Test public void mergeWith_noiseMismatch_throwsException() { BoundedVariance targetVariance = - getVarianceBuilder().noise(new LaplaceNoise()).delta(null).build(); - BoundedVariance sourceVariance = getVarianceBuilder().noise(new GaussianNoise()).build(); + getVarianceWithZeroNoiseBuilder().noise(new LaplaceNoise()).delta(0.0).build(); + BoundedVariance sourceVariance = + getVarianceWithZeroNoiseBuilder().noise(new GaussianNoise()).delta(0.1).build(); assertThrows( IllegalArgumentException.class, @@ -471,8 +475,10 @@ public void mergeWith_noiseMismatch_throwsException() { @Test public void mergeWith_maxPartitionsContributedMismatch_throwsException() { - BoundedVariance targetVariance = getVarianceBuilder().maxPartitionsContributed(1).build(); - BoundedVariance sourceVariance = getVarianceBuilder().maxPartitionsContributed(2).build(); + BoundedVariance targetVariance = + getVarianceWithZeroNoiseBuilder().maxPartitionsContributed(1).build(); + BoundedVariance sourceVariance = + getVarianceWithZeroNoiseBuilder().maxPartitionsContributed(2).build(); assertThrows( IllegalArgumentException.class, @@ -481,8 +487,10 @@ public void mergeWith_maxPartitionsContributedMismatch_throwsException() { @Test public void mergeWith_differentMaxContributionsPerPartitionMismatch_throwsException() { - BoundedVariance targetVariance = getVarianceBuilder().maxContributionsPerPartition(1).build(); - BoundedVariance sourceVariance = getVarianceBuilder().maxContributionsPerPartition(2).build(); + BoundedVariance targetVariance = + getVarianceWithZeroNoiseBuilder().maxContributionsPerPartition(1).build(); + BoundedVariance sourceVariance = + getVarianceWithZeroNoiseBuilder().maxContributionsPerPartition(2).build(); assertThrows( IllegalArgumentException.class, @@ -491,8 +499,8 @@ public void mergeWith_differentMaxContributionsPerPartitionMismatch_throwsExcept @Test public void mergeWith_lowerBoundsMismatch_throwsException() { - BoundedVariance targetVariance = getVarianceBuilder().lower(-1).build(); - BoundedVariance sourceVariance = getVarianceBuilder().lower(-100).build(); + BoundedVariance targetVariance = getVarianceWithZeroNoiseBuilder().lower(-1).build(); + BoundedVariance sourceVariance = getVarianceWithZeroNoiseBuilder().lower(-100).build(); assertThrows( IllegalArgumentException.class, @@ -501,8 +509,8 @@ public void mergeWith_lowerBoundsMismatch_throwsException() { @Test public void mergeWith_upperBoundsMismatch_throwsException() { - BoundedVariance targetVariance = getVarianceBuilder().upper(1).build(); - BoundedVariance sourceVariance = getVarianceBuilder().upper(100).build(); + BoundedVariance targetVariance = getVarianceWithZeroNoiseBuilder().upper(1).build(); + BoundedVariance sourceVariance = getVarianceWithZeroNoiseBuilder().upper(100).build(); assertThrows( IllegalArgumentException.class, @@ -511,8 +519,8 @@ public void mergeWith_upperBoundsMismatch_throwsException() { @Test public void mergeWith_calledAfterComputeResult_throwsException() { - BoundedVariance targetVariance = getVarianceBuilder().build(); - BoundedVariance sourceVariance = getVarianceBuilder().build(); + BoundedVariance targetVariance = getVarianceWithZeroNoiseBuilder().build(); + BoundedVariance sourceVariance = getVarianceWithZeroNoiseBuilder().build(); targetVariance.computeResult(); byte[] summary = sourceVariance.getSerializableSummary(); @@ -521,19 +529,19 @@ public void mergeWith_calledAfterComputeResult_throwsException() { @Test public void mergeWith_calledAfterSerializationOnTargetVariance_throwsException() { - BoundedVariance targetVariance = getVarianceBuilder().build(); - BoundedVariance sourceVariance = getVarianceBuilder().build(); + BoundedVariance targetVariance = getVarianceWithZeroNoiseBuilder().build(); + BoundedVariance sourceVariance = getVarianceWithZeroNoiseBuilder().build(); targetVariance.getSerializableSummary(); byte[] summary = sourceVariance.getSerializableSummary(); assertThrows(IllegalStateException.class, () -> targetVariance.mergeWith(summary)); } - private BoundedVariance.Params.Builder getVarianceBuilder() { + private BoundedVariance.Params.Builder getVarianceWithZeroNoiseBuilder() { return BoundedVariance.builder() .epsilon(EPSILON) .delta(DELTA) - .noise(noise) + .noise(new ZeroNoise()) .maxPartitionsContributed(1) // lower, upper and, maxContributionsPerPartition have arbitrarily chosen values. .maxContributionsPerPartition(10) @@ -542,12 +550,12 @@ private BoundedVariance.Params.Builder getVarianceBuilder() { } private void mockDoubleNoise(double value) { - when(noise.addNoise(anyDouble(), anyInt(), anyDouble(), anyDouble(), anyDouble())) + when(gaussianNoiseMock.addNoise(anyDouble(), anyInt(), anyDouble(), anyDouble(), anyDouble())) .thenAnswer(invocation -> (double) invocation.getArguments()[0] + value); } private void mockLongNoise(long value) { - when(noise.addNoise(anyLong(), anyInt(), anyLong(), anyDouble(), anyDouble())) + when(gaussianNoiseMock.addNoise(anyLong(), anyInt(), anyLong(), anyDouble(), anyDouble())) .thenAnswer(invocation -> (long) invocation.getArguments()[0] + value); } diff --git a/java/tests/com/google/privacy/differentialprivacy/DiscreteLaplaceNoiseTest.java b/java/tests/com/google/privacy/differentialprivacy/DiscreteLaplaceNoiseTest.java index fbfff49d..e6ea9c15 100644 --- a/java/tests/com/google/privacy/differentialprivacy/DiscreteLaplaceNoiseTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/DiscreteLaplaceNoiseTest.java @@ -55,7 +55,7 @@ public void addNoise_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } double variance = @@ -80,7 +80,7 @@ public void addNoise_differentX_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } double mean = 42; @@ -106,7 +106,7 @@ public void addNoise_differentSensitivity_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ 2, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } double variance = getVariance(DEFAULT_EPSILON, DEFAULT_L_0_SENSITIVITY, 2); @@ -130,7 +130,7 @@ public void addNoise_differentEpsilon_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, /* epsilon= */ 0.5 * LN_3, - /* delta= */ null)); + /* delta= */ 0.0)); } double variance = getVariance(0.5 * LN_3, DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY); @@ -153,7 +153,7 @@ public void addNoise_epsilonTooSmall_throwsException() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, /* epsilon= */ 1.0 / (1L << 51), - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -166,7 +166,7 @@ public void addNoise_epsilonPosInfinity_throwsException() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, /* epsilon= */ Double.POSITIVE_INFINITY, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -179,7 +179,7 @@ public void addNoise_epsilonNan_throwsException() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, /* epsilon= */ Double.NaN, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -205,7 +205,7 @@ public void addNoise_lInfSensitivityTooHigh_throwsException() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ Double.MAX_VALUE, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -218,7 +218,7 @@ public void addNoise_lInfSensitivityNan_throwsException() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ Double.NaN, /* epsilon= */ 1.0, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -231,7 +231,7 @@ public void addNoise_lInfSensitivityNegative_throwsException() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ -1.0, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -244,7 +244,7 @@ public void addNoise_lInfSensitivityZero_throwsException() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ 0.0, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -257,7 +257,7 @@ public void addNoise_l0SensitivityNegative_throwsException() { /* l0Sensitivity= */ -1, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -270,7 +270,7 @@ public void addNoise_l0SensitivityZero_throwsException() { /* l0Sensitivity= */ 0, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -278,7 +278,7 @@ public void addNoise_l1SensitivityNegative_throwsException() { assertThrows( IllegalArgumentException.class, () -> - NOISE.addNoise(DEFAULT_X, /* l1Sensitivity= */ -1, DEFAULT_EPSILON, /* delta= */ null)); + NOISE.addNoise(DEFAULT_X, /* l1Sensitivity= */ -1, DEFAULT_EPSILON, /* delta= */ 0.0)); } @Test @@ -286,7 +286,7 @@ public void addNoise_l1SensitivityZero_throwsException() { assertThrows( IllegalArgumentException.class, () -> - NOISE.addNoise(DEFAULT_X, /* l1Sensitivity= */ 0, DEFAULT_EPSILON, /* delta= */ null)); + NOISE.addNoise(DEFAULT_X, /* l1Sensitivity= */ 0, DEFAULT_EPSILON, /* delta= */ 0.0)); } @Test diff --git a/java/tests/com/google/privacy/differentialprivacy/GaussianNoiseTest.java b/java/tests/com/google/privacy/differentialprivacy/GaussianNoiseTest.java index 6c531306..618adaa5 100644 --- a/java/tests/com/google/privacy/differentialprivacy/GaussianNoiseTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/GaussianNoiseTest.java @@ -266,7 +266,7 @@ public void addNoise_deltaNull_throwsException() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test diff --git a/java/tests/com/google/privacy/differentialprivacy/LaplaceNoiseTest.java b/java/tests/com/google/privacy/differentialprivacy/LaplaceNoiseTest.java index 92026e4b..03b6fcbe 100644 --- a/java/tests/com/google/privacy/differentialprivacy/LaplaceNoiseTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/LaplaceNoiseTest.java @@ -54,7 +54,7 @@ public void addNoise_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } Stats stats = Stats.of(samples.build()); @@ -78,7 +78,7 @@ public void addNoise_differentX_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } Stats stats = Stats.of(samples.build()); @@ -103,7 +103,7 @@ public void addNoise_differentSensitivity_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ 0.5, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } Stats stats = Stats.of(samples.build()); @@ -126,7 +126,7 @@ public void addNoise_differentEpsilon_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, /* epsilon= */ 2 * LN_3, - /* delta= */ null)); + /* delta= */ 0.0)); } Stats stats = Stats.of(samples.build()); @@ -149,7 +149,7 @@ public void addNoise_integralX_hasAccurateStatisticalProperties() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ 1L, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } Stats stats = Stats.of(samples.build()); @@ -172,7 +172,7 @@ public void addNoise_epsilonTooSmall_throwsException() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, /* epsilon= */ 1.0 / (1L << 51), - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -185,7 +185,7 @@ public void addNoise_epsilonPosInfinity_throwsException() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, /* epsilon= */ Double.POSITIVE_INFINITY, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -198,7 +198,7 @@ public void addNoise_epsilonNan_throwsException() { DEFAULT_L_0_SENSITIVITY, DEFAULT_L_INF_SENSITIVITY, /* epsilon= */ Double.NaN, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -224,7 +224,7 @@ public void addNoise_lInfSensitivityTooHigh_throwsException() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ Double.MAX_VALUE, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -237,7 +237,7 @@ public void addNoise_lInfSensitivityNan_throwsException() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ Double.NaN, /* epsilon= */ 1.0, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -250,7 +250,7 @@ public void addNoise_lInfSensitivityNegative_throwsException() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ -1.0, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -263,7 +263,7 @@ public void addNoise_lInfSensitivityZero_throwsException() { DEFAULT_L_0_SENSITIVITY, /* lInfSensitivity= */ 0.0, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -276,7 +276,7 @@ public void addNoise_l0SensitivityNegative_throwsException() { /* l0Sensitivity= */ -1, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -289,7 +289,7 @@ public void addNoise_l0SensitivityZero_throwsException() { /* l0Sensitivity= */ 0, DEFAULT_L_INF_SENSITIVITY, DEFAULT_EPSILON, - /* delta= */ null)); + /* delta= */ 0.0)); } @Test @@ -298,7 +298,7 @@ public void addNoise_l1SensitivityNegative_throwsException() { IllegalArgumentException.class, () -> NOISE.addNoise( - DEFAULT_X, /* l1Sensitivity= */ -1.0, DEFAULT_EPSILON, /* delta= */ null)); + DEFAULT_X, /* l1Sensitivity= */ -1.0, DEFAULT_EPSILON, /* delta= */ 0.0)); } @Test @@ -307,7 +307,7 @@ public void addNoise_l1SensitivityZero_throwsException() { IllegalArgumentException.class, () -> NOISE.addNoise( - DEFAULT_X, /* l1Sensitivity= */ 0.0, DEFAULT_EPSILON, /* delta= */ null)); + DEFAULT_X, /* l1Sensitivity= */ 0.0, DEFAULT_EPSILON, /* delta= */ 0.0)); } @Test @@ -316,7 +316,7 @@ public void addNoise_l1SensitivityNan_throwsException() { IllegalArgumentException.class, () -> NOISE.addNoise( - DEFAULT_X, /* l1Sensitivity= */ Double.NaN, DEFAULT_EPSILON, /* delta= */ null)); + DEFAULT_X, /* l1Sensitivity= */ Double.NaN, DEFAULT_EPSILON, /* delta= */ 0.0)); } @Test @@ -335,7 +335,7 @@ public void addNoise_returnsMultipleOfGranularity() { /* l0Sensitivity= */ 1, /* lInfSensitivity= */ 1.0, /* epsilon= */ 4.7e-10, - /* delta= */ null); + /* delta= */ 0.0); assertThat(Math.floor(noisedX * 1024.0)).isEqualTo(noisedX * 1024.0); // The following choice of epsilon, l0 sensitivity and linf sensitivity should result in a @@ -346,7 +346,7 @@ public void addNoise_returnsMultipleOfGranularity() { /* l0Sensitivity= */ 1, /* lInfSensitivity= */ 1.0, /* epsilon= */ 9.1e-13, - /* delta= */ null); + /* delta= */ 0.0); assertThat(Math.floor(noisedX)).isEqualTo(noisedX); // The following choice of epsilon, l0 sensitivity and linf sensitivity should result in a @@ -357,7 +357,7 @@ public void addNoise_returnsMultipleOfGranularity() { /* l0Sensitivity= */ 1, /* lInfSensitivity= */ 1.0, /* epsilon= */ 8.9e-16, - /* delta= */ null); + /* delta= */ 0.0); assertThat(Math.floor(noisedX / 1024.0)).isEqualTo(noisedX / 1024.0); } } @@ -378,7 +378,7 @@ public void addNoise_integralX_returnsMultipleOfGranularity() { /* l0Sensitivity= */ 1, /* lInfSensitivity= */ 1, /* epsilon= */ 4.6e-13, - /* delta= */ null); + /* delta= */ 0.0); assertThat(noisedX % 2).isEqualTo(0); // The following choice of epsilon, l0 sensitivity and linf sensitivity should result in a @@ -389,7 +389,7 @@ public void addNoise_integralX_returnsMultipleOfGranularity() { /* l0Sensitivity= */ 1, /* lInfSensitivity= */ 1, /* epsilon= */ 8.9e-16, - /* delta= */ null); + /* delta= */ 0.0); assertThat(noisedX % 1024).isEqualTo(0); } } diff --git a/java/tests/com/google/privacy/differentialprivacy/LongBoundedSumConfidenceIntervalTest.java b/java/tests/com/google/privacy/differentialprivacy/LongBoundedSumConfidenceIntervalTest.java index 3127d3b2..ea0fa1ba 100644 --- a/java/tests/com/google/privacy/differentialprivacy/LongBoundedSumConfidenceIntervalTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/LongBoundedSumConfidenceIntervalTest.java @@ -105,7 +105,7 @@ public void computeConfidenceInterval_gaussianNoise_calledTwiceForSameAlpha_retu @Test public void computeConfidenceInterval_laplaceNoise_calledTwiceForSameAlpha_returnsSameResult() { - LongBoundedSum sum = builder.noise(new LaplaceNoise()).delta(null).build(); + LongBoundedSum sum = builder.noise(new LaplaceNoise()).delta(0.0).build(); var unused = sum.computeResult(); assertThat(sum.computeConfidenceInterval(ARBITRARY_ALPHA)) @@ -127,7 +127,7 @@ public void computeConfidenceInterval_laplaceNoise_calledTwiceForSameAlpha_retur @Test public void computeConfidenceInterval_laplaceNoise_resultForSmallAlphaContainedInResultForLargeAlpha() { - LongBoundedSum sum = builder.noise(new LaplaceNoise()).delta(null).build(); + LongBoundedSum sum = builder.noise(new LaplaceNoise()).delta(0.0).build(); var unused = sum.computeResult(); assertThat(sum.computeConfidenceInterval(ARBITRARY_ALPHA * 0.5).lowerBound()) @@ -171,7 +171,7 @@ public void computeConfidenceInterval_laplaceNoise_calledTwiceForSameAlpha_retur LongBoundedSum sum = builder .epsilon(ARBITRARY_EPSILON) - .delta(null) + .delta(0.0) .noise(new LaplaceNoise()) .maxPartitionsContributed(ARBITRARY_MAX_PARTITIONS_CONTRIBUTED) .maxContributionsPerPartition(ARBITRARY_MAX_CONTRIBUTIONS_PER_PARTITION) @@ -188,7 +188,7 @@ public void computeConfidenceInterval_laplaceNoise_calledTwiceForSameAlpha_retur /* l0Sensitivity= */ ARBITRARY_MAX_PARTITIONS_CONTRIBUTED, /* lInfSensitivity= */ ARBITRARY_MAX_CONTRIBUTIONS_PER_PARTITION * 875, ARBITRARY_EPSILON, - /* delta= */ null, + /* delta= */ 0.0, ARBITRARY_ALPHA)); } diff --git a/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedMeanDpTest.java b/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedMeanDpTest.java index ee8ea3ae..d9addacf 100644 --- a/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedMeanDpTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedMeanDpTest.java @@ -64,11 +64,11 @@ public void boundedMeanDpTest() { DpTestParameters dpTestParameters = testCase.getDpTestParameters(); Noise noise; - Double delta; + double delta; switch (samplingParameters.getNoiseType()) { case LAPLACE: noise = TestNoiseFactory.createLaplaceNoise(new Random()); - delta = null; + delta = 0.0; break; case GAUSSIAN: noise = TestNoiseFactory.createGaussianNoise(new Random()); diff --git a/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedQuantilesDpTest.java b/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedQuantilesDpTest.java index 081ac08f..bec9da99 100644 --- a/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedQuantilesDpTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedQuantilesDpTest.java @@ -67,11 +67,11 @@ public static Iterable testcases() { private static BoundedQuantiles getBoundedQuantiles( BoundedQuantilesSamplingParameters samplingParameters) { Noise noise; - Double delta; + double delta; switch (samplingParameters.getNoiseType()) { case LAPLACE: noise = TestNoiseFactory.createLaplaceNoise(ThreadLocalRandom.current()); - delta = null; + delta = 0.0; break; case GAUSSIAN: noise = TestNoiseFactory.createGaussianNoise(ThreadLocalRandom.current()); diff --git a/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedSumDpTest.java b/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedSumDpTest.java index 4e9e3aa9..15c8a783 100644 --- a/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedSumDpTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedSumDpTest.java @@ -62,11 +62,11 @@ public void boundedSumDpTest() { DpTestParameters dpTestParameters = testCase.getDpTestParameters(); Noise noise; - Double delta; + double delta; switch (samplingParameters.getNoiseType()) { case LAPLACE: noise = TestNoiseFactory.createLaplaceNoise(new Random()); - delta = null; + delta = 0.0; break; case GAUSSIAN: noise = TestNoiseFactory.createGaussianNoise(new Random()); diff --git a/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedVarianceDpTest.java b/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedVarianceDpTest.java index be05894e..b1acbb0a 100644 --- a/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedVarianceDpTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/statistical/BoundedVarianceDpTest.java @@ -62,11 +62,11 @@ public static Iterable testCases() { private static BoundedVariance getBoundedVariance( BoundedStdvSamplingParameters samplingParameters) { Noise noise; - Double delta; + double delta; switch (samplingParameters.getNoiseType()) { case LAPLACE: noise = TestNoiseFactory.createLaplaceNoise(ThreadLocalRandom.current()); - delta = null; + delta = 0.0; break; case GAUSSIAN: noise = TestNoiseFactory.createGaussianNoise(ThreadLocalRandom.current()); diff --git a/java/tests/com/google/privacy/differentialprivacy/statistical/CountDpTest.java b/java/tests/com/google/privacy/differentialprivacy/statistical/CountDpTest.java index fac23f4c..7c7770e4 100644 --- a/java/tests/com/google/privacy/differentialprivacy/statistical/CountDpTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/statistical/CountDpTest.java @@ -61,11 +61,11 @@ public void countDpTest() { DpTestParameters dpTestParameters = testCase.getDpTestParameters(); Noise noise; - Double delta; + double delta; switch (samplingParameters.getNoiseType()) { case LAPLACE: noise = TestNoiseFactory.createLaplaceNoise(new Random()); - delta = null; + delta = 0.0; break; case GAUSSIAN: noise = TestNoiseFactory.createGaussianNoise(new Random()); diff --git a/java/tests/com/google/privacy/differentialprivacy/statistical/LaplaceClosenessTest.java b/java/tests/com/google/privacy/differentialprivacy/statistical/LaplaceClosenessTest.java index 1c289015..259deb97 100644 --- a/java/tests/com/google/privacy/differentialprivacy/statistical/LaplaceClosenessTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/statistical/LaplaceClosenessTest.java @@ -69,7 +69,7 @@ public void laplaceClosenessTest() { samplingParameters.getL0Sensitivity(), samplingParameters.getLinfSensitivity(), samplingParameters.getEpsilon(), - /* delta= */ null); + /* delta= */ 0.0); Supplier referenceSampleGenerator = () -> ReferenceNoiseUtil.sampleLaplace( diff --git a/java/tests/com/google/privacy/differentialprivacy/statistical/LongBoundedSumDpTest.java b/java/tests/com/google/privacy/differentialprivacy/statistical/LongBoundedSumDpTest.java index dac1d207..220cbe0c 100644 --- a/java/tests/com/google/privacy/differentialprivacy/statistical/LongBoundedSumDpTest.java +++ b/java/tests/com/google/privacy/differentialprivacy/statistical/LongBoundedSumDpTest.java @@ -65,11 +65,11 @@ public void longBoundedSumDpTest() { DpTestParameters dpTestParameters = testCase.getDpTestParameters(); Noise noise; - Double delta; + double delta; switch (samplingParameters.getNoiseType()) { case LAPLACE: noise = TestNoiseFactory.createLaplaceNoise(new Random()); - delta = null; + delta = 0.0; break; case GAUSSIAN: noise = TestNoiseFactory.createGaussianNoise(new Random()); diff --git a/learning/.bazelversion b/learning/.bazelversion index 024b066c..19b860c1 100644 --- a/learning/.bazelversion +++ b/learning/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/privacy-on-beam/.bazelversion b/privacy-on-beam/.bazelversion index 024b066c..19b860c1 100644 --- a/privacy-on-beam/.bazelversion +++ b/privacy-on-beam/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0 diff --git a/python/.bazelversion b/python/.bazelversion index 024b066c..19b860c1 100644 --- a/python/.bazelversion +++ b/python/.bazelversion @@ -1 +1 @@ -6.2.1 +6.4.0