- aoclda.metrics.pairwise_distances(X, Y=None, metric='euclidean', p=2.0, force_all_finite='allow_infinite')#
Pairwise distance metrics.
- Parameters:
X (array-like) – The feature matrix for which the distance matrix needs to be computed. Its shape is (n_samples_X, n_features).
Y (array-like, 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’, ‘l2’, ‘sqeuclidean’, ‘manhattan’, ‘l1’, ‘cityblock’, ‘cosine’, ‘minkowski’, ‘euclidean_gemm’, or ‘sqeuclidean_gemm’. Default: ‘euclidean’.
p (float, optional) – The power parameter used for the Minkowski metric. For p = 1.0, this defaults to ‘manhattan’ metric and for p = 2.0 this defaults to ‘euclidean’ metric. p is only used for Miknowski distance and will be ignored otherwise. Will return an error when p is not positive. Default p = 2.0.
- 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.
-
da_status da_pairwise_distances_s(da_order order, 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, float p, da_metric metric)#
-
da_status da_pairwise_distances_d(da_order order, 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, double p, da_metric metric)#
Compute the distance matrix for an
mbykmatrixXand optionally annbykmatrixY.- Parameters:
order – [in] a da_order enumerated type, specifying whether
X,YandDare stored in row-major order or column-major order.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
XandY.X – [in] the
m\(\times \)kmatrix.ldx – [in] the leading dimension of the matrix
X. Constraint:ldx\(\ge\)miforder=column_major, orldx\(\ge\)kiforder=row_major.Y – [in] the
n\(\times \)kmatrix.ldy – [in] the leading dimension of the matrix
Y. Constraint:ldy\(\ge\)niforder=column_major, orldy\(\ge\)kiforder=row_major.D – [out] if Y is nullptr, the
m\(\times \)mdistance matrix, and them\(\times \)ndistance matrix, otherwise.ldd – [in] the leading dimension of the matrix D. Constraint:
ldd\(\ge\)m, ifYis nullptr ororder=column_major, andldd\(\ge\)n, otherwise.p – [in] the order of the Minkowski metric used to compute the distance matrix. For p = 1.0, this defaults to Manhattan metric and for p = 2.0 this defaults to Euclidean metric.
pis only used for Minkowski distance and will be ignored otherwise.metric – [in] enum that specifies the metric to use to compute the distance matrix. The default value is da_euclidean.
- Returns:
da_status. The function returns:
da_status_success - the operation was successfully completed.
da_status_invalid_leading_dimension - one of the constraints on
ldx,ldyorlddwas violated.da_status_invalid_pointer - one of the arrays
XorDis null.da_status_invalid_array_dimension - either
m\(< 1\), ork\(< 1\), orn\(< 1\), whileYis not nullptr.da_status_not_implemented - an option that is currently not implemented was set.
da_status_memory_error - a memory allocation error occurred.
-
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_l2#
Use l2 distance.
-
enumerator da_sqeuclidean#
Use squared euclidean distance.
-
enumerator da_minkowski#
Use Minkowski distance.
-
enumerator da_manhattan#
Use Manhattan distance.
-
enumerator da_l1#
Use l1 distance.
-
enumerator da_cityblock#
Use cityblock distance.
-
enumerator da_cosine#
Use Cosine distance.
-
enumerator da_euclidean_gemm#
Use gemm-based euclidean distance.
-
enumerator da_sqeuclidean_gemm#
Use gemm-based squared euclidean distance.
-
enumerator da_euclidean#
-
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.
-
enumerator da_all_finite#