Skip to content

Commit 8d1c557

Browse files
Differential Privacy Teammiracvbasaran
Differential Privacy Team
authored andcommitted
Add quantile trees and deprecate order statistics in C++
C++: - Add an interface for multiple quantiles, supported by Quantile Trees - Mark OrderStatistics as deprecated in favor of the new quantile implementation Go & Privacy on Beam: - Various fixes and improvements for CI with the `go` tool Privacy on Beam: - Improve instructions for depending on the library with Bazel - Fix typos in DistinctPerKey tests Accounting: - Add a function to conveniently create PLD for Discrete Laplace, Discrete Gaussian and Gaussian Mechanisms GitOrigin-RevId: 958acb2199902126d3d333dd8d1da150fa281911 Change-Id: I89de361be98dcc6da9675d5730f5b06bb7c59a31
1 parent e149618 commit 8d1c557

32 files changed

+3773
-108
lines changed

.github/workflows/go.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
# Version 1.0 does not work with the "go" tool properly.
7+
- "1.0"
8+
pull_request:
9+
branches-ignore:
10+
# Version 1.0 does not work with the "go" tool properly.
11+
- "1.0"
12+
schedule:
13+
# Every Thursday at 1PM UTC
14+
- cron: "0 13 * * 4"
15+
16+
jobs:
17+
18+
build:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 15
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v2
26+
with:
27+
go-version: 1.16
28+
29+
- name: Build go
30+
run: go build -mod=mod -v ./...
31+
working-directory: ./go
32+
33+
- name: Test go
34+
run: go test -mod=mod -v ./...
35+
working-directory: ./go
36+
37+
- name: Build examples/go
38+
run: go build -mod=mod -v ./...
39+
working-directory: ./examples/go
40+
41+
- name: Build privacy-on-beam
42+
run: go build -mod=mod -v ./...
43+
working-directory: ./privacy-on-beam
44+
45+
- name: Test privacy-on-beam
46+
run: go test -mod=mod -v ./...
47+
working-directory: ./privacy-on-beam

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Currently, the DP building block libraries support the following algorithms:
2828
| Count | Supported | Supported | Supported |
2929
| Sum | Supported | Supported | Supported |
3030
| Mean | Supported | Supported | Supported |
31-
| Variance | Supported | Planned | Planned |
32-
| Standard deviation | Supported | Planned | Planned |
31+
| Variance | Supported | Supported | Planned |
32+
| Standard deviation | Supported | Supported | Planned |
3333
| Quantiles | Supported | Supported | Supported |
3434
| Automatic bounds approximation | Supported | Planned | Planned |
3535
| Truncated geometric thresholding | Supported | Supported | Supported |

cc/accounting/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ cc_library(
4747
"@com_google_absl//absl/container:flat_hash_map",
4848
"@com_google_absl//absl/status",
4949
"@com_google_absl//absl/strings:str_format",
50+
"@com_google_absl//absl/types:optional",
5051
"@com_google_cc_differential_privacy//base:status",
5152
"@com_google_cc_differential_privacy//base:statusor",
5253
],
@@ -81,6 +82,7 @@ cc_test(
8182
"//accounting/common:test_util",
8283
"@com_google_differential_privacy//proto/accounting:privacy_loss_distribution_cc_proto",
8384
"@com_google_absl//absl/status",
85+
"@com_google_absl//absl/types:optional",
8486
"@com_google_cc_differential_privacy//base:statusor",
8587
],
8688
)

cc/accounting/privacy_loss_distribution.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "absl/strings/str_format.h"
2323
#include "accounting/common/common.h"
2424
#include "accounting/convolution.h"
25+
#include "accounting/privacy_loss_mechanism.h"
2526
#include "proto/accounting/privacy-loss-distribution.pb.h"
2627
#include "base/status_macros.h"
2728

@@ -204,6 +205,39 @@ PrivacyLossDistribution::CreateForLaplaceMechanism(
204205
discretization_interval);
205206
}
206207

208+
base::StatusOr<std::unique_ptr<PrivacyLossDistribution>>
209+
PrivacyLossDistribution::CreateForDiscreteLaplaceMechanism(
210+
double parameter, int sensitivity, EstimateType estimate_type,
211+
double discretization_interval) {
212+
ASSIGN_OR_RETURN(std::unique_ptr<DiscreteLaplacePrivacyLoss> privacy_loss,
213+
DiscreteLaplacePrivacyLoss::Create(parameter, sensitivity));
214+
return CreateForAdditiveNoise(*privacy_loss, estimate_type,
215+
discretization_interval);
216+
}
217+
218+
base::StatusOr<std::unique_ptr<PrivacyLossDistribution>>
219+
PrivacyLossDistribution::CreateForGaussianMechanism(
220+
double standard_deviation, double sensitivity, EstimateType estimate_type,
221+
double discretization_interval, double mass_truncation_bound) {
222+
ASSIGN_OR_RETURN(
223+
std::unique_ptr<GaussianPrivacyLoss> privacy_loss,
224+
GaussianPrivacyLoss::Create(standard_deviation, sensitivity,
225+
estimate_type, mass_truncation_bound));
226+
return CreateForAdditiveNoise(*privacy_loss, estimate_type,
227+
discretization_interval);
228+
}
229+
230+
base::StatusOr<std::unique_ptr<PrivacyLossDistribution>>
231+
PrivacyLossDistribution::CreateForDiscreteGaussianMechanism(
232+
double sigma, int sensitivity, EstimateType estimate_type,
233+
double discretization_interval, absl::optional<int> truncation_bound) {
234+
ASSIGN_OR_RETURN(std::unique_ptr<DiscreteGaussianPrivacyLoss> privacy_loss,
235+
DiscreteGaussianPrivacyLoss::Create(sigma, sensitivity,
236+
truncation_bound));
237+
return CreateForAdditiveNoise(*privacy_loss, estimate_type,
238+
discretization_interval);
239+
}
240+
207241
std::unique_ptr<PrivacyLossDistribution>
208242
PrivacyLossDistribution::CreateForPrivacyParameters(
209243
EpsilonDelta epsilon_delta, double discretization_interval) {

cc/accounting/privacy_loss_distribution.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "absl/container/flat_hash_map.h"
2424
#include "base/statusor.h"
25+
#include "absl/types/optional.h"
2526
#include "accounting/common/common.h"
2627
#include "accounting/privacy_loss_mechanism.h"
2728
#include "proto/accounting/privacy-loss-distribution.pb.h"
@@ -122,12 +123,80 @@ class PrivacyLossDistribution {
122123
// estimate_type: kPessimistic denoting that the rounding is done in such a
123124
// way that the resulting epsilon-hockey stick divergence computation gives
124125
// an upper estimate to the real value.
126+
// discretization_interval: the length of the dicretization interval for the
127+
// privacy loss distribution. The values will be rounded up/down to be
128+
// integer multiples of this number.
125129
static base::StatusOr<std::unique_ptr<PrivacyLossDistribution>>
126130
CreateForLaplaceMechanism(
127131
double parameter, double sensitivity = 1,
128132
EstimateType estimate_type = EstimateType::kPessimistic,
129133
double discretization_interval = 1e-4);
130134

135+
// Creates {@link PrivacyLossDistribution} for the Discrete Laplace mechanism.
136+
//
137+
// parameter: the parameter of the Discrete Laplace distribution.
138+
// sensitivity: the sensitivity of function f. (i.e. the maximum absolute
139+
// change in f when an input to a single user changes.)
140+
// estimate_type: kPessimistic denoting that the rounding is done in such a
141+
// way that the resulting epsilon-hockey stick divergence computation gives
142+
// an upper estimate to the real value.
143+
// discretization_interval: the length of the dicretization interval for the
144+
// privacy loss distribution. The values will be rounded up/down to be
145+
// integer multiples of this number.
146+
static base::StatusOr<std::unique_ptr<PrivacyLossDistribution>>
147+
CreateForDiscreteLaplaceMechanism(
148+
double parameter, int sensitivity = 1,
149+
EstimateType estimate_type = EstimateType::kPessimistic,
150+
double discretization_interval = 1e-4);
151+
152+
// Creates {@link PrivacyLossDistribution} for the Gaussian mechanism.
153+
//
154+
// standard_deviation: the standard_deviation of the Gaussian distribution.
155+
// sensitivity: the sensitivity of function f. (i.e. the maximum absolute
156+
// change in f when an input to a single user changes.)
157+
// estimate_type: kPessimistic denoting that the rounding is done in such a
158+
// way that the resulting epsilon-hockey stick divergence computation gives
159+
// an upper estimate to the real value.
160+
// discretization_interval: the length of the dicretization interval for the
161+
// privacy loss distribution. The values will be rounded up/down to be
162+
// integer multiples of this number.
163+
// mass_truncation_bound: the natural log of the probability mass that might
164+
// be discarded from the noise distribution. The larger this number, the
165+
// more error it may introduce in divergence calculations.
166+
static base::StatusOr<std::unique_ptr<PrivacyLossDistribution>>
167+
CreateForGaussianMechanism(
168+
double standard_deviation, double sensitivity = 1,
169+
EstimateType estimate_type = EstimateType::kPessimistic,
170+
double discretization_interval = 1e-4,
171+
double mass_truncation_bound = -50);
172+
173+
// Creates {@link PrivacyLossDistribution} for the Gaussian mechanism.
174+
//
175+
// sigma: he parameter of the discrete Gaussian distribution. Note that unlike
176+
// the (continuous) Gaussian distribution this is not equal to the standard
177+
// deviation of the noise.
178+
// sensitivity: the sensitivity of function f. (i.e. the maximum absolute
179+
// change in f when an input to a single user changes.)
180+
// estimate_type: kPessimistic denoting that the rounding is done in such a
181+
// way that the resulting epsilon-hockey stick divergence computation gives
182+
// an upper estimate to the real value.
183+
// discretization_interval: the length of the dicretization interval for the
184+
// privacy loss distribution. The values will be rounded up/down to be
185+
// integer multiples of this number.
186+
// mass_truncation_bound: the natural log of the probability mass that might
187+
// be discarded from the noise distribution. The larger this number, the
188+
// more error it may introduce in divergence calculations.
189+
// truncation_bound: bound for truncating the noise, i.e. the noise will only
190+
// have a support in [-truncation_bound, truncation_bound]. When not set,
191+
// truncation_bound will be chosen in such a way that the mass of the noise
192+
// outside of this range is at most 1e-30.
193+
static base::StatusOr<std::unique_ptr<PrivacyLossDistribution>>
194+
CreateForDiscreteGaussianMechanism(
195+
double sigma, int sensitivity = 1,
196+
EstimateType estimate_type = EstimateType::kPessimistic,
197+
double discretization_interval = 1e-4,
198+
absl::optional<int> truncation_bound = absl::nullopt);
199+
131200
// Creates {@link PrivacyLossDistribution} from epsilon and delta parameters.
132201
//
133202
// When the mechanism is (epsilon, delta)-differentially private, the

0 commit comments

Comments
 (0)