distance — Some distance functions

This module provides some basic distance measures and a class to instantiate arbitrary distance functions based on Minkowski metrics. For more exotic distance functions (and faster implementations) have a look at scipy.spatial.distance.

class diversipy.distance.DistanceMatrixFunction(exponent=2, max_dists_per_dim=None)

General distance function.

This distance function can handle arbitrary exponents and can optionally calculate torus distances. Slightly slower than the specialized versions. Special cases exponent = 1 and exponent = 2 correspond to Manhattan and Euclidean distance, respectively.

diversipy.distance.calc_manhattan_dist_matrix(points1, points2)

Calculate Manhattan distance matrix between points1 and points2.

Generates one column of the matrix at a time.

Parameters:
  • points1 (array_like) – 2-D array of n points.
  • points2 (array_like) – 2-D array of m points.
Returns:

distances

Return type:

(n,m) numpy array

diversipy.distance.calc_euclidean_dist_matrix(points1, points2)

Calculate Euclidean distance matrix between points1 and points2.

Generates one column of the matrix at a time.

Parameters:
  • points1 (array_like) – 2-D array of n points.
  • points2 (array_like) – 2-D array of m points.
Returns:

distances

Return type:

(n,m) numpy array

diversipy.distance.calc_dists_to_boundary(points, cuboid=None)

Calculate the distance of each point to the boundary of some cuboid.

This distance is simply the minimum of all differences between a point and the lower and upper bounds. This function also checks if all calculated distances are larger than zero. If not, some points must be located outside the cuboid.

Parameters:
  • points (array_like) – 2-D array of n points.
  • cuboid (tuple of array_like, optional) – Contains the min and max bounds of the considered cuboid. If omitted, the unit hypercube is assumed.
Returns:

distances – 1-D array of n distances

Return type:

numpy array