Distances

Implementation of different distance metrics.

class ecgan.utils.distances.DistanceMetric[source]

Bases: abc.ABC

A base class for different distance metrics to inherit from.

abstract calculate(point_1, point_2)[source]

Calculate the distance between two points (arrays of same size).

Parameters
  • point_1 (Union[ndarray, Tensor]) -- Some data with at least 1 dimension.

  • point_2 (Union[ndarray, Tensor]) -- Some data with at least 1 dimension.

Return type

Tensor

Returns

The distance.

class ecgan.utils.distances.MinkowskiDistance(order=3, reduction='none')[source]

Bases: ecgan.utils.distances.DistanceMetric

Implementation of the Minkowski distance of two vectors.

p=1: Manhattan Distance, p=2: Euclidean distance. Default is p=3.

calculate(point_1, point_2)[source]

Calculate the Minkowski distance.

Parameters
  • point_1 (Union[ndarray, Tensor]) -- Coordinates of one point.

  • point_2 (Union[ndarray, Tensor]) -- Coordinate of another point.

Return type

Tensor

Returns

The Minkowski distance of point_1 and point_2.

class ecgan.utils.distances.L1Distance(reduction='none')[source]

Bases: ecgan.utils.distances.DistanceMetric

Implementation of the \(L_1\)-distance.

calculate(point_1, point_2)[source]

Return the average \(L_1\) distance per sample in the batch.

The pairwise \(L_1\) distance of any shape - usually \((b \times c \times s)\) or \((b \times c)\) is calculated, reshaped to \((b, -1)\) and returned.

Return type

Tensor

class ecgan.utils.distances.L2Distance(reduction='none')[source]

Bases: ecgan.utils.distances.DistanceMetric

Implementation of the \(L_2\)-distance.

calculate(point_1, point_2)[source]

Return the average \(L_2\) distance per sample in the batch.

The pairwise \(L_2\) distance of any shape - usually \((b \times c \times s)\) or \((b \times c)\) is calculated, reshaped to \((b, -1)\) and returned.

Return type

Tensor

class ecgan.utils.distances.RGANMedianPairwiseDistance[source]

Bases: ecgan.utils.distances.DistanceMetric

Based on the tensorflow implementation from https://github.com/ratschlab/RGAN/blob/master/mmd.py.

Wsed as a heuristic for the RBF bandwidth.

calculate(point_1, point_2)[source]

Calculate the RGAN median pairwise distance.

If y cannot be provided: pass x as y argument.

Return type

Tensor