This documentation is for an old version of OpenDP.

The current release of OpenDP is v0.11.1.

opendp.meas module#

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

Make a Measurement that adds noise from the discrete_gaussian(scale) distribution to the input. Adjust D to noise vector-valued data.

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

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

  • MO (Type Arguments) – Output measure. The only valid measure is ZeroConcentratedDivergence<Q>, but Q can be f32 or f64

Returns:

A base_discrete_gaussian step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.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. Adjust D to noise vector-valued data. This uses make_base_discrete_laplace_cks20 if scale is greater than 10, otherwise it uses make_base_discrete_laplace_linear.

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

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

  • QO (Type Arguments) – Data type of the sensitivity, scale, and budget.

Returns:

A base_discrete_laplace step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.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. Uses the sampling algorithm from CKS20, The Discrete Gaussian for Differential Privacy. Adjust D to noise vector-valued data.

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

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

  • QO (Type Arguments) – Data type of the sensitivity, scale, and budget.

Returns:

A base_discrete_laplace_cks20 step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.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. This algorithm can be executed in constant time if bounds are passed. Adjust D to noise vector-valued data.

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 Arguments) – Domain of the data type to be privatized. Valid values are VectorDomain<AllDomain<T>> or AllDomain<T>

  • QO (Type Arguments) – Data type of the sensitivity, scale, and budget.

Returns:

A base_discrete_laplace_linear step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.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. Adjust D to noise vector-valued data. The output epsilon may be no greater than one.

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

  • k (int) – The noise granularity in terms of 2^k. Larger values are more computationally efficient, but have a looser privacy map. Defaults to the smallest granularity.

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

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

Returns:

A base_gaussian step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.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.

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

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

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

  • QO (Type Arguments) – Data type of the sensitivity, scale, and budget.

Returns:

A base_geometric step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.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. Adjust D to noise vector-valued data.

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

  • k (int) – The noise granularity in terms of 2^k. Larger values are more computationally efficient, but have a looser privacy map. Defaults to the smallest granularity.

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

Returns:

A base_laplace step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.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.

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. Larger values are more computationally efficient, but have a looser privacy map. Defaults to the smallest granularity.

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

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

Returns:

A base_ptr step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.make_randomized_response(categories, prob, constant_time=False, T=None, Q=None)[source]#

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

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

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

  • Q (Type Arguments) – Data type of probability and budget.

Returns:

A randomized_response step.

Return type:

Measurement

Raises:
  • AssertionError – 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.meas.make_randomized_response_bool(prob, constant_time=False, Q=None)[source]#

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

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

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

  • Q (Type Arguments) – Data type of probability and budget.

Returns:

A randomized_response_bool step.

Return type:

Measurement

Raises:
  • AssertionError – 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