Documentation ¶
Overview ¶
Package testutils provides helper functions, structs, etc. for testing Privacy on Beam pipelines.
Index ¶
- func ApproxEquals(x, y float64) bool
- func ApproxEqualsKVFloat64(t *testing.T, s beam.Scope, col1, col2 beam.PCollection, tolerance float64)
- func ApproxEqualsKVFloat64Slice(t *testing.T, s beam.Scope, col1, col2 beam.PCollection, tolerance float64)
- func ApproxEqualsKVInt64(t *testing.T, s beam.Scope, col1, col2 beam.PCollection, tolerance float64)
- func CheckAllValuesNegativeFloat64(v float64) error
- func CheckApproxNumPartitions(s beam.Scope, col beam.PCollection, expected, tolerance int)
- func CheckAtLeastOneValueNegativeInt64(s beam.Scope, col beam.PCollection)
- func CheckFloat64MetricsAreNoisy(s beam.Scope, col beam.PCollection, exactMetric, tolerance float64)
- func CheckInt64MetricsAreNoisy(s beam.Scope, col beam.PCollection, exactMetric int, tolerance float64)
- func CheckNoNegativeValuesFloat64(v float64) error
- func CheckNoNegativeValuesInt64(v int64) error
- func CheckNumPartitions(s beam.Scope, col beam.PCollection, expected int)
- func CheckSomePartitionsAreDropped(s beam.Scope, col beam.PCollection, numPartitions int)
- func ComplementaryGaussianTolerance(flakinessK, l0Sensitivity, lInfSensitivity, epsilon, delta float64) float64
- func ComplementaryLaplaceTolerance(flakinessK, l1Sensitivity, epsilon float64) float64
- func DereferenceFloat64Slice(v beam.V, r []float64) (beam.V, float64, error)
- func EqualsKVFloat64(t *testing.T, s beam.Scope, col1, col2 beam.PCollection)
- func EqualsKVInt(t *testing.T, s beam.Scope, col1, col2 beam.PCollection)
- func EqualsKVInt64(t *testing.T, s beam.Scope, col1, col2 beam.PCollection)
- func Float64Ptr(f float64) *float64
- func GaussianTolerance(flakinessK, l0Sensitivity, lInfSensitivity, epsilon, delta float64) float64
- func Int64Ptr(i int64) *int64
- func LaplaceTolerance(flakinessK, l1Sensitivity, epsilon float64) float64
- func LaplaceToleranceForMean(flakinessK, lower, upper float64, ...) (float64, error)
- func LessThanOrEqualToKVFloat64(t *testing.T, s beam.Scope, col1, col2 beam.PCollection)
- func NotEqualsFloat64(t *testing.T, s beam.Scope, col1, col2 beam.PCollection)
- func OneFn(beam.V) int
- func PairICodedKVToKV(p PairICodedKV) (k int, v kv.Pair)
- func PairIF64SliceToKV(tm PairIF64Slice) (int, []float64)
- func PairIF64ToKV(tm PairIF64) (int, float64)
- func PairII64ToKV(tm PairII64) (int, int64)
- func PairToKV(p PairII) (k, v int)
- func QuantilesTolerance(lower, upper float64) float64
- func RoundedLaplaceTolerance(flakinessK, l1Sensitivity, epsilon float64) float64
- func ToleranceForMean(...) (float64, error)
- func TripleWithFloatValueToKV(t TripleWithFloatValue) (int, float32)
- func TripleWithIntValueToKV(t TripleWithIntValue) (int, int)
- type PairICodedKV
- type PairIF64
- type PairIF64Slice
- type PairII
- type PairII64
- type TripleWithFloatValue
- func ConcatenateTriplesWithFloatValue(slices ...[]TripleWithFloatValue) []TripleWithFloatValue
- func ExtractIDFromTripleWithFloatValue(t TripleWithFloatValue) (int, TripleWithFloatValue)
- func MakeSampleTripleWithFloatValue(numKeys, p int) []TripleWithFloatValue
- func MakeTripleWithFloatValue(numKeys, p int, v float32) []TripleWithFloatValue
- func MakeTripleWithFloatValueStartingFromKey(kOffset, numKeys, p int, v float32) []TripleWithFloatValue
- type TripleWithIntValue
- func ConcatenateTriplesWithIntValue(slices ...[]TripleWithIntValue) []TripleWithIntValue
- func ExtractIDFromTripleWithIntValue(t TripleWithIntValue) (int, TripleWithIntValue)
- func MakeSampleTripleWithIntValue(numKeys, p int) []TripleWithIntValue
- func MakeTripleWithIntValue(numKeys, p, v int) []TripleWithIntValue
- func MakeTripleWithIntValueStartingFromKey(kOffset, numKeys, p, v int) []TripleWithIntValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApproxEquals ¶
ApproxEquals returns true if x and y are approximately equal within a tolerance of 1e-10.
func ApproxEqualsKVFloat64 ¶
func ApproxEqualsKVFloat64(t *testing.T, s beam.Scope, col1, col2 beam.PCollection, tolerance float64)
ApproxEqualsKVFloat64 checks that two PCollections col1 and col2 of type <K,float64> are approximately equal, where "approximately equal" means "the keys are the same in both col1 and col2, and the value associated with key k in col1 is within the specified tolerance of the value associated with k in col2". Each key can only hold a single value.
func ApproxEqualsKVFloat64Slice ¶
func ApproxEqualsKVFloat64Slice(t *testing.T, s beam.Scope, col1, col2 beam.PCollection, tolerance float64)
ApproxEqualsKVFloat64Slice checks that two PCollections col1 and col2 of type <K,[]float64> are approximately equal, where "approximately equal" means "the keys are the same in both col1 and col2, and each value in the slice associated with key k in col1 is within the specified tolerance of each value in the slice associated with k in col2". Each key can only hold a single slice.
func ApproxEqualsKVInt64 ¶
func ApproxEqualsKVInt64(t *testing.T, s beam.Scope, col1, col2 beam.PCollection, tolerance float64)
ApproxEqualsKVInt64 checks that two PCollections col1 and col2 of type <K,int64> are approximately equal, where "approximately equal" means "the keys are the same in both col1 and col2, and the value associated with key k in col1 is within the specified tolerance of the value associated with k in col2". Each key can only hold a single value.
func CheckAllValuesNegativeFloat64 ¶
CheckAllValuesNegativeFloat64 returns an error if an float64 value is non-negative.
func CheckApproxNumPartitions ¶
func CheckApproxNumPartitions(s beam.Scope, col beam.PCollection, expected, tolerance int)
CheckApproxNumPartitions checks that col has approximately expected number of partitions. col is allowed to have number of partitions within tolerance of expected.
func CheckAtLeastOneValueNegativeInt64 ¶
func CheckAtLeastOneValueNegativeInt64(s beam.Scope, col beam.PCollection)
CheckAtLeastOneValueNegativeInt64 operates on a PCollection<int64> and will return an error during runtime if none of the int64 values is negative.
func CheckFloat64MetricsAreNoisy ¶
func CheckFloat64MetricsAreNoisy(s beam.Scope, col beam.PCollection, exactMetric, tolerance float64)
CheckFloat64MetricsAreNoisy checks that no values in a PCollection<pairIF64> (where pairIF64 contains the aggregate statistic) is equal to exactMetric.
func CheckInt64MetricsAreNoisy ¶
func CheckInt64MetricsAreNoisy(s beam.Scope, col beam.PCollection, exactMetric int, tolerance float64)
CheckInt64MetricsAreNoisy checks that no values in a PCollection<pairII64> (where pairII64 contains the aggregate statistic) is equal to exactMetric.
func CheckNoNegativeValuesFloat64 ¶
CheckNoNegativeValuesFloat64 returns an error if an float64 value is negative.
func CheckNoNegativeValuesInt64 ¶
CheckNoNegativeValuesInt64 returns an error if an int64 value is negative.
func CheckNumPartitions ¶
func CheckNumPartitions(s beam.Scope, col beam.PCollection, expected int)
CheckNumPartitions checks that col has expected number of partitions.
func CheckSomePartitionsAreDropped ¶
func CheckSomePartitionsAreDropped(s beam.Scope, col beam.PCollection, numPartitions int)
CheckSomePartitionsAreDropped checks that the number of values in the PCollection is smaller than numPartitions, but larger than 0.
func ComplementaryGaussianTolerance ¶
func ComplementaryGaussianTolerance(flakinessK, l0Sensitivity, lInfSensitivity, epsilon, delta float64) float64
ComplementaryGaussianTolerance returns tolerance to be used in checkMetricsAreNoisy for tests with Gaussian Noise to pass with 10⁻ᵏ flakiness. flakinessK is the parameter used to specify this.
l0Sensitivity, lInfSensitivity, epsilon and delta are the DP parameters of the test.
To see the logic and the math behind flakiness and tolerance calculation, See https://github.com/google/differential-privacy/blob/main/privacy-on-beam/docs/Tolerance_Calculation.pdf
func ComplementaryLaplaceTolerance ¶
ComplementaryLaplaceTolerance returns tolerance to be used in checkMetricsAreNoisy for tests with Laplace Noise to pass with 10⁻ᵏ flakiness. flakinessK is the parameter used to specify this.
l1Sensitivity, epsilon and delta are the DP parameters of the test.
To see the logic and the math behind flakiness and tolerance calculation, See https://github.com/google/differential-privacy/blob/main/privacy-on-beam/docs/Tolerance_Calculation.pdf
func DereferenceFloat64Slice ¶
DereferenceFloat64Slice returns the first and only element of the slice for each key in a PCollection<K, []float64>. Returns an error if the slice does not contain exactly 1 element.
func EqualsKVFloat64 ¶
EqualsKVFloat64 checks that two PCollections col1 and col2 of type <K,float64> are exactly equal. Each key can only hold a single value.
func EqualsKVInt ¶
EqualsKVInt checks that two PCollections col1 and col2 of type <K,int> are exactly equal.
func EqualsKVInt64 ¶
EqualsKVInt64 checks that two PCollections col1 and col2 of type <K,int64> are exactly equal. Each key can only hold a single value.
func Float64Ptr ¶
Float64Ptr transforms a float64 into a *float64.
func GaussianTolerance ¶
GaussianTolerance returns tolerance to be used in approxEquals or in threshold computations for tests with Gaussian Noise to pass with 10⁻ᵏ flakiness. flakinessK is the parameter used to specify this.
l0Sensitivity, lInfSensitivity, epsilon and delta are the DP parameters of the test.
To see the logic and the math behind flakiness and tolerance calculation, See https://github.com/google/differential-privacy/blob/main/privacy-on-beam/docs/Tolerance_Calculation.pdf
func LaplaceTolerance ¶
LaplaceTolerance returns tolerance to be used in approxEquals or in threshold computations for tests with Laplace Noise to pass with 10⁻ᵏ flakiness. flakinessK is the parameter used to specify this.
l1Sensitivity and epsilon are the DP parameters of the test.
To see the logic and the math behind flakiness and tolerance calculation, See https://github.com/google/differential-privacy/blob/main/privacy-on-beam/docs/Tolerance_Calculation.pdf.
func LaplaceToleranceForMean ¶
func LaplaceToleranceForMean(flakinessK, lower, upper float64, maxContributionsPerPartition, maxPartitionsContributed int64, epsilon float64, exactNormalizedSum, exactCount, exactMean float64) (float64, error)
LaplaceToleranceForMean returns tolerance to be used in approxEquals for tests for mean to pass with 10⁻ᵏ flakiness.
flakinessK is the parameter used to specify k in the flakiness. distanceFromMidPoint = upper - midPoint, where midPoint = (lower + upper)/2. exactNormalizedSum is a clamped (with boundaries -distanceFromMidPoint and distanceFromMidPoint) sum of distances of the input entities from the midPoint. exactNormalizedSum is needed for calculating tolerance because the algorithm of the mean aggregation uses noisy normalized sum in its calculations.
To see the logic and the math behind flakiness and tolerance calculation, See https://github.com/google/differential-privacy/blob/main/privacy-on-beam/docs/Tolerance_Calculation.pdf
func LessThanOrEqualToKVFloat64 ¶
LessThanOrEqualToKVFloat64 checks that for PCollections col1 and col2 of type <K,float64>, for each key k, value corresponding to col1 is less than or equal to the value corresponding in col2. Each key can only hold a single value.
func NotEqualsFloat64 ¶
NotEqualsFloat64 checks that two PCollections col1 and col2 of type <K,float64> are different. Each key can only hold a single value.
func PairICodedKVToKV ¶
func PairICodedKVToKV(p PairICodedKV) (k int, v kv.Pair)
PairICodedKVToKV transforms a PairICodedKV into an (int, kv.Pair) key-value pair.
func PairIF64SliceToKV ¶
func PairIF64SliceToKV(tm PairIF64Slice) (int, []float64)
PairIF64SliceToKV transforms a PairIF64Slice into an (int, []float64) key-value pair.
func PairIF64ToKV ¶
PairIF64ToKV transforms a PairIF64 into an (int, float64) key-value pair.
func PairII64ToKV ¶
PairII64ToKV transforms a PairII64 into an (int, int64) key-value pair.
func QuantilesTolerance ¶
QuantilesTolerance returns tolerance to be used in approxEquals for tests for quantiles to pass with negligible flakiness.
When no noise is added, the quantiles should return a value that differs from the true quantile by no more than the size of the buckets the range is partitioned into, i.e., (upper - lower) / (branchingFactor^treeHeight - 1).
The tests don't disable noise, hence we multiply the tolerance by a reasonably small number, in this case 5, to account for the noise addition.
func RoundedLaplaceTolerance ¶
RoundedLaplaceTolerance rounds laplace tolerance value to the nearest integer, in order to work with tests for integer-valued aggregations.
To see the logic and the math behind flakiness and tolerance calculation, See https://github.com/google/differential-privacy/blob/main/privacy-on-beam/docs/Tolerance_Calculation.pdf
func ToleranceForMean ¶
func ToleranceForMean(lower, upper, exactNormalizedSum, exactCount, exactMean, countTolerance, normalizedSumTolerance float64) (float64, error)
ToleranceForMean returns tolerance to be used in approxEquals or checkMetricsAreNoisy for tests for mean to pass with 10⁻ᵏ flakiness.
flakinessK is the parameter used to specify k in the flakiness. distanceFromMidPoint = upper - midPoint, where midPoint = (lower + upper)/2. exactNormalizedSum is a clamped (with boundaries -distanceFromMidPoint and distanceFromMidPoint) sum of distances of the input entities from the midPoint. exactNormalizedSum is needed for calculating tolerance because the algorithm of the mean aggregation uses noisy normalized sum in its calculations.
To see the logic and the math behind flakiness and tolerance calculation, see https://github.com/google/differential-privacy/blob/main/privacy-on-beam/docs/Tolerance_Calculation.pdf.
func TripleWithFloatValueToKV ¶
func TripleWithFloatValueToKV(t TripleWithFloatValue) (int, float32)
TripleWithFloatValueToKV extracts the partition ID and the value from a tripleWithFloatValue. It is used once the PrivatePCollection has been initialized, to transform it into a PrivatePCollection<partitionID,value>.
func TripleWithIntValueToKV ¶
func TripleWithIntValueToKV(t TripleWithIntValue) (int, int)
TripleWithIntValueToKV extracts the partition ID and the value from a tripleWithIntValue. It is used once the PrivatePCollection has been initialized, to transform it into a PrivatePCollection<partitionID,value>.
Types ¶
type PairICodedKV ¶
PairICodedKV holds a key-value pair of type (int, kv.Pair).
func KVToPairICodedKV ¶
func KVToPairICodedKV(k int, v kv.Pair) PairICodedKV
KVToPairICodedKV transforms an (int, kv.Pair) key-value pair into a PairICodedKV.
type PairIF64 ¶
PairIF64 holds a key-value pair of type (int, float64).
func KVToPairIF64 ¶
KVToPairIF64 transforms an (int, float64) key-value pair into a PairIF64.
type PairIF64Slice ¶
PairIF64Slice holds a key-value pair of type (int, []float64).
func KVToPairIF64Slice ¶
func KVToPairIF64Slice(v int, m []float64) PairIF64Slice
KVToPairIF64Slice transforms an (int, []float64) key-value pair into a PairIF64Slice.
type PairII ¶
PairII holds a key-value pair of type (int, int).
func ConcatenatePairs ¶
ConcatenatePairs concatenates pairII slices.
func MakePairsWithFixedV ¶
MakePairsWithFixedV returns sample data where the same value is associated with multiple privacy keys: it returns a slice of pairs {0, v}, {1, v}, ..., {numKeys-1, v}.
func MakePairsWithFixedVStartingFromKey ¶
MakePairsWithFixedVStartingFromKey returns sample data where the same value is associated with multiple privacy keys: it returns a slice of pairs {0, v}, {1, v}, ..., {numKeys-1, v}. Privacy keys start from kOffset.
type PairII64 ¶
PairII64 holds a key-value pair of type (int, int64).
func KVToPairII64 ¶
KVToPairII64 transforms an (int, int64) key-value pair into a PairII64.
type TripleWithFloatValue ¶
TripleWithFloatValue contains a privacy ID, a partition ID, and a float value.
func ConcatenateTriplesWithFloatValue ¶
func ConcatenateTriplesWithFloatValue(slices ...[]TripleWithFloatValue) []TripleWithFloatValue
ConcatenateTriplesWithFloatValue concatenates tripleWithFloatValue slices.
func ExtractIDFromTripleWithFloatValue ¶
func ExtractIDFromTripleWithFloatValue(t TripleWithFloatValue) (int, TripleWithFloatValue)
ExtractIDFromTripleWithFloatValue extracts and returns the ID from a tripleWithFloatValue. It is used to initialize PrivatePCollections.
func MakeSampleTripleWithFloatValue ¶
func MakeSampleTripleWithFloatValue(numKeys, p int) []TripleWithFloatValue
MakeSampleTripleWithFloatValue returns sample float data where the same partition ID is associated with multiple privacy keys, every time with the value 1.0: it returns a slice of tripleFloats {0,p,1}, {1,p,1}, ..., {numKeys-1,p,1}.
func MakeTripleWithFloatValue ¶
func MakeTripleWithFloatValue(numKeys, p int, v float32) []TripleWithFloatValue
MakeTripleWithFloatValue returns float data where the same partition ID is associated with multiple privacy keys, to the given value v: it returns a slice of tripleInts {0,p,v}, {1,p,v}, ..., {numKeys-1,p,v}.
func MakeTripleWithFloatValueStartingFromKey ¶
func MakeTripleWithFloatValueStartingFromKey(kOffset, numKeys, p int, v float32) []TripleWithFloatValue
MakeTripleWithFloatValueStartingFromKey returns float data where the same partition ID is associated with multiple privacy keys (starting from provided key), to the given value v: it returns a slice of tripleFloats {kOffset,p,v}, {kOffset + 1,p,v}, ..., {numKeys + kOffset - 1,p,v}. Privacy keys start from kOffset.
type TripleWithIntValue ¶
TripleWithIntValue contains a privacy ID, a partition ID, and an int value.
func ConcatenateTriplesWithIntValue ¶
func ConcatenateTriplesWithIntValue(slices ...[]TripleWithIntValue) []TripleWithIntValue
ConcatenateTriplesWithIntValue concatenates tripleWithIntValue slices.
func ExtractIDFromTripleWithIntValue ¶
func ExtractIDFromTripleWithIntValue(t TripleWithIntValue) (int, TripleWithIntValue)
ExtractIDFromTripleWithIntValue extracts and returns the ID from a tripleWithIntValue. It is used to initialize PrivatePCollections.
func MakeSampleTripleWithIntValue ¶
func MakeSampleTripleWithIntValue(numKeys, p int) []TripleWithIntValue
MakeSampleTripleWithIntValue returns sample int data where the same partition ID is associated with multiple privacy keys, every time with the value 1: it returns a slice of tripleInts {0,p,1}, {1,p,1}, ..., {numKeys-1,p,1}.
func MakeTripleWithIntValue ¶
func MakeTripleWithIntValue(numKeys, p, v int) []TripleWithIntValue
MakeTripleWithIntValue returns int data where the same partition ID is associated with multiple privacy keys, to the given value v: it returns a slice of tripleInts {0,p,v}, {1,p,v}, ..., {numKeys-1,p,v}.
func MakeTripleWithIntValueStartingFromKey ¶
func MakeTripleWithIntValueStartingFromKey(kOffset, numKeys, p, v int) []TripleWithIntValue
MakeTripleWithIntValueStartingFromKey returns int data where the same partition ID is associated with multiple privacy keys (starting from provided key), to the given value v: it returns a slice of tripleInts {kOffset,p,v}, {kOffset + 1,p,v}, ..., {numKeys + kOffset - 1,p,v}. Privacy keys start from kOffset.