GradientBased {innsight} | R Documentation |
Super class for gradient-based interpretation methods
Description
Super class for gradient-based interpretation methods. This
class inherits from InterpretingMethod
. It summarizes all implemented
gradient-based methods and provides a private function to calculate the
gradients w.r.t. to the input for given data. Implemented are:
-
Vanilla Gradients and Gradient
\times
Input (Gradient
) -
Integrated Gradients (
IntegratedGradient
) -
SmoothGrad and SmoothGrad
\times
Input (SmoothGrad
) -
ExpectedGradients (
ExpectedGradient
)
Super class
innsight::InterpretingMethod
-> GradientBased
Public fields
times_input
(
logical(1
))
This logical value indicates whether the results were multiplied by the provided input data or not.
Methods
Public methods
Inherited methods
Method new()
Create a new instance of this class. When initialized,
the method is applied to the given data and the results are stored in
the field result
.
Usage
GradientBased$new( converter, data, channels_first = TRUE, output_idx = NULL, output_label = NULL, ignore_last_act = TRUE, times_input = TRUE, verbose = interactive(), dtype = "float" )
Arguments
converter
(
Converter
)
An instance of theConverter
class that includes the torch-converted model and some other model-specific attributes. SeeConverter
for details.data
(
array
,data.frame
,torch_tensor
orlist
)
The data to which the method is to be applied. These must have the same format as the input data of the passed model to the converter object. This means eitheran
array
,data.frame
,torch_tensor
or array-like format of size (batch_size, dim_in), if e.g., the model has only one input layer, ora
list
with the corresponding input data (according to the upper point) for each of the input layers.
channels_first
(
logical(1)
)
The channel position of the given data (argumentdata
). IfTRUE
, the channel axis is placed at the second position between the batch size and the rest of the input axes, e.g.,c(10,3,32,32)
for a batch of ten images with three channels and a height and width of 32 pixels. Otherwise (FALSE
), the channel axis is at the last position, i.e.,c(10,32,32,3)
. If the data has no channel axis, use the default valueTRUE
.output_idx
(
integer
,list
orNULL
)
These indices specify the output nodes for which the method is to be applied. In order to allow models with multiple output layers, there are the following possibilities to select the indices of the output nodes in the individual output layers:An
integer
vector of indices: If the model has only one output layer, the values correspond to the indices of the output nodes, e.g.,c(1,3,4)
for the first, third and fourth output node. If there are multiple output layers, the indices of the output nodes from the first output layer are considered.A
list
ofinteger
vectors of indices: If the method is to be applied to output nodes from different layers, a list can be passed that specifies the desired indices of the output nodes for each output layer. Unwanted output layers have the entryNULL
instead of a vector of indices, e.g.,list(NULL, c(1,3))
for the first and third output node in the second output layer.-
NULL
(default): The method is applied to all output nodes in the first output layer but is limited to the first ten as the calculations become more computationally expensive for more output nodes.
output_label
(
character
,factor
,list
orNULL
)
These values specify the output nodes for which the method is to be applied. Only values that were previously passed with the argumentoutput_names
in theconverter
can be used. In order to allow models with multiple output layers, there are the following possibilities to select the names of the output nodes in the individual output layers:A
character
vector orfactor
of labels: If the model has only one output layer, the values correspond to the labels of the output nodes named in the passedConverter
object, e.g.,c("a", "c", "d")
for the first, third and fourth output node if the output names arec("a", "b", "c", "d")
. If there are multiple output layers, the names of the output nodes from the first output layer are considered.A
list
ofcharactor
/factor
vectors of labels: If the method is to be applied to output nodes from different layers, a list can be passed that specifies the desired labels of the output nodes for each output layer. Unwanted output layers have the entryNULL
instead of a vector of labels, e.g.,list(NULL, c("a", "c"))
for the first and third output node in the second output layer.-
NULL
(default): The method is applied to all output nodes in the first output layer but is limited to the first ten as the calculations become more computationally expensive for more output nodes.
ignore_last_act
(
logical(1)
)
Set this logical value to include the last activation functions for each output layer, or not (default:TRUE
). In practice, the last activation (especially for softmax activation) is often omitted.times_input
(
logical(1
)
Multiplies the gradients with the input features. This method is called Gradient\times
Input.verbose
(
logical(1)
)
This logical argument determines whether a progress bar is displayed for the calculation of the method or not. The default value is the output of the primitive R functioninteractive()
.dtype
(
character(1)
)
The data type for the calculations. Use either'float'
for torch_float or'double'
for torch_double.
Method clone()
The objects of this class are cloneable with this method.
Usage
GradientBased$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.