peal.explainers.counterfactual_explainer.SCEConfig

class peal.explainers.counterfactual_explainer.SCEConfig[source]

Bases: ExplainerConfig

This class defines the config of the SCE explainer.

Methods

Attributes

allow_overlap

Whether to use the diversification tool that forbids changing the same area of the input image again or not.

batch_size

The batch size used for the counterfactual search

data_config

The data config used for the counterfactual search

dilation

The level of dilation for the masking that is used for RePaint.

dist_l1

Regularizing factor that keeps changes between original image and counterfactual sparse.

distilled_predictor

The config for the predictor distillation.

explainer_type

The type of explanation that shall be used.

generator

The generator that shall be used for the counterfactual search

gradient_clipping

The maximum absolute value that gradient update step can change one input variable at once.

gradient_steps

The maximum number of gradients step done for explaining the network

greedy

Whether to only keep the best explanation while counterfactual search or not.

inpaint

The threshold what is RePainted in the preexplanation.

iterationwise_encoding

Whether to encode every iteration again or not.

learning_rate

The learning rate used for finding the counterfactual

mask_momentum

Momentum term that prevents counterfactual search from changing the area that is changed for creating the counterfactual to rapidly.

merge_clusters

The strategy on how to merge clusters when calculating them.

momentum

Momentum term for the optimizer that does the updates of the preexplanations.

num_discretization_steps

The number of discretizations when going into the latent space

optimizer

The optimizer used for searching the counterfactual

orthogonalization_penatly

The strength of the orthogonalization penalty for parallel counterfactuals.

predictor

The path to either the predictor or its config.

predictor_path

The path to the predictor that shall be explained.

replace_with_activation

leakyrelu, leakysoftplus This helps the distilled predictor to be more sensitive and smooth without saturating gradients.

sampling_time_fraction

How deep to go into the latent space for the counterfactual search

stochastic

Whether to use stochastic counterfactual search (e.g. DDPM) or not (e.g. deterministic DDIM).

use_gradient_filtering

Whether to use a generative model to filter the gradients or not.

use_masking

Whether samples in the current search batch are masked after reaching y_target_goal_confidence.

visualize_gradients

Whether to visualize gradients for every step of the counterfactual search or not.

y_target_goal_confidence

The desired target confidence.

explainer_type: str = 'SCEConfig'

The type of explanation that shall be used.

predictor_path: str | None = None

The path to the predictor that shall be explained.

generator: None | GeneratorConfig = None

The generator that shall be used for the counterfactual search

data_config: None | DataConfig = None

The data config used for the counterfactual search

gradient_steps: pydantic.PositiveInt = 50

The maximum number of gradients step done for explaining the network

optimizer: str = 'Adam'

The optimizer used for searching the counterfactual

learning_rate: float = 1.0

The learning rate used for finding the counterfactual

y_target_goal_confidence: None | float = None

The desired target confidence. Consider the tradeoff between minimality and clarity of counterfactual

use_masking: bool = True

Whether samples in the current search batch are masked after reaching y_target_goal_confidence. Otherwise they are continued to be updated until the last surpasses the threshold

dist_l1: float = 0.0

Regularizing factor that keeps changes between original image and counterfactual sparse.

batch_size: int = 1

The batch size used for the counterfactual search

distilled_predictor: None | str | dict = None

The config for the predictor distillation.

predictor: str | None | dict = None

The path to either the predictor or its config.

sampling_time_fraction: float = 0.3

How deep to go into the latent space for the counterfactual search

num_discretization_steps: int = 15

The number of discretizations when going into the latent space

iterationwise_encoding: bool = True

Whether to encode every iteration again or not.

stochastic: None | str = 'fully'

Whether to use stochastic counterfactual search (e.g. DDPM) or not (e.g. deterministic DDIM).

dilation: int = 5

The level of dilation for the masking that is used for RePaint. If it is higher the mask is more coarse. If it is lower the mask is more finegrained.

inpaint: float = 0.0

The threshold what is RePainted in the preexplanation. The repainting back to the original in the preexplanation is done for everything that has changes below 100 * inpaint percent of the maximum change between sample and preexplanation.

replace_with_activation: str = 'leakysoftplus'

leakyrelu, leakysoftplus This helps the distilled predictor to be more sensitive and smooth without saturating gradients.

Type:

The activation function ReLU is replaced with

greedy: bool = False

Whether to only keep the best explanation while counterfactual search or not. While the greedy solution tends to be more stable it has bigger problems with strong local optima.

visualize_gradients: bool = False

Whether to visualize gradients for every step of the counterfactual search or not. Helpful for debugging, but decreases speed and clutters disk.

mask_momentum: float = 0.0

Momentum term that prevents counterfactual search from changing the area that is changed for creating the counterfactual to rapidly.

momentum: float = 0.9

Momentum term for the optimizer that does the updates of the preexplanations.

gradient_clipping: float = 0.05

The maximum absolute value that gradient update step can change one input variable at once.

merge_clusters: str = 'select_best'

The strategy on how to merge clusters when calculating them. E.g. select_best uses the cluster that does the most salient changes, while merge just merges all clusters.

allow_overlap: bool = False

Whether to use the diversification tool that forbids changing the same area of the input image again or not.

use_gradient_filtering: bool = True

Whether to use a generative model to filter the gradients or not.

orthogonalization_penatly: float = 0.0

The strength of the orthogonalization penalty for parallel counterfactuals.