alibi.explainers.similarity.metrics module

alibi.explainers.similarity.metrics.asym_dot(X, Y, eps=1e-07)[source]

Computes the influence of training instances Y to test instances X. This is an asymmetric kernel. (\(X^T Y/\|Y\|^2\)). See the paper for more details. Each of X and Y should have a leading batch dimension of size at least 1.

Parameters:
  • X (ndarray) – Matrix of vectors.

  • Y (ndarray) – Matrix of vectors.

  • eps (float) – Numerical stability.

Return type:

Union[float, ndarray]

Returns:

Matrix of asymmetric dot product similarity values between the vector(s) in X and vectors in Y.

alibi.explainers.similarity.metrics.cos(X, Y, eps=1e-07)[source]

Computes the cosine between the vector(s) in X and vector Y. (\(X^T Y/\|X\|\|Y\|\)). Each of X and Y should have a leading batch dimension of size at least 1.

Parameters:
  • X (ndarray) – Matrix of vectors.

  • Y (ndarray) – Matrix of vectors.

  • eps (float) – Numerical stability.

Return type:

Union[float, ndarray]

Returns:

Matrix of cosine similarities between the vector(s) in X and vectors in Y.

alibi.explainers.similarity.metrics.dot(X, Y)[source]

Performs a dot product between the vector(s) in X and vector Y. (\(X^T Y = \sum_i X_i Y_i\)). Each of X and Y should have a leading batch dimension of size at least 1.

Parameters:
  • X (ndarray) – Matrix of vectors.

  • Y (ndarray) – Matrix of vectors.

Return type:

Union[float, ndarray]

Returns:

Matrix of dot products between the vector(s) in X and vectors in Y.