Documentation ¶
Overview ¶
Package testutils provides helper functions, structs, etc. for testing Privacy on Beam pipelines.
Index ¶
- func ApproxEquals(x, y float64) bool
- func ApproxEqualsKVFloat64(s beam.Scope, col1, col2 beam.PCollection, tolerance float64) error
- func ApproxEqualsKVFloat64Slice(s beam.Scope, col1, col2 beam.PCollection, tolerance float64) error
- func ApproxEqualsKVInt64(s beam.Scope, col1, col2 beam.PCollection, tolerance float64) error
- func CheckAllValuesNegativeFloat64Fn(v float64) error
- func CheckFloat64MetricsAreNoisy(s beam.Scope, col beam.PCollection, exactMetric, tolerance float64)
- func CheckInt64MetricsAreNoisy(s beam.Scope, col beam.PCollection, exactMetric int, tolerance float64)
- func CheckNoNegativeValuesFloat64Fn(v float64) error
- func CheckNoNegativeValuesInt64Fn(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(s beam.Scope, col1, col2 beam.PCollection) error
- func EqualsKVInt(s beam.Scope, col1, col2 beam.PCollection) error
- func EqualsKVInt64(s beam.Scope, col1, col2 beam.PCollection) error
- func Float64MetricToKV(tm TestFloat64Metric) (int, float64)
- func Float64Ptr(f float64) *float64
- func Float64SliceMetricToKV(tm TestFloat64SliceMetric) (int, []float64)
- func GaussianTolerance(flakinessK, l0Sensitivity, lInfSensitivity, epsilon, delta float64) float64
- func Int64MetricToKV(tm TestInt64Metric) (int, int64)
- func Int64Ptr(i int64) *int64
- func LaplaceTolerance(flakinessK, l1Sensitivity, epsilon float64) float64
- func LaplaceToleranceForMean(flakinessK, lower, upper float64, ...) (float64, error)
- func LessThanOrEqualToKVFloat64(s beam.Scope, col1, col2 beam.PCollection) error
- func NotEqualsFloat64(s beam.Scope, col1, col2 beam.PCollection) error
- func OneFn(beam.V) int
- func PairICodedKVToKV(p PairICodedKV) (k int, v kv.Pair)
- func PairIFToKV(p PairIF64) (a int, b float64)
- func PairII64ToKV(p PairII64) (a int, b int64)
- func PairToKV(p PairII) (a, b 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 PairII
- type PairII64
- type TestFloat64Metric
- type TestFloat64SliceMetric
- type TestInt64Metric
- 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 ¶
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 ¶
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 ¶
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 CheckAllValuesNegativeFloat64Fn ¶
CheckAllValuesNegativeFloat64Fn returns an error if an float64 value is non-negative.
func CheckFloat64MetricsAreNoisy ¶
func CheckFloat64MetricsAreNoisy(s beam.Scope, col beam.PCollection, exactMetric, tolerance float64)
CheckFloat64MetricsAreNoisy checks that no values in a PCollection<testFloat64Metric> (where testFloat64Metric 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<testInt64Metric> (where testInt64Metric contains the aggregate statistic) is equal to exactMetric.
func CheckNoNegativeValuesFloat64Fn ¶
CheckNoNegativeValuesFloat64Fn returns an error if an float64 value is negative.
func CheckNoNegativeValuesInt64Fn ¶
CheckNoNegativeValuesInt64Fn 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 ¶
func EqualsKVFloat64(s beam.Scope, col1, col2 beam.PCollection) error
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 ¶
func EqualsKVInt(s beam.Scope, col1, col2 beam.PCollection) error
EqualsKVInt checks that two PCollections col1 and col2 of type <K,int> are exactly equal.
func EqualsKVInt64 ¶
func EqualsKVInt64(s beam.Scope, col1, col2 beam.PCollection) error
EqualsKVInt64 checks that two PCollections col1 and col2 of type <K,int64> are exactly equal. Each key can only hold a single value.
func Float64MetricToKV ¶
func Float64MetricToKV(tm TestFloat64Metric) (int, float64)
Float64MetricToKV transforms a TestFloat64Metric into an (int, float64) key-value pair.
func Float64Ptr ¶
Float64Ptr transforms a float64 into a *float64.
func Float64SliceMetricToKV ¶
func Float64SliceMetricToKV(tm TestFloat64SliceMetric) (int, []float64)
Float64SliceMetricToKV transforms a TestFloat64SliceMetric into an (int, []float64) key-value pair.
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 Int64MetricToKV ¶
func Int64MetricToKV(tm TestInt64Metric) (int, int64)
Int64MetricToKV transforms a TestInt64Metric into an (int, int64) key-value pair.
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 ¶
func LessThanOrEqualToKVFloat64(s beam.Scope, col1, col2 beam.PCollection) error
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 ¶
func NotEqualsFloat64(s beam.Scope, col1, col2 beam.PCollection) error
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 PairIFToKV ¶
PairIFToKV 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(a int, b kv.Pair) PairICodedKV
KVToPairICodedKV transforms an (int, kv.Pair) key-value pair into a PairICodedKV.
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 TestFloat64Metric ¶
TestFloat64Metric holds a Value and an associated float64 metric (aggregation).
func KVToFloat64Metric ¶
func KVToFloat64Metric(v int, m float64) TestFloat64Metric
KVToFloat64Metric transforms an (int, float64) key-value pair into a TestFloat64Metric.
type TestFloat64SliceMetric ¶
TestFloat64SliceMetric holds a Value and an associated []float64 metric (aggregation).
func KVToFloat64SliceMetric ¶
func KVToFloat64SliceMetric(v int, m []float64) TestFloat64SliceMetric
KVToFloat64SliceMetric transforms an (int, []float64) key-value pair into a TestFloat64SliceMetric.
type TestInt64Metric ¶
TestInt64Metric holds a Value and an associated int64 metric (aggregation).
func Float64MetricToInt64Metric ¶
func Float64MetricToInt64Metric(tm TestFloat64Metric) TestInt64Metric
Float64MetricToInt64Metric transforms a TestFloat64Metric into a TestInt64Metric.
func KVToInt64Metric ¶
func KVToInt64Metric(v int, m int64) TestInt64Metric
KVToInt64Metric transforms an (int, int64) key-value pair into a TestInt64Metric.
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.