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:

## Super class

innsight::InterpretingMethod -> GradientBased

## Public fields

times_input

Multiplies the gradients with the input features. This method is called 'Gradient x Input'.

## Methods

### Public methods

Inherited methods

### Method new()

Create a new instance of this class.

GradientBased$new( converter, data, channels_first = TRUE, output_idx = NULL, ignore_last_act = TRUE, times_input = TRUE, dtype = "float" ) #### Arguments converter The converter of class Converter with the stored and torch-converted model. data The given data in an array-like format to be interpreted with the selected gradient-based method. channels_first The format of the given date, i.e. channels on last dimension (FALSE) or after the batch dimension (TRUE). If the data has no channels, use the default value TRUE. output_idx This vector determines for which outputs the method will be applied. By default (NULL), all outputs (but limited to the first 10) are considered. ignore_last_act Set this boolean value to include the last activation, or not (default: TRUE). In some cases, the last activation leads to a saturation problem. times_input Multiplies the gradients with the input features. This method is called 'Gradient x Input'. dtype The data type for the calculations. Use either 'float' for torch::torch_float or 'double' for torch::torch_double. ### Method plot() This method visualizes the result of the selected method in a ggplot2::ggplot. You can use the argument data_idx to select the data points in the given data for the plot. In addition, the individual output nodes for the plot can be selected with the argument output_idx. The different results for the selected data points and outputs are visualized using the method ggplot2::facet_grid. You can also use the as_plotly argument to generate an interactive plot based on the plot function plotly::plot_ly. #### Usage GradientBased$plot(
data_idx = 1,
output_idx = NULL,
aggr_channels = "sum",
as_plotly = FALSE
)

#### Arguments

data_idx

An integer vector containing the numbers of the data points whose result is to be plotted, e.g. c(1,3) for the first and third data point in the given data. Default: c(1).

output_idx

An integer vector containing the numbers of the output indices whose result is to be plotted, e.g. c(1,4) for the first and fourth model output. But this vector must be included in the vector output_idx from the initialization, otherwise, no results were calculated for this output node and can not be plotted. By default (NULL), the smallest index of all calculated output nodes is used.

aggr_channels

Pass one of 'norm', 'sum', 'mean' or a custom function to aggregate the channels, e.g. the maximum (base::max) or minimum (base::min) over the channels or only individual channels with function(x) x[1]. By default ('sum'), the sum of all channels is used.
Note: This argument is used only for 2D and 3D inputs.

as_plotly

This boolean value (default: FALSE) can be used to create an interactive plot based on the library plotly. This function takes use of plotly::ggplotly, hence make sure that the suggested package plotly is installed in your R session.
Advanced: You can first output the results as a ggplot (as_plotly = FALSE) and then make custom changes to the plot, e.g. other theme or other fill color. Then you can manually call the function ggplotly to get an interactive plotly plot.

#### Returns

Returns either a ggplot2::ggplot (as_plotly = FALSE) or a plotly::plot_ly (as_plotly = TRUE) with the plotted results.

### Method boxplot()

This function visualizes the results of this method in a boxplot, where the type of visualization depends on the input dimension of the data. By default a ggplot2::ggplot is returned, but with the argument as_plotly an interactive plotly::plot_ly plot can be created, which however requires a successful installation of the package plotly.

#### Arguments

deep

Whether to make a deep clone.