pycvi.dist

Low-level distance functions for (non-) time-series data.

Functions

f_cdist(clusterA, clusterB[, dist_kwargs])

Distances between two (groups of) elements.

f_pdist(cluster[, dist_kwargs])

Pairwise distances within a group of elements.

reduce(dist[, reduction])

Applies a given operation on a distance matrix.

pycvi.dist.reduce(dist: numpy.ndarray, reduction: str | callable = None) float | numpy.ndarray

Applies a given operation on a distance matrix.

reduction available: “sum”, “mean”, “max”, “median”, “min”, “”, None or a callable.

Parameters:
  • dist (np.ndarray,) – A distance matrix, either condensed (if pdist) or not (if cdist).

  • reduction (Union[str, callable], optional) – The type of reduction to apply to the distance matrix, by default None.

Returns:

The result of applying the reduction on the distance matrix.

Return type:

Union[float, np.ndarray]

pycvi.dist.f_pdist(cluster: numpy.ndarray, dist_kwargs: dict = {}) numpy.ndarray

Pairwise distances within a group of elements.

Parameters:
Returns:

The pairwise distance within the cluster (a condensed matrix).

Return type:

np.ndarray

Raises:

ShapeError – Raised if cluster doesn’t have the shape (N, d) or (N, w,     d)

pycvi.dist.f_cdist(clusterA: numpy.ndarray, clusterB: numpy.ndarray, dist_kwargs: dict = {}) numpy.ndarray

Distances between two (groups of) elements.

Parameters:
Returns:

The pairwise distance matrix between the clusters.

Return type:

np.ndarray, shape (NA, NB)

Raises:

ShapeError – Raised if clusterA or clusterB don’t have the shape (N, d) or (N, w, d).