eeprivacy

Operations

An Operation encapsulates the full workflow of common analytics tasks: running statistics (like means, histograms, and quantiles), reporting on accuracy, and supporting analysis of privacy/accuracy tradeoffs.

class eeprivacy.operations.PrivateAboveThreshold

Return the index of the first query that exceeds a target threshold.

This technique was first describe in Chapter 3.6 of [Dwork and Roth] and the implementation below is based on Chapter 10 of Programming Differential Privacy [Near].

References

execute(*, queries: List[float], threshold: float, epsilon: float)
Parameters
  • queries – List of sensitivity-1 queries to choose from

  • threshold – Threshold above which the first query will be returned

  • epsilon – Privacy parameter

Returns

The index of the query that exceeds threshold.

class eeprivacy.operations.PrivateClampedMean(*, lower_bound: float, upper_bound: float)

Compute a mean, bounding sensitivity with clamping. Employs the Laplace Mechanism.

confidence_interval(*, epsilon, N, confidence=0.95)

Compute the two-sided confidence interval for the mean.

epsilon_for_confidence_interval(*, target_ci, N, confidence=0.95)

Return epsilon for a desired confidence interval.

execute(*, values: List[float], epsilon: float) → float

Computes the mean of values privately using a clamped mean.

Implements Algorithm 2.3 from [Li et al]

Returns

The private mean.

References

  • Li, N., Yang, W., Lyu, M., Su, D. (2016). Differential Privacy: From Theory to Practice. United States: Morgan & Claypool Publishers.

class eeprivacy.operations.PrivateClampedSum(*, lower_bound: float, upper_bound: float)

Compute a sum, bounding sensitivity with clamping. Employs the Laplace Mechanism.

confidence_interval(*, epsilon, confidence=0.95)

Compute the two-sided confidence interval for the sum.

epsilon_for_confidence_interval(*, target_ci, confidence=0.95)

Return epsilon for a desired confidence interval.

execute(*, values: List[float], epsilon: float) → float

Computes the mean of values privately using a clamped sum.

Returns

The private sum.

class eeprivacy.operations.PrivateHistogram(*, bins: List[float], max_individual_contribution: int = 1)

Compute a private histogram with the Laplace Mechanism.

Parameters
  • bins – Edges of bins for results. These must be specified up-front otherwise information will be leaked by the choice of bins. Read more

  • max_individual_contribution – Maximum count any individual in the dataset could contribute to the histogram. Normally 1.

confidence_interval(*, epsilon: float, confidence: float = 0.95) → float

Return the confidence interval for each bar of the histogram.

execute(*, values: List[float], epsilon: float) → List[float]

Computes the histogram of values privately.

Values are clamped to the bound specified by bins.

Returns

A list of private counts, one for each bin.

class eeprivacy.operations.PrivateQuantile(*, options: List[float], max_individual_contribution: int = 1)

Find quantiles privately with the Report Noisy Max mechanism.

Parameters
  • options – List of possible outputs

  • max_individual_contribution – Normally 1, unless an individual can contribute multiple points to the dataset.

execute(*, values: List[float], epsilon: float, quantile: float)

Computes the quantile of a list of values privately.

Implemented using Report Noisy Max (Claim 3.9) of [Dwork and Roth].

Parameters
  • values – Dataset

  • epsilon – Privacy parameter

  • quantile – Quantile to return (between 0 and 1)

References

class eeprivacy.operations.PrivateVectorClampedMeanGaussian(*, lower_bound: float, upper_bound: float, k: float, N: float)

A vector mean computes the elementwise mean of a vector-valued dataset. That is, a dataset in which each row is a vector of values corresponding to each individual. For example:

six_hourly_energy_consumptions = [
    [4.2, 11.1, 14.1, 3.2],
    [1.4, 4.5.1, 4.8, 1.6],
    ...
]

This implementation requires the size of the dataset upfront (either pass it exactly if it is not private or compute with a private count).

With the Gaussian Mechanism, noise is scaled to the L2 norm of the dataset.

Parameters
  • lower_bound – Lower bound of input data

  • upper_bound – Upper bound of input data

  • k – Size of vectors in dataset

  • N – Number of elements in dataset

confidence_interval(*, epsilon: float, delta: float, confidence: float = 0.95) → float

Compute the two-sided confidence interval for the mean.

epsilon_for_confidence_interval(*, target_ci: float, delta: float, confidence: float = 0.95) → float

Return epsilon for a desired confidence interval.

execute(*, vectors: List[float], epsilon: float, delta: float) → float

Computes the elementwise mean of vectors privately using a clamped sum and exact count with the Gaussian Mechanism.

class eeprivacy.operations.PrivateVectorClampedMeanLaplace(*, lower_bound: float, upper_bound: float, k: float, N: float)

A simple implementation of the mean operation that requires the size of the dataset up front (either pass it exactly if it is not private or compute with a private count).

With the Laplace Mechanism, noise is scaled to the L1 norm of the dataset.

Parameters
  • lower_bound – Lower bound of input data

  • upper_bound – Upper bound of input data

  • k – Size of vectors in dataset

  • N – Number of elements in dataset

execute(*, vectors: List[float], epsilon: float, delta: float) → float

Computes the mean of vectors privately using a clamped sum and exact count with the Laplace Mechanism.

Mechanisms

Mechanisms are differential privacy primitives. The raw implementations should be used with care by non-experts.

A Note on Confidence Intervals

The confidence intervals returned by Mechanism classes are two-sided.

For example, in the algorithm design helper function epsilon_for_confidence_interval the ε value returned for the Laplace Mechanism at the default confidence = 0.95 and target_ci = 5, the distribution of outputs for the returned ε would be the following:

  2.5% │      █      │ 2.5%
◀──────│      █      │──────▶
       │      █      │
       │     ███     │
       │     ███     │
       │     ███     │
       │     ███     │
       │     ███     │
       │    █████    │
       │   ███████   │
       │  █████████  │
       │█████████████│
    ███│█████████████│███
  ─────┼──────┬──────┼────
       │      │      │
            True
      -5    Count    5
class eeprivacy.mechanisms.GaussianMechanism

The Gaussian Mechanism.

static confidence_interval(*, epsilon: float, delta: float, sensitivity: float, confidence: float = 0.95) → float

Return the confidence interval for the Gaussian Mechanism at a given epsilon, delta, and sensitivity.

static epsilon_for_confidence_interval(target_ci: float, sensitivity: float, delta: float, confidence: float = 0.95) → float

Returns the ε for the Gaussian Mechanism that will produce outputs +/-target_ci at confidence for queries with sensitivity and delta.

static execute(*, value: float, epsilon: float, delta: float, sensitivity: float) → float

Run the Gaussian Mechanism, adding noise to value to realize differential private at (epsilon, delta) for the provided sensitivity.

static execute_batch(*, values: List[float], epsilon: float, delta: float, sensitivity: float) → List[float]

Run the Gaussian Mechanism, adding noise to value to realize differential private at (epsilon, delta) for the provided sensitivity.

Runs the Gaussian Mechanism multiple times, once for each item in the list.

class eeprivacy.mechanisms.LaplaceMechanism

The Laplace Mechanism.

static confidence_interval(*, epsilon: float, sensitivity: float, confidence: float = 0.95) → float

Determine the two-sided confidence interval for a given privacy parameter.

static epsilon_for_confidence_interval(*, target_ci: float, sensitivity: float, confidence: float = 0.95) → float

Determine the privacy parameter for a desired accuracy.

static execute(*, value: float, epsilon: float, sensitivity: float) → float

Run the Laplace Mechanism, adding noise to value to realize differential private at epsilon for the provided sensitivity.

static execute_batch(*, values: List[float], epsilon: float, sensitivity: float) → List[float]

Run the Laplace Mechanism, adding noise to value to realize differential private at epsilon for the provided sensitivity.

Runs the Laplace Mechanism multiple times, once for each item in the list.