quantus.functions.normalise_func module

This module provides some basic functionality to normalise and denormalise images.

quantus.functions.normalise_func.denormalise(a: ndarray, mean: ndarray, std: ndarray) ndarray
Parameters:
a: np.ndarray

the array to normalise, e.g., an image or an explanation.

mean: np.ndarray

The mean points to sample from, len(mean) = nr_channels.

std: np.ndarray

The standard deviations to sample from, len(mean) = nr_channels.

kwargs: optional

Keyword arguments.

Returns:
np.ndarray

A denormalised array.

quantus.functions.normalise_func.normalise_by_average_second_moment_estimate(a: ndarray, normalise_axes: Sequence[int] | None = None) ndarray

Normalise attributions by dividing the attribution map by the square-root of its average second moment estimate (that is, similar to the standard deviation, but centered around zero instead of the data mean).

This normalisation function does not normalise the attributions into a fixed range. Instead, it ensures that each score in the attribution map has an average squared distance to zero that is equal to one. This is not meant for visualisation purposes, rather it is meant to preserve a quantity that is useful for the comparison of distances between different attribution methods.

References:

1) Binder et al., (2022): “Shortcomings of Top-Down Randomization-Based Sanity Checks for Evaluations of Deep Neural Network Explanations.” arXiv: https://arxiv.org/abs/2211.12486.

Parameters:
a: np.ndarray

the array to normalise, e.g., an image or an explanation.

normalise_axes: optional, sequence

the axes to normalise over.

kwargs: optional

Keyword arguments.

Returns:
a: np.ndarray

a normalised array.

quantus.functions.normalise_func.normalise_by_max(a: ndarray, normalise_axes: Sequence[int] | None = None) ndarray

Normalise attributions by the maximum absolute value of the explanation.

Parameters:
a: np.ndarray

the array to normalise, e.g., an image or an explanation.

normalise_axes: optional, sequence

the axes to normalise over.

kwargs: optional

Keyword arguments.

Returns:
a: np.ndarray

a normalised array.

quantus.functions.normalise_func.normalise_by_negative(a: ndarray, normalise_axes: Sequence[int] | None = None) ndarray

Normalise attributions between [-1, 1].

Parameters:
a: np.ndarray

the array to normalise, e.g., an image or an explanation.

normalise_axes: optional, sequence

the axes to normalise over.

kwargs: optional

Keyword arguments.

Returns:
a: np.ndarray

a normalised array.