opendp.measurements module#

The measurements module provides functions that apply calibrated noise to data to ensure differential privacy. For more context, see measurements in the User Guide.

For convenience, all the functions of this module are also available from opendp.prelude. We suggest importing under the conventional name dp:

>>> import opendp.prelude as dp

The methods of this module will then be accessible at dp.m.

opendp.measurements.make_alp_queryable(input_domain, input_metric, scale, total_limit, value_limit=None, size_factor=50, alpha=4, CO=None)[source]#

Measurement to release a queryable containing a DP projection of bounded sparse data.

The size of the projection is O(total * size_factor * scale / alpha). The evaluation time of post-processing is O(beta * scale / alpha).

size_factor is an optional multiplier (defaults to 50) for setting the size of the projection. There is a memory/utility trade-off. The value should be sufficiently large to limit hash collisions.

make_alp_queryable in Rust documentation.

Citations:

Supporting Elements:

  • Input Domain: MapDomain<AtomDomain<K>, AtomDomain<CI>>

  • Output Type: Queryable<K, CO>

  • Input Metric: L1Distance<CI>

  • Output Measure: MaxDivergence<CO>

Parameters:
  • input_domain (Domain) –

  • input_metric (Metric) –

  • scale – Privacy loss parameter. This is equal to epsilon/sensitivity.

  • total_limit – Either the true value or an upper bound estimate of the sum of all values in the input.

  • value_limit – Upper bound on individual values (referred to as β). Entries above β are clamped.

  • size_factor – Optional multiplier (default of 50) for setting the size of the projection.

  • alpha – Optional parameter (default of 4) for scaling and determining p in randomized response step.

  • CO (Type Argument) –

Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_base_laplace_threshold(input_domain, input_metric, scale, threshold, k=-1074)[source]#

Make a Measurement that uses propose-test-release to privatize a hashmap of counts.

This function takes a noise granularity in terms of 2^k. Larger granularities are more computationally efficient, but have a looser privacy map. If k is not set, k defaults to the smallest granularity.

make_base_laplace_threshold in Rust documentation.

Supporting Elements:

  • Input Domain: MapDomain<AtomDomain<TK>, AtomDomain<TV>>

  • Output Type: HashMap<TK, TV>

  • Input Metric: L1Distance<TV>

  • Output Measure: FixedSmoothedMaxDivergence<TV>

Parameters:
  • input_domain (Domain) – Domain of the input.

  • input_metric (Metric) – Metric for the input domain.

  • scale – Noise scale parameter for the laplace distribution. scale == standard_deviation / sqrt(2).

  • threshold – Exclude counts that are less than this minimum value.

  • k (int) – The noise granularity in terms of 2^k.

Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_gaussian(input_domain, input_metric, scale, k=None, MO='ZeroConcentratedDivergence<QO>')[source]#

Make a Measurement that adds noise from the Gaussian(scale) distribution to the input.

Valid inputs for input_domain and input_metric are:

input_domain

input type

input_metric

atom_domain(T)

T

absolute_distance(QI)

vector_domain(atom_domain(T))

Vec<T>

l2_distance(QI)

make_gaussian in Rust documentation.

Supporting Elements:

  • Input Domain: D

  • Output Type: D::Carrier

  • Input Metric: D::InputMetric

  • Output Measure: MO

Parameters:
  • input_domain (Domain) – Domain of the data type to be privatized.

  • input_metric (Metric) – Metric of the data type to be privatized.

  • scale – Noise scale parameter for the gaussian distribution. scale == standard_deviation.

  • k – The noise granularity in terms of 2^k.

  • MO (Type Argument) – Output Measure. The only valid measure is ZeroConcentratedDivergence<T>.

Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_geometric(input_domain, input_metric, scale, bounds=None, QO=None)[source]#

Equivalent to make_laplace but restricted to an integer support. Can specify bounds to run the algorithm in near constant-time.

make_geometric in Rust documentation.

Citations:

Supporting Elements:

  • Input Domain: D

  • Output Type: D::Carrier

  • Input Metric: D::InputMetric

  • Output Measure: MaxDivergence<QO>

Parameters:
Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_laplace(input_domain, input_metric, scale, k=None, QO='float')[source]#

Make a Measurement that adds noise from the Laplace(scale) distribution to the input.

Valid inputs for input_domain and input_metric are:

input_domain

input type

input_metric

atom_domain(T) (default)

T

absolute_distance(T)

vector_domain(atom_domain(T))

Vec<T>

l1_distance(T)

Internally, all sampling is done using the discrete Laplace distribution.

make_laplace in Rust documentation.

Citations:

Supporting Elements:

  • Input Domain: D

  • Output Type: D::Carrier

  • Input Metric: D::InputMetric

  • Output Measure: MaxDivergence<QO>

Parameters:
  • input_domain (Domain) – Domain of the data type to be privatized.

  • input_metric (Metric) – Metric of the data type to be privatized.

  • scale – Noise scale parameter for the Laplace distribution. scale == standard_deviation / sqrt(2).

  • k – The noise granularity in terms of 2^k, only valid for domains over floats.

  • QO (Type Argument) – Data type of the output distance and scale. f32 or f64.

Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_randomized_response(categories, prob, constant_time=False, T=None, QO=None)[source]#

Make a Measurement that implements randomized response on a categorical value.

make_randomized_response in Rust documentation.

Supporting Elements:

  • Input Domain: AtomDomain<T>

  • Output Type: T

  • Input Metric: DiscreteDistance

  • Output Measure: MaxDivergence<QO>

Parameters:
  • categories (Any) – Set of valid outcomes

  • prob – Probability of returning the correct answer. Must be in [1/num_categories, 1)

  • constant_time (bool) – Set to true to enable constant time. Slower.

  • T (Type Argument) – Data type of a category.

  • QO (Type Argument) – Data type of probability and output distance.

Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_randomized_response_bool(prob, constant_time=False, QO=None)[source]#

Make a Measurement that implements randomized response on a boolean value.

make_randomized_response_bool in Rust documentation.

Supporting Elements:

  • Input Domain: AtomDomain<bool>

  • Output Type: bool

  • Input Metric: DiscreteDistance

  • Output Measure: MaxDivergence<QO>

Proof Definition:

(Proof Document)

Parameters:
  • prob – Probability of returning the correct answer. Must be in [0.5, 1)

  • constant_time (bool) – Set to true to enable constant time. Slower.

  • QO (Type Argument) – Data type of probability and output distance.

Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_report_noisy_max_gumbel(input_domain, input_metric, scale, optimize, QO=None)[source]#

Make a Measurement that takes a vector of scores and privately selects the index of the highest score.

make_report_noisy_max_gumbel in Rust documentation.

Supporting Elements:

  • Input Domain: VectorDomain<AtomDomain<TIA>>

  • Output Type: usize

  • Input Metric: LInfDistance<TIA>

  • Output Measure: MaxDivergence<QO>

Proof Definition:

(Proof Document)

Parameters:
  • input_domain (Domain) – Domain of the input vector. Must be a non-nullable VectorDomain.

  • input_metric (Metric) – Metric on the input domain. Must be LInfDistance

  • scale (Any) – Higher scales are more private.

  • optimize (str) – Indicate whether to privately return the “Max” or “Min”

  • QO (Type Argument) – Output Distance Type.

Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_user_measurement(input_domain, input_metric, output_measure, function, privacy_map, TO='ExtrinsicObject')[source]#

Construct a Measurement from user-defined callbacks.

Supporting Elements:

  • Input Domain: AnyDomain

  • Output Type: AnyObject

  • Input Metric: AnyMetric

  • Output Measure: AnyMeasure

Parameters:
  • input_domain (Domain) – A domain describing the set of valid inputs for the function.

  • input_metric (Metric) – The metric from which distances between adjacent inputs are measured.

  • output_measure (Measure) – The measure from which distances between adjacent output distributions are measured.

  • function – A function mapping data from input_domain to a release of type TO.

  • privacy_map – A function mapping distances from input_metric to output_measure.

  • TO (Type Argument) – The data type of outputs from the function.

Return type:

Measurement

Raises:
  • TypeError – if an argument’s type differs from the expected type

  • UnknownTypeException – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.then_alp_queryable(scale, total_limit, value_limit=None, size_factor=50, alpha=4, CO=None)[source]#

partial constructor of make_alp_queryable

See also

Delays application of input_domain and input_metric in opendp.measurements.make_alp_queryable()

Parameters:
  • scale – Privacy loss parameter. This is equal to epsilon/sensitivity.

  • total_limit – Either the true value or an upper bound estimate of the sum of all values in the input.

  • value_limit – Upper bound on individual values (referred to as β). Entries above β are clamped.

  • size_factor – Optional multiplier (default of 50) for setting the size of the projection.

  • alpha – Optional parameter (default of 4) for scaling and determining p in randomized response step.

  • CO (Type Argument) –

opendp.measurements.then_base_laplace_threshold(scale, threshold, k=-1074)[source]#

partial constructor of make_base_laplace_threshold

See also

Delays application of input_domain and input_metric in opendp.measurements.make_base_laplace_threshold()

Parameters:
  • scale – Noise scale parameter for the laplace distribution. scale == standard_deviation / sqrt(2).

  • threshold – Exclude counts that are less than this minimum value.

  • k (int) – The noise granularity in terms of 2^k.

opendp.measurements.then_gaussian(scale, k=None, MO='ZeroConcentratedDivergence<QO>')[source]#

partial constructor of make_gaussian

See also

Delays application of input_domain and input_metric in opendp.measurements.make_gaussian()

Parameters:
  • scale – Noise scale parameter for the gaussian distribution. scale == standard_deviation.

  • k – The noise granularity in terms of 2^k.

  • MO (Type Argument) – Output Measure. The only valid measure is ZeroConcentratedDivergence<T>.

opendp.measurements.then_geometric(scale, bounds=None, QO=None)[source]#

partial constructor of make_geometric

See also

Delays application of input_domain and input_metric in opendp.measurements.make_geometric()

Parameters:
opendp.measurements.then_laplace(scale, k=None, QO='float')[source]#

partial constructor of make_laplace

See also

Delays application of input_domain and input_metric in opendp.measurements.make_laplace()

Parameters:
  • scale – Noise scale parameter for the Laplace distribution. scale == standard_deviation / sqrt(2).

  • k – The noise granularity in terms of 2^k, only valid for domains over floats.

  • QO (Type Argument) – Data type of the output distance and scale. f32 or f64.

opendp.measurements.then_report_noisy_max_gumbel(scale, optimize, QO=None)[source]#

partial constructor of make_report_noisy_max_gumbel

See also

Delays application of input_domain and input_metric in opendp.measurements.make_report_noisy_max_gumbel()

Parameters:
  • scale (Any) – Higher scales are more private.

  • optimize (str) – Indicate whether to privately return the “Max” or “Min”

  • QO (Type Argument) – Output Distance Type.

opendp.measurements.then_user_measurement(output_measure, function, privacy_map, TO='ExtrinsicObject')[source]#

partial constructor of make_user_measurement

See also

Delays application of input_domain and input_metric in opendp.measurements.make_user_measurement()

Parameters:
  • output_measure (Measure) – The measure from which distances between adjacent output distributions are measured.

  • function – A function mapping data from input_domain to a release of type TO.

  • privacy_map – A function mapping distances from input_metric to output_measure.

  • TO (Type Argument) – The data type of outputs from the function.