Quantities of Interest¶
trulens.nn.quantities
¶
A Quantity of Interest (QoI) is a function of the output that determines the network output behavior that the attributions describe.
The quantity of interest lets us specify what we want to explain. Often, this is the output of the network corresponding to a particular class, addressing, e.g., "Why did the model classify a given image as a car?" However, we could also consider various combinations of outputs, allowing us to ask more specific questions, such as, "Why did the model classify a given image as a sedan and not a convertible?" The former may highlight general “car features,” such as tires, while the latter (called a comparative explanation) might focus on the roof of the car, a “car feature” not shared by convertibles.
Classes¶
QoiCutSupportError
¶
Bases: ValueError
Exception raised if the quantity of interest is called on a cut whose output is not supported by the quantity of interest.
QoI
¶
Bases: ABC
Interface for quantities of interest. The Quantity of Interest (QoI) is a function of the output specified by the slice that determines the network output behavior that the attributions describe.
Functions¶
__call__
abstractmethod
¶
__call__(y: OM[Outputs, Tensor]) -> OM[Outputs, Tensor]
Computes the distribution of interest from an initial point.
PARAMETER | DESCRIPTION |
---|---|
y |
Output point from which the quantity is derived. Must be a differentiable tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OM[Outputs, Tensor]
|
A differentiable batched scalar tensor representing the QoI. |
MaxClassQoI
¶
Bases: QoI
Quantity of interest for attributing output towards the maximum-predicted class.
Functions¶
__init__
¶
PARAMETER | DESCRIPTION |
---|---|
axis |
Output dimension over which max operation is taken.
TYPE:
|
activation |
Activation function to be applied to the output before taking
the max. If
If |
InternalChannelQoI
¶
Bases: QoI
Quantity of interest for attributing output towards the output of an internal convolutional layer channel, aggregating using a specified operation.
Also works for non-convolutional dense layers, where the given neuron's activation is returned.
Functions¶
__init__
¶
__init__(channel: Union[int, List[int]], channel_axis: Optional[int] = None, agg_fn: Optional[Callable] = None)
PARAMETER | DESCRIPTION |
---|---|
channel |
Channel to return. If a list is provided, then the quantity sums over each of the channels in the list. |
channel_axis |
Channel dimension index, if relevant, e.g., for 2D convolutional
layers. If |
agg_fn |
Function with which to aggregate the remaining dimensions
(except the batch dimension) in order to get a single scalar
value for each channel. If |
ClassQoI
¶
ComparativeQoI
¶
LambdaQoI
¶
Bases: QoI
Generic quantity of interest allowing the user to specify a function of the model's output as the QoI.
ThresholdQoI
¶
Bases: QoI
Quantity of interest for attributing network output toward the difference between two regions seperated by a given threshold. I.e., the quantity of interest is the "high" elements minus the "low" elements, where the high elements have activations above the threshold and the low elements have activations below the threshold.
Use case: bianry segmentation.
Functions¶
__init__
¶
__init__(threshold: float, low_minus_high: bool = False, activation: Union[Callable, str, None] = None)
PARAMETER | DESCRIPTION |
---|---|
threshold |
A threshold to determine the element-wise sign of the input
tensor. The elements with activations higher than the threshold
will retain their sign, while the elements with activations
lower than the threshold will have their sign flipped (or vice
versa if
TYPE:
|
low_minus_high |
If
TYPE:
|
activation |
str or function, optional
Activation function to be applied to the quantity before taking
the threshold. If |