Skip to content

Commit

Permalink
Fix broken Privacy on Beam build
Browse files Browse the repository at this point in the history
Privacy on Beam:
- Update Go Lib dependency to the latest commit, this fixes the build being broken

Go:
- More documentation & tests for pre-thresholding in PreAggSelectPartition

Java:
- Add missing license header to ZeroNoise.java

Change-Id: I448925072b118c08f4521258e4ed399039372979
GitOrigin-RevId: 7d05c446cdb9966ce98037447c5664a2d34aa069
  • Loading branch information
Differential Privacy Team authored and miracvbasaran committed Aug 9, 2023
1 parent f2a2682 commit 9b28daa
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 14 deletions.
1 change: 1 addition & 0 deletions cc/algorithms/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ cc_test(
"//base/testing:status_matchers",
"//proto:util-lib",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_differential_privacy//proto:data_cc_proto",
"@com_google_googletest//:gtest_main",
],
Expand Down
2 changes: 2 additions & 0 deletions cc/algorithms/bounded-sum_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
#include <cstdlib>
#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/memory/memory.h"
#include "absl/status/status.h"
#include "algorithms/algorithm.h"
#include "algorithms/approx-bounds.h"
#include "algorithms/numerical-mechanisms-testing.h"
Expand Down
6 changes: 6 additions & 0 deletions go/dpagg/select_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ import (
// partition and then determining whether the partition should be
// materialized. Use Increment() to increment the count of IDs and ShouldKeepPartition() to decide
// if the partition should be materialized.
//
// PreAggSelectPartition also supports doing additional pre-thresholding on top of the
// differentially private partition selection via the PreThreshold in PreAggSelectPartitionOptions.
//
// See https://github.com/google/differential-privacy/blob/main/common_docs/pre_thresholding.md
// for more information.
type PreAggSelectPartition struct {
// parameters
epsilon float64
Expand Down
56 changes: 45 additions & 11 deletions go/dpagg/select_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,50 @@ func TestPreAggSelectPartition(t *testing.T) {
}

// Tests that an idCount smaller than prethreshold deterministically returns false.
func TestNewPreAggSelectPartition_PreThresholding(t *testing.T) {
s := getTestPreAggSelectPartition(t)
s.IncrementBy(9)
should, err := s.ShouldKeepPartition()
if err != nil {
t.Fatalf("Couldn't compute ShouldKeepPartition: %v", err)
func TestNewPreAggSelectPartition_CountSmallerThanPreThresholdReturnsFalse(t *testing.T) {
for _, tc := range []struct {
name string
maxPartitionsContributed int64 // > 3 leads to gaussian thresholding being used
}{
{"magic_partition_selection", 1},
{"gaussian_thresholding", 4},
} {
t.Run(tc.name, func(t *testing.T) {
s := getTestPreAggSelectPartition(t)
s.preThreshold = 10
s.l0Sensitivity = tc.maxPartitionsContributed
s.IncrementBy(9)
should, err := s.ShouldKeepPartition()
if err != nil {
t.Fatalf("Couldn't compute ShouldKeepPartition: %v", err)
}
if should {
t.Errorf("ShouldKeepPartition returned true for a count smaller than prethreshold")
}
})
}
if should {
t.Errorf("ShouldKeepPartition returned true for a count smaller than prethreshold")
}

// Tests that an idCount greater than the pre-threshold deterministically returns true for a large enough delta & epsilon.
func TestNewPreAggSelectPartition_CountGreaterThanPreThresholdReturnsTrue(t *testing.T) {
for _, tc := range []struct {
name string
maxPartitionsContributed int64 // > 3 leads to gaussian thresholding being used
}{
{"magic_partition_selection", 1},
{"gaussian_thresholding", 4},
} {
s := getTestPreAggSelectPartition(t)
s.preThreshold = 10
s.l0Sensitivity = tc.maxPartitionsContributed
s.IncrementBy(11)
should, err := s.ShouldKeepPartition()
if err != nil {
t.Fatalf("Couldn't compute ShouldKeepPartition: %v", err)
}
if !should {
t.Errorf("ShouldKeepPartition returned false for a count larger than prethreshold")
}
}
}

Expand Down Expand Up @@ -660,9 +695,8 @@ func TestPreAggSelectPartitionResultSetsStateCorrectly(t *testing.T) {
func getTestPreAggSelectPartition(t *testing.T) *PreAggSelectPartition {
t.Helper()
s, err := NewPreAggSelectPartition(&PreAggSelectPartitionOptions{
Epsilon: 1e10,
Delta: 1 - 1e-15,
PreThreshold: 10,
Epsilon: 100,
Delta: 1 - 1e-5,
MaxPartitionsContributed: 1,
})
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions java/main/com/google/privacy/differentialprivacy/ZeroNoise.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
//
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.google.privacy.differentialprivacy;

import com.google.privacy.differentialprivacy.proto.SummaryOuterClass.MechanismType;
Expand Down
2 changes: 1 addition & 1 deletion privacy-on-beam/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/apache/beam/sdks/v2 v2.46.0
github.com/golang/glog v1.1.1
github.com/google/differential-privacy/go/v2 v2.1.0
github.com/google/differential-privacy/go/v2 v2.1.1-0.20230808111858-f2a2682a6752
github.com/google/go-cmp v0.5.9
gonum.org/v1/plot v0.12.0
google.golang.org/protobuf v1.30.0
Expand Down
4 changes: 2 additions & 2 deletions privacy-on-beam/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/golang/glog v1.1.1/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/differential-privacy/go/v2 v2.1.0 h1:v3hCOAaUMnY7Fkk+osv3cgMXUAFqaI2l8agICV6IJl4=
github.com/google/differential-privacy/go/v2 v2.1.0/go.mod h1:KRaNc5O0mzJ6cBC3iJbQNk9OHTzRLdmp1IXMaFlOxt8=
github.com/google/differential-privacy/go/v2 v2.1.1-0.20230808111858-f2a2682a6752 h1:KDTY1QPsjXM21cV0pzvvJl2G/dUdcJHPkBRMjcHUSwk=
github.com/google/differential-privacy/go/v2 v2.1.1-0.20230808111858-f2a2682a6752/go.mod h1:KRaNc5O0mzJ6cBC3iJbQNk9OHTzRLdmp1IXMaFlOxt8=
github.com/google/go-cmp v0.2.1-0.20190312032427-6f77996f0c42/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
Expand Down

0 comments on commit 9b28daa

Please sign in to comment.