Skip to content

Commit

Permalink
PlumeGo CountParams improvements, updates to DP libraries, dependency…
Browse files Browse the repository at this point in the history
… fixes, deprecation cleanups.

General:
- Update freshness of documents and fix minor issues.
- Remove documentation for deprecated functions Bounded Standard Deviation and Order Statistics.

Plume Go:
- Add option to CountParams to allow negative outputs to improve data quality of the output.

C++ DP:
- Fix Float-cast-overflow in quantiles.
- Fix import and quantile test dependencies.

Java DP:
- Update bazel for java to 7.0.0.
- Fix truth8 import style.

Go DP:
- Update go version to 1.21, upgrade Bazel & gazelle versions, upgrade Apache Beam dependency to the latest version.

Privacy on Beam:
- Mark PrivacySpec constructors of pbeamtest as deprecated.
- Add missing doFn registers to fix tests failing with the new Prism runner.

Change-Id: Ie08898ee34bdfeb6329701abefd22aa92b1c004a
GitOrigin-RevId: 0aa22f05d11bb130df248e842b2ccc6a649c6b00
  • Loading branch information
Differential Privacy Team authored and jspacek committed Feb 8, 2024
1 parent fd0020d commit 7b02d98
Show file tree
Hide file tree
Showing 86 changed files with 886 additions and 522 deletions.
2 changes: 2 additions & 0 deletions cc/algorithms/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ cc_test(
"//base/testing:proto_matchers",
"//base/testing:status_matchers",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest_main",
],
)
Expand Down
1 change: 1 addition & 0 deletions cc/algorithms/binary-search.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define DIFFERENTIAL_PRIVACY_ALGORITHMS_BINARY_SEARCH_H_

#include <cmath>
#include <cstdint>
#include <cstdlib>

#include "base/percentile.h"
Expand Down
10 changes: 6 additions & 4 deletions cc/algorithms/quantiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef DIFFERENTIAL_PRIVACY_CPP_ALGORITHMS_QUANTILES_H_
#define DIFFERENTIAL_PRIVACY_CPP_ALGORITHMS_QUANTILES_H_

#include <cstdint>

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "algorithms/algorithm.h"
Expand Down Expand Up @@ -115,10 +117,10 @@ class Quantiles : public Algorithm<T> {

private:
Quantiles(std::unique_ptr<QuantileTree<T>> tree,
std::vector<double> quantiles, double epsilon, double delta,
int max_contributions_per_partition,
int max_partitions_contributed_to,
std::unique_ptr<NumericalMechanismBuilder> mechanism_builder)
std::vector<double> quantiles, double epsilon, double delta,
int max_contributions_per_partition,
int max_partitions_contributed_to,
std::unique_ptr<NumericalMechanismBuilder> mechanism_builder)
: Algorithm<T>(epsilon, delta),
tree_(std::move(tree)),
quantiles_(quantiles),
Expand Down
13 changes: 13 additions & 0 deletions cc/algorithms/quantiles_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
#include "algorithms/quantiles.h"

#include <algorithm>
#include <cstdint>
#include <limits>
#include <memory>
#include <vector>

#include "base/testing/proto_matchers.h"
#include "base/testing/status_matchers.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/random/random.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "algorithms/numerical-mechanisms-testing.h"

namespace differential_privacy {
Expand Down Expand Up @@ -77,6 +82,14 @@ TEST(QuantilesTest, InvalidParametersTest) {
.Build(),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Lower bound cannot be greater than upper bound")));
EXPECT_THAT(
Quantiles<double>::Builder()
.SetLower(1)
.SetUpper(1)
.SetQuantiles({0.5})
.Build(),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Lower bound cannot be equal to upper bound")));
EXPECT_THAT(Quantiles<double>::Builder().SetQuantiles({0.5}).Build(),
StatusIs(absl::StatusCode::kInvalidArgument,
HasSubstr("Lower and upper bounds must both be set")));
Expand Down
4 changes: 4 additions & 0 deletions cc/algorithms/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ absl::Status ValidateBounds(absl::optional<T> lower, absl::optional<T> upper) {
return absl::InvalidArgumentError(
"Lower bound cannot be greater than upper bound.");
}
if (lower.value() == upper.value()) {
return absl::InvalidArgumentError(
"Lower bound cannot be equal to upper bound.");
}
return absl::OkStatus();
}

Expand Down
1 change: 1 addition & 0 deletions cc/base/percentile.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define DIFFERENTIAL_PRIVACY_BASE_PERCENTILE_H_

#include <cmath>
#include <cstdint>

#include "google/protobuf/repeated_field.h"
#include "proto/util.h"
Expand Down
5 changes: 3 additions & 2 deletions cc/docs/algorithms/algorithm.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ absl::StatusOr<std::unique_ptr<Algorithm>> algorithm =
noise during testing.

### Partitions

Several of the parameters refer to the concept of a partition. We define a
partition as a portion of the data for which a single statistic will be
released. This is best explained through examples: if you're counting the number
Expand Down Expand Up @@ -126,6 +127,6 @@ Note that whichever method of getting a result you use, you can only get a
single result before your `epsilon` and `delta` are exhausted.

Values are returned from `Result` in an [`Output`](../protos.md) proto. For most
algorithms, this is a single `int64` or `double` value. Some algorithms contain
additional data about accuracy and algorithm mechanisms. You can use
algorithms, this is a single `int64_t` or `double` value. Some algorithms
contain additional data about accuracy and algorithm mechanisms. You can use
[`GetValue<Type>`](../protos.md) to get values out of `Output`s easily.
4 changes: 2 additions & 2 deletions cc/docs/algorithms/approx-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bounds of input sets inside [bounded algorithms](bounded-algorithm.md).

## Input & Output

`ApproxBounds` supports `int64` and `double` type input sets. When successful,
`ApproxBounds` supports `int64_t` and `double` type input sets. When successful,
the returned [`Output`](../protos.md) message will contain two elements. The
first is the differentially private lower bound; the second is the upper. The
`Output` message will contain an error status instead if not enough inputs were
Expand All @@ -21,7 +21,7 @@ are additional parameters.

```
ApproxBounds<T>::Builder builder =
ApproxBounds<T>::Builder.SetNumBins(int64 num_bins)
ApproxBounds<T>::Builder.SetNumBins(int64_t num_bins)
.SetScale(double scale)
.SetBase(double base)
Expand Down
12 changes: 6 additions & 6 deletions cc/docs/algorithms/bounded-mean.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ computes the average of values in a dataset in a differentially private manner.

## Input & Output

`BoundedMean` supports `int64`s and `double`s as inputs. When successful,
`BoundedMean` supports `int64_t` and `double` types as input. When successful,
the returned [`Output`](../protos.md) message will contain one element
containing the differentially private mean. When bounds are inferred, the
`Output` additionally contains a `BoundingReport`. The returned value is
Expand All @@ -19,11 +19,11 @@ Information on how to construct a `BoundedMean` is found in the
construction example.

```
absl::StatusOr<std::unique_ptr<BoundedMean<int64>>> bounded_mean =
BoundedMean<int64>::Builder.SetEpsilon(1)
.SetLower(-10)
.SetUpper(10)
.Build();
absl::StatusOr<std::unique_ptr<BoundedMean<int64_t>>> bounded_mean =
BoundedMean<int64_t>::Builder.SetEpsilon(1)
.SetLower(-10)
.SetUpper(10)
.Build();
```

## Use
Expand Down
43 changes: 0 additions & 43 deletions cc/docs/algorithms/bounded-standard-deviation.md

This file was deleted.

16 changes: 8 additions & 8 deletions cc/docs/algorithms/bounded-sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ computes the sum of values in a dataset in a differentially private manner.

## Input & Output

`BoundedSum` supports `int64`s and `double`s as input. When successful, the
returned [`Output`](../protos.md) message will contain one element with
the differentially private sum, and a `ConfidenceInterval` describing the 95%
`BoundedSum` supports `int64_t` and `double` types as input. When successful,
the returned [`Output`](../protos.md) message will contain one element with the
differentially private sum, and a `ConfidenceInterval` describing the 95%
confidence interval of the noise added. When bounds are inferred, the `Output`
also contains a `BoundingReport`.

Expand All @@ -23,11 +23,11 @@ Information on how to construct a `BoundedSum` is found in the
construction example.

```
absl::StatusOr<std::unique_ptr<BoundedSum<int64>>> bounded_sum =
BoundedSum<int64>::Builder.SetEpsilon(1)
.SetLower(-10)
.SetUpper(10)
.Build();
absl::StatusOr<std::unique_ptr<BoundedSum<int64_t>>> bounded_sum =
BoundedSum<int64_t>::Builder.SetEpsilon(1)
.SetLower(-10)
.SetUpper(10)
.Build();
```

## Use
Expand Down
20 changes: 10 additions & 10 deletions cc/docs/algorithms/bounded-variance.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ variance of values in a dataset, in a differentially private manner.

## Input & Output

`BoundedVariance` supports `int64`s and `double`s as inputs. When
`BoundedVariance` supports `int64_t` and `double` types as input. When
successful, the returned [`Output`](../protos.md) message will contain one
element with the differentially private variance. When bounds are
inferred, the `Output` additionally contains a `BoundingReport`. The returned
value is guaranteed to be non-negative, with a maximum possible value of the
maximum variance (length of the bounded interval squared divided by four).
element with the differentially private variance. When bounds are inferred, the
`Output` additionally contains a `BoundingReport`. The returned value is
guaranteed to be non-negative, with a maximum possible value of the maximum
variance (length of the bounded interval squared divided by four).

## Construction

Expand All @@ -20,11 +20,11 @@ Information on how to construct a `BoundedVariance` is found in the
construction example.

```
absl::StatusOr<std::unique_ptr<BoundedVariance<int64>>> bounded_var =
BoundedVariance<int64>::Builder.SetEpsilon(1)
.SetLower(-10)
.SetUpper(10)
.Build();
absl::StatusOr<std::unique_ptr<BoundedVariance<int64_t>>> bounded_var =
BoundedVariance<int64_t>::Builder.SetEpsilon(1)
.SetLower(-10)
.SetUpper(10)
.Build();
```

## Use
Expand Down
6 changes: 3 additions & 3 deletions cc/docs/algorithms/count.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ additional parameters.
minimal construction example.

```
absl::StatusOr<std::unique_ptr<Count<int64>>> count =
Count<int64>::Builder.SetEpsilon(1)
.Build();
absl::StatusOr<std::unique_ptr<Count<int64_t>>> count =
Count<int64_t>::Builder.SetEpsilon(1)
.Build();
```

### Result Performance
Expand Down
52 changes: 0 additions & 52 deletions cc/docs/algorithms/order-statistics.md

This file was deleted.

4 changes: 2 additions & 2 deletions cc/docs/algorithms/quantiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ absl::StatusOr<std::unique_ptr<Quantiles<T>>> quantile =
.Build();
```

* `T`: The input type, for example `double` or `int64`.
* `T`: The input type, for example `double` or `int64_t`.
* `T upper, lower`: The upper and lower bounds on each input element. If any
input elements are greater than `upper` or less than `lower`, they will be
replaced with `upper` or `lower` respectively.
Expand Down Expand Up @@ -93,7 +93,7 @@ absl::StatusOr<std::unique_ptr<QuantileTree<T>>> quantile_tree =
.Build();
```

* `T`: The input type, for example `double` or `int64`.
* `T`: The input type, for example `double` or `int64_t`.
* `T upper, lower`: The upper and lower bounds for each input element. If any
inputs are greater than `upper` or less than `lower` they will be replaced
with `upper` or `lower` respectively.
Expand Down
8 changes: 4 additions & 4 deletions cc/docs/protos.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ functions for the common cases. We outline some of these functions below. See
the [utility function file](https://github.com/google/differential-privacy/blob/main/cc/proto/util.h)
for the full list.

### GetValue&lt;T&gt;
### `GetValue<T>`

```
template <typename T>
Expand All @@ -69,7 +69,7 @@ Extracts the first element from the provided `Output` proto. `T` is the
requested return type; the value in the proto must match that type. For example,
if `T` is an integral type, the element must have `int_value` set.

### MakeOutput
### `MakeOutput`

Creates an `Output` with one element. Which field gets set depends on the type
of the template parameter `T`. For example, `MakeOutput(7)` will set
Expand All @@ -80,13 +80,13 @@ template <typename T>
MakeOutput(T value);
```

### AddToOutput
### `AddToOutput`

Adds an element to the given output. Which field gets set depends on the type of
the template parameter `T`. For example, `AddToOutput(&output, 7.0)` will add an
element to `output` and set the `float_value`.

```
template <typename T>
void AddToOutput(Output* output, T value) {
void AddToOutput(Output* output, T value);
```
1 change: 1 addition & 0 deletions cc/testing/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define DIFFERENTIAL_PRIVACY_TESTING_SEQUENCE_H_

#include <algorithm>
#include <cstdint>
#include <memory>
#include <vector>

Expand Down
Loading

0 comments on commit 7b02d98

Please sign in to comment.