peal.generators.interfaces.EditCapableGenerator

class peal.generators.interfaces.EditCapableGenerator[source]

Bases: Generator

A generator that can search for counterfactuals on its own.

Where an explainer normally drives the search, these generators implement edit() end to end: given a batch of inputs, the predictor and the source/target classes, they return the counterfactuals they found together with the latent differences, the confidences the predictor assigns them and the matching originals. The diffusion autoencoders and the tabular VAE use this to keep the search inside their own latent parameterisation.

Methods

edit

This function edits the input to match the target confidence goal and target classes :param predictor_datasets: :param explainer_config: :param base_path: :param x_in: The input :param target_confidence_goal: The target confidence goal :param source_classes: The source classes :param target_classes: The target classes :param predictor: The predictor according to which the confidence is measured :param pbar: A progress bar :param mode: The mode of the edit.

abstract edit(x_in, target_confidence_goal, source_classes, target_classes, predictor, explainer_config, predictor_datasets, boolmask_in=None, attempt_number=None, pbar=None, mode='', base_path='')[source]

This function edits the input to match the target confidence goal and target classes :param predictor_datasets: :param explainer_config: :param base_path: :param x_in: The input :param target_confidence_goal: The target confidence goal :param source_classes: The source classes :param target_classes: The target classes :param predictor: The predictor according to which the confidence is measured :param pbar: A progress bar :param mode: The mode of the edit. This is used to determine the edit method

Returns:

List of the counterfactuals list[torch.Tensor]: List of the differences in latent codes. In the simplest case just x_in - x_counterfactual list[torch.Tensor]: List of the achieved target confidences of the counterfactuals list[torch.Tensor]: List of x_in. This is necessary since the counterfactuals might be in a different order

Return type:

list[torch.Tensor]

Parameters:

If not implemented, it will throw a NotImplementedError.