peal.explainers.counterfactual_explainer

The counterfactual explainer of PEAL and the configs of its baselines.

CounterfactualExplainer implements SCE: a counterfactual is searched by optimising a generator latent (or the image itself) with gradients of the predictor - optionally a distilled copy of it - until the target class is reached, while an L1 anchor, a repaint step and an orthogonality penalty keep the edit small and, across attempts, diverse. The same class also dispatches to the re-implemented baselines (ACE, DiME, FastDiME, TIME, DAE distillation and a perfect-false-counterfactual oracle) through their config classes defined here.

Besides the search, the module clusters the resulting explanations, renders collages, computes the reported sparsity and diversity statistics, and can collect human feedback on the collages through a small Flask GUI.

Functions

flatten_explanations

Give every entry of an explanations dict one row per counterfactual.

Classes

ACEConfig

This class defines the config of a ACE, DiME or FastDiME explainer.

CounterfactualExplainer

This class implements the counterfactual explanation method

DAEdistillConfig

This class defines the config of the SCE explainer.

PerfectFalseCounterfactualConfig

This class defines the config of a PerfectFalseCounterfactualConfig.

SCEConfig

This class defines the config of the SCE explainer.

TIMEConfig

This class defines the config of a ACEConfig.