quantus.functions.similarity_func module
This module holds a collection of similarity functions i.e., ways to measure the distance between two inputs (or explanations).
- quantus.functions.similarity_func.abs_difference(a: array, b: array, **kwargs) float
Calculate the mean of the absolute differences between two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- kwargs: optional
Keyword arguments.
- Returns:
- float
The similarity score.
- quantus.functions.similarity_func.correlation_kendall_tau(a: array, b: array, batched: bool = False, **kwargs) float | array
Calculate Kendall Tau correlation of two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- batched: bool
True if arrays are batched. Arrays are expected to be 2D (B x F), where B is batch size and F is the number of features
- kwargs: optional
Keyword arguments.
- Returns:
- Union[float, np.array]
The similarity score or a batch of similarity scores.
- quantus.functions.similarity_func.correlation_pearson(a: array, b: array, batched: bool = False, **kwargs) float | array
Calculate Pearson correlation of two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- batched: bool
True if arrays are batched. Arrays are expected to be 2D (B x F), where B is batch size and F is the number of features
- kwargs: optional
Keyword arguments.
- Returns:
- Union[float, np.array]
The similarity score or a batch of similarity scores.
- quantus.functions.similarity_func.correlation_spearman(a: array, b: array, batched: bool = False, **kwargs) float | array
Calculate Spearman rank of two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- batched: bool
True if arrays are batched. Arrays are expected to be 2D (B x F), where B is batch size and F is the number of features
- kwargs: optional
Keyword arguments.
- Returns:
- Union[float, np.array]
The similarity score or a batch of similarity scores.
- quantus.functions.similarity_func.cosine(a: array, b: array, **kwargs) float
Calculate Cosine of two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- kwargs: optional
Keyword arguments.
- Returns:
- float
The similarity score.
- quantus.functions.similarity_func.difference(a: array, b: array, **kwargs) array
Calculate the difference between two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- kwargs: optional
Keyword arguments.
- Returns:
- np.array
The difference in each element.
- quantus.functions.similarity_func.distance_chebyshev(a: array, b: array, **kwargs) float
Calculate Chebyshev distance of two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- kwargs: optional
Keyword arguments.
- Returns:
- float
The similarity score.
- quantus.functions.similarity_func.distance_euclidean(a: array, b: array, **kwargs) float | array
Calculate Euclidean distance of two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- kwargs: optional
Keyword arguments.
- Returns:
- Union[float, np.array]
The similarity score or a batch of similarity scores.
- quantus.functions.similarity_func.distance_manhattan(a: array, b: array, **kwargs) float | array
Calculate Manhattan distance of two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- kwargs: optional
Keyword arguments.
- Returns:
- Union[float, np.array]
The similarity score or a batch of similarity scores.
- quantus.functions.similarity_func.lipschitz_constant(a: array, b: array, c: array | None, d: array | None, **kwargs) float
Calculate non-negative local Lipschitz abs(||a-b||/||c-d||), where a,b can be f(x) or a(x) and c,d is x.
For numerical stability, a small value is added to division.
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- c: np.ndarray
The third array to use for similarity scoring.
- d: np.ndarray
The fourth array to use for similarity scoring.
- kwargs: optional
Keyword arguments.
- Returns:
- float
The similarity score.
- quantus.functions.similarity_func.squared_difference(a: array, b: array, **kwargs) float
Calculate the sqaured differences between two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- kwargs: optional
Keyword arguments.
- Returns:
- float
The similarity score.
- quantus.functions.similarity_func.ssim(a: array, b: array, batched: bool = False, **kwargs) float | List[float]
Calculate Structural Similarity Index Measure of two images (or explanations).
- Parameters:
- a: np.ndarray
The first array to use for similarity scoring.
- b: np.ndarray
The second array to use for similarity scoring.
- batched: bool
Whether the arrays are batched.
- kwargs: optional
Keyword arguments.
- Returns:
- Union[float, List[float]]
The similarity score, returns a list if batched.