This documentation is for a development version of OpenDP.

The current release of OpenDP is v0.11.1.

opendp.metrics module#

The metrics module provides fuctions that measure the distance between two elements of a domain. For more context, see metrics 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
opendp.metrics.absolute_distance(T)[source]#

Construct an instance of the AbsoluteDistance metric.

absolute_distance in Rust documentation.

Parameters:

T (Type Argument) –

Return type:

Metric

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.metrics.change_one_distance()[source]#

Construct an instance of the ChangeOneDistance metric.

Return type:

Metric

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.metrics.discrete_distance()[source]#

Construct an instance of the DiscreteDistance metric.

Return type:

Metric

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.metrics.hamming_distance()[source]#

Construct an instance of the HammingDistance metric.

Return type:

Metric

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.metrics.insert_delete_distance()[source]#

Construct an instance of the InsertDeleteDistance metric.

Return type:

Metric

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.metrics.l1_distance(T)[source]#

Construct an instance of the L1Distance metric.

l1_distance in Rust documentation.

Parameters:

T (Type Argument) –

Return type:

Metric

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.metrics.l2_distance(T)[source]#

Construct an instance of the L2Distance metric.

l2_distance in Rust documentation.

Parameters:

T (Type Argument) –

Return type:

Metric

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.metrics.linf_distance(T, monotonic=False)[source]#

Construct an instance of the LInfDistance metric.

linf_distance in Rust documentation.

Parameters:
  • monotonic (bool) – set to true if non-monotonicity implies infinite distance

  • T (Type Argument) – The type of the distance.

Return type:

Metric

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.metrics.metric_debug(this)[source]#

Debug a metric.

Parameters:

this (Metric) – The metric to debug (stringify).

Return type:

str

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.metrics.metric_distance_type(this)[source]#

Get the distance type of a metric.

Parameters:

this (Metric) – The metric to retrieve the distance type from.

Return type:

str

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.metrics.metric_type(this)[source]#

Get the type of a metric.

Parameters:

this (Metric) – The metric to retrieve the type from.

Return type:

str

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.metrics.partition_distance(metric)[source]#

Construct an instance of the PartitionDistance metric.

partition_distance in Rust documentation.

Parameters:

metric (Metric) – The metric used to compute distance between partitions.

Return type:

Metric

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.metrics.symmetric_distance()[source]#

Construct an instance of the SymmetricDistance metric.

Return type:

Metric

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.metrics.user_distance(descriptor)[source]#

Construct a new UserDistance. Any two instances of an UserDistance are equal if their string descriptors are equal.

Required features: honest-but-curious

Why honest-but-curious?:

Your definition of d must satisfy the requirements of a pseudo-metric: 1. for any \(x\), \(d(x, x) = 0\) 2. for any \(x, y\), \(d(x, y) \ge 0\) (non-negativity) 3. for any \(x, y\), \(d(x, y) = d(y, x)\) (symmetry) 4. for any \(x, y, z\), \(d(x, z) \le d(x, y) + d(y, z)\) (triangle inequality)

Parameters:

descriptor (str) – A string description of the metric.

Return type:

Metric

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