This documentation is for an old version of OpenDP.

The current release of OpenDP is v0.11.1.

opendp.measurements module#

opendp.measurements.make_base_discrete_gaussian(scale, D='AllDomain<int>', MO='ZeroConcentratedDivergence<QO>', QI='int')[source]#

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

Set D to change the input data type and input metric:

D

input type

D::InputMetric

AllDomain<T> (default)

T

AbsoluteDistance<QI>

VectorDomain<AllDomain<T>>

Vec<T>

L2Distance<QI>

make_base_discrete_gaussian in Rust documentation.

Supporting Elements:

  • Input Domain: D

  • Output Domain: D

  • Input Metric: D::InputMetric

  • Output Measure: MO

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

  • D (Type Argument) – Domain of the data type to be privatized. Valid values are VectorDomain<AllDomain<T>> or AllDomain<T>.

  • MO (Type Argument) – Output measure. The only valid measure is ZeroConcentratedDivergence<QO>, but QO can be any float.

  • QI (Type Argument) – Input distance. The type of sensitivities. Can be any integer or float.

Return type:

Measurement

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

  • UnknownTypeError – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_base_discrete_laplace(scale, D='AllDomain<int>', QO=None)[source]#

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

Set D to change the input data type and input metric:

D

input type

D::InputMetric

AllDomain<T> (default)

T

AbsoluteDistance<T>

VectorDomain<AllDomain<T>>

Vec<T>

L1Distance<T>

This uses make_base_discrete_laplace_cks20 if scale is greater than 10, otherwise it uses make_base_discrete_laplace_linear.

make_base_discrete_laplace in Rust documentation.

Citations:

Supporting Elements:

  • Input Domain: D

  • Output Domain: D

  • Input Metric: D::InputMetric

  • Output Measure: MaxDivergence<QO>

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

  • D (Type Argument) – Domain of the data type to be privatized. Valid values are VectorDomain<AllDomain<T>> or AllDomain<T>

  • 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

  • UnknownTypeError – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_base_discrete_laplace_cks20(scale, D='AllDomain<int>', QO=None)[source]#

Make a Measurement that adds noise from the discrete_laplace(scale) distribution to the input, using an efficient algorithm on rational bignums.

Set D to change the input data type and input metric:

D

input type

D::InputMetric

AllDomain<T> (default)

T

AbsoluteDistance<T>

VectorDomain<AllDomain<T>>

Vec<T>

L1Distance<T>

make_base_discrete_laplace_cks20 in Rust documentation.

Citations:

Supporting Elements:

  • Input Domain: D

  • Output Domain: D

  • Input Metric: D::InputMetric

  • Output Measure: MaxDivergence<QO>

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

  • D (Type Argument) – Domain of the data type to be privatized. Valid values are VectorDomain<AllDomain<T>> or AllDomain<T>

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

Return type:

Measurement

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

  • UnknownTypeError – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_base_discrete_laplace_linear(scale, bounds=None, D='AllDomain<int>', QO=None)[source]#

Make a Measurement that adds noise from the discrete_laplace(scale) distribution to the input, using a linear-time algorithm on finite data types.

This algorithm can be executed in constant time if bounds are passed. Set D to change the input data type and input metric:

D

input type

D::InputMetric

AllDomain<T> (default)

T

AbsoluteDistance<T>

VectorDomain<AllDomain<T>>

Vec<T>

L1Distance<T>

make_base_discrete_laplace_linear in Rust documentation.

Citations:

Supporting Elements:

  • Input Domain: D

  • Output Domain: D

  • Input Metric: D::InputMetric

  • Output Measure: MaxDivergence<QO>

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

  • bounds (Any) – Set bounds on the count to make the algorithm run in constant-time.

  • D (Type Argument) – Domain of the data type to be privatized. Valid values are VectorDomain<AllDomain<T>> or AllDomain<T>

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

Return type:

Measurement

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

  • UnknownTypeError – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_base_gaussian(scale, k=-1074, D='AllDomain<T>', MO='ZeroConcentratedDivergence<T>')[source]#

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

Set D to change the input data type and input metric:

D

input type

D::InputMetric

AllDomain<T> (default)

T

AbsoluteDistance<T>

VectorDomain<AllDomain<T>>

Vec<T>

L2Distance<T>

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_gaussian in Rust documentation.

Supporting Elements:

  • Input Domain: D

  • Output Domain: D

  • Input Metric: D::InputMetric

  • Output Measure: MO

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

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

  • D (Type Argument) – Domain of the data type to be privatized. Valid values are VectorDomain<AllDomain<T>> or AllDomain<T>.

  • 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

  • UnknownTypeError – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_base_geometric(scale, bounds=None, D='AllDomain<int>', QO=None)[source]#

Deprecated. Use make_base_discrete_laplace instead (more efficient). make_base_discrete_laplace_linear has a similar interface with the optional constant-time bounds.

make_base_geometric in Rust documentation.

Supporting Elements:

  • Input Domain: D

  • Output Domain: D

  • Input Metric: D::InputMetric

  • Output Measure: MaxDivergence<QO>

Parameters:
Return type:

Measurement

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

  • UnknownTypeError – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_base_laplace(scale, k=-1074, D='AllDomain<T>')[source]#

Make a Measurement that adds noise from the laplace(scale) distribution to a scalar value.

Set D to change the input data type and input metric:

D

input type

D::InputMetric

AllDomain<T> (default)

T

AbsoluteDistance<T>

VectorDomain<AllDomain<T>>

Vec<T>

L1Distance<T>

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 in Rust documentation.

Supporting Elements:

  • Input Domain: D

  • Output Domain: D

  • Input Metric: D::InputMetric

  • Output Measure: MaxDivergence<D::Atom>

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

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

  • D (Type Argument) – Domain of the data type to be privatized. Valid values are VectorDomain<AllDomain<T>> or AllDomain<T>

Return type:

Measurement

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

  • UnknownTypeError – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library

opendp.measurements.make_base_ptr(scale, threshold, TK, k=-1074, TV=None)[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_ptr in Rust documentation.

Supporting Elements:

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

  • Output Domain: MapDomain<AllDomain<TK>, AllDomain<TV>>

  • Input Metric: L1Distance<TV>

  • Output Measure: SmoothedMaxDivergence<TV>

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

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

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

  • TK (Type Argument) – Type of Key. Must be hashable/categorical.

  • TV (Type Argument) – Type of Value. Must be float.

Return type:

Measurement

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

  • UnknownTypeError – 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: AllDomain<T>

  • Output Domain: AllDomain<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

  • UnknownTypeError – 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: AllDomain<bool>

  • Output Domain: AllDomain<bool>

  • Input Metric: DiscreteDistance

  • Output Measure: MaxDivergence<QO>

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

  • UnknownTypeError – if a type argument fails to parse

  • OpenDPException – packaged error from the core OpenDP library