Distance Metrics APIs#

aoclda.metrics.pairwise_distances(X, Y=None, metric='euclidean', force_all_finite='allow_infinite')#

Pairwise distance metrics.

Parameters
  • X (numpy.ndarray) – The feature matrix for which the distance matrix needs to be computed. Its shape is (n_samples_X, n_features).

  • Y (numpy.ndarray, optional) – The optional second feature matrix for which the distance matrix needs to be computed. Its shape is (n_samples_Y, n_features).

  • metric (str, optional) – The type of metric used to compute the distance matrix. It can take the values ‘euclidean’ or ‘sqeuclidean’. Default: ‘euclidean’.

  • force_all_finite (str, optional) – Denotes whether infinite values are allowed in input data. Placeholder for adding options in the future.

Returns

numpy.ndarray with shape (n_samples_X, n_samples_Y) if Y is provided, or shape (n_samples_X, n_samples_X), if Y is None and the distance matrix for the rows of X is required.

typedef enum da_metric_ da_metric#

Alias for the da_metric_ enum.

enum da_metric_#

Defines the metric used when calculating the pairwise distances.

Values:

enumerator da_euclidean#

Use euclidean distance.

enumerator da_sqeuclidean#

Use squared euclidean distance.

enumerator da_minkowski#

Use Minkowski distance (used internally only).

enumerator da_manhattan#

Use Manhattan distance (used internally only).

typedef enum da_data_types_ da_data_types#

Alias for the da_data_types_ enum.

enum da_data_types_#

Defines the type of data that is allowed as inputs when pairwise distances are computed.

Values:

enumerator da_all_finite#

Force all values to be finite.

enumerator da_allow_infinite#

Allow infinite and NaN values in input data.

enumerator da_allow_NaN#

Allow NaN values in input data.

da_status da_pairwise_distances_s(da_int m, da_int n, da_int k, const float *X, da_int ldx, const float *Y, da_int ldy, float *D, da_int ldd, da_metric metric, da_data_types force_all_finite)#
da_status da_pairwise_distances_d(da_int m, da_int n, da_int k, const double *X, da_int ldx, const double *Y, da_int ldy, double *D, da_int ldd, da_metric metric, da_data_types force_all_finite)#

Compute the distance matrix for an m by k matrix X and optionally an n by k matrix Y (both in column major order).

Parameters
  • m – [in] the number of rows of matrix X.

  • n – [in] the number of rows of matrix Y.

  • k – [in] the number of columns of matrices X and Y.

  • X – [in] the m \(\times \) k matrix. Data is expected to be stored in column major order, so that the element in the \(i\)th row and \(j\)th column (indexed from 0, so that \(0 \le i \le\) m \(-1\) and \(0 \le j \le\) k \(-1\)) is stored in the [j \(\times\) ldx + i]th entry of X.

  • ldx – [in] the leading dimension of the matrix X. Constraint: ldx \(\ge\) m.

  • Y – [in] the n \(\times \) k matrix. Data is expected to be stored in column major order, so that the element in the \(i\)th row and \(j\)th column (indexed from 0, so that \(0 \le i \le\) n \(-1\) and \(0 \le j \le\) k \(-1\)) is stored in the [j \(\times\) ldy + i]th entry of Y.

  • ldy – [in] the leading dimension of the matrix Y. Constraint: ldy \(\ge\) n.

  • D – [out] if Y is nullptr, the m \(\times \) m distance matrix, and the m \(\times \) n distance matrix, otherwise. Data is expected to be stored in column major order, so that the element in the \(i\)th row and \(j\)th column (indexed from 0, so that \(0 \le i \le\) m \(-1\) and \(0 \le j \le\) n \(-1\)) is stored in the [j \(\times\) ldd + i]th entry of D.

  • ldd – [in] the leading dimension of the matrix D. Constraint: ldd \(\ge\) m, if Y is nullptr, and ldd \(\ge\) n, otherwise.

  • metric – [in] enum that specifies the metric to use to compute the distance matrix. The default value is da_euclidean.

  • force_all_finite – [in] enum that specifies whether to raise an error on infinite or NaN values.

Returns

da_status. The function returns: