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.

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