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_analytic_gaussian(scale, D='AllDomain<T>')[source]#

Make a Measurement that adds noise from the gaussian(scale) distribution to the input. Adjust D to noise vector-valued data. The privacy relation is based on the analytic gaussian mechanism.

Parameters:
  • scale – noise scale parameter to the gaussian distribution

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

Returns:

A base_analytic_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_gaussian(scale, D='AllDomain<T>')[source]#

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

Parameters:
  • scale – noise scale parameter to the gaussian distribution

  • D (RuntimeTypeDescriptor) – Domain of the data type to be privatized. Valid values are VectorDomain<AllDomain<T>> or AllDomain<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<i32>', QO=None)[source]#

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

Parameters:
  • scale – noise scale parameter to the geometric distribution

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

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

  • QO (RuntimeTypeDescriptor) – 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, 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 of the laplace distribution.

  • D (RuntimeTypeDescriptor) – 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, TV=None)[source]#

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

Parameters:
  • scale – Noise scale parameter.

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

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

  • TV (RuntimeTypeDescriptor) – 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 (RuntimeTypeDescriptor) – Data type of a category.

  • Q (RuntimeTypeDescriptor) – 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 (RuntimeTypeDescriptor) – 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